Skip to content

Commit 7c70a14

Browse files
Implement ZE_ENABLE_PCI_ID_DEVICE_ORDER environment variable
Signed-off-by: Jitendra Sharma <[email protected]>
1 parent 9ff19c5 commit 7c70a14

File tree

14 files changed

+193
-0
lines changed

14 files changed

+193
-0
lines changed

level_zero/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,18 @@ if(BUILD_WITH_L0)
361361
L0_SOURCES_WINDOWS
362362
L0_SRCS_COMPILER_INTERFACE
363363
L0_SRCS_DEBUGGER
364+
L0_SRCS_DRIVER
364365
L0_SRCS_OCLOC_SHARED
365366
)
366367
if(WIN32)
367368
append_sources_from_properties(L0_RUNTIME_SOURCES
368369
L0_SRCS_DEBUGGER_WINDOWS
370+
L0_SRCS_DRIVER_WINDOWS
369371
)
370372
else()
371373
append_sources_from_properties(L0_RUNTIME_SOURCES
372374
L0_SRCS_DEBUGGER_LINUX
375+
L0_SRCS_DRIVER_LINUX
373376
)
374377
endif()
375378

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (C) 2020 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
set(L0_SRCS_DRIVER
8+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
)
10+
11+
add_subdirectories()
12+
set_property(GLOBAL PROPERTY L0_SRCS_DRIVER ${L0_SRCS_DRIVER})

level_zero/core/source/driver/driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void DriverImp::initialize(ze_result_t *result) {
4141
envReader.getSetting("ZET_ENABLE_PROGRAM_INSTRUMENTATION", false);
4242
envVariables.sysman =
4343
envReader.getSetting("ZES_ENABLE_SYSMAN", false);
44+
envVariables.pciIdDeviceOrder =
45+
envReader.getSetting("ZE_ENABLE_PCI_ID_DEVICE_ORDER", false);
4446

4547
auto executionEnvironment = new NEO::ExecutionEnvironment();
4648
UNRECOVERABLE_IF(nullptr == executionEnvironment);

level_zero/core/source/driver/driver_handle_imp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
229229

230230
uint32_t affinityMask = std::numeric_limits<uint32_t>::max();
231231

232+
if (enablePciIdDeviceOrder) {
233+
sortNeoDevices(neoDevices);
234+
}
235+
232236
if (this->affinityMaskString.length() > 0) {
233237
affinityMask = parseAffinityMask(neoDevices);
234238
}
@@ -292,6 +296,7 @@ DriverHandle *DriverHandle::create(std::vector<std::unique_ptr<NEO::Device>> dev
292296
driverHandle->affinityMaskString = envVariables.affinityMask;
293297
driverHandle->enableProgramDebugging = envVariables.programDebugging;
294298
driverHandle->enableSysman = envVariables.sysman;
299+
driverHandle->enablePciIdDeviceOrder = envVariables.pciIdDeviceOrder;
295300

296301
ze_result_t res = driverHandle->initialize(std::move(devices));
297302
if (res != ZE_RESULT_SUCCESS) {

level_zero/core/source/driver/driver_handle_imp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct DriverHandleImp : public DriverHandle {
8282
uintptr_t *gpuAddress) override;
8383
uint32_t parseAffinityMask(std::vector<std::unique_ptr<NEO::Device>> &neoDevices);
8484
void createHostPointerManager();
85+
void sortNeoDevices(std::vector<std::unique_ptr<NEO::Device>> &neoDevices);
8586

8687
std::unique_ptr<HostPointerManager> hostPointerManager;
8788
// Experimental functions
@@ -107,6 +108,7 @@ struct DriverHandleImp : public DriverHandle {
107108
// Environment Variables
108109
bool enableProgramDebugging = false;
109110
bool enableSysman = false;
111+
bool enablePciIdDeviceOrder = false;
110112
};
111113

112114
extern struct DriverHandleImp *GlobalDriver;

level_zero/core/source/driver/driver_imp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct L0EnvVariables {
3131
bool metrics;
3232
bool pin;
3333
bool sysman;
34+
bool pciIdDeviceOrder;
3435
};
3536

3637
} // namespace L0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright (C) 2020 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
set(L0_SRCS_DRIVER_LINUX
8+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
${CMAKE_CURRENT_SOURCE_DIR}/driver_handle_imp_linux.cpp
10+
)
11+
12+
if(UNIX)
13+
set_property(GLOBAL PROPERTY L0_SRCS_DRIVER_LINUX ${L0_SRCS_DRIVER_LINUX})
14+
endif()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2020 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/linux/drm_neo.h"
9+
#include "shared/source/os_interface/linux/os_interface.h"
10+
11+
#include "level_zero/core/source/driver/driver_handle_imp.h"
12+
13+
namespace L0 {
14+
15+
bool comparePciIdBusNumber(std::unique_ptr<NEO::Device> &neoDevice1, std::unique_ptr<NEO::Device> &neoDevice2) {
16+
// BDF sample format is : 00:02.0
17+
auto bdfDevice1 = neoDevice1.get()->getRootDeviceEnvironment().osInterface.get()->get()->getDrm()->getPciPath();
18+
uint32_t bus1 = 0;
19+
std::stringstream ss;
20+
ss << std::hex << bdfDevice1;
21+
ss >> bus1;
22+
ss.str("");
23+
ss.clear();
24+
auto bdfDevice2 = neoDevice2.get()->getRootDeviceEnvironment().osInterface.get()->get()->getDrm()->getPciPath();
25+
uint32_t bus2 = 0;
26+
ss << std::hex << bdfDevice2;
27+
ss >> bus2;
28+
return bus1 < bus2;
29+
}
30+
31+
void DriverHandleImp::sortNeoDevices(std::vector<std::unique_ptr<NEO::Device>> &neoDevices) {
32+
std::sort(neoDevices.begin(), neoDevices.end(), comparePciIdBusNumber);
33+
}
34+
35+
} // namespace L0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright (C) 2020 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
set(L0_SRCS_DRIVER_WINDOWS
8+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
${CMAKE_CURRENT_SOURCE_DIR}/driver_handle_imp_windows.cpp
10+
)
11+
12+
if(WIN32)
13+
set_property(GLOBAL PROPERTY L0_SRCS_DRIVER_WINDOWS ${L0_SRCS_DRIVER_WINDOWS})
14+
endif()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (C) 2020 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "level_zero/core/source/driver/driver_handle_imp.h"
9+
10+
namespace L0 {
11+
12+
void DriverHandleImp::sortNeoDevices(std::vector<std::unique_ptr<NEO::Device>> &neoDevices) {
13+
}
14+
15+
} // namespace L0

0 commit comments

Comments
 (0)