diff --git a/runtime/device/cl_device.cpp b/runtime/device/cl_device.cpp index 00e2947736..381d546ed2 100644 --- a/runtime/device/cl_device.cpp +++ b/runtime/device/cl_device.cpp @@ -49,7 +49,8 @@ unsigned int ClDevice::getSupportedClVersion() const { return device.getSupporte void ClDevice::retainApi() { if (device.isReleasable()) { - platform()->getClDevice(device.getRootDeviceIndex())->incRefInternal(); + auto pPlatform = castToObject(platformId); + pPlatform->getClDevice(device.getRootDeviceIndex())->incRefInternal(); this->incRefApi(); } }; @@ -57,7 +58,8 @@ unique_ptr_if_unused ClDevice::releaseApi() { if (!device.isReleasable()) { return unique_ptr_if_unused(this, false); } - platform()->getClDevice(device.getRootDeviceIndex())->decRefInternal(); + auto pPlatform = castToObject(platformId); + pPlatform->getClDevice(device.getRootDeviceIndex())->decRefInternal(); return this->decRefApi(); } @@ -113,5 +115,4 @@ void ClDeviceVector::toDeviceIDs(std::vector &devIDs) { const std::string &ClDevice::peekCompilerExtensions() const { return compilerExtensions; } - } // namespace NEO diff --git a/unit_tests/device/sub_device_tests.cpp b/unit_tests/device/sub_device_tests.cpp index 2d10d4a7d0..d6aaf7fb2e 100644 --- a/unit_tests/device/sub_device_tests.cpp +++ b/unit_tests/device/sub_device_tests.cpp @@ -54,25 +54,34 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceRefcountsAreChangedTh DebugManager.flags.CreateMultipleSubDevices.set(2); VariableBackup mockDeviceFlagBackup(&MockDevice::createSingleDevice, false); constructPlatform()->initialize(); - auto device = platform()->getClDevice(0); + auto nonDefaultPlatform = std::make_unique(); + nonDefaultPlatform->initialize(); + auto device = nonDefaultPlatform->getClDevice(0); + auto defaultDevice = platform()->getClDevice(0); auto subDevice = device->getDeviceById(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 + 1, device->getRefInternalCount()); EXPECT_EQ(baseSubDeviceApiRefCount + 1, subDevice->getRefApiCount()); EXPECT_EQ(baseSubDeviceInternalRefCount + 1, 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, givenDeviceWithSubDevicesWhenSubDeviceCreationFailThenWholeDeviceIsDestroyed) {