diff --git a/opencl/source/cl_device/cl_device.cpp b/opencl/source/cl_device/cl_device.cpp index 16f8057781..d7b03e077d 100644 --- a/opencl/source/cl_device/cl_device.cpp +++ b/opencl/source/cl_device/cl_device.cpp @@ -35,23 +35,24 @@ ClDevice::ClDevice(Device &device, ClDevice &rootClDevice, Platform *platform) : compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(deviceInfo.deviceExtensions, emptyOpenClCFeatures); compilerExtensionsWithFeatures = convertEnabledExtensionsToCompilerInternalOptions(deviceInfo.deviceExtensions, deviceInfo.openclCFeatures); - auto numAvailableDevices = device.getNumSubDevices(); - if (numAvailableDevices > 1) { - for (uint32_t i = 0; i < numAvailableDevices; i++) { - auto &coreSubDevice = static_cast(*device.getSubDevice(i)); - auto pClSubDevice = std::make_unique(coreSubDevice, rootClDevice, platform); - pClSubDevice->incRefInternal(); - pClSubDevice->decRefApi(); - - auto &deviceInfo = pClSubDevice->deviceInfo; - deviceInfo.parentDevice = this; - deviceInfo.partitionType[0] = CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN; - deviceInfo.partitionType[1] = CL_DEVICE_AFFINITY_DOMAIN_NUMA; - deviceInfo.partitionType[2] = 0; - - subDevices.push_back(std::move(pClSubDevice)); + for (auto &subDevice : device.getSubDevices()) { + if (!subDevice) { + continue; } + + auto pClSubDevice = std::make_unique(*subDevice, rootClDevice, platform); + pClSubDevice->incRefInternal(); + pClSubDevice->decRefApi(); + + auto &deviceInfo = pClSubDevice->deviceInfo; + deviceInfo.parentDevice = this; + deviceInfo.partitionType[0] = CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN; + deviceInfo.partitionType[1] = CL_DEVICE_AFFINITY_DOMAIN_NUMA; + deviceInfo.partitionType[2] = 0; + + subDevices.push_back(std::move(pClSubDevice)); } + if (getSharedDeviceInfo().debuggerActive && getSourceLevelDebugger()) { auto osInterface = device.getRootDeviceEnvironment().osInterface.get(); getSourceLevelDebugger()->notifyNewDevice(osInterface ? osInterface->getDriverModel()->getDeviceHandle() : 0); diff --git a/opencl/test/unit_test/device/sub_device_tests.cpp b/opencl/test/unit_test/device/sub_device_tests.cpp index 9117f7584e..8fff762574 100644 --- a/opencl/test/unit_test/device/sub_device_tests.cpp +++ b/opencl/test/unit_test/device/sub_device_tests.cpp @@ -850,6 +850,23 @@ TEST_F(EngineInstancedDeviceTests, givenAffinityMaskForSecondLevelOnSingleTileDe EXPECT_EQ(0u, rootDevice->getNumSubDevices()); } +TEST_F(EngineInstancedDeviceTests, givenAffinityMaskWhenCreatingClSubDevicesThenSkipDisabledDevices) { + constexpr uint32_t genericDevicesCount = 3; + constexpr uint32_t ccsCount = 1; + + DebugManager.flags.ZE_AFFINITY_MASK.set("0.0,0.2"); + + if (!createDevices(genericDevicesCount, ccsCount)) { + GTEST_SKIP(); + } + + auto clRootDevice = std::make_unique(*rootDevice, nullptr); + + ASSERT_EQ(2u, clRootDevice->getNumSubDevices()); + EXPECT_EQ(0b1u, clRootDevice->getSubDevice(0)->getDeviceBitfield().to_ulong()); + EXPECT_EQ(0b100u, clRootDevice->getSubDevice(1)->getDeviceBitfield().to_ulong()); +} + HWTEST2_F(EngineInstancedDeviceTests, givenEngineInstancedDeviceWhenProgrammingCfeStateThenSetSingleSliceDispatch, IsAtLeastXeHpCore) { using CFE_STATE = typename FamilyType::CFE_STATE; diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 64f04e742c..e7c0b04714 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -125,6 +125,7 @@ class Device : public ReferenceTrackedObject { void initializeRayTracing(); virtual uint64_t getGlobalMemorySize(uint32_t deviceBitfield) const; + const std::vector getSubDevices() const { return subdevices; } protected: Device() = delete;