From 3b981331c97a7a9687ad33e7fe6ff1cf3f3655fc Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Tue, 13 Jun 2023 15:19:02 +0000 Subject: [PATCH] fix: correct handling ZE_ENABLE_PCI_ID_DEVICE_ORDER flag - by default ZE_ENABLE_PCI_ID_DEVICE_ORDER is disabled - by default devices are sorted by type (discrete first), then by pci order - when ZE_ENABLE_PCI_ID_DEVICE_ORDER is enabled, devices are sorted by pci id Related-To: LOCI-4520 Signed-off-by: Mateusz Jablonski --- .../linux/test_driver_handle_imp_linux.cpp | 486 ------------------ .../os_interface/device_factory_tests.cpp | 9 +- .../unit_test/windows/os_interface_tests.cpp | 9 +- .../debug_settings/release_variables.inl | 4 +- .../execution_environment/drm/CMakeLists.txt | 4 +- .../drm/execution_environment_drm.cpp | 64 --- .../drm/sort_devices_drm.cpp | 33 ++ .../execution_environment.cpp | 31 ++ .../execution_environment.h | 1 + .../execution_environment/wddm/CMakeLists.txt | 4 +- .../wddm/execution_environment_wddm.cpp | 43 -- .../wddm/sort_devices_wddm.cpp | 19 + shared/source/os_interface/device_factory.cpp | 9 - shared/source/os_interface/linux/drm_neo.cpp | 1 - shared/source/os_interface/linux/drm_neo.h | 6 - .../source/os_interface/windows/wddm/wddm.h | 4 - shared/test/common/libult/linux/drm_mock.h | 1 + shared/test/common/mocks/mock_driver_model.h | 3 +- shared/test/common/test_files/igdrcl.config | 2 +- .../execution_environment/CMakeLists.txt | 2 + .../execution_environment_tests.cpp | 84 +-- .../execution_environment_tests.h | 28 + ...execution_environment_tests_helper_drm.cpp | 23 + ...n_environment_tests_helper_drm_or_wddm.cpp | 21 + ...xecution_environment_tests_helper_wddm.cpp | 21 + .../linux/device_factory_tests_linux.cpp | 34 +- .../os_interface/linux/drm_tests.cpp | 6 +- 27 files changed, 278 insertions(+), 674 deletions(-) delete mode 100644 shared/source/execution_environment/drm/execution_environment_drm.cpp create mode 100644 shared/source/execution_environment/drm/sort_devices_drm.cpp delete mode 100644 shared/source/execution_environment/wddm/execution_environment_wddm.cpp create mode 100644 shared/source/execution_environment/wddm/sort_devices_wddm.cpp create mode 100644 shared/test/unit_test/execution_environment/execution_environment_tests.h create mode 100644 shared/test/unit_test/execution_environment/execution_environment_tests_helper_drm.cpp create mode 100644 shared/test/unit_test/execution_environment/execution_environment_tests_helper_drm_or_wddm.cpp create mode 100644 shared/test/unit_test/execution_environment/execution_environment_tests_helper_wddm.cpp diff --git a/level_zero/core/test/unit_tests/sources/driver/linux/test_driver_handle_imp_linux.cpp b/level_zero/core/test/unit_tests/sources/driver/linux/test_driver_handle_imp_linux.cpp index a5e99754c8..2582fcd4e9 100644 --- a/level_zero/core/test/unit_tests/sources/driver/linux/test_driver_handle_imp_linux.cpp +++ b/level_zero/core/test/unit_tests/sources/driver/linux/test_driver_handle_imp_linux.cpp @@ -13,7 +13,6 @@ #include "shared/source/os_interface/os_interface.h" #include "shared/test/common/libult/linux/drm_mock.h" #include "shared/test/common/mocks/mock_compilers.h" -#include "shared/test/common/mocks/mock_driver_model.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/ult_device_factory.h" #include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h" @@ -31,437 +30,6 @@ extern std::map> directoryFilesMap; namespace L0 { namespace ult { -constexpr int mockFd = 0; - -class TestDriverMockDrm : public Drm { - public: - TestDriverMockDrm(std::string &bdf, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique(mockFd, bdf.c_str()), rootDeviceEnvironment) {} -}; - -class DriverLinuxFixture : public ::testing::Test { - public: - void SetUp() override { - - auto executionEnvironment = new NEO::ExecutionEnvironment(); - executionEnvironment->prepareRootDeviceEnvironments(numRootDevices); - NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo); - } - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique(*executionEnvironment->rootDeviceEnvironments[i], i); - } - deviceFactory = std::make_unique(numRootDevices, numSubDevices, *executionEnvironment); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - devices.push_back(std::unique_ptr(deviceFactory->rootDevices[i])); - } - for (auto i = 0u; i < devices.size(); i++) { - devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique(); - auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get(); - osInterface->setDriverModel(std::make_unique(bdf[i], const_cast(devices[i]->getRootDeviceEnvironment()))); - } - executionEnvironment->sortNeoDevices(); - - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - NEO::DrmMemoryOperationsHandlerBind *drm = static_cast(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get()); - EXPECT_EQ(drm->getRootDeviceIndex(), i); - } - } - void TearDown() override {} - - static constexpr uint32_t numRootDevices = 5u; - static constexpr uint32_t numSubDevices = 2u; - std::vector> devices; - std::string bdf[numRootDevices] = {"0000:03:04.0", "0000:08:02.0", "0000:08:03.1", "0000:10:03.0", "0000:02:01.0"}; - std::string sortedBdf[numRootDevices] = {"0000:02:01.0", "0000:03:04.0", "0000:08:02.0", "0000:08:03.1", "0000:10:03.0"}; - std::unique_ptr deviceFactory; -}; - -class DriverLinuxWithPciOrderTests : public DriverLinuxFixture { - public: - void SetUp() override { - DebugManagerStateRestore restorer; - DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1); - - DriverLinuxFixture::SetUp(); - } - void TearDown() override { - DriverLinuxFixture::TearDown(); - } -}; - -TEST_F(DriverLinuxWithPciOrderTests, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToBusOrderRetrieved) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - - for (uint32_t i = 0; i < numRootDevices; i++) { - auto l0Device = driverHandle->devices[i]; - if (l0Device != nullptr) { - auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as(); - EXPECT_NE(pDrm, nullptr); - EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i])); - } - } - delete driverHandle; -} - -class DriverLinuxWithouthPciOrderTests : public DriverLinuxFixture { - public: - void SetUp() override { - DebugManagerStateRestore restorer; - DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(0); - - DriverLinuxFixture::SetUp(); - } - void TearDown() override { - DriverLinuxFixture::TearDown(); - } -}; - -TEST_F(DriverLinuxWithouthPciOrderTests, GivenNoEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAreNotSorted) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - - for (uint32_t i = 0; i < numRootDevices; i++) { - auto l0Device = driverHandle->devices[i]; - if (l0Device != nullptr) { - auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as(); - EXPECT_NE(pDrm, nullptr); - EXPECT_FALSE(!pDrm->getPciPath().compare(sortedBdf[i])); - } - } - delete driverHandle; -} - -class DriverPciOrderWithSimilarBusLinuxFixture : public ::testing::Test { - public: - void SetUp() override { - DebugManagerStateRestore restorer; - DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1); - - auto executionEnvironment = new NEO::ExecutionEnvironment(); - executionEnvironment->prepareRootDeviceEnvironments(numRootDevices); - NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo); - } - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique(*executionEnvironment->rootDeviceEnvironments[i], i); - } - deviceFactory = std::make_unique(numRootDevices, numSubDevices, *executionEnvironment); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - devices.push_back(std::unique_ptr(deviceFactory->rootDevices[i])); - } - for (auto i = 0u; i < devices.size(); i++) { - devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique(); - auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get(); - osInterface->setDriverModel(std::make_unique(bdf[i], const_cast(devices[i]->getRootDeviceEnvironment()))); - } - executionEnvironment->sortNeoDevices(); - - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - NEO::DrmMemoryOperationsHandlerBind *drm = static_cast(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get()); - EXPECT_EQ(drm->getRootDeviceIndex(), i); - } - } - void TearDown() override {} - - static constexpr uint32_t numRootDevices = 4u; - static constexpr uint32_t numSubDevices = 2u; - std::vector> devices; - std::string bdf[numRootDevices] = {"0000:03:04.0", "0000:03:05.0", "0000:03:06.0", "0000:03:01.0"}; - std::string sortedBdf[numRootDevices] = {"0000:03:01.0", "0000:03:04.0", "0000:03:05.0", "0000:03:06.0"}; - std::unique_ptr deviceFactory; -}; - -TEST_F(DriverPciOrderWithSimilarBusLinuxFixture, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToBusOrderRetrieved) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - - for (uint32_t i = 0; i < numRootDevices; i++) { - auto l0Device = driverHandle->devices[i]; - if (l0Device != nullptr) { - auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as(); - EXPECT_NE(pDrm, nullptr); - EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i])); - } - } - delete driverHandle; -} - -TEST_F(DriverPciOrderWithSimilarBusLinuxFixture, - GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesAndThenInitializingVertexesThenNeoDevicesAccordingToBusOrderRetrieved) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - - driverHandle->initializeVertexes(); - - for (uint32_t i = 0; i < numRootDevices; i++) { - auto l0Device = driverHandle->devices[i]; - if (l0Device != nullptr) { - auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as(); - EXPECT_NE(pDrm, nullptr); - EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i])); - } - } - delete driverHandle; -} - -class DriverPciOrderWithDifferentDeviceLinuxFixture : public ::testing::Test { - public: - void SetUp() override { - DebugManagerStateRestore restorer; - DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1); - - auto executionEnvironment = new NEO::ExecutionEnvironment(); - executionEnvironment->prepareRootDeviceEnvironments(numRootDevices); - NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo); - } - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique(*executionEnvironment->rootDeviceEnvironments[i], i); - } - deviceFactory = std::make_unique(numRootDevices, numSubDevices, *executionEnvironment); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - devices.push_back(std::unique_ptr(deviceFactory->rootDevices[i])); - } - for (auto i = 0u; i < devices.size(); i++) { - devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique(); - auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get(); - osInterface->setDriverModel(std::make_unique(bdf[i], const_cast(devices[i]->getRootDeviceEnvironment()))); - } - executionEnvironment->sortNeoDevices(); - - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - NEO::DrmMemoryOperationsHandlerBind *drm = static_cast(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get()); - EXPECT_EQ(drm->getRootDeviceIndex(), i); - } - } - void TearDown() override {} - - static constexpr uint32_t numRootDevices = 2u; - static constexpr uint32_t numSubDevices = 2u; - std::vector> devices; - std::string bdf[numRootDevices] = {"0000:03:05.0", "0000:03:04.0"}; - std::string sortedBdf[numRootDevices] = {"0000:03:04.0", "0000:03:05.0"}; - std::unique_ptr deviceFactory; -}; - -TEST_F(DriverPciOrderWithDifferentDeviceLinuxFixture, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToBusOrderRetrieved) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - - for (uint32_t i = 0; i < numRootDevices; i++) { - auto l0Device = driverHandle->devices[i]; - if (l0Device != nullptr) { - auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as(); - EXPECT_NE(pDrm, nullptr); - EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i])); - } - } - delete driverHandle; -} - -TEST_F(DriverPciOrderWithDifferentDeviceLinuxFixture, - GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesAndThenInitializingVertexesThenNeoDevicesAccordingToBusOrderRetrieved) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - - driverHandle->initializeVertexes(); - - for (uint32_t i = 0; i < numRootDevices; i++) { - auto l0Device = driverHandle->devices[i]; - if (l0Device != nullptr) { - auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as(); - EXPECT_NE(pDrm, nullptr); - EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i])); - } - } - delete driverHandle; -} - -class DriverPciOrderWithSimilarBusAndDeviceLinuxFixture : public ::testing::Test { - public: - void SetUp() override { - DebugManagerStateRestore restorer; - DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1); - - auto executionEnvironment = new NEO::ExecutionEnvironment(); - executionEnvironment->prepareRootDeviceEnvironments(numRootDevices); - NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo); - } - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique(*executionEnvironment->rootDeviceEnvironments[i], i); - } - deviceFactory = std::make_unique(numRootDevices, numSubDevices, *executionEnvironment); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - devices.push_back(std::unique_ptr(deviceFactory->rootDevices[i])); - } - for (auto i = 0u; i < devices.size(); i++) { - devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique(); - auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get(); - osInterface->setDriverModel(std::make_unique(bdf[i], const_cast(devices[i]->getRootDeviceEnvironment()))); - } - executionEnvironment->sortNeoDevices(); - - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - NEO::DrmMemoryOperationsHandlerBind *drm = static_cast(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get()); - EXPECT_EQ(drm->getRootDeviceIndex(), i); - } - } - void TearDown() override {} - - static constexpr uint32_t numRootDevices = 2u; - static constexpr uint32_t numSubDevices = 2u; - std::vector> devices; - std::string bdf[numRootDevices] = {"0000:03:04.1", "0000:03:04.0"}; - std::string sortedBdf[numRootDevices] = {"0000:03:04.0", "0000:03:04.1"}; - std::unique_ptr deviceFactory; -}; - -TEST_F(DriverPciOrderWithSimilarBusAndDeviceLinuxFixture, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToBusOrderRetrieved) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - - for (uint32_t i = 0; i < numRootDevices; i++) { - auto l0Device = driverHandle->devices[i]; - if (l0Device != nullptr) { - auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as(); - EXPECT_NE(pDrm, nullptr); - EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i])); - } - } - delete driverHandle; -} - -class DriverPciOrderWitSimilarBDFLinuxFixture : public ::testing::Test { - public: - void SetUp() override { - DebugManagerStateRestore restorer; - DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1); - - auto executionEnvironment = new NEO::MockExecutionEnvironment(NEO::defaultHwInfo.get(), true, numRootDevices); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique(*executionEnvironment->rootDeviceEnvironments[i], i); - } - deviceFactory = std::make_unique(numRootDevices, numSubDevices, *executionEnvironment); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - devices.push_back(std::unique_ptr(deviceFactory->rootDevices[i])); - } - for (auto i = 0u; i < devices.size(); i++) { - devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique(); - auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get(); - osInterface->setDriverModel(std::make_unique(bdf[i], const_cast(devices[i]->getRootDeviceEnvironment()))); - } - executionEnvironment->sortNeoDevices(); - - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - NEO::DrmMemoryOperationsHandlerBind *drm = static_cast(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get()); - EXPECT_EQ(drm->getRootDeviceIndex(), i); - } - } - void TearDown() override {} - - static constexpr uint32_t numRootDevices = 2u; - static constexpr uint32_t numSubDevices = 2u; - std::vector> devices; - std::string bdf[numRootDevices] = {"0001:03:04.0", "0000:03:04.0"}; - std::string sortedBdf[numRootDevices] = {"0000:03:04.0", "0001:03:04.0"}; - std::unique_ptr deviceFactory; -}; - -TEST_F(DriverPciOrderWitSimilarBDFLinuxFixture, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToDomainOrderRetrieved) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - - for (uint32_t i = 0; i < numRootDevices; i++) { - auto l0Device = driverHandle->devices[i]; - if (l0Device != nullptr) { - auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as(); - EXPECT_NE(pDrm, nullptr); - EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i])); - } - } - delete driverHandle; -} - -class DriverPciOrderSortDoesNothing : public ::testing::Test { - public: - void SetUp() override { - DebugManagerStateRestore restorer; - DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1); - - auto executionEnvironment = new NEO::ExecutionEnvironment(); - executionEnvironment->prepareRootDeviceEnvironments(numRootDevices); - NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo); - } - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique(*executionEnvironment->rootDeviceEnvironments[i], i); - } - deviceFactory = std::make_unique(numRootDevices, numSubDevices, *executionEnvironment); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - devices.push_back(std::unique_ptr(deviceFactory->rootDevices[i])); - } - for (auto i = 0u; i < devices.size(); i++) { - devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique(); - auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get(); - osInterface->setDriverModel(std::make_unique(bdf[i], const_cast(devices[i]->getRootDeviceEnvironment()))); - } - executionEnvironment->sortNeoDevices(); - - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - NEO::DrmMemoryOperationsHandlerBind *drm = static_cast(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get()); - EXPECT_EQ(drm->getRootDeviceIndex(), i); - } - } - void TearDown() override {} - - static constexpr uint32_t numRootDevices = 2u; - static constexpr uint32_t numSubDevices = 2u; - std::vector> devices; - std::string bdf[numRootDevices] = {"0000:03:04.0", "0001:03:04.0"}; - std::string sortedBdf[numRootDevices] = {"0000:03:04.0", "0001:03:04.0"}; - std::unique_ptr deviceFactory; -}; - -TEST_F(DriverPciOrderSortDoesNothing, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetThenVerifyCaseSortDoesNothing) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - - for (uint32_t i = 0; i < numRootDevices; i++) { - auto l0Device = driverHandle->devices[i]; - if (l0Device != nullptr) { - auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as(); - EXPECT_NE(pDrm, nullptr); - EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i])); - } - } - delete driverHandle; -} - class MockIoctlQueryFabricStats : public NEO::IoctlHelperPrelim20 { public: using IoctlHelperPrelim20::IoctlHelperPrelim20; @@ -875,59 +443,5 @@ TEST_F(DriverQueryPeerTestFail, whenQueryingPeerStatsWithFabricAndIoctlFailsThen NEO::directoryFilesMap.clear(); } -class DriverWDDMLinuxFixture : public ::testing::Test { - public: - void SetUp() override { - - executionEnvironment->prepareRootDeviceEnvironments(numRootDevices); - NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo); - } - deviceFactory = std::make_unique(numRootDevices, numSubDevices, *executionEnvironment); - for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { - devices.push_back(std::unique_ptr(deviceFactory->rootDevices[i])); - } - for (auto i = 0u; i < devices.size(); i++) { - devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.reset(new NEO::OSInterface()); - devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::make_unique()); - } - } - void TearDown() override {} - - NEO::ExecutionEnvironment *executionEnvironment = new NEO::ExecutionEnvironment(); - static constexpr uint32_t numRootDevices = 5u; - static constexpr uint32_t numSubDevices = 2u; - std::vector> devices; - std::unique_ptr deviceFactory; -}; - -TEST_F(DriverWDDMLinuxFixture, ClearPciSortFlagToVerifyCodeCoverageOnly) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - DebugManagerStateRestore restorer; - DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(0); - - executionEnvironment->sortNeoDevices(); - - delete driverHandle; -} - -TEST_F(DriverWDDMLinuxFixture, ClearPciSortFlagWithFabricEnumerationToVerifyCodeCoverageOnly) { - - DriverHandleImp *driverHandle = new DriverHandleImp; - EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices))); - - driverHandle->initializeVertexes(); - - DebugManagerStateRestore restorer; - DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(0); - - executionEnvironment->sortNeoDevices(); - - delete driverHandle; -} - } // namespace ult } // namespace L0 diff --git a/opencl/test/unit_test/os_interface/device_factory_tests.cpp b/opencl/test/unit_test/os_interface/device_factory_tests.cpp index f41ed72f2b..fb3e9916e4 100644 --- a/opencl/test/unit_test/os_interface/device_factory_tests.cpp +++ b/opencl/test/unit_test/os_interface/device_factory_tests.cpp @@ -326,7 +326,7 @@ TEST_F(DeviceFactoryTest, givenPrepareDeviceEnvironmentsCallWhenItIsDoneThenOsIn EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0]->osInterface); } -TEST(DeviceFactory, givenCreateMultipleRootDevicesWhenCreateDevicesIsCalledThenVectorReturnedWouldContainFirstDiscreteDevicesThenIntegratedDevices) { +TEST(DeviceFactory, givenCreateMultipleRootDevicesWhenCreateDevicesIsCalledThenVectorReturnedWouldContainDevicesInTheSameOrder) { uint32_t numRootDevices = 8u; NEO::HardwareInfo hwInfo[8]; auto executionEnvironment = new NEO::ExecutionEnvironment(); @@ -345,11 +345,8 @@ TEST(DeviceFactory, givenCreateMultipleRootDevicesWhenCreateDevicesIsCalledThenV executionEnvironment->rootDeviceEnvironments[6]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true; executionEnvironment->rootDeviceEnvironments[7]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = false; auto devices = DeviceFactory::createDevices(*executionEnvironment); - for (auto iterator = 0u; iterator < 3; iterator++) { - EXPECT_FALSE(devices[iterator]->getHardwareInfo().capabilityTable.isIntegratedDevice); // Initial entries would be for discrete devices - } - for (auto iterator = 3u; iterator < 8u; iterator++) { - EXPECT_TRUE(devices[iterator]->getHardwareInfo().capabilityTable.isIntegratedDevice); // Later entries would be for integrated + for (auto iterator = 0u; iterator < 8; iterator++) { + EXPECT_EQ(iterator, devices[iterator]->getRootDeviceIndex()); } } diff --git a/opencl/test/unit_test/windows/os_interface_tests.cpp b/opencl/test/unit_test/windows/os_interface_tests.cpp index 03de21e49b..1b75dd2bf1 100644 --- a/opencl/test/unit_test/windows/os_interface_tests.cpp +++ b/opencl/test/unit_test/windows/os_interface_tests.cpp @@ -36,18 +36,13 @@ TEST(osInterfaceTests, whenOsInterfaceSetupGmmInputArgsThenArgsAreSet) { uint32_t function = 0x56; adapterBDF.Function = function; - auto adapterBDFretrieved = wddm->getAdapterBDF(); - EXPECT_EQ(bus, adapterBDFretrieved.Bus); - EXPECT_EQ(device, adapterBDFretrieved.Device); - EXPECT_EQ(function, adapterBDFretrieved.Function); - GMM_INIT_IN_ARGS gmmInputArgs = {}; - EXPECT_NE(0, memcmp(&wddm->getAdapterBDF(), &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF))); + EXPECT_NE(0, memcmp(&wddm->adapterBDF, &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF))); EXPECT_STRNE(expectedRegistryPath, gmmInputArgs.DeviceRegistryPath); rootDeviceEnvironment.osInterface->getDriverModel()->setGmmInputArgs(&gmmInputArgs); - EXPECT_EQ(0, memcmp(&wddm->getAdapterBDF(), &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF))); + EXPECT_EQ(0, memcmp(&wddm->adapterBDF, &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF))); EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, gmmInputArgs.ClientType); EXPECT_STREQ(expectedRegistryPath, gmmInputArgs.DeviceRegistryPath); } diff --git a/shared/source/debug_settings/release_variables.inl b/shared/source/debug_settings/release_variables.inl index daa84781b9..4e66914872 100644 --- a/shared/source/debug_settings/release_variables.inl +++ b/shared/source/debug_settings/release_variables.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,4 +14,4 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideDefaultFP64Settings, -1, "-1: dont overr DECLARE_DEBUG_VARIABLE(bool, NEO_CAL_ENABLED, false, "Set by the Compute Aggregation Layer.") DECLARE_DEBUG_VARIABLE(std::string, ZE_AFFINITY_MASK, std::string("default"), "Refer to the Level Zero Specification for a description") DECLARE_DEBUG_VARIABLE(std::string, ZEX_NUMBER_OF_CCS, std::string("default"), "Define number of CCS engines per root device, e.g. setting Root Device Index 0 to 4 CCS, and Root Device Index 1 To 1 CCS: ZEX_NUMBER_OF_CCS=0:4,1:1") -DECLARE_DEBUG_VARIABLE(bool, ZE_ENABLE_PCI_ID_DEVICE_ORDER, true, "Refer to the Level Zero Specification for a description") +DECLARE_DEBUG_VARIABLE(bool, ZE_ENABLE_PCI_ID_DEVICE_ORDER, false, "Refer to the Level Zero Specification for a description") diff --git a/shared/source/execution_environment/drm/CMakeLists.txt b/shared/source/execution_environment/drm/CMakeLists.txt index 32d60f5a20..7994b1f562 100644 --- a/shared/source/execution_environment/drm/CMakeLists.txt +++ b/shared/source/execution_environment/drm/CMakeLists.txt @@ -1,12 +1,12 @@ # -# Copyright (C) 2022 Intel Corporation +# Copyright (C) 2022-2023 Intel Corporation # # SPDX-License-Identifier: MIT # set(NEO_CORE_EXECUTION_ENVIRONMENT_DRM ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_drm.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/sort_devices_drm.cpp ) set_property(GLOBAL PROPERTY NEO_CORE_EXECUTION_ENVIRONMENT_DRM ${NEO_CORE_EXECUTION_ENVIRONMENT_DRM}) diff --git a/shared/source/execution_environment/drm/execution_environment_drm.cpp b/shared/source/execution_environment/drm/execution_environment_drm.cpp deleted file mode 100644 index e0486d4958..0000000000 --- a/shared/source/execution_environment/drm/execution_environment_drm.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2021-2022 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/debug_settings/debug_settings_manager.h" -#include "shared/source/execution_environment/execution_environment.h" -#include "shared/source/execution_environment/root_device_environment.h" -#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h" -#include "shared/source/os_interface/linux/drm_neo.h" -#include "shared/source/os_interface/os_interface.h" - -#include - -namespace NEO { - -bool comparePciIdBusNumberDRM(std::unique_ptr &rootDeviceEnvironment1, std::unique_ptr &rootDeviceEnvironment2) { - // BDF sample format is : 00:02.0 - rootDeviceEnvironment1->osInterface->getDriverModel()->as()->queryAdapterBDF(); - auto bdfDevice1 = rootDeviceEnvironment1->osInterface->getDriverModel()->as()->getAdapterBDF(); - auto domain1 = rootDeviceEnvironment1->osInterface->getDriverModel()->as()->getPciDomain(); - - rootDeviceEnvironment2->osInterface->getDriverModel()->as()->queryAdapterBDF(); - auto bdfDevice2 = rootDeviceEnvironment2->osInterface->getDriverModel()->as()->getAdapterBDF(); - auto domain2 = rootDeviceEnvironment2->osInterface->getDriverModel()->as()->getPciDomain(); - - if (domain1 != domain2) { - return (domain1 < domain2); - } - - if (bdfDevice1.Bus != bdfDevice2.Bus) { - return (bdfDevice1.Bus < bdfDevice2.Bus); - } - - if (bdfDevice1.Device != bdfDevice2.Device) { - return (bdfDevice1.Device < bdfDevice2.Device); - } - - return bdfDevice1.Function < bdfDevice2.Function; -} - -void ExecutionEnvironment::sortNeoDevicesDRM() { - const auto pciOrderVar = DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.get(); - if (pciOrderVar) { - std::vector presortIndex; - for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) { - NEO::DrmMemoryOperationsHandler *drm = static_cast(rootDeviceEnvironments[i]->memoryOperationsInterface.get()); - presortIndex.push_back(drm->getRootDeviceIndex()); - } - - std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumberDRM); - - for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) { - NEO::DrmMemoryOperationsHandler *drm = static_cast(rootDeviceEnvironments[i]->memoryOperationsInterface.get()); - if (drm->getRootDeviceIndex() != presortIndex[i]) { - drm->setRootDeviceIndex(presortIndex[i]); - } - } - } -} - -} // namespace NEO diff --git a/shared/source/execution_environment/drm/sort_devices_drm.cpp b/shared/source/execution_environment/drm/sort_devices_drm.cpp new file mode 100644 index 0000000000..29a279064f --- /dev/null +++ b/shared/source/execution_environment/drm/sort_devices_drm.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021-2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/execution_environment.h" +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h" + +#include + +namespace NEO { + +void ExecutionEnvironment::sortNeoDevicesDRM() { + std::vector presortIndex; + for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) { + NEO::DrmMemoryOperationsHandler *drm = static_cast(rootDeviceEnvironments[i]->memoryOperationsInterface.get()); + presortIndex.push_back(drm->getRootDeviceIndex()); + } + + std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber); + + for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) { + NEO::DrmMemoryOperationsHandler *drm = static_cast(rootDeviceEnvironments[i]->memoryOperationsInterface.get()); + if (drm->getRootDeviceIndex() != presortIndex[i]) { + drm->setRootDeviceIndex(presortIndex[i]); + } + } +} + +} // namespace NEO diff --git a/shared/source/execution_environment/execution_environment.cpp b/shared/source/execution_environment/execution_environment.cpp index 8b43ec05f5..33c28d81a0 100644 --- a/shared/source/execution_environment/execution_environment.cpp +++ b/shared/source/execution_environment/execution_environment.cpp @@ -19,6 +19,7 @@ #include "shared/source/helpers/string_helpers.h" #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/memory_manager/os_agnostic_memory_manager.h" +#include "shared/source/os_interface/driver_info.h" #include "shared/source/os_interface/os_environment.h" #include "shared/source/os_interface/os_interface.h" #include "shared/source/os_interface/product_helper.h" @@ -312,4 +313,34 @@ void ExecutionEnvironment::configureNeoEnvironment() { DebugManager.flags.SplitBcsSize.setIfDefault(256); } } + +bool ExecutionEnvironment::comparePciIdBusNumber(std::unique_ptr &rootDeviceEnvironment1, std::unique_ptr &rootDeviceEnvironment2) { + const auto pciOrderVar = DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.get(); + if (!pciOrderVar) { + auto isIntegrated1 = rootDeviceEnvironment1->getHardwareInfo()->capabilityTable.isIntegratedDevice; + auto isIntegrated2 = rootDeviceEnvironment2->getHardwareInfo()->capabilityTable.isIntegratedDevice; + if (isIntegrated1 != isIntegrated2) { + return isIntegrated2; + } + } + + // BDF sample format is : 00:02.0 + auto pciBusInfo1 = rootDeviceEnvironment1->osInterface->getDriverModel()->getPciBusInfo(); + auto pciBusInfo2 = rootDeviceEnvironment2->osInterface->getDriverModel()->getPciBusInfo(); + + if (pciBusInfo1.pciDomain != pciBusInfo2.pciDomain) { + return (pciBusInfo1.pciDomain < pciBusInfo2.pciDomain); + } + + if (pciBusInfo1.pciBus != pciBusInfo2.pciBus) { + return (pciBusInfo1.pciBus < pciBusInfo2.pciBus); + } + + if (pciBusInfo1.pciDevice != pciBusInfo2.pciDevice) { + return (pciBusInfo1.pciDevice < pciBusInfo2.pciDevice); + } + + return (pciBusInfo1.pciFunction < pciBusInfo2.pciFunction); +} + } // namespace NEO diff --git a/shared/source/execution_environment/execution_environment.h b/shared/source/execution_environment/execution_environment.h index e6ab617da0..248253a142 100644 --- a/shared/source/execution_environment/execution_environment.h +++ b/shared/source/execution_environment/execution_environment.h @@ -58,6 +58,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject void releaseRootDeviceEnvironmentResources(RootDeviceEnvironment *rootDeviceEnvironment); protected: + static bool comparePciIdBusNumber(std::unique_ptr &rootDeviceEnvironment1, std::unique_ptr &rootDeviceEnvironment2); void parseCcsCountLimitations(); void adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const; void configureNeoEnvironment(); diff --git a/shared/source/execution_environment/wddm/CMakeLists.txt b/shared/source/execution_environment/wddm/CMakeLists.txt index b2b5185bb7..2c80549a27 100644 --- a/shared/source/execution_environment/wddm/CMakeLists.txt +++ b/shared/source/execution_environment/wddm/CMakeLists.txt @@ -1,12 +1,12 @@ # -# Copyright (C) 2021-2022 Intel Corporation +# Copyright (C) 2021-2023 Intel Corporation # # SPDX-License-Identifier: MIT # set(NEO_CORE_EXECUTION_ENVIRONMENT_WDDM ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_wddm.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/sort_devices_wddm.cpp ) set_property(GLOBAL PROPERTY NEO_CORE_EXECUTION_ENVIRONMENT_WDDM ${NEO_CORE_EXECUTION_ENVIRONMENT_WDDM}) diff --git a/shared/source/execution_environment/wddm/execution_environment_wddm.cpp b/shared/source/execution_environment/wddm/execution_environment_wddm.cpp deleted file mode 100644 index 8b1ba211a9..0000000000 --- a/shared/source/execution_environment/wddm/execution_environment_wddm.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2021-2023 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/debug_settings/debug_settings_manager.h" -#include "shared/source/execution_environment/execution_environment.h" -#include "shared/source/execution_environment/root_device_environment.h" -#include "shared/source/os_interface/os_interface.h" -#include "shared/source/os_interface/windows/wddm/wddm.h" - -#include -#include - -namespace NEO { - -bool comparePciIdBusNumberWDDM(std::unique_ptr &rootDeviceEnvironment1, std::unique_ptr &rootDeviceEnvironment2) { - // BDF sample format is : 00:02.0 - auto bdfDevice1 = rootDeviceEnvironment1->osInterface->getDriverModel()->as()->getAdapterBDF(); - - auto bdfDevice2 = rootDeviceEnvironment2->osInterface->getDriverModel()->as()->getAdapterBDF(); - - if (bdfDevice1.Bus != bdfDevice2.Bus) { - return (bdfDevice1.Bus < bdfDevice2.Bus); - } - - if (bdfDevice1.Device != bdfDevice2.Device) { - return (bdfDevice1.Device < bdfDevice2.Device); - } - - return bdfDevice1.Function < bdfDevice2.Function; -} - -void ExecutionEnvironment::sortNeoDevicesWDDM() { - const auto pciOrderVar = DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.get(); - if (pciOrderVar) { - std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumberWDDM); - } -} - -} // namespace NEO diff --git a/shared/source/execution_environment/wddm/sort_devices_wddm.cpp b/shared/source/execution_environment/wddm/sort_devices_wddm.cpp new file mode 100644 index 0000000000..dbdaa1b34a --- /dev/null +++ b/shared/source/execution_environment/wddm/sort_devices_wddm.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2021-2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/execution_environment.h" +#include "shared/source/execution_environment/root_device_environment.h" + +#include + +namespace NEO { + +void ExecutionEnvironment::sortNeoDevicesWDDM() { + std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber); +} + +} // namespace NEO diff --git a/shared/source/os_interface/device_factory.cpp b/shared/source/os_interface/device_factory.cpp index 8154420f35..71e2d09932 100644 --- a/shared/source/os_interface/device_factory.cpp +++ b/shared/source/os_interface/device_factory.cpp @@ -229,18 +229,9 @@ std::vector> DeviceFactory::createDevices(ExecutionEnvir return devices; } - auto discreteDeviceIndex = 0u; for (uint32_t rootDeviceIndex = 0u; rootDeviceIndex < executionEnvironment.rootDeviceEnvironments.size(); rootDeviceIndex++) { auto device = createRootDeviceFunc(executionEnvironment, rootDeviceIndex); if (device) { - if (device->getHardwareInfo().capabilityTable.isIntegratedDevice == false) { - // If we are here, it means we are processing entry for discrete device. - // And lets first insert discrete device's entry in devices vector. - devices.insert(devices.begin() + discreteDeviceIndex, std::move(device)); - discreteDeviceIndex++; - continue; - } - // Ensure to push integrated device's entry at the end of devices vector devices.push_back(std::move(device)); } } diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 3d3efd6729..1e0d066396 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -786,7 +786,6 @@ int Drm::queryAdapterBDF() { void Drm::setGmmInputArgs(void *args) { auto gmmInArgs = reinterpret_cast(args); - auto adapterBDF = this->getAdapterBDF(); #if defined(__linux__) gmmInArgs->FileDescriptor = adapterBDF.Data; #endif diff --git a/shared/source/os_interface/linux/drm_neo.h b/shared/source/os_interface/linux/drm_neo.h index a97b794f45..65b79b267f 100644 --- a/shared/source/os_interface/linux/drm_neo.h +++ b/shared/source/os_interface/linux/drm_neo.h @@ -103,9 +103,6 @@ class Drm : public DriverModel { MOCKABLE_VIRTUAL void checkPreemptionSupport(); inline int getFileDescriptor() const { return hwDeviceId->getFileDescriptor(); } - ADAPTER_BDF getAdapterBDF() const { - return adapterBDF; - } int queryAdapterBDF(); MOCKABLE_VIRTUAL int createDrmVirtualMemory(uint32_t &drmVmId); void destroyDrmVirtualMemory(uint32_t drmVmId); @@ -247,9 +244,6 @@ class Drm : public DriverModel { pciDomain = domain; } - uint32_t getPciDomain() { - return pciDomain; - } MOCKABLE_VIRTUAL std::vector getMemoryRegions(); MOCKABLE_VIRTUAL bool completionFenceSupport(); diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index ac3358ee3c..62a839152a 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -193,10 +193,6 @@ class Wddm : public DriverModel { static std::vector> discoverDevices(ExecutionEnvironment &executionEnvironment); - ADAPTER_BDF getAdapterBDF() const { - return adapterBDF; - } - PhysicalDevicePciSpeedInfo getPciSpeedInfo() const override; bool buildTopologyMapping(); diff --git a/shared/test/common/libult/linux/drm_mock.h b/shared/test/common/libult/linux/drm_mock.h index 54b7719b3c..160df620cd 100644 --- a/shared/test/common/libult/linux/drm_mock.h +++ b/shared/test/common/libult/linux/drm_mock.h @@ -24,6 +24,7 @@ using namespace NEO; class DrmMock : public Drm { public: + using Drm::adapterBDF; using Drm::bindAvailable; using Drm::cacheInfo; using Drm::checkQueueSliceSupport; diff --git a/shared/test/common/mocks/mock_driver_model.h b/shared/test/common/mocks/mock_driver_model.h index f4723915e2..5437f01f54 100644 --- a/shared/test/common/mocks/mock_driver_model.h +++ b/shared/test/common/mocks/mock_driver_model.h @@ -18,7 +18,8 @@ namespace NEO { class MockDriverModel : public NEO::DriverModel { public: - MockDriverModel() : NEO::DriverModel(NEO::DriverModelType::UNKNOWN) {} + MockDriverModel() : MockDriverModel(NEO::DriverModelType::UNKNOWN) {} + MockDriverModel(DriverModelType driverModelType) : DriverModel(driverModelType) {} void setGmmInputArgs(void *args) override {} diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index 10e0796ece..8282eccfeb 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -11,7 +11,7 @@ OverrideGdiPath = unk AubDumpAddMmioRegistersList = unk ZE_AFFINITY_MASK = default ZEX_NUMBER_OF_CCS = default -ZE_ENABLE_PCI_ID_DEVICE_ORDER = 1 +ZE_ENABLE_PCI_ID_DEVICE_ORDER = 0 NEO_CAL_ENABLED = 0 AUBDumpFilterNamedKernelStartIdx = 0 AUBDumpFilterNamedKernelEndIdx = -1 diff --git a/shared/test/unit_test/execution_environment/CMakeLists.txt b/shared/test/unit_test/execution_environment/CMakeLists.txt index 3a698e5666..c5bd16b994 100644 --- a/shared/test/unit_test/execution_environment/CMakeLists.txt +++ b/shared/test/unit_test/execution_environment/CMakeLists.txt @@ -7,4 +7,6 @@ target_sources(neo_shared_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_tests.h + ${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_tests_helper_${DRIVER_MODEL}.cpp ) diff --git a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp index 8f4b19a551..620a4faf43 100644 --- a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -5,6 +5,8 @@ * */ +#include "shared/test/unit_test/execution_environment/execution_environment_tests.h" + #include "shared/source/aub/aub_center.h" #include "shared/source/built_ins/built_ins.h" #include "shared/source/compiler_interface/compiler_interface.h" @@ -23,6 +25,7 @@ #include "shared/source/source_level_debugger/source_level_debugger.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_driver_model.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/mocks/mock_memory_operations_handler.h" @@ -324,11 +327,11 @@ TEST(ExecutionEnvironment, givenMultipleRootDevicesWhenTheyAreCreatedThenReuseMe EXPECT_EQ(memoryManager, device2->getMemoryManager()); } -uint64_t isDriverAvailableCounter = 0u; +uint32_t isDriverAvailableCounter = 0u; -class DriverModelMock : public DriverModel { +class DefaultDriverModelMock : public MockDriverModel { public: - DriverModelMock(DriverModelType driverModelType) : DriverModel(driverModelType) { + DefaultDriverModelMock(DriverModelType driverModelType) : MockDriverModel(driverModelType) { } bool isDriverAvailable() override { @@ -358,43 +361,12 @@ class DriverModelMock : public DriverModel { } }; -class DefaultDriverModelMock : public DriverModel { - public: - DefaultDriverModelMock(DriverModelType driverModelType) : DriverModel(driverModelType) { - } - - bool isDriverAvailable() override { - return true; - } - void setGmmInputArgs(void *args) override { - } - - uint32_t getDeviceHandle() const override { - return 0; - } - - PhysicalDevicePciBusInfo getPciBusInfo() const override { - return {}; - } - PhysicalDevicePciSpeedInfo getPciSpeedInfo() const override { - return {}; - } - - bool skipResourceCleanup() const { - return skipResourceCleanupVar; - } - - bool isGpuHangDetected(OsContext &osContext) override { - return false; - } -}; - TEST(ExecutionEnvironment, givenRootDeviceWhenPrepareForCleanupThenIsDriverAvailableIsCalled) { - VariableBackup varBackup = &isDriverAvailableCounter; + VariableBackup varBackup{&isDriverAvailableCounter, 0u}; ExecutionEnvironment executionEnvironment{}; std::unique_ptr osInterface = std::make_unique(); - osInterface->setDriverModel(std::make_unique(DriverModelType::UNKNOWN)); + osInterface->setDriverModel(std::make_unique(DriverModelType::UNKNOWN)); executionEnvironment.prepareRootDeviceEnvironments(1); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::move(osInterface); @@ -463,3 +435,43 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenSettingFP64EmulationEnab executionEnvironment.setFP64EmulationEnabled(); EXPECT_TRUE(executionEnvironment.isFP64EmulationEnabled()); } + +void ExecutionEnvironmentSortTests::SetUp() { + executionEnvironment.prepareRootDeviceEnvironments(numRootDevices); + for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + setupOsSpecifcEnvironment(rootDeviceIndex); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = false; + } + executionEnvironment.rootDeviceEnvironments[1]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true; // {0,0,2,0} + executionEnvironment.rootDeviceEnvironments[3]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true; // {0,1,2,1} +} +TEST_F(ExecutionEnvironmentSortTests, givenEnabledPciIdDeviceOrderFlagWhenSortingDevicesThenRootDeviceEnvironmentsAreSortedByPciId) { + DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1); + + NEO::PhysicalDevicePciBusInfo expectedBusInfos[numRootDevices] = {{0, 0, 2, 0}, {0, 0, 2, 1}, {0, 1, 2, 1}, {0, 1, 3, 0}, {3, 1, 2, 0}, {3, 1, 2, 1}}; + + executionEnvironment.sortNeoDevices(); + + for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + auto pciBusInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->getPciBusInfo(); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDomain, pciBusInfo.pciDomain); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciBus, pciBusInfo.pciBus); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDevice, pciBusInfo.pciDevice); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciFunction, pciBusInfo.pciFunction); + } +} + +TEST_F(ExecutionEnvironmentSortTests, givenDisabledPciIdDeviceOrderFlagWhenSortingDevicesThenRootDeviceEnvironmentsAreSortedByTypeThenByPciOrder) { + DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(0); + NEO::PhysicalDevicePciBusInfo expectedBusInfos[numRootDevices] = {{0, 0, 2, 1}, {0, 1, 3, 0}, {3, 1, 2, 0}, {3, 1, 2, 1}, {0, 0, 2, 0}, {0, 1, 2, 1}}; + + executionEnvironment.sortNeoDevices(); + + for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + auto pciBusInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->getPciBusInfo(); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDomain, pciBusInfo.pciDomain); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciBus, pciBusInfo.pciBus); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDevice, pciBusInfo.pciDevice); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciFunction, pciBusInfo.pciFunction); + } +} diff --git a/shared/test/unit_test/execution_environment/execution_environment_tests.h b/shared/test/unit_test/execution_environment/execution_environment_tests.h new file mode 100644 index 0000000000..3fefdb6fe2 --- /dev/null +++ b/shared/test/unit_test/execution_environment/execution_environment_tests.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/execution_environment/execution_environment.h" +#include "shared/source/os_interface/driver_info.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/test_macros/test.h" + +namespace NEO { + +class ExecutionEnvironmentSortTests : public ::testing::Test { + public: + void SetUp() override; + + void setupOsSpecifcEnvironment(uint32_t rootDeviceIndex); + + DebugManagerStateRestore restorer; + ExecutionEnvironment executionEnvironment{}; + static const auto numRootDevices = 6; + NEO::PhysicalDevicePciBusInfo inputBusInfos[numRootDevices] = {{3, 1, 2, 1}, {0, 0, 2, 0}, {0, 1, 3, 0}, {0, 1, 2, 1}, {0, 0, 2, 1}, {3, 1, 2, 0}}; +}; +} // namespace NEO diff --git a/shared/test/unit_test/execution_environment/execution_environment_tests_helper_drm.cpp b/shared/test/unit_test/execution_environment/execution_environment_tests_helper_drm.cpp new file mode 100644 index 0000000000..bb6787daae --- /dev/null +++ b/shared/test/unit_test/execution_environment/execution_environment_tests_helper_drm.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h" +#include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/unit_test/execution_environment/execution_environment_tests.h" + +using namespace NEO; + +void ExecutionEnvironmentSortTests::setupOsSpecifcEnvironment(uint32_t rootDeviceIndex) { + auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]; + auto osInterface = std::make_unique(); + auto driverModel = std::make_unique(DriverModelType::DRM); + driverModel->pciBusInfo = inputBusInfos[rootDeviceIndex]; + osInterface->setDriverModel(std::move(driverModel)); + rootDeviceEnvironment.osInterface = std::move(osInterface); + rootDeviceEnvironment.memoryOperationsInterface = std::make_unique(rootDeviceEnvironment, rootDeviceIndex); +} diff --git a/shared/test/unit_test/execution_environment/execution_environment_tests_helper_drm_or_wddm.cpp b/shared/test/unit_test/execution_environment/execution_environment_tests_helper_drm_or_wddm.cpp new file mode 100644 index 0000000000..d38df62709 --- /dev/null +++ b/shared/test/unit_test/execution_environment/execution_environment_tests_helper_drm_or_wddm.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/unit_test/execution_environment/execution_environment_tests.h" + +using namespace NEO; + +void ExecutionEnvironmentSortTests::setupOsSpecifcEnvironment(uint32_t rootDeviceIndex) { + auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]; + auto osInterface = std::make_unique(); + auto driverModel = std::make_unique(DriverModelType::WDDM); + driverModel->pciBusInfo = inputBusInfos[rootDeviceIndex]; + osInterface->setDriverModel(std::move(driverModel)); + rootDeviceEnvironment.osInterface = std::move(osInterface); +} diff --git a/shared/test/unit_test/execution_environment/execution_environment_tests_helper_wddm.cpp b/shared/test/unit_test/execution_environment/execution_environment_tests_helper_wddm.cpp new file mode 100644 index 0000000000..d38df62709 --- /dev/null +++ b/shared/test/unit_test/execution_environment/execution_environment_tests_helper_wddm.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/unit_test/execution_environment/execution_environment_tests.h" + +using namespace NEO; + +void ExecutionEnvironmentSortTests::setupOsSpecifcEnvironment(uint32_t rootDeviceIndex) { + auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]; + auto osInterface = std::make_unique(); + auto driverModel = std::make_unique(DriverModelType::WDDM); + driverModel->pciBusInfo = inputBusInfos[rootDeviceIndex]; + osInterface->setDriverModel(std::move(driverModel)); + rootDeviceEnvironment.osInterface = std::move(osInterface); +} diff --git a/shared/test/unit_test/os_interface/linux/device_factory_tests_linux.cpp b/shared/test/unit_test/os_interface/linux/device_factory_tests_linux.cpp index 4b37fb6c2a..75f125421f 100644 --- a/shared/test/unit_test/os_interface/linux/device_factory_tests_linux.cpp +++ b/shared/test/unit_test/os_interface/linux/device_factory_tests_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,8 +9,11 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/os_interface/device_factory.h" +#include "shared/source/os_interface/driver_info.h" +#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h" #include "shared/source/os_interface/os_interface.h" #include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/mocks/mock_driver_model.h" TEST_F(DeviceFactoryLinuxTest, WhenPreparingDeviceEnvironmentsThenInitializedCorrectly) { const HardwareInfo *refHwinfo = defaultHwInfo.get(); @@ -64,3 +67,32 @@ TEST_F(DeviceFactoryLinuxTest, whenDrmIsNotCretedThenPrepareDeviceEnvironmentsFa bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment); EXPECT_FALSE(success); } + +TEST(SortDevicesDrmTest, whenSortingDevicesThenMemoryOperationHandlersHaveProperIndices) { + ExecutionEnvironment executionEnvironment{}; + static const auto numRootDevices = 6; + NEO::PhysicalDevicePciBusInfo inputBusInfos[numRootDevices] = {{3, 1, 2, 1}, {0, 0, 2, 0}, {0, 1, 3, 0}, {0, 1, 2, 1}, {0, 0, 2, 1}, {3, 1, 2, 0}}; + NEO::PhysicalDevicePciBusInfo expectedBusInfos[numRootDevices] = {{0, 0, 2, 0}, {0, 0, 2, 1}, {0, 1, 2, 1}, {0, 1, 3, 0}, {3, 1, 2, 0}, {3, 1, 2, 1}}; + + executionEnvironment.prepareRootDeviceEnvironments(numRootDevices); + for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]; + auto osInterface = std::make_unique(); + auto driverModel = std::make_unique(DriverModelType::DRM); + driverModel->pciBusInfo = inputBusInfos[rootDeviceIndex]; + osInterface->setDriverModel(std::move(driverModel)); + rootDeviceEnvironment.osInterface = std::move(osInterface); + rootDeviceEnvironment.memoryOperationsInterface = std::make_unique(rootDeviceEnvironment, rootDeviceIndex); + } + + executionEnvironment.sortNeoDevices(); + + for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + auto pciBusInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->getPciBusInfo(); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDomain, pciBusInfo.pciDomain); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciBus, pciBusInfo.pciBus); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDevice, pciBusInfo.pciDevice); + EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciFunction, pciBusInfo.pciFunction); + EXPECT_EQ(rootDeviceIndex, static_cast(*executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface).getRootDeviceIndex()); + } +} diff --git a/shared/test/unit_test/os_interface/linux/drm_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_tests.cpp index 832eddf85c..a21a27daea 100644 --- a/shared/test/unit_test/os_interface/linux/drm_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_tests.cpp @@ -60,7 +60,7 @@ TEST(DrmTest, GivenValidPciPathWhenGettingAdapterBdfThenCorrectValuesAreReturned { drm.setPciPath("0000:ab:cd.e"); EXPECT_EQ(0, drm.queryAdapterBDF()); - auto adapterBdf = drm.getAdapterBDF(); + auto adapterBdf = drm.adapterBDF; EXPECT_EQ(0xabu, adapterBdf.Bus); EXPECT_EQ(0xcdu, adapterBdf.Device); EXPECT_EQ(0xeu, adapterBdf.Function); @@ -75,7 +75,7 @@ TEST(DrmTest, GivenValidPciPathWhenGettingAdapterBdfThenCorrectValuesAreReturned { drm.setPciPath("0000:01:23.4"); EXPECT_EQ(0, drm.queryAdapterBDF()); - auto adapterBdf = drm.getAdapterBDF(); + auto adapterBdf = drm.adapterBDF; EXPECT_EQ(0x1u, adapterBdf.Bus); EXPECT_EQ(0x23u, adapterBdf.Device); EXPECT_EQ(0x4u, adapterBdf.Function); @@ -94,7 +94,7 @@ TEST(DrmTest, GivenInvalidPciPathWhenGettingAdapterBdfThenInvalidPciInfoIsReturn drm.setPciPath("invalidPci"); EXPECT_EQ(1, drm.queryAdapterBDF()); - auto adapterBdf = drm.getAdapterBDF(); + auto adapterBdf = drm.adapterBDF; EXPECT_EQ(std::numeric_limits::max(), adapterBdf.Data); auto pciInfo = drm.getPciBusInfo();