Skip to content

Commit bd724de

Browse files
fix: adjust root device indices when filtering root device environments
Related-To: NEO-8166 Signed-off-by: Mateusz Jablonski <[email protected]> Source: 4e464e9
1 parent d464d5d commit bd724de

12 files changed

+66
-115
lines changed

shared/source/execution_environment/drm/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

shared/source/execution_environment/drm/sort_devices_drm.cpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

shared/source/execution_environment/execution_environment.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ void ExecutionEnvironment::parseAffinityMask() {
253253
rootDeviceEnvironments.swap(filteredEnvironments);
254254
}
255255

256+
void ExecutionEnvironment::sortNeoDevices() {
257+
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber);
258+
}
259+
256260
void ExecutionEnvironment::adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const {
257261
auto hwInfo = rootDeviceEnvironment->getMutableHardwareInfo();
258262
auto &productHelper = rootDeviceEnvironment->getHelper<ProductHelper>();

shared/source/execution_environment/execution_environment.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
3232
void adjustCcsCount();
3333
void adjustCcsCount(const uint32_t rootDeviceIndex) const;
3434
void sortNeoDevices();
35-
void sortNeoDevicesDRM();
36-
void sortNeoDevicesWDDM();
35+
void adjustRootDeviceEnvironments();
3736
void prepareForCleanup() const;
3837
void setDebuggingMode(DebuggingMode debuggingMode) {
3938
debuggingEnabledMode = debuggingMode;
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
/*
2-
* Copyright (C) 2022 Intel Corporation
2+
* Copyright (C) 2022-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
66
*/
77

88
#include "shared/source/execution_environment/execution_environment.h"
9+
#include "shared/source/execution_environment/root_device_environment.h"
10+
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
911

1012
namespace NEO {
1113

12-
void ExecutionEnvironment::sortNeoDevices() {
13-
return ExecutionEnvironment::sortNeoDevicesDRM();
14+
void ExecutionEnvironment::adjustRootDeviceEnvironments() {
15+
for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) {
16+
auto drmMemoryOperationsHandler = static_cast<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface.get());
17+
drmMemoryOperationsHandler->setRootDeviceIndex(rootDeviceIndex);
18+
}
1419
}
15-
1620
} // namespace NEO

shared/source/execution_environment/execution_environment_drm_or_wddm.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88
#include "shared/source/execution_environment/execution_environment.h"
99
#include "shared/source/execution_environment/root_device_environment.h"
1010
#include "shared/source/helpers/driver_model_type.h"
11+
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
1112
#include "shared/source/os_interface/os_interface.h"
1213

1314
namespace NEO {
1415

15-
void ExecutionEnvironment::sortNeoDevices() {
16-
16+
void ExecutionEnvironment::adjustRootDeviceEnvironments() {
1717
if (rootDeviceEnvironments[0]->osInterface->getDriverModel()->getDriverModelType() == DriverModelType::DRM) {
18-
return ExecutionEnvironment::sortNeoDevicesDRM();
19-
} else {
20-
return ExecutionEnvironment::sortNeoDevicesWDDM();
18+
for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) {
19+
auto drmMemoryOperationsHandler = static_cast<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface.get());
20+
drmMemoryOperationsHandler->setRootDeviceIndex(rootDeviceIndex);
21+
}
2122
}
2223
}
2324

24-
} // namespace NEO
25+
} // namespace NEO
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022 Intel Corporation
2+
* Copyright (C) 2022-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -9,8 +9,7 @@
99

1010
namespace NEO {
1111

12-
void ExecutionEnvironment::sortNeoDevices() {
13-
return ExecutionEnvironment::sortNeoDevicesWDDM();
12+
void ExecutionEnvironment::adjustRootDeviceEnvironments() {
1413
}
1514

16-
} // namespace NEO
15+
} // namespace NEO

shared/source/execution_environment/wddm/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

shared/source/execution_environment/wddm/sort_devices_wddm.cpp

Lines changed: 0 additions & 19 deletions
This file was deleted.

shared/source/os_interface/device_factory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ bool DeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnv
179179

180180
executionEnvironment.sortNeoDevices();
181181
executionEnvironment.parseAffinityMask();
182+
executionEnvironment.adjustRootDeviceEnvironments();
182183
executionEnvironment.adjustCcsCount();
183184
executionEnvironment.calculateMaxOsContextCount();
184185

shared/test/common/libult/linux/directory_linux.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021-2022 Intel Corporation
2+
* Copyright (C) 2021-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -26,6 +26,11 @@ std::vector<std::string> Directory::getFiles(const std::string &path) {
2626
return files;
2727
}
2828

