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 <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2023-06-13 15:19:02 +00:00
committed by Compute-Runtime-Automation
parent 13b0fb59f7
commit 3b981331c9
27 changed files with 278 additions and 674 deletions

View File

@@ -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})

View File

@@ -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 <sstream>
namespace NEO {
bool comparePciIdBusNumberDRM(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2) {
// BDF sample format is : 00:02.0
rootDeviceEnvironment1->osInterface->getDriverModel()->as<NEO::Drm>()->queryAdapterBDF();
auto bdfDevice1 = rootDeviceEnvironment1->osInterface->getDriverModel()->as<NEO::Drm>()->getAdapterBDF();
auto domain1 = rootDeviceEnvironment1->osInterface->getDriverModel()->as<NEO::Drm>()->getPciDomain();
rootDeviceEnvironment2->osInterface->getDriverModel()->as<NEO::Drm>()->queryAdapterBDF();
auto bdfDevice2 = rootDeviceEnvironment2->osInterface->getDriverModel()->as<NEO::Drm>()->getAdapterBDF();
auto domain2 = rootDeviceEnvironment2->osInterface->getDriverModel()->as<NEO::Drm>()->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<uint32_t> presortIndex;
for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandler *drm = static_cast<DrmMemoryOperationsHandler *>(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<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[i]->memoryOperationsInterface.get());
if (drm->getRootDeviceIndex() != presortIndex[i]) {
drm->setRootDeviceIndex(presortIndex[i]);
}
}
}
}
} // namespace NEO

View File

@@ -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 <algorithm>
namespace NEO {
void ExecutionEnvironment::sortNeoDevicesDRM() {
std::vector<uint32_t> presortIndex;
for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandler *drm = static_cast<DrmMemoryOperationsHandler *>(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<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[i]->memoryOperationsInterface.get());
if (drm->getRootDeviceIndex() != presortIndex[i]) {
drm->setRootDeviceIndex(presortIndex[i]);
}
}
}
} // namespace NEO

View File

@@ -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<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &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

View File

@@ -58,6 +58,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
void releaseRootDeviceEnvironmentResources(RootDeviceEnvironment *rootDeviceEnvironment);
protected:
static bool comparePciIdBusNumber(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2);
void parseCcsCountLimitations();
void adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const;
void configureNeoEnvironment();

View File

@@ -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})

View File

@@ -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 <algorithm>
#include <sstream>
namespace NEO {
bool comparePciIdBusNumberWDDM(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2) {
// BDF sample format is : 00:02.0
auto bdfDevice1 = rootDeviceEnvironment1->osInterface->getDriverModel()->as<NEO::Wddm>()->getAdapterBDF();
auto bdfDevice2 = rootDeviceEnvironment2->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::sortNeoDevicesWDDM() {
const auto pciOrderVar = DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.get();
if (pciOrderVar) {
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumberWDDM);
}
}
} // namespace NEO

View File

@@ -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 <algorithm>
namespace NEO {
void ExecutionEnvironment::sortNeoDevicesWDDM() {
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber);
}
} // namespace NEO