diff --git a/shared/source/execution_environment/drm/CMakeLists.txt b/shared/source/execution_environment/drm/CMakeLists.txt deleted file mode 100644 index 7994b1f562..0000000000 --- a/shared/source/execution_environment/drm/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# -# 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}/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/sort_devices_drm.cpp b/shared/source/execution_environment/drm/sort_devices_drm.cpp deleted file mode 100644 index 29a279064f..0000000000 --- a/shared/source/execution_environment/drm/sort_devices_drm.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 33c28d81a0..86ce60baf7 100644 --- a/shared/source/execution_environment/execution_environment.cpp +++ b/shared/source/execution_environment/execution_environment.cpp @@ -253,6 +253,10 @@ void ExecutionEnvironment::parseAffinityMask() { rootDeviceEnvironments.swap(filteredEnvironments); } +void ExecutionEnvironment::sortNeoDevices() { + std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber); +} + void ExecutionEnvironment::adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const { auto hwInfo = rootDeviceEnvironment->getMutableHardwareInfo(); auto &productHelper = rootDeviceEnvironment->getHelper(); diff --git a/shared/source/execution_environment/execution_environment.h b/shared/source/execution_environment/execution_environment.h index 248253a142..72d4d7d003 100644 --- a/shared/source/execution_environment/execution_environment.h +++ b/shared/source/execution_environment/execution_environment.h @@ -32,8 +32,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject void adjustCcsCount(); void adjustCcsCount(const uint32_t rootDeviceIndex) const; void sortNeoDevices(); - void sortNeoDevicesDRM(); - void sortNeoDevicesWDDM(); + void adjustRootDeviceEnvironments(); void prepareForCleanup() const; void setDebuggingMode(DebuggingMode debuggingMode) { debuggingEnabledMode = debuggingMode; diff --git a/shared/source/execution_environment/execution_environment_drm.cpp b/shared/source/execution_environment/execution_environment_drm.cpp index e29ec83af3..24c7de3e3f 100644 --- a/shared/source/execution_environment/execution_environment_drm.cpp +++ b/shared/source/execution_environment/execution_environment_drm.cpp @@ -1,16 +1,20 @@ /* - * Copyright (C) 2022 Intel Corporation + * Copyright (C) 2022-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.h" namespace NEO { -void ExecutionEnvironment::sortNeoDevices() { - return ExecutionEnvironment::sortNeoDevicesDRM(); +void ExecutionEnvironment::adjustRootDeviceEnvironments() { + for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) { + auto drmMemoryOperationsHandler = static_cast(rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface.get()); + drmMemoryOperationsHandler->setRootDeviceIndex(rootDeviceIndex); + } } - } // namespace NEO diff --git a/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp b/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp index bbf02e498b..419ad19163 100644 --- a/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp +++ b/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp @@ -8,17 +8,18 @@ #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/driver_model_type.h" +#include "shared/source/os_interface/linux/drm_memory_operations_handler.h" #include "shared/source/os_interface/os_interface.h" namespace NEO { -void ExecutionEnvironment::sortNeoDevices() { - +void ExecutionEnvironment::adjustRootDeviceEnvironments() { if (rootDeviceEnvironments[0]->osInterface->getDriverModel()->getDriverModelType() == DriverModelType::DRM) { - return ExecutionEnvironment::sortNeoDevicesDRM(); - } else { - return ExecutionEnvironment::sortNeoDevicesWDDM(); + for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) { + auto drmMemoryOperationsHandler = static_cast(rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface.get()); + drmMemoryOperationsHandler->setRootDeviceIndex(rootDeviceIndex); + } } } -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/source/execution_environment/execution_environment_wddm.cpp b/shared/source/execution_environment/execution_environment_wddm.cpp index dd7b316c9c..8317bb7843 100644 --- a/shared/source/execution_environment/execution_environment_wddm.cpp +++ b/shared/source/execution_environment/execution_environment_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Intel Corporation + * Copyright (C) 2022-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,8 +9,7 @@ namespace NEO { -void ExecutionEnvironment::sortNeoDevices() { - return ExecutionEnvironment::sortNeoDevicesWDDM(); +void ExecutionEnvironment::adjustRootDeviceEnvironments() { } -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/source/execution_environment/wddm/CMakeLists.txt b/shared/source/execution_environment/wddm/CMakeLists.txt deleted file mode 100644 index 2c80549a27..0000000000 --- a/shared/source/execution_environment/wddm/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# -# 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}/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/sort_devices_wddm.cpp b/shared/source/execution_environment/wddm/sort_devices_wddm.cpp deleted file mode 100644 index dbdaa1b34a..0000000000 --- a/shared/source/execution_environment/wddm/sort_devices_wddm.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 71e2d09932..322dd4c9f3 100644 --- a/shared/source/os_interface/device_factory.cpp +++ b/shared/source/os_interface/device_factory.cpp @@ -179,6 +179,7 @@ bool DeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnv executionEnvironment.sortNeoDevices(); executionEnvironment.parseAffinityMask(); + executionEnvironment.adjustRootDeviceEnvironments(); executionEnvironment.adjustCcsCount(); executionEnvironment.calculateMaxOsContextCount(); diff --git a/shared/test/common/libult/linux/directory_linux.cpp b/shared/test/common/libult/linux/directory_linux.cpp index 6fc8653375..359a16ab70 100644 --- a/shared/test/common/libult/linux/directory_linux.cpp +++ b/shared/test/common/libult/linux/directory_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 Intel Corporation + * Copyright (C) 2021-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -26,6 +26,11 @@ std::vector Directory::getFiles(const std::string &path) { return files; } + auto it = directoryFilesMap.find(path); + if (it != directoryFilesMap.end()) { + return directoryFilesMap[path]; + } + if (path == byPathPattern) { files.push_back(byPathPattern + "/pci-0000:00:02.0-card"); files.push_back(byPathPattern + "/pci-0000:00:02.0-render"); @@ -58,11 +63,6 @@ std::vector Directory::getFiles(const std::string &path) { }; } - auto it = directoryFilesMap.find(path); - if (it != directoryFilesMap.end()) { - return directoryFilesMap[path]; - } - return files; } }; // namespace NEO 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 75f125421f..5f4f87c9f1 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 @@ -11,9 +11,16 @@ #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/linux/os_inc.h" #include "shared/source/os_interface/os_interface.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h" + +namespace NEO { +extern std::map> directoryFilesMap; +}; TEST_F(DeviceFactoryLinuxTest, WhenPreparingDeviceEnvironmentsThenInitializedCorrectly) { const HardwareInfo *refHwinfo = defaultHwInfo.get(); @@ -68,26 +75,38 @@ TEST_F(DeviceFactoryLinuxTest, whenDrmIsNotCretedThenPrepareDeviceEnvironmentsFa EXPECT_FALSE(success); } -TEST(SortDevicesDrmTest, whenSortingDevicesThenMemoryOperationHandlersHaveProperIndices) { - ExecutionEnvironment executionEnvironment{}; +TEST(SortAndFilterDevicesDrmTest, whenSortingAndFilteringDevicesThenMemoryOperationHandlersHaveProperIndices) { 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}}; + DebugManagerStateRestore dbgRestorer; + DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices); + DebugManager.flags.ZE_AFFINITY_MASK.set("1,2,3,4,5"); - 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); - } + VariableBackup>> directoryFilesMapBackup(&directoryFilesMap); + VariableBackup pciDevicesDirectoryBackup(&Os::pciDevicesDirectory); + VariableBackup mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return SysCalls::fakeFileDescriptor; + }); - executionEnvironment.sortNeoDevices(); + Os::pciDevicesDirectory = "/"; + directoryFilesMap.clear(); + directoryFilesMap[Os::pciDevicesDirectory] = {}; + directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0003:01:02.1-render"); + directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0000:00:02.0-render"); + directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0000:01:03.0-render"); + directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0000:01:02.1-render"); + directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0000:00:02.1-render"); + directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0003:01:02.0-render"); - for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + ExecutionEnvironment executionEnvironment{}; + bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment); + EXPECT_TRUE(success); + + static const auto newNumRootDevices = 5u; + EXPECT_EQ(newNumRootDevices, executionEnvironment.rootDeviceEnvironments.size()); + + NEO::PhysicalDevicePciBusInfo expectedBusInfos[newNumRootDevices] = {{0, 0, 2, 1}, {0, 1, 2, 1}, {0, 1, 3, 0}, {3, 1, 2, 0}, {3, 1, 2, 1}}; + + for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < newNumRootDevices; rootDeviceIndex++) { auto pciBusInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->getPciBusInfo(); EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDomain, pciBusInfo.pciDomain); EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciBus, pciBusInfo.pciBus);