2019-08-27 15:34:20 +08:00
|
|
|
/*
|
2025-01-15 21:44:10 +08:00
|
|
|
* Copyright (C) 2019-2025 Intel Corporation
|
2019-08-27 15:34:20 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/device/root_device.h"
|
2019-08-27 15:34:20 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/command_stream/preemption.h"
|
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
|
|
|
#include "shared/source/device/sub_device.h"
|
2022-12-29 20:27:52 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
2022-12-16 01:32:03 +08:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2020-10-19 16:02:28 +08:00
|
|
|
#include "shared/source/helpers/api_specific_config.h"
|
2023-02-02 00:23:01 +08:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2023-02-06 17:05:43 +08:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2024-10-26 00:13:17 +08:00
|
|
|
#include "shared/source/os_interface/debug_env_reader.h"
|
2024-08-27 02:15:34 +08:00
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2025-04-24 18:45:06 +08:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2021-01-26 19:22:10 +08:00
|
|
|
#include "shared/source/utilities/software_tags_manager.h"
|
2019-08-27 15:34:20 +08:00
|
|
|
|
|
|
|
namespace NEO {
|
2020-10-29 22:33:35 +08:00
|
|
|
extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment,
|
|
|
|
uint32_t rootDeviceIndex,
|
|
|
|
const DeviceBitfield deviceBitfield);
|
2020-01-20 14:02:07 +08:00
|
|
|
|
2021-12-16 19:08:32 +08:00
|
|
|
RootDevice::RootDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) : Device(executionEnvironment, rootDeviceIndex) {}
|
2019-08-27 15:34:20 +08:00
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
RootDevice::~RootDevice() {
|
2024-07-02 03:50:09 +08:00
|
|
|
if (getDebugSurface()) {
|
2024-09-11 19:21:09 +08:00
|
|
|
|
|
|
|
for (auto *subDevice : this->getSubDevices()) {
|
|
|
|
if (subDevice) {
|
|
|
|
subDevice->setDebugSurface(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 03:50:09 +08:00
|
|
|
getMemoryManager()->freeGraphicsMemory(debugSurface);
|
|
|
|
debugSurface = nullptr;
|
|
|
|
}
|
2021-01-26 19:22:10 +08:00
|
|
|
if (getRootDeviceEnvironment().tagsManager) {
|
|
|
|
getRootDeviceEnvironment().tagsManager->shutdown();
|
|
|
|
}
|
2020-01-14 21:32:11 +08:00
|
|
|
}
|
2019-08-28 19:12:44 +08:00
|
|
|
|
2021-04-08 01:00:33 +08:00
|
|
|
Device *RootDevice::getRootDevice() const {
|
|
|
|
return const_cast<RootDevice *>(this);
|
2020-07-15 18:38:34 +08:00
|
|
|
}
|
2019-10-10 21:56:10 +08:00
|
|
|
|
2021-04-22 22:28:27 +08:00
|
|
|
void RootDevice::createBindlessHeapsHelper() {
|
2023-05-30 16:26:29 +08:00
|
|
|
|
2024-10-26 00:13:17 +08:00
|
|
|
EnvironmentVariableReader envReader;
|
|
|
|
bool disableGlobalBindless = envReader.getSetting("NEO_L0_SYSMAN_NO_CONTEXT_MODE", false);
|
|
|
|
|
|
|
|
if (!disableGlobalBindless && ApiSpecificConfig::getGlobalBindlessHeapConfiguration(this->getReleaseHelper()) && ApiSpecificConfig::getBindlessMode(*this)) {
|
2024-03-20 19:45:31 +08:00
|
|
|
this->executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->createBindlessHeapsHelper(this, getNumGenericSubDevices() > 1);
|
2020-10-19 16:02:28 +08:00
|
|
|
}
|
2019-08-28 19:12:44 +08:00
|
|
|
}
|
2021-01-25 17:24:00 +08:00
|
|
|
|
2019-10-07 18:42:28 +08:00
|
|
|
bool RootDevice::createEngines() {
|
2021-04-27 17:51:03 +08:00
|
|
|
if (hasGenericSubDevices) {
|
2025-04-24 18:45:06 +08:00
|
|
|
if (getRootDeviceEnvironment().isExposeSingleDeviceMode()) {
|
|
|
|
return createSingleDeviceEngines();
|
|
|
|
}
|
2020-01-20 14:02:07 +08:00
|
|
|
initializeRootCommandStreamReceiver();
|
2021-04-27 17:51:03 +08:00
|
|
|
} else {
|
|
|
|
return Device::createEngines();
|
2019-10-07 18:42:28 +08:00
|
|
|
}
|
2021-04-27 17:51:03 +08:00
|
|
|
|
2019-10-07 18:42:28 +08:00
|
|
|
return true;
|
|
|
|
}
|
2020-01-20 14:02:07 +08:00
|
|
|
|
|
|
|
void RootDevice::initializeRootCommandStreamReceiver() {
|
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
auto defaultEngineType = getChosenEngineType(hwInfo);
|
2025-04-24 18:45:06 +08:00
|
|
|
EngineTypeUsage engineTypeUsage = {defaultEngineType, EngineUsage::regular};
|
|
|
|
|
|
|
|
createRootDeviceEngine(engineTypeUsage, getDeviceBitfield());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RootDevice::createRootDeviceEngine(EngineTypeUsage engineTypeUsage, DeviceBitfield deviceBitfield) {
|
|
|
|
std::unique_ptr<CommandStreamReceiver> rootCommandStreamReceiver(createCommandStream(*executionEnvironment, rootDeviceIndex, deviceBitfield));
|
|
|
|
|
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
auto engineType = engineTypeUsage.first;
|
2020-01-20 14:02:07 +08:00
|
|
|
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo);
|
|
|
|
|
2025-04-24 18:45:06 +08:00
|
|
|
EngineDescriptor engineDescriptor(EngineTypeUsage{engineType, EngineUsage::regular}, deviceBitfield, preemptionMode, deviceBitfield.count() > 1);
|
2021-08-12 01:36:00 +08:00
|
|
|
|
2024-08-27 02:15:34 +08:00
|
|
|
auto &gfxCoreHelper = getGfxCoreHelper();
|
2025-04-24 18:45:06 +08:00
|
|
|
bool isPrimaryEngine = EngineHelpers::isCcs(engineType);
|
|
|
|
DEBUG_BREAK_IF(EngineHelpers::isBcs(engineType));
|
|
|
|
|
|
|
|
isPrimaryEngine &= engineTypeUsage.second == EngineUsage::regular;
|
|
|
|
|
2024-08-27 02:15:34 +08:00
|
|
|
if (debugManager.flags.SecondaryContextEngineTypeMask.get() != -1) {
|
2025-04-24 18:45:06 +08:00
|
|
|
isPrimaryEngine &= (static_cast<uint32_t>(debugManager.flags.SecondaryContextEngineTypeMask.get()) & (1 << static_cast<uint32_t>(engineType))) != 0;
|
|
|
|
}
|
|
|
|
bool useContextGroup = isPrimaryEngine && gfxCoreHelper.areSecondaryContextsSupported();
|
|
|
|
|
|
|
|
if ((static_cast<uint32_t>(debugManager.flags.SecondaryContextEngineTypeMask.get()) & (1 << static_cast<uint32_t>(engineType))) == 0) {
|
|
|
|
useContextGroup = false;
|
2024-08-27 02:15:34 +08:00
|
|
|
}
|
|
|
|
|
2021-08-12 01:36:00 +08:00
|
|
|
auto osContext = getMemoryManager()->createAndRegisterOsContext(rootCommandStreamReceiver.get(), engineDescriptor);
|
2020-01-20 14:02:07 +08:00
|
|
|
|
2024-08-27 02:15:34 +08:00
|
|
|
osContext->setContextGroup(useContextGroup);
|
|
|
|
osContext->setIsPrimaryEngine(isPrimaryEngine);
|
|
|
|
|
2020-01-20 14:02:07 +08:00
|
|
|
rootCommandStreamReceiver->setupContext(*osContext);
|
2025-01-15 21:44:10 +08:00
|
|
|
rootCommandStreamReceiver->initializeResources(false, preemptionMode);
|
2020-01-20 14:02:07 +08:00
|
|
|
rootCommandStreamReceiver->initializeTagAllocation();
|
2020-02-06 03:00:08 +08:00
|
|
|
rootCommandStreamReceiver->createGlobalFenceAllocation();
|
2025-04-24 18:45:06 +08:00
|
|
|
if (EngineHelpers::isComputeEngine(engineType)) {
|
|
|
|
rootCsrCreated = true;
|
|
|
|
rootCommandStreamReceiver->createWorkPartitionAllocation(*this);
|
|
|
|
}
|
2020-01-20 14:02:07 +08:00
|
|
|
commandStreamReceivers.push_back(std::move(rootCommandStreamReceiver));
|
2020-12-30 21:36:22 +08:00
|
|
|
|
|
|
|
EngineControl engine{commandStreamReceivers.back().get(), osContext};
|
2021-12-13 20:45:24 +08:00
|
|
|
allEngines.push_back(engine);
|
2020-12-30 21:36:22 +08:00
|
|
|
addEngineToEngineGroup(engine);
|
2024-08-27 02:15:34 +08:00
|
|
|
|
|
|
|
if (useContextGroup) {
|
2025-04-24 18:45:06 +08:00
|
|
|
bool hpEngineAvailable = engineTypeUsage.second == EngineUsage::highPriority;
|
2024-08-27 02:15:34 +08:00
|
|
|
auto contextCount = gfxCoreHelper.getContextGroupContextsCount();
|
2025-04-24 18:45:06 +08:00
|
|
|
|
2024-08-27 02:15:34 +08:00
|
|
|
EngineGroupType engineGroupType = gfxCoreHelper.getEngineGroupType(engine.getEngineType(), engine.getEngineUsage(), hwInfo);
|
2025-04-24 18:45:06 +08:00
|
|
|
auto highPriorityContextCount = gfxCoreHelper.getContextGroupHpContextsCount(engineGroupType, hpEngineAvailable);
|
2024-08-27 02:15:34 +08:00
|
|
|
|
|
|
|
if (debugManager.flags.OverrideNumHighPriorityContexts.get() != -1) {
|
|
|
|
highPriorityContextCount = static_cast<uint32_t>(debugManager.flags.OverrideNumHighPriorityContexts.get());
|
|
|
|
}
|
2025-04-24 18:45:06 +08:00
|
|
|
|
|
|
|
if (getRootDeviceEnvironment().osInterface && getRootDeviceEnvironment().osInterface->getAggregatedProcessCount() > 1) {
|
|
|
|
const auto numProcesses = getRootDeviceEnvironment().osInterface->getAggregatedProcessCount();
|
|
|
|
|
|
|
|
contextCount = std::max(contextCount / numProcesses, 2u);
|
|
|
|
highPriorityContextCount = std::max(contextCount / 2, 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
UNRECOVERABLE_IF(secondaryEngines.find(engineType) != secondaryEngines.end());
|
|
|
|
auto &secondaryEnginesForType = secondaryEngines[engineType];
|
2024-08-27 02:15:34 +08:00
|
|
|
|
|
|
|
createSecondaryContexts(engine, secondaryEnginesForType, contextCount, contextCount - highPriorityContextCount, highPriorityContextCount);
|
|
|
|
}
|
2025-04-24 18:45:06 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RootDevice::createSingleDeviceEngines() {
|
|
|
|
|
|
|
|
auto &gfxCoreHelper = getGfxCoreHelper();
|
|
|
|
auto &gpgpuEngines = gfxCoreHelper.getGpgpuEngineInstances(getRootDeviceEnvironment());
|
|
|
|
|
|
|
|
for (auto &engine : gpgpuEngines) {
|
|
|
|
|
|
|
|
if (EngineHelpers::isComputeEngine(engine.first)) {
|
|
|
|
if (!createRootDeviceEngine(engine, getDeviceBitfield())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2020-01-20 14:02:07 +08:00
|
|
|
}
|
|
|
|
|
2019-08-27 15:34:20 +08:00
|
|
|
} // namespace NEO
|