fix: Taking into account variable ReturnSubDevicesAsApiDevices

Taking into account variable ReturnSubDevicesAsApiDevices
during Retain and Release Device

Related-To: NEO-8161

Signed-off-by: Andrzej Koska <andrzej.koska@intel.com>
This commit is contained in:
Andrzej Koska
2023-08-11 11:00:22 +00:00
committed by Compute-Runtime-Automation
parent 81d037f59b
commit 0a3b135673
5 changed files with 73 additions and 2 deletions

View File

@@ -130,6 +130,24 @@ TEST_F(ClCreateSubDevicesTests, GivenValidInputWhenCreatingSubDevicesThenDeviceA
EXPECT_EQ(2, device->getSubDevice(1)->getRefApiCount());
}
TEST_F(ClCreateSubDevicesTests, GivenValidInputAndReturnSubDevicesAsApiDevicesIsSetWhenCreatingSubDevicesThenDeviceApiReferenceCountIsNotIncreased) {
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(1);
setup(2);
EXPECT_EQ(0, device->getSubDevice(0)->getRefApiCount());
EXPECT_EQ(0, device->getSubDevice(1)->getRefApiCount());
auto retVal = clCreateSubDevices(device.get(), properties, outDevicesCount, outDevices, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(0, device->getSubDevice(0)->getRefApiCount());
EXPECT_EQ(0, device->getSubDevice(1)->getRefApiCount());
retVal = clCreateSubDevices(device.get(), properties, outDevicesCount, outDevices, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(0, device->getSubDevice(0)->getRefApiCount());
EXPECT_EQ(0, device->getSubDevice(1)->getRefApiCount());
}
struct ClCreateSubDevicesDeviceInfoTests : ClCreateSubDevicesTests {
void setup(int numberOfDevices) {
ClCreateSubDevicesTests::setup(numberOfDevices);

View File

@@ -100,6 +100,42 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceApiRefCountsAreChange
EXPECT_EQ(baseDefaultDeviceInternalRefCount, defaultDevice->getRefInternalCount());
}
TEST(SubDevicesTest, givenDeviceWithSubDevicesAndSubDevicesAsDevicesIsSetWhenSubDeviceApiRefCountsAreChangedThenChangeIsNotPropagatedToRootDevice) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(2);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
initPlatform();
platform()->peekExecutionEnvironment()->setExposeSubDevicesAsDevices(1);
auto nonDefaultPlatform = std::make_unique<MockPlatform>(*platform()->peekExecutionEnvironment());
nonDefaultPlatform->initializeWithNewDevices();
auto device = nonDefaultPlatform->getClDevice(0);
auto defaultDevice = platform()->getClDevice(0);
auto subDevice = device->getSubDevice(1);
auto baseDeviceApiRefCount = device->getRefApiCount();
auto baseDeviceInternalRefCount = device->getRefInternalCount();
auto baseSubDeviceApiRefCount = subDevice->getRefApiCount();
auto baseSubDeviceInternalRefCount = subDevice->getRefInternalCount();
auto baseDefaultDeviceApiRefCount = defaultDevice->getRefApiCount();
auto baseDefaultDeviceInternalRefCount = defaultDevice->getRefInternalCount();
subDevice->retainApi();
EXPECT_EQ(baseDeviceApiRefCount, device->getRefApiCount());
EXPECT_EQ(baseDeviceInternalRefCount, device->getRefInternalCount());
EXPECT_EQ(baseSubDeviceApiRefCount, subDevice->getRefApiCount());
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
EXPECT_EQ(baseDefaultDeviceApiRefCount, defaultDevice->getRefApiCount());
EXPECT_EQ(baseDefaultDeviceInternalRefCount, defaultDevice->getRefInternalCount());
subDevice->releaseApi();
EXPECT_EQ(baseDeviceApiRefCount, device->getRefApiCount());
EXPECT_EQ(baseDeviceInternalRefCount, device->getRefInternalCount());
EXPECT_EQ(baseSubDeviceApiRefCount, subDevice->getRefApiCount());
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
EXPECT_EQ(baseDefaultDeviceApiRefCount, defaultDevice->getRefApiCount());
EXPECT_EQ(baseDefaultDeviceInternalRefCount, defaultDevice->getRefInternalCount());
}
TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAreChangedThenChangeIsPropagatedToRootDevice) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(2);