Refactor ZE_ENABLE_PCI_ID_DEVICE_ORDER

- Make it avaialble also to OpenCL
- Use it before parsing affinity mask, so devices are masked also
following PCI order.


Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2021-07-11 00:12:15 +00:00
committed by Compute-Runtime-Automation
parent 42c5f2235b
commit 058c30c9a8
19 changed files with 242 additions and 96 deletions

View File

@@ -392,13 +392,11 @@ if(BUILD_WITH_L0)
append_sources_from_properties(L0_RUNTIME_SOURCES
L0_SRCS_CACHE_RESERVATION_WINDOWS
L0_SRCS_DEBUGGER_WINDOWS
L0_SRCS_DRIVER_WINDOWS
)
else()
append_sources_from_properties(L0_RUNTIME_SOURCES
L0_SRCS_CACHE_RESERVATION_LINUX
L0_SRCS_DEBUGGER_LINUX
L0_SRCS_DRIVER_LINUX
)
endif()

View File

@@ -140,10 +140,6 @@ DriverHandleImp::~DriverHandleImp() {
}
ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>> neoDevices) {
if (enablePciIdDeviceOrder) {
sortNeoDevices(neoDevices);
}
bool multiOsContextDriver = false;
for (auto &neoDevice : neoDevices) {
ze_result_t returnValue = ZE_RESULT_SUCCESS;

View File

@@ -1,14 +0,0 @@
#
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(L0_SRCS_DRIVER_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/driver_handle_imp_linux.cpp
)
if(UNIX)
set_property(GLOBAL PROPERTY L0_SRCS_DRIVER_LINUX ${L0_SRCS_DRIVER_LINUX})
endif()

View File

@@ -1,35 +0,0 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/os_interface.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
namespace L0 {
bool comparePciIdBusNumber(std::unique_ptr<NEO::Device> &neoDevice1, std::unique_ptr<NEO::Device> &neoDevice2) {
// BDF sample format is : 00:02.0
auto bdfDevice1 = neoDevice1.get()->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>()->getPciPath();
uint32_t bus1 = 0;
std::stringstream ss;
ss << std::hex << bdfDevice1;
ss >> bus1;
ss.str("");
ss.clear();
auto bdfDevice2 = neoDevice2.get()->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>()->getPciPath();
uint32_t bus2 = 0;
ss << std::hex << bdfDevice2;
ss >> bus2;
return bus1 < bus2;
}
void DriverHandleImp::sortNeoDevices(std::vector<std::unique_ptr<NEO::Device>> &neoDevices) {
std::sort(neoDevices.begin(), neoDevices.end(), comparePciIdBusNumber);
}
} // namespace L0

View File

@@ -1,14 +0,0 @@
#
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(L0_SRCS_DRIVER_WINDOWS
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/driver_handle_imp_windows.cpp
)
if(WIN32)
set_property(GLOBAL PROPERTY L0_SRCS_DRIVER_WINDOWS ${L0_SRCS_DRIVER_WINDOWS})
endif()

View File

@@ -1,15 +0,0 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/core/source/driver/driver_handle_imp.h"
namespace L0 {
void DriverHandleImp::sortNeoDevices(std::vector<std::unique_ptr<NEO::Device>> &neoDevices) {
}
} // namespace L0

View File

@@ -19,9 +19,9 @@ using namespace NEO;
namespace L0 {
namespace ult {
const uint32_t numRootDevices = 4u;
const uint32_t numSubDevices = 2u;
constexpr int mockFd = 0;
class TestDriverMockDrm : public Drm {
public:
TestDriverMockDrm(std::string &bdf, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(mockFd, bdf.c_str()), rootDeviceEnvironment) {}
@@ -46,19 +46,116 @@ class DriverLinuxFixture : public ::testing::Test {
auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get();
osInterface->setDriverModel(std::make_unique<TestDriverMockDrm>(bdf[i], const_cast<NEO::RootDeviceEnvironment &>(devices[i]->getRootDeviceEnvironment())));
}
executionEnvironment->sortNeoDevices();
}
void TearDown() override {}
static constexpr uint32_t numRootDevices = 5u;
static constexpr uint32_t numSubDevices = 2u;
std::vector<std::unique_ptr<NEO::Device>> devices;
std::string bdf[numRootDevices] = {"08:02.0", "03:04.0", "10:03.0", "02:01.0"};
std::string sortedBdf[numRootDevices] = {"02:01.0", "03:04.0", "08:02.0", "10:03.0"};
std::string bdf[numRootDevices] = {"03:04.0", "08:02.0", "08:03.1", "10:03.0", "02:01.0"};
std::string sortedBdf[numRootDevices] = {"02:01.0", "03:04.0", "08:02.0", "08:03.1", "10:03.0"};
std::unique_ptr<UltDeviceFactory> deviceFactory;
};
TEST_F(DriverLinuxFixture, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToBusOrderRetrieved) {
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) {
NEO::MockCompilerEnableGuard mock(true);
DriverHandleImp *driverHandle = new DriverHandleImp;
driverHandle->enablePciIdDeviceOrder = true;
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<Drm>();
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) {
NEO::MockCompilerEnableGuard mock(true);
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<Drm>();
EXPECT_NE(pDrm, nullptr);
EXPECT_FALSE(!pDrm->getPciPath().compare(sortedBdf[i]));
}
}
delete driverHandle;
}
class DriverPciOrderWitSimilarBusLinuxFixture : public ::testing::Test {
public:
void SetUp() override {
DebugManagerStateRestore restorer;
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1);
NEO::MockCompilerEnableGuard mock(true);
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]->setHwInfo(&hwInfo);
}
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
}
for (auto i = 0u; i < devices.size(); i++) {
devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique<NEO::OSInterface>();
auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get();
osInterface->setDriverModel(std::make_unique<TestDriverMockDrm>(bdf[i], const_cast<NEO::RootDeviceEnvironment &>(devices[i]->getRootDeviceEnvironment())));
}
executionEnvironment->sortNeoDevices();
}
void TearDown() override {}
static constexpr uint32_t numRootDevices = 4u;
static constexpr uint32_t numSubDevices = 2u;
std::vector<std::unique_ptr<NEO::Device>> devices;
std::string bdf[numRootDevices] = {"03:04.0", "03:05.0", "03:06.0", "03:01.0"};
std::string sortedBdf[numRootDevices] = {"03:01.0", "03:04.0", "03:05.0", "03:06.0"};
std::unique_ptr<UltDeviceFactory> deviceFactory;
};
TEST_F(DriverPciOrderWitSimilarBusLinuxFixture, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToBusOrderRetrieved) {
NEO::MockCompilerEnableGuard mock(true);
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
for (uint32_t i = 0; i < numRootDevices; i++) {

View File

@@ -10,6 +10,7 @@ AUBDumpToggleFileName = unk
OverrideGdiPath = unk
AubDumpAddMmioRegistersList = unk
ZE_AFFINITY_MASK = default
ZE_ENABLE_PCI_ID_DEVICE_ORDER = 1
AUBDumpFilterNamedKernelStartIdx = 0
AUBDumpFilterNamedKernelEndIdx = -1
AUBDumpSubCaptureMode = 0

View File

@@ -29,17 +29,25 @@ TEST(osInterfaceTests, whenOsInterfaceSetupGmmInputArgsThenArgsAreSet) {
wddm->deviceRegistryPath = "registryPath";
auto expectedRegistryPath = wddm->deviceRegistryPath.c_str();
auto &adapterBDF = wddm->adapterBDF;
adapterBDF.Bus = 0x12;
adapterBDF.Device = 0x34;
adapterBDF.Function = 0x56;
uint32_t bus = 0x12;
adapterBDF.Bus = bus;
uint32_t device = 0x34;
adapterBDF.Device = device;
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(&adapterBDF, &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
EXPECT_NE(0, memcmp(&wddm->getAdapterBDF(), &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
EXPECT_STRNE(expectedRegistryPath, gmmInputArgs.DeviceRegistryPath);
rootDeviceEnvironment.osInterface->getDriverModel()->setGmmInputArgs(&gmmInputArgs);
EXPECT_EQ(0, memcmp(&adapterBDF, &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
EXPECT_EQ(0, memcmp(&wddm->getAdapterBDF(), &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, gmmInputArgs.ClientType);
EXPECT_STREQ(expectedRegistryPath, gmmInputArgs.DeviceRegistryPath);
}

View File

@@ -137,6 +137,7 @@ if(WIN32)
NEO_CORE_SKU_INFO_WINDOWS
NEO_CORE_SRCS_HELPERS_WINDOWS
NEO_CORE_UTILITIES_WINDOWS
NEO_CORE_EXECUTION_ENVIRONMENT_WINDOWS
)
else()
append_sources_from_properties(CORE_SOURCES
@@ -144,6 +145,7 @@ else()
NEO_CORE_OS_INTERFACE_LINUX
NEO_CORE_PAGE_FAULT_MANAGER_LINUX
NEO_CORE_UTILITIES_LINUX
NEO_CORE_EXECUTION_ENVIRONMENT_LINUX
)
if(NOT DISABLE_WDDM_LINUX)
append_sources_from_properties(CORE_SOURCES

View File

@@ -12,4 +12,5 @@
DECLARE_DEBUG_VARIABLE(bool, MakeAllBuffersResident, false, "Make all buffers resident after creation")
DECLARE_DEBUG_VARIABLE(int32_t, OverrideDefaultFP64Settings, -1, "-1: dont override, 0: disable, 1: enable.")
DECLARE_DEBUG_VARIABLE(int32_t, EnableCrossDeviceAccess, -1, "-1: default behavior, 0: disabled, 1: enabled, Allows one device to access another device's memory")
DECLARE_DEBUG_VARIABLE(std::string, ZE_AFFINITY_MASK, std::string("default"), "Refer to the Level Zero Specification for a desricption")
DECLARE_DEBUG_VARIABLE(std::string, ZE_AFFINITY_MASK, std::string("default"), "Refer to the Level Zero Specification for a description")
DECLARE_DEBUG_VARIABLE(bool, ZE_ENABLE_PCI_ID_DEVICE_ORDER, true, "Refer to the Level Zero Specification for a description")

View File

@@ -13,4 +13,5 @@ set(NEO_CORE_EXECUTION_ENVIRONMENT
)
add_subdirectories()
set_property(GLOBAL PROPERTY NEO_CORE_EXECUTION_ENVIRONMENT ${NEO_CORE_EXECUTION_ENVIRONMENT})

View File

@@ -25,6 +25,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
void calculateMaxOsContextCount();
void prepareRootDeviceEnvironments(uint32_t numRootDevices);
void parseAffinityMask();
void sortNeoDevices();
void setDebuggingEnabled() {
debuggingEnabled = true;
}

View File

@@ -0,0 +1,14 @@
#
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(NEO_CORE_EXECUTION_ENVIRONMENT_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_linux.cpp
)
if(UNIX)
set_property(GLOBAL PROPERTY NEO_CORE_EXECUTION_ENVIRONMENT_LINUX ${NEO_CORE_EXECUTION_ENVIRONMENT_LINUX})
endif()

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2021 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_neo.h"
#include "shared/source/os_interface/os_interface.h"
#include <sstream>
namespace NEO {
bool comparePciIdBusNumber(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2) {
// BDF sample format is : 00:02.0
rootDeviceEnvironment1.get()->osInterface->getDriverModel()->as<NEO::Drm>()->queryAdapterBDF();
auto bdfDevice1 = rootDeviceEnvironment1.get()->osInterface->getDriverModel()->as<NEO::Drm>()->getAdapterBDF();
rootDeviceEnvironment2.get()->osInterface->getDriverModel()->as<NEO::Drm>()->queryAdapterBDF();
auto bdfDevice2 = rootDeviceEnvironment2.get()->osInterface->getDriverModel()->as<NEO::Drm>()->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::sortNeoDevices() {
const auto pciOrderVar = DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.get();
if (pciOrderVar) {
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber);
}
}
} // namespace NEO

View File

@@ -0,0 +1,14 @@
#
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(NEO_CORE_EXECUTION_ENVIRONMENT_WINDOWS
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_windows.cpp
)
if(WIN32)
set_property(GLOBAL PROPERTY NEO_CORE_EXECUTION_ENVIRONMENT_WINDOWS ${NEO_CORE_EXECUTION_ENVIRONMENT_WINDOWS})
endif()

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2021 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 <sstream>
namespace NEO {
bool comparePciIdBusNumber(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2) {
// BDF sample format is : 00:02.0
auto bdfDevice1 = rootDeviceEnvironment1.get()->osInterface->getDriverModel()->as<NEO::Wddm>()->getAdapterBDF();
auto bdfDevice2 = rootDeviceEnvironment2.get()->osInterface->getDriverModel()->as<NEO::Wddm>()->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::sortNeoDevices() {
const auto pciOrderVar = DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.get();
if (pciOrderVar) {
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber);
}
}
} // namespace NEO

View File

@@ -122,6 +122,7 @@ bool DeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnv
rootDeviceIndex++;
}
executionEnvironment.sortNeoDevices();
executionEnvironment.parseAffinityMask();
executionEnvironment.calculateMaxOsContextCount();

View File

@@ -189,6 +189,10 @@ class Wddm : public DriverModel {
static std::vector<std::unique_ptr<HwDeviceId>> discoverDevices(ExecutionEnvironment &executionEnvironment);
ADAPTER_BDF getAdapterBDF() const {
return adapterBDF;
}
protected:
std::unique_ptr<HwDeviceIdWddm> hwDeviceId;
D3DKMT_HANDLE device = 0;