diff --git a/runtime/command_stream/create_command_stream_impl.cpp b/runtime/command_stream/create_command_stream_impl.cpp index 730c708cbb..798185e26c 100644 --- a/runtime/command_stream/create_command_stream_impl.cpp +++ b/runtime/command_stream/create_command_stream_impl.cpp @@ -97,8 +97,6 @@ bool getDevicesImpl(HardwareInfo **hwInfo, size_t &numDevicesReturned) { } result = DeviceFactory::getDevices(hwInfo, numDevicesReturned); DEBUG_BREAK_IF(result && (hwInfo == nullptr)); - // For now only one device should be present - DEBUG_BREAK_IF(result && (numDevicesReturned != 1)); return result; } diff --git a/runtime/os_interface/DebugVariables.inl b/runtime/os_interface/DebugVariables.inl index e4ad3d318c..aeb7e9b2d5 100644 --- a/runtime/os_interface/DebugVariables.inl +++ b/runtime/os_interface/DebugVariables.inl @@ -88,6 +88,7 @@ DECLARE_DEBUG_VARIABLE(bool, EnableForcePin, true, "Enables early pinning for me DECLARE_DEBUG_VARIABLE(bool, EnableComputeWorkSizeND, true, "Enables diffrent algorithm to compute local work size") DECLARE_DEBUG_VARIABLE(bool, EnableComputeWorkSizeSquared, false, "Enables algorithm to compute the most squared work group as possible") DECLARE_DEBUG_VARIABLE(bool, EnableVaLibCalls, true, "Enable cl-va sharing lib calls") +DECLARE_DEBUG_VARIABLE(int32_t, CreateMultipleDevices, 0, "0: default - disable, 1+: Driver will create multiple (N) devices during initialization.") DECLARE_DEBUG_VARIABLE(int32_t, Enable64kbpages, -1, "-1: default behaviour, 0 Disables, 1 Enables support for 64KB pages for driver allocated fine grain svm buffers") DECLARE_DEBUG_VARIABLE(int32_t, OverrideEnableKmdNotify, -1, "-1: dont override, 0: disable, 1: enable") DECLARE_DEBUG_VARIABLE(int32_t, OverrideKmdNotifyDelayMicroseconds, -1, "-1: dont override, 0: infinite timeout, >0: timeout in microseconds") diff --git a/runtime/os_interface/linux/device_factory.cpp b/runtime/os_interface/linux/device_factory.cpp index 483854864a..c6f30f4832 100644 --- a/runtime/os_interface/linux/device_factory.cpp +++ b/runtime/os_interface/linux/device_factory.cpp @@ -41,29 +41,30 @@ HardwareInfo *DeviceFactory::hwInfos = nullptr; bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices) { std::vector tHwInfos; unsigned int devNum = 0; - Drm *drm = nullptr; + size_t requiredDeviceCount = 1; + + if (DebugManager.flags.CreateMultipleDevices.get()) { + requiredDeviceCount = DebugManager.flags.CreateMultipleDevices.get(); + } + + Drm *drm = Drm::create(devNum); + if (!drm) { + return false; + } std::unique_ptr osInterface = std::unique_ptr(new OSInterface()); + osInterface.get()->get()->setDrm(drm); + const HardwareInfo *pCurrDevice = platformDevices[devNum]; - while ((drm = Drm::create(devNum)) != nullptr) { - const HardwareInfo *pCurrDevice = platformDevices[devNum]; - + while (devNum < requiredDeviceCount) { HardwareInfo tmpHwInfo; - - osInterface.get()->get()->setDrm(drm); - HwInfoConfig *hwConfig = HwInfoConfig::get(pCurrDevice->pPlatform->eProductFamily); if (hwConfig->configureHwInfo(pCurrDevice, &tmpHwInfo, osInterface.get())) { return false; } tHwInfos.push_back(tmpHwInfo); - devNum++; - break; } - if (devNum < 1) - return false; - HardwareInfo *ptr = new HardwareInfo[devNum]; for (size_t i = 0; i < tHwInfos.size(); i++) ptr[i] = tHwInfos[i]; diff --git a/runtime/os_interface/windows/device_factory.cpp b/runtime/os_interface/windows/device_factory.cpp index ca7bfad648..f556062aa5 100644 --- a/runtime/os_interface/windows/device_factory.cpp +++ b/runtime/os_interface/windows/device_factory.cpp @@ -23,6 +23,7 @@ #ifdef _WIN32 #include "runtime/device/device.h" +#include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/device_factory.h" #include "runtime/os_interface/hw_info_config.h" #include "runtime/os_interface/windows/os_interface.h" @@ -36,29 +37,32 @@ size_t DeviceFactory::numDevices = 0; HardwareInfo *DeviceFactory::hwInfos = nullptr; bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices) { - HardwareInfo *tempHwInfos = new HardwareInfo[1]; - constexpr unsigned int devNum = 0; + auto totalDeviceCount = 1u; + if (DebugManager.flags.CreateMultipleDevices.get()) { + totalDeviceCount = DebugManager.flags.CreateMultipleDevices.get(); + } + std::unique_ptr tempHwInfos(new HardwareInfo[totalDeviceCount]); + std::unique_ptr osInterface = std::unique_ptr(new OSInterface()); + numDevices = 0; - if (Wddm::enumAdapters(devNum, tempHwInfos[devNum])) { - std::unique_ptr osInterface = std::unique_ptr(new OSInterface()); - - HwInfoConfig *hwConfig = HwInfoConfig::get(tempHwInfos->pPlatform->eProductFamily); - if (hwConfig->configureHwInfo(tempHwInfos, tempHwInfos, osInterface.get())) { + while (numDevices < totalDeviceCount) { + if (!Wddm::enumAdapters(tempHwInfos[numDevices])) { return false; } - numDevices = 1; - *pHWInfos = tempHwInfos; - DeviceFactory::numDevices = 1; - DeviceFactory::hwInfos = tempHwInfos; - - return true; - - } else { - delete[] tempHwInfos; - return false; + HwInfoConfig *hwConfig = HwInfoConfig::get(tempHwInfos[numDevices].pPlatform->eProductFamily); + if (hwConfig->configureHwInfo(&tempHwInfos[numDevices], &tempHwInfos[numDevices], osInterface.get())) { + return false; + } + numDevices++; } + + *pHWInfos = tempHwInfos.get(); + DeviceFactory::numDevices = numDevices; + DeviceFactory::hwInfos = tempHwInfos.get(); + tempHwInfos.release(); + return true; } void DeviceFactory::releaseDevices() { diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index 9b836e5ac4..fc94de1f99 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -92,11 +92,7 @@ Wddm::~Wddm() { closeAdapter(); } -bool Wddm::enumAdapters(unsigned int devNum, HardwareInfo &outHardwareInfo) { - if (devNum > 0) { - return false; - } - +bool Wddm::enumAdapters(HardwareInfo &outHardwareInfo) { std::unique_ptr wddm(createWddm(Wddm::pickWddmInterfaceVersion(outHardwareInfo))); UNRECOVERABLE_IF(!wddm.get()); diff --git a/runtime/os_interface/windows/wddm/wddm.h b/runtime/os_interface/windows/wddm/wddm.h index d0b2e63fd4..2af9600335 100644 --- a/runtime/os_interface/windows/wddm/wddm.h +++ b/runtime/os_interface/windows/wddm/wddm.h @@ -65,7 +65,7 @@ class Wddm { static Wddm *createWddm(WddmInterfaceVersion interfaceVersion); static WddmInterfaceVersion pickWddmInterfaceVersion(const HardwareInfo &hwInfo); - static bool enumAdapters(unsigned int devNum, HardwareInfo &outHardwareInfo); + static bool enumAdapters(HardwareInfo &outHardwareInfo); MOCKABLE_VIRTUAL bool evict(D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim); MOCKABLE_VIRTUAL bool makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim); diff --git a/unit_tests/os_interface/device_factory_tests.cpp b/unit_tests/os_interface/device_factory_tests.cpp index 9b7588a847..39da73d961 100644 --- a/unit_tests/os_interface/device_factory_tests.cpp +++ b/unit_tests/os_interface/device_factory_tests.cpp @@ -157,3 +157,26 @@ TEST_F(DeviceFactoryTest, givenPointerToHwInfoWhenGetDevicedCalledThenRequiedSur EXPECT_EQ(hwInfo->pSysInfo->CsrSizeInMb * MemoryConstants::megaByte, hwInfo->capabilityTable.requiredPreemptionSurfaceSize); DeviceFactory::releaseDevices(); } + +TEST_F(DeviceFactoryTest, givenCreateMultipleDevicesDebugFlagWhenGetDevicesIsCalledThenNumberOfReturnedDevicesIsEqualToDebugVariable) { + DebugManagerStateRestore stateRestore; + auto requiredDeviceCount = 2u; + DebugManager.flags.CreateMultipleDevices.set(requiredDeviceCount); + HardwareInfo *hwInfo = nullptr; + size_t numDevices = 0; + bool success = DeviceFactory::getDevices(&hwInfo, numDevices); + ASSERT_NE(nullptr, hwInfo); + + for (auto deviceIndex = 0u; deviceIndex < requiredDeviceCount; deviceIndex++) { + EXPECT_NE(nullptr, hwInfo[deviceIndex].pPlatform); + EXPECT_NE(nullptr, hwInfo[deviceIndex].pSkuTable); + EXPECT_NE(nullptr, hwInfo[deviceIndex].pSysInfo); + EXPECT_NE(nullptr, hwInfo[deviceIndex].pWaTable); + } + + EXPECT_EQ(hwInfo[0].pPlatform->eDisplayCoreFamily, hwInfo[1].pPlatform->eDisplayCoreFamily); + + ASSERT_TRUE(success); + EXPECT_EQ(requiredDeviceCount, numDevices); + DeviceFactory::releaseDevices(); +} diff --git a/unit_tests/os_interface/linux/drm_neo_create.cpp b/unit_tests/os_interface/linux/drm_neo_create.cpp index 885a938388..6ce56d4a7b 100644 --- a/unit_tests/os_interface/linux/drm_neo_create.cpp +++ b/unit_tests/os_interface/linux/drm_neo_create.cpp @@ -80,9 +80,6 @@ Drm *Drm::create(int32_t deviceOrdinal) { } void Drm::closeDevice(int32_t deviceOrdinal) { - // We silently skip deviceOrdinal - EXPECT_EQ(deviceOrdinal, 0); - drmMockStack[drmMockStack.size() - 1]->fd = -1; } } // namespace OCLRT diff --git a/unit_tests/os_interface/windows/hw_info_config_win_tests.cpp b/unit_tests/os_interface/windows/hw_info_config_win_tests.cpp index 1215624e44..ea275db960 100644 --- a/unit_tests/os_interface/windows/hw_info_config_win_tests.cpp +++ b/unit_tests/os_interface/windows/hw_info_config_win_tests.cpp @@ -43,7 +43,7 @@ void HwInfoConfigTestWindows::SetUp() { HwInfoConfigTest::SetUp(); osInterface.reset(new OSInterface()); - Wddm::enumAdapters(0, outHwInfo); + Wddm::enumAdapters(outHwInfo); testHwInfo = outHwInfo; } diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 8b7506600a..043bb96aa4 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -118,7 +118,7 @@ TEST(Wddm20EnumAdaptersTest, expectTrue) { const HardwareInfo hwInfo = *platformDevices[0]; OsLibrary *mockGdiDll = setAdapterInfo(hwInfo.pPlatform, hwInfo.pSysInfo); - bool success = Wddm::enumAdapters(0, outHwInfo); + bool success = Wddm::enumAdapters(outHwInfo); EXPECT_TRUE(success); const HardwareInfo *hwinfo = *platformDevices; @@ -139,7 +139,7 @@ TEST(Wddm20EnumAdaptersTest, givenEmptyHardwareInfoWhenEnumAdapterIsCalledThenCa auto hwInfo = *platformDevices[0]; std::unique_ptr mockGdiDll(setAdapterInfo(hwInfo.pPlatform, hwInfo.pSysInfo)); - bool success = Wddm::enumAdapters(0, outHwInfo); + bool success = Wddm::enumAdapters(outHwInfo); EXPECT_TRUE(success); const HardwareInfo *hwinfo = *platformDevices; @@ -180,7 +180,7 @@ TEST(Wddm20EnumAdaptersTest, givenUnknownPlatformWhenEnumAdapterIsCalledThenFals fSetAdpaterInfo(&platform, hwInfo.pSysInfo); delete ptr; }); - bool ret = Wddm::enumAdapters(0, outHwInfo); + bool ret = Wddm::enumAdapters(outHwInfo); EXPECT_FALSE(ret); EXPECT_EQ(nullptr, outHwInfo.pPlatform); EXPECT_EQ(nullptr, outHwInfo.pSkuTable); @@ -188,13 +188,6 @@ TEST(Wddm20EnumAdaptersTest, givenUnknownPlatformWhenEnumAdapterIsCalledThenFals EXPECT_EQ(nullptr, outHwInfo.pWaTable); } -TEST(Wddm20EnumAdaptersTest, devIdExpectFalse) { - HardwareInfo tempHwInfos; - - bool success = Wddm::enumAdapters(1, tempHwInfos); - EXPECT_FALSE(success); -} - HWTEST_F(Wddm20Tests, context) { EXPECT_TRUE(wddm->getOsDeviceContext() == static_cast(0)); wddm->init(); diff --git a/unit_tests/test_files/igdrcl.config b/unit_tests/test_files/igdrcl.config index 726801da37..69b623049e 100644 --- a/unit_tests/test_files/igdrcl.config +++ b/unit_tests/test_files/igdrcl.config @@ -74,4 +74,5 @@ AUBDumpToggleCaptureOnOff = 0 AUBDumpFilterKernelName = unk AUBDumpFilterKernelStartIdx = 0 AUBDumpFilterKernelEndIdx = -1 -RebuildPrecompiledKernels = false \ No newline at end of file +RebuildPrecompiledKernels = false +CreateMultipleDevices = 0 \ No newline at end of file