29+
auto it = directoryFilesMap.find(path);
30+
if (it != directoryFilesMap.end()) {
31+
return directoryFilesMap[path];
32+
}
33+
2934
if (path == byPathPattern) {
3035
files.push_back(byPathPattern + "/pci-0000:00:02.0-card");
3136
files.push_back(byPathPattern + "/pci-0000:00:02.0-render");
@@ -58,11 +63,6 @@ std::vector<std::string> Directory::getFiles(const std::string &path) {
5863
};
5964
}
6065

61-
auto it = directoryFilesMap.find(path);
62-
if (it != directoryFilesMap.end()) {
63-
return directoryFilesMap[path];
64-
}
65-
6666
return files;
6767
}
6868
}; // namespace NEO

shared/test/unit_test/os_interface/linux/device_factory_tests_linux.cpp

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111
#include "shared/source/os_interface/device_factory.h"
1212
#include "shared/source/os_interface/driver_info.h"
1313
#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h"
14+
#include "shared/source/os_interface/linux/os_inc.h"
1415
#include "shared/source/os_interface/os_interface.h"
16+
#include "shared/test/common/helpers/debug_manager_state_restore.h"
1517
#include "shared/test/common/helpers/default_hw_info.h"
1618
#include "shared/test/common/mocks/mock_driver_model.h"
19+
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
20+
21+
namespace NEO {
22+
extern std::map<std::string, std::vector<std::string>> directoryFilesMap;
23+
};
1724

1825
TEST_F(DeviceFactoryLinuxTest, WhenPreparingDeviceEnvironmentsThenInitializedCorrectly) {
1926
const HardwareInfo *refHwinfo = defaultHwInfo.get();
@@ -68,26 +75,38 @@ TEST_F(DeviceFactoryLinuxTest, whenDrmIsNotCretedThenPrepareDeviceEnvironmentsFa
6875
EXPECT_FALSE(success);
6976
}
7077

71-
TEST(SortDevicesDrmTest, whenSortingDevicesThenMemoryOperationHandlersHaveProperIndices) {
72-
ExecutionEnvironment executionEnvironment{};
78+
TEST(SortAndFilterDevicesDrmTest, whenSortingAndFilteringDevicesThenMemoryOperationHandlersHaveProperIndices) {
7379
static const auto numRootDevices = 6;
74-
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}};
75-
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}};
76-
77-
executionEnvironment.prepareRootDeviceEnvironments(numRootDevices);
78-
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
79-
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex];
80-
auto osInterface = std::make_unique<OSInterface>();
81-
auto driverModel = std::make_unique<MockDriverModel>(DriverModelType::DRM);
82-
driverModel->pciBusInfo = inputBusInfos[rootDeviceIndex];
83-
osInterface->setDriverModel(std::move(driverModel));
84-
rootDeviceEnvironment.osInterface = std::move(osInterface);
85-
rootDeviceEnvironment.memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandlerBind>(rootDeviceEnvironment, rootDeviceIndex);
86-
}
80+
DebugManagerStateRestore dbgRestorer;
81+
DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
82+
DebugManager.flags.ZE_AFFINITY_MASK.set("1,2,3,4,5");
83+
84+
VariableBackup<std::map<std::string, std::vector<std::string>>> directoryFilesMapBackup(&directoryFilesMap);
85+
VariableBackup<const char *> pciDevicesDirectoryBackup(&Os::pciDevicesDirectory);
86+
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
87+
return SysCalls::fakeFileDescriptor;
88+
});
89+
90+
Os::pciDevicesDirectory = "/";
91+
directoryFilesMap.clear();
92+
directoryFilesMap[Os::pciDevicesDirectory] = {};
93+
directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0003:01:02.1-render");
94+
directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0000:00:02.0-render");
95+
directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0000:01:03.0-render");
96+
directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0000:01:02.1-render");
97+
directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0000:00:02.1-render");
98+
directoryFilesMap[Os::pciDevicesDirectory].push_back("/pci-0003:01:02.0-render");
99+
100+
ExecutionEnvironment executionEnvironment{};
101+
bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
102+
EXPECT_TRUE(success);
103+
104+
static const auto newNumRootDevices = 5u;
105+
EXPECT_EQ(newNumRootDevices, executionEnvironment.rootDeviceEnvironments.size());
87106

88-
executionEnvironment.sortNeoDevices();
107+
NEO::PhysicalDevicePciBusInfo expectedBusInfos[newNumRootDevices] = {{0, 0, 2, 1}, {0, 1, 2, 1}, {0, 1, 3, 0}, {3, 1, 2, 0}, {3, 1, 2, 1}};
89108

90-
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
109+
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < newNumRootDevices; rootDeviceIndex++) {
91110
auto pciBusInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->getPciBusInfo();
92111
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDomain, pciBusInfo.pciDomain);
93112
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciBus, pciBusInfo.pciBus);

0 commit comments

Comments
 (0)