2018-06-22 18:54:33 +08:00
|
|
|
/*
|
2025-01-13 20:18:55 +08:00
|
|
|
* Copyright (C) 2018-2025 Intel Corporation
|
2018-09-20 11:54:29 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2018-06-27 17:35:37 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-12-02 18:22:27 +08:00
|
|
|
#include "shared/source/built_ins/built_ins.h"
|
2021-04-16 20:52:30 +08:00
|
|
|
#include "shared/source/built_ins/sip.h"
|
2022-12-16 00:01:37 +08:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2021-07-30 17:56:58 +08:00
|
|
|
#include "shared/source/direct_submission/direct_submission_controller.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2021-05-05 16:07:53 +08:00
|
|
|
#include "shared/source/helpers/affinity_mask.h"
|
2024-08-09 01:11:59 +08:00
|
|
|
#include "shared/source/helpers/bindless_heaps_helper.h"
|
2023-01-10 01:14:18 +08:00
|
|
|
#include "shared/source/helpers/driver_model_type.h"
|
2023-02-02 00:23:01 +08:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2022-12-06 19:19:36 +08:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2021-05-06 00:00:12 +08:00
|
|
|
#include "shared/source/helpers/string_helpers.h"
|
2020-03-19 21:26:08 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2020-11-02 22:54:01 +08:00
|
|
|
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
|
2025-01-21 19:30:02 +08:00
|
|
|
#include "shared/source/memory_manager/unified_memory_reuse_cleaner.h"
|
2023-07-12 10:14:09 +08:00
|
|
|
#include "shared/source/os_interface/debug_env_reader.h"
|
2023-06-13 23:19:02 +08:00
|
|
|
#include "shared/source/os_interface/driver_info.h"
|
2020-03-17 14:26:46 +08:00
|
|
|
#include "shared/source/os_interface/os_environment.h"
|
2021-05-21 07:17:57 +08:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2023-03-10 20:28:11 +08:00
|
|
|
#include "shared/source/os_interface/product_helper.h"
|
2021-03-31 02:11:00 +08:00
|
|
|
#include "shared/source/utilities/wait_util.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2021-03-31 02:11:00 +08:00
|
|
|
ExecutionEnvironment::ExecutionEnvironment() {
|
|
|
|
WaitUtils::init();
|
2022-10-26 20:41:36 +08:00
|
|
|
this->configureNeoEnvironment();
|
2021-03-31 02:11:00 +08:00
|
|
|
}
|
2019-05-06 18:33:44 +08:00
|
|
|
|
2021-10-11 23:34:03 +08:00
|
|
|
void ExecutionEnvironment::releaseRootDeviceEnvironmentResources(RootDeviceEnvironment *rootDeviceEnvironment) {
|
|
|
|
if (rootDeviceEnvironment == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SipKernel::freeSipKernels(rootDeviceEnvironment, memoryManager.get());
|
|
|
|
if (rootDeviceEnvironment->builtins.get()) {
|
2022-05-10 00:21:21 +08:00
|
|
|
rootDeviceEnvironment->builtins->freeSipKernels(memoryManager.get());
|
2024-06-19 19:04:27 +08:00
|
|
|
rootDeviceEnvironment->builtins.reset();
|
2021-10-11 23:34:03 +08:00
|
|
|
}
|
2024-05-16 01:26:24 +08:00
|
|
|
rootDeviceEnvironment->releaseDummyAllocation();
|
2024-08-09 01:11:59 +08:00
|
|
|
rootDeviceEnvironment->bindlessHeapsHelper.reset();
|
2021-10-11 23:34:03 +08:00
|
|
|
}
|
|
|
|
|
2019-10-24 19:34:25 +08:00
|
|
|
ExecutionEnvironment::~ExecutionEnvironment() {
|
2024-03-29 19:24:19 +08:00
|
|
|
if (directSubmissionController) {
|
|
|
|
directSubmissionController->stopThread();
|
|
|
|
}
|
2025-01-21 19:30:02 +08:00
|
|
|
if (unifiedMemoryReuseCleaner) {
|
|
|
|
unifiedMemoryReuseCleaner->stopThread();
|
|
|
|
}
|
2020-02-12 00:48:40 +08:00
|
|
|
if (memoryManager) {
|
|
|
|
memoryManager->commonCleanup();
|
2020-12-02 18:22:27 +08:00
|
|
|
for (const auto &rootDeviceEnvironment : this->rootDeviceEnvironments) {
|
2021-10-11 23:34:03 +08:00
|
|
|
releaseRootDeviceEnvironmentResources(rootDeviceEnvironment.get());
|
2020-12-02 18:22:27 +08:00
|
|
|
}
|
2020-02-12 00:48:40 +08:00
|
|
|
}
|
2019-10-24 19:34:25 +08:00
|
|
|
rootDeviceEnvironments.clear();
|
2023-08-16 11:00:31 +08:00
|
|
|
mapOfSubDeviceIndices.clear();
|
2024-03-15 21:14:45 +08:00
|
|
|
this->restoreCcsMode();
|
2019-10-24 19:34:25 +08:00
|
|
|
}
|
2018-07-16 23:11:43 +08:00
|
|
|
|
2020-09-18 22:19:41 +08:00
|
|
|
bool ExecutionEnvironment::initializeMemoryManager() {
|
2018-07-17 17:11:48 +08:00
|
|
|
if (this->memoryManager) {
|
2020-09-18 22:19:41 +08:00
|
|
|
return memoryManager->isInitialized();
|
2018-07-17 17:11:48 +08:00
|
|
|
}
|
2018-07-20 15:01:58 +08:00
|
|
|
|
2024-04-09 20:43:12 +08:00
|
|
|
auto csrType = obtainCsrTypeFromIntegerValue(debugManager.flags.SetCommandStreamReceiver.get(), CommandStreamReceiverType::hardware);
|
2019-02-19 15:55:11 +08:00
|
|
|
|
2024-04-09 20:43:12 +08:00
|
|
|
switch (csrType) {
|
|
|
|
case CommandStreamReceiverType::tbx:
|
|
|
|
case CommandStreamReceiverType::tbxWithAub:
|
|
|
|
case CommandStreamReceiverType::aub:
|
|
|
|
case CommandStreamReceiverType::nullAub:
|
2019-03-15 17:22:35 +08:00
|
|
|
memoryManager = std::make_unique<OsAgnosticMemoryManager>(*this);
|
2019-02-19 15:55:11 +08:00
|
|
|
break;
|
2024-04-09 20:43:12 +08:00
|
|
|
case CommandStreamReceiverType::hardware:
|
|
|
|
case CommandStreamReceiverType::hardwareWithAub:
|
2021-05-25 23:37:44 +08:00
|
|
|
default: {
|
2023-12-14 00:09:52 +08:00
|
|
|
auto driverModelType = DriverModelType::unknown;
|
2021-05-25 23:37:44 +08:00
|
|
|
if (this->rootDeviceEnvironments[0]->osInterface && this->rootDeviceEnvironments[0]->osInterface->getDriverModel()) {
|
|
|
|
driverModelType = this->rootDeviceEnvironments[0]->osInterface->getDriverModel()->getDriverModelType();
|
|
|
|
}
|
|
|
|
memoryManager = MemoryManager::createMemoryManager(*this, driverModelType);
|
|
|
|
} break;
|
2019-02-19 15:55:11 +08:00
|
|
|
}
|
2020-09-18 22:19:41 +08:00
|
|
|
|
|
|
|
return memoryManager->isInitialized();
|
2018-07-16 23:11:43 +08:00
|
|
|
}
|
2019-12-17 15:11:16 +08:00
|
|
|
|
|
|
|
void ExecutionEnvironment::calculateMaxOsContextCount() {
|
2020-08-17 19:41:48 +08:00
|
|
|
MemoryManager::maxOsContextCount = 0u;
|
2020-02-12 18:27:28 +08:00
|
|
|
for (const auto &rootDeviceEnvironment : this->rootDeviceEnvironments) {
|
2020-02-21 22:25:04 +08:00
|
|
|
auto hwInfo = rootDeviceEnvironment->getHardwareInfo();
|
2022-12-08 20:22:35 +08:00
|
|
|
auto &gfxCoreHelper = rootDeviceEnvironment->getHelper<GfxCoreHelper>();
|
2024-06-07 01:17:54 +08:00
|
|
|
auto &engineInstances = gfxCoreHelper.getGpgpuEngineInstances(*rootDeviceEnvironment);
|
|
|
|
auto osContextCount = static_cast<uint32_t>(engineInstances.size());
|
2023-10-26 21:04:39 +08:00
|
|
|
auto subDevicesCount = GfxCoreHelper::getSubDevicesCount(hwInfo);
|
2020-02-12 18:27:28 +08:00
|
|
|
bool hasRootCsr = subDevicesCount > 1;
|
2019-12-17 15:11:16 +08:00
|
|
|
|
2024-06-07 01:17:54 +08:00
|
|
|
uint32_t numRegularEngines = 0;
|
2024-07-26 17:24:38 +08:00
|
|
|
uint32_t numHpEngines = 0;
|
2024-06-07 01:17:54 +08:00
|
|
|
for (const auto &engine : engineInstances) {
|
|
|
|
if (engine.second == EngineUsage::regular) {
|
|
|
|
numRegularEngines++;
|
2024-07-26 17:24:38 +08:00
|
|
|
} else if (engine.second == EngineUsage::highPriority) {
|
|
|
|
numHpEngines++;
|
2024-06-07 01:17:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-27 02:15:34 +08:00
|
|
|
uint32_t numRootContexts = hasRootCsr ? 1 : 0;
|
2024-08-07 23:42:42 +08:00
|
|
|
uint32_t numSecondaryContexts = 0;
|
2025-01-24 18:50:51 +08:00
|
|
|
if (gfxCoreHelper.areSecondaryContextsSupported()) {
|
2024-08-07 23:42:42 +08:00
|
|
|
numSecondaryContexts += numRegularEngines * gfxCoreHelper.getContextGroupContextsCount();
|
|
|
|
numSecondaryContexts += numHpEngines * gfxCoreHelper.getContextGroupContextsCount();
|
|
|
|
osContextCount -= (numRegularEngines + numHpEngines);
|
2024-08-27 02:15:34 +08:00
|
|
|
|
|
|
|
numRootContexts *= gfxCoreHelper.getContextGroupContextsCount();
|
2024-03-08 00:50:57 +08:00
|
|
|
}
|
|
|
|
|
2024-08-27 02:15:34 +08:00
|
|
|
MemoryManager::maxOsContextCount += (numSecondaryContexts + osContextCount) * subDevicesCount + numRootContexts;
|
2020-02-12 18:27:28 +08:00
|
|
|
}
|
2019-12-17 15:11:16 +08:00
|
|
|
}
|
|
|
|
|
2021-10-25 23:33:38 +08:00
|
|
|
DirectSubmissionController *ExecutionEnvironment::initializeDirectSubmissionController() {
|
2023-07-18 18:48:49 +08:00
|
|
|
std::lock_guard<std::mutex> lockForInit(initializeDirectSubmissionControllerMutex);
|
2021-10-25 23:33:38 +08:00
|
|
|
auto initializeDirectSubmissionController = DirectSubmissionController::isSupported();
|
2021-07-30 17:56:58 +08:00
|
|
|
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.SetCommandStreamReceiver.get() > 0) {
|
2022-02-28 20:03:29 +08:00
|
|
|
initializeDirectSubmissionController = false;
|
|
|
|
}
|
|
|
|
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.EnableDirectSubmissionController.get() != -1) {
|
|
|
|
initializeDirectSubmissionController = debugManager.flags.EnableDirectSubmissionController.get();
|
2021-07-30 17:56:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (initializeDirectSubmissionController && this->directSubmissionController == nullptr) {
|
|
|
|
this->directSubmissionController = std::make_unique<DirectSubmissionController>();
|
2024-03-27 02:08:25 +08:00
|
|
|
this->directSubmissionController->startThread();
|
2021-07-30 17:56:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return directSubmissionController.get();
|
|
|
|
}
|
|
|
|
|
2025-01-21 19:30:02 +08:00
|
|
|
void ExecutionEnvironment::initializeUnifiedMemoryReuseCleaner() {
|
|
|
|
std::lock_guard<std::mutex> lock(initializeUnifiedMemoryReuseCleanerMutex);
|
|
|
|
auto initializeUnifiedMemoryReuseCleaner = UnifiedMemoryReuseCleaner::isSupported();
|
|
|
|
|
|
|
|
if (debugManager.flags.ExperimentalUSMAllocationReuseCleaner.get() != -1) {
|
|
|
|
initializeUnifiedMemoryReuseCleaner = debugManager.flags.ExperimentalUSMAllocationReuseCleaner.get() == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initializeUnifiedMemoryReuseCleaner && nullptr == this->unifiedMemoryReuseCleaner) {
|
|
|
|
this->unifiedMemoryReuseCleaner = std::make_unique<UnifiedMemoryReuseCleaner>();
|
|
|
|
this->unifiedMemoryReuseCleaner->startThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-15 16:59:48 +08:00
|
|
|
void ExecutionEnvironment::prepareRootDeviceEnvironments(uint32_t numRootDevices) {
|
|
|
|
if (rootDeviceEnvironments.size() < numRootDevices) {
|
|
|
|
rootDeviceEnvironments.resize(numRootDevices);
|
|
|
|
}
|
|
|
|
for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
|
|
|
|
if (!rootDeviceEnvironments[rootDeviceIndex]) {
|
|
|
|
rootDeviceEnvironments[rootDeviceIndex] = std::make_unique<RootDeviceEnvironment>(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-06 00:00:12 +08:00
|
|
|
|
2022-05-17 23:23:15 +08:00
|
|
|
void ExecutionEnvironment::prepareForCleanup() const {
|
|
|
|
for (auto &rootDeviceEnvironment : rootDeviceEnvironments) {
|
|
|
|
if (rootDeviceEnvironment) {
|
|
|
|
rootDeviceEnvironment->prepareForCleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 23:34:03 +08:00
|
|
|
void ExecutionEnvironment::prepareRootDeviceEnvironment(const uint32_t rootDeviceIndexForReInit) {
|
|
|
|
rootDeviceEnvironments[rootDeviceIndexForReInit] = std::make_unique<RootDeviceEnvironment>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-20 08:14:56 +08:00
|
|
|
int ExecutionEnvironment::setErrorDescription(const std::string &str) {
|
|
|
|
auto threadId = std::this_thread::get_id();
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> errorDescsLock(errorDescsMutex);
|
|
|
|
if (errorDescs.find(threadId) == errorDescs.end()) {
|
|
|
|
errorDescs[threadId] = str;
|
|
|
|
} else {
|
|
|
|
errorDescs[threadId].clear();
|
|
|
|
errorDescs[threadId] = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return static_cast<int>(str.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExecutionEnvironment::getErrorDescription(const char **ppString) {
|
|
|
|
auto threadId = std::this_thread::get_id();
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> errorDescsLock(errorDescsMutex);
|
|
|
|
if (errorDescs.find(threadId) == errorDescs.end()) {
|
|
|
|
errorDescs[threadId] = std::string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ppString = errorDescs[threadId].c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ExecutionEnvironment::clearErrorDescription() {
|
|
|
|
auto threadId = std::this_thread::get_id();
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> errorDescsLock(errorDescsMutex);
|
|
|
|
if (errorDescs.find(threadId) != errorDescs.end()) {
|
|
|
|
errorDescs[threadId].clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-08-16 11:00:31 +08:00
|
|
|
bool ExecutionEnvironment::getSubDeviceHierarchy(uint32_t index, std::tuple<uint32_t, uint32_t, uint32_t> *subDeviceMap) {
|
|
|
|
if (mapOfSubDeviceIndices.find(index) != mapOfSubDeviceIndices.end()) {
|
|
|
|
*subDeviceMap = mapOfSubDeviceIndices.at(index);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-25 17:24:00 +08:00
|
|
|
void ExecutionEnvironment::parseAffinityMask() {
|
2023-11-30 16:32:25 +08:00
|
|
|
const auto &affinityMaskString = debugManager.flags.ZE_AFFINITY_MASK.get();
|
2021-01-25 17:24:00 +08:00
|
|
|
|
|
|
|
if (affinityMaskString.compare("default") == 0 ||
|
|
|
|
affinityMaskString.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-01-13 20:18:55 +08:00
|
|
|
// If the user has requested FLAT or COMBINED device hierarchy models, then report all the sub devices as devices.
|
2025-01-16 22:25:29 +08:00
|
|
|
bool exposeSubDevices = this->deviceHierarchyMode != DeviceHierarchyMode::composite;
|
feature: Affinity mask plus ReturnSubDevicesAsApiDevices
When using ReturnSubDevicesAsApiDevices=1 to have
sub-devices-as-root-devices, then the driver should read the values
passed in the mask as those corresponding to the physical
sub-devices.
For instance, in a dual system with multi-tile device, we would have:
card 0, tile 0
card 0, tile 1
card 1, tile 0
card 1, tile 1
With:
ReturnSubDevicesAsApiDevices=0
ZE_AFFINITY_MASK=0,1
Then all tiles in card 0 and card 1 need to be exposed.
With:
ReturnSubDevicesAsApiDevices=1
ZE_AFFINITY_MASK=0,3
Then card 0 tile 0, and card 1 tile 1 need to be exposed.
Related-To: NEO-7137
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
2023-02-02 10:54:47 +08:00
|
|
|
|
|
|
|
// Reserve at least for a size equal to rootDeviceEnvironments.size() times four,
|
|
|
|
// which is enough for typical configurations
|
2025-01-13 20:18:55 +08:00
|
|
|
uint32_t numRootDevices = static_cast<uint32_t>(rootDeviceEnvironments.size());
|
|
|
|
uint32_t numDevices = numRootDevices;
|
feature: Affinity mask plus ReturnSubDevicesAsApiDevices
When using ReturnSubDevicesAsApiDevices=1 to have
sub-devices-as-root-devices, then the driver should read the values
passed in the mask as those corresponding to the physical
sub-devices.
For instance, in a dual system with multi-tile device, we would have:
card 0, tile 0
card 0, tile 1
card 1, tile 0
card 1, tile 1
With:
ReturnSubDevicesAsApiDevices=0
ZE_AFFINITY_MASK=0,1
Then all tiles in card 0 and card 1 need to be exposed.
With:
ReturnSubDevicesAsApiDevices=1
ZE_AFFINITY_MASK=0,3
Then card 0 tile 0, and card 1 tile 1 need to be exposed.
Related-To: NEO-7137
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
2023-02-02 10:54:47 +08:00
|
|
|
size_t reservedSizeForIndices = numRootDevices * 4;
|
2025-01-13 20:18:55 +08:00
|
|
|
RootDeviceIndicesMap mapOfIndices;
|
2023-10-10 23:03:57 +08:00
|
|
|
mapOfIndices.reserve(reservedSizeForIndices);
|
2023-08-16 11:00:31 +08:00
|
|
|
uint32_t hwSubDevicesCount = 0u;
|
2025-01-13 20:18:55 +08:00
|
|
|
|
2025-01-15 00:36:45 +08:00
|
|
|
if (exposeSubDevices) {
|
2025-01-13 20:18:55 +08:00
|
|
|
for (uint32_t currentRootDevice = 0u; currentRootDevice < numRootDevices; currentRootDevice++) {
|
feature: Affinity mask plus ReturnSubDevicesAsApiDevices
When using ReturnSubDevicesAsApiDevices=1 to have
sub-devices-as-root-devices, then the driver should read the values
passed in the mask as those corresponding to the physical
sub-devices.
For instance, in a dual system with multi-tile device, we would have:
card 0, tile 0
card 0, tile 1
card 1, tile 0
card 1, tile 1
With:
ReturnSubDevicesAsApiDevices=0
ZE_AFFINITY_MASK=0,1
Then all tiles in card 0 and card 1 need to be exposed.
With:
ReturnSubDevicesAsApiDevices=1
ZE_AFFINITY_MASK=0,3
Then card 0 tile 0, and card 1 tile 1 need to be exposed.
Related-To: NEO-7137
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
2023-02-02 10:54:47 +08:00
|
|
|
auto hwInfo = rootDeviceEnvironments[currentRootDevice]->getHardwareInfo();
|
2025-01-13 20:18:55 +08:00
|
|
|
|
2023-10-26 21:04:39 +08:00
|
|
|
hwSubDevicesCount = GfxCoreHelper::getSubDevicesCount(hwInfo);
|
feature: Affinity mask plus ReturnSubDevicesAsApiDevices
When using ReturnSubDevicesAsApiDevices=1 to have
sub-devices-as-root-devices, then the driver should read the values
passed in the mask as those corresponding to the physical
sub-devices.
For instance, in a dual system with multi-tile device, we would have:
card 0, tile 0
card 0, tile 1
card 1, tile 0
card 1, tile 1
With:
ReturnSubDevicesAsApiDevices=0
ZE_AFFINITY_MASK=0,1
Then all tiles in card 0 and card 1 need to be exposed.
With:
ReturnSubDevicesAsApiDevices=1
ZE_AFFINITY_MASK=0,3
Then card 0 tile 0, and card 1 tile 1 need to be exposed.
Related-To: NEO-7137
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
2023-02-02 10:54:47 +08:00
|
|
|
uint32_t currentSubDevice = 0;
|
2023-10-10 23:03:57 +08:00
|
|
|
mapOfIndices.push_back(std::make_tuple(currentRootDevice, currentSubDevice));
|
2023-08-16 11:00:31 +08:00
|
|
|
for (currentSubDevice = 1; currentSubDevice < hwSubDevicesCount; currentSubDevice++) {
|
2023-10-10 23:03:57 +08:00
|
|
|
mapOfIndices.push_back(std::make_tuple(currentRootDevice, currentSubDevice));
|
feature: Affinity mask plus ReturnSubDevicesAsApiDevices
When using ReturnSubDevicesAsApiDevices=1 to have
sub-devices-as-root-devices, then the driver should read the values
passed in the mask as those corresponding to the physical
sub-devices.
For instance, in a dual system with multi-tile device, we would have:
card 0, tile 0
card 0, tile 1
card 1, tile 0
card 1, tile 1
With:
ReturnSubDevicesAsApiDevices=0
ZE_AFFINITY_MASK=0,1
Then all tiles in card 0 and card 1 need to be exposed.
With:
ReturnSubDevicesAsApiDevices=1
ZE_AFFINITY_MASK=0,3
Then card 0 tile 0, and card 1 tile 1 need to be exposed.
Related-To: NEO-7137
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
2023-02-02 10:54:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-13 20:18:55 +08:00
|
|
|
numDevices = static_cast<uint32_t>(mapOfIndices.size());
|
feature: Affinity mask plus ReturnSubDevicesAsApiDevices
When using ReturnSubDevicesAsApiDevices=1 to have
sub-devices-as-root-devices, then the driver should read the values
passed in the mask as those corresponding to the physical
sub-devices.
For instance, in a dual system with multi-tile device, we would have:
card 0, tile 0
card 0, tile 1
card 1, tile 0
card 1, tile 1
With:
ReturnSubDevicesAsApiDevices=0
ZE_AFFINITY_MASK=0,1
Then all tiles in card 0 and card 1 need to be exposed.
With:
ReturnSubDevicesAsApiDevices=1
ZE_AFFINITY_MASK=0,3
Then card 0 tile 0, and card 1 tile 1 need to be exposed.
Related-To: NEO-7137
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
2023-02-02 10:54:47 +08:00
|
|
|
}
|
2021-05-05 16:07:53 +08:00
|
|
|
|
|
|
|
std::vector<AffinityMaskHelper> affinityMaskHelper(numRootDevices);
|
2021-01-25 17:24:00 +08:00
|
|
|
|
2021-05-06 00:00:12 +08:00
|
|
|
auto affinityMaskEntries = StringHelpers::split(affinityMaskString, ",");
|
|
|
|
|
2023-08-16 11:00:31 +08:00
|
|
|
// Index of the Device to be returned to the user, not the physcial device index.
|
|
|
|
uint32_t deviceIndex = 0;
|
2021-05-06 00:00:12 +08:00
|
|
|
for (const auto &entry : affinityMaskEntries) {
|
|
|
|
auto subEntries = StringHelpers::split(entry, ".");
|
2025-01-13 20:18:55 +08:00
|
|
|
uint32_t entryIndex = StringHelpers::toUint32t(subEntries[0]);
|
2021-05-06 00:00:12 +08:00
|
|
|
|
2025-01-13 20:18:55 +08:00
|
|
|
if (entryIndex >= numDevices) {
|
|
|
|
continue;
|
2025-01-15 00:36:45 +08:00
|
|
|
} else if (exposeSubDevices) {
|
2025-01-13 20:18:55 +08:00
|
|
|
// tiles as devices
|
feature: Affinity mask plus ReturnSubDevicesAsApiDevices
When using ReturnSubDevicesAsApiDevices=1 to have
sub-devices-as-root-devices, then the driver should read the values
passed in the mask as those corresponding to the physical
sub-devices.
For instance, in a dual system with multi-tile device, we would have:
card 0, tile 0
card 0, tile 1
card 1, tile 0
card 1, tile 1
With:
ReturnSubDevicesAsApiDevices=0
ZE_AFFINITY_MASK=0,1
Then all tiles in card 0 and card 1 need to be exposed.
With:
ReturnSubDevicesAsApiDevices=1
ZE_AFFINITY_MASK=0,3
Then card 0 tile 0, and card 1 tile 1 need to be exposed.
Related-To: NEO-7137
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
2023-02-02 10:54:47 +08:00
|
|
|
// so ignore X.Y
|
|
|
|
if (subEntries.size() > 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2025-01-13 20:18:55 +08:00
|
|
|
std::tuple<uint32_t, uint32_t> indexKey = mapOfIndices[entryIndex];
|
2023-08-16 11:00:31 +08:00
|
|
|
auto hwDeviceIndex = std::get<0>(indexKey);
|
feature: Affinity mask plus ReturnSubDevicesAsApiDevices
When using ReturnSubDevicesAsApiDevices=1 to have
sub-devices-as-root-devices, then the driver should read the values
passed in the mask as those corresponding to the physical
sub-devices.
For instance, in a dual system with multi-tile device, we would have:
card 0, tile 0
card 0, tile 1
card 1, tile 0
card 1, tile 1
With:
ReturnSubDevicesAsApiDevices=0
ZE_AFFINITY_MASK=0,1
Then all tiles in card 0 and card 1 need to be exposed.
With:
ReturnSubDevicesAsApiDevices=1
ZE_AFFINITY_MASK=0,3
Then card 0 tile 0, and card 1 tile 1 need to be exposed.
Related-To: NEO-7137
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
2023-02-02 10:54:47 +08:00
|
|
|
auto tileIndex = std::get<1>(indexKey);
|
2025-01-13 20:18:55 +08:00
|
|
|
|
2023-08-16 11:00:31 +08:00
|
|
|
affinityMaskHelper[hwDeviceIndex].enableGenericSubDevice(tileIndex);
|
|
|
|
// Store the Physical Hierarchy for this SubDevice mapped to the Device Index passed to the user.
|
|
|
|
mapOfSubDeviceIndices[deviceIndex++] = std::make_tuple(hwDeviceIndex, tileIndex, hwSubDevicesCount);
|
2025-01-13 20:18:55 +08:00
|
|
|
} else {
|
|
|
|
// cards as devices
|
|
|
|
auto hwInfo = rootDeviceEnvironments[entryIndex]->getHardwareInfo();
|
2023-10-26 21:04:39 +08:00
|
|
|
auto subDevicesCount = GfxCoreHelper::getSubDevicesCount(hwInfo);
|
2021-05-05 16:07:53 +08:00
|
|
|
|
2021-05-06 19:33:39 +08:00
|
|
|
if (subEntries.size() > 1) {
|
2021-05-06 00:00:12 +08:00
|
|
|
uint32_t subDeviceIndex = StringHelpers::toUint32t(subEntries[1]);
|
2021-05-06 19:33:39 +08:00
|
|
|
|
2024-10-08 21:23:41 +08:00
|
|
|
if (subDeviceIndex < subDevicesCount) {
|
2021-05-06 19:33:39 +08:00
|
|
|
if (subEntries.size() == 2) {
|
2023-08-16 11:00:31 +08:00
|
|
|
// Store the Physical Hierarchy for this SubDevice mapped to the Device Index passed to the user.
|
2025-01-13 20:18:55 +08:00
|
|
|
mapOfSubDeviceIndices[entryIndex] = std::make_tuple(entryIndex, subDeviceIndex, subDevicesCount);
|
|
|
|
affinityMaskHelper[entryIndex].enableGenericSubDevice(subDeviceIndex); // Mask: X.Y
|
2021-05-06 19:33:39 +08:00
|
|
|
} else {
|
|
|
|
UNRECOVERABLE_IF(subEntries.size() != 3);
|
|
|
|
}
|
2021-01-25 17:24:00 +08:00
|
|
|
}
|
|
|
|
} else {
|
2025-01-13 20:18:55 +08:00
|
|
|
affinityMaskHelper[entryIndex].enableAllGenericSubDevices(subDevicesCount); // Mask: X
|
2021-01-25 17:24:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<RootDeviceEnvironment>> filteredEnvironments;
|
2021-05-05 16:07:53 +08:00
|
|
|
for (uint32_t i = 0u; i < numRootDevices; i++) {
|
|
|
|
if (!affinityMaskHelper[i].isDeviceEnabled()) {
|
2021-01-25 17:24:00 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-05-05 16:07:53 +08:00
|
|
|
rootDeviceEnvironments[i]->deviceAffinityMask = affinityMaskHelper[i];
|
2021-01-25 17:24:00 +08:00
|
|
|
filteredEnvironments.emplace_back(rootDeviceEnvironments[i].release());
|
|
|
|
}
|
|
|
|
|
|
|
|
rootDeviceEnvironments.swap(filteredEnvironments);
|
|
|
|
}
|
2022-07-25 20:13:27 +08:00
|
|
|
|
2023-07-11 18:55:25 +08:00
|
|
|
void ExecutionEnvironment::sortNeoDevices() {
|
|
|
|
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber);
|
|
|
|
}
|
|
|
|
|
2025-01-15 00:36:45 +08:00
|
|
|
void ExecutionEnvironment::setDeviceHierarchyMode(const GfxCoreHelper &gfxCoreHelper) {
|
2023-10-06 07:12:34 +08:00
|
|
|
NEO::EnvironmentVariableReader envReader;
|
2025-01-15 00:36:45 +08:00
|
|
|
std::string deviceHierarchyMode = envReader.getSetting("ZE_FLAT_DEVICE_HIERARCHY", std::string(""));
|
|
|
|
if (strcmp(deviceHierarchyMode.c_str(), "COMPOSITE") == 0) {
|
2025-01-16 22:25:29 +08:00
|
|
|
this->deviceHierarchyMode = DeviceHierarchyMode::composite;
|
2025-01-15 00:36:45 +08:00
|
|
|
} else if (strcmp(deviceHierarchyMode.c_str(), "FLAT") == 0) {
|
2025-01-16 22:25:29 +08:00
|
|
|
this->deviceHierarchyMode = DeviceHierarchyMode::flat;
|
2025-01-15 00:36:45 +08:00
|
|
|
} else if (strcmp(deviceHierarchyMode.c_str(), "COMBINED") == 0) {
|
2025-01-16 22:25:29 +08:00
|
|
|
this->deviceHierarchyMode = DeviceHierarchyMode::combined;
|
2025-01-15 00:36:45 +08:00
|
|
|
} else {
|
|
|
|
this->deviceHierarchyMode = gfxCoreHelper.getDefaultDeviceHierarchy();
|
2023-10-06 07:12:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-22 16:48:55 +08:00
|
|
|
void ExecutionEnvironment::adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const {
|
|
|
|
auto hwInfo = rootDeviceEnvironment->getMutableHardwareInfo();
|
2022-12-06 19:19:36 +08:00
|
|
|
auto &productHelper = rootDeviceEnvironment->getHelper<ProductHelper>();
|
|
|
|
productHelper.adjustNumberOfCcs(*hwInfo);
|
2022-09-22 16:48:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExecutionEnvironment::adjustCcsCount() {
|
2022-07-25 20:13:27 +08:00
|
|
|
parseCcsCountLimitations();
|
|
|
|
|
2022-09-22 16:48:55 +08:00
|
|
|
for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) {
|
|
|
|
auto &rootDeviceEnvironment = rootDeviceEnvironments[rootDeviceIndex];
|
2022-07-25 20:13:27 +08:00
|
|
|
UNRECOVERABLE_IF(!rootDeviceEnvironment);
|
|
|
|
if (!rootDeviceEnvironment->isNumberOfCcsLimited()) {
|
2022-09-22 16:48:55 +08:00
|
|
|
adjustCcsCountImpl(rootDeviceEnvironment.get());
|
2022-07-25 20:13:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-22 16:48:55 +08:00
|
|
|
void ExecutionEnvironment::adjustCcsCount(const uint32_t rootDeviceIndex) const {
|
|
|
|
auto &rootDeviceEnvironment = rootDeviceEnvironments[rootDeviceIndex];
|
|
|
|
UNRECOVERABLE_IF(!rootDeviceEnvironment);
|
|
|
|
if (rootDeviceNumCcsMap.find(rootDeviceIndex) != rootDeviceNumCcsMap.end()) {
|
|
|
|
rootDeviceEnvironment->limitNumberOfCcs(rootDeviceNumCcsMap.at(rootDeviceIndex));
|
|
|
|
} else {
|
|
|
|
adjustCcsCountImpl(rootDeviceEnvironment.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExecutionEnvironment::parseCcsCountLimitations() {
|
2023-11-30 16:32:25 +08:00
|
|
|
const auto &numberOfCcsString = debugManager.flags.ZEX_NUMBER_OF_CCS.get();
|
2022-07-25 20:13:27 +08:00
|
|
|
|
|
|
|
if (numberOfCcsString.compare("default") == 0 ||
|
|
|
|
numberOfCcsString.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint32_t numRootDevices = static_cast<uint32_t>(rootDeviceEnvironments.size());
|
|
|
|
|
|
|
|
auto numberOfCcsEntries = StringHelpers::split(numberOfCcsString, ",");
|
|
|
|
|
|
|
|
for (const auto &entry : numberOfCcsEntries) {
|
|
|
|
auto subEntries = StringHelpers::split(entry, ":");
|
|
|
|
uint32_t rootDeviceIndex = StringHelpers::toUint32t(subEntries[0]);
|
|
|
|
|
|
|
|
if (rootDeviceIndex < numRootDevices) {
|
|
|
|
if (subEntries.size() > 1) {
|
|
|
|
uint32_t maxCcsCount = StringHelpers::toUint32t(subEntries[1]);
|
2022-09-22 16:48:55 +08:00
|
|
|
rootDeviceNumCcsMap.insert({rootDeviceIndex, maxCcsCount});
|
2022-07-25 20:13:27 +08:00
|
|
|
rootDeviceEnvironments[rootDeviceIndex]->limitNumberOfCcs(maxCcsCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-26 20:41:36 +08:00
|
|
|
|
|
|
|
void ExecutionEnvironment::configureNeoEnvironment() {
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.NEO_CAL_ENABLED.get()) {
|
|
|
|
debugManager.flags.UseKmdMigration.setIfDefault(0);
|
|
|
|
debugManager.flags.SplitBcsSize.setIfDefault(256);
|
2022-10-26 20:41:36 +08:00
|
|
|
}
|
|
|
|
}
|
2023-06-13 23:19:02 +08:00
|
|
|
|
|
|
|
bool ExecutionEnvironment::comparePciIdBusNumber(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2) {
|
2023-11-30 16:32:25 +08:00
|
|
|
const auto pciOrderVar = debugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.get();
|
2023-06-13 23:19:02 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|