2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2020-01-13 14:47:05 +01:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/device/device.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/command_stream/experimental_command_buffer.h"
|
|
|
|
#include "shared/source/command_stream/preemption.h"
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2020-02-24 18:04:30 +01:00
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2020-03-16 12:41:25 +01:00
|
|
|
#include "shared/source/os_interface/driver_info.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/os_context.h"
|
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
|
|
|
#include "shared/source/os_interface/os_time.h"
|
2020-03-06 10:11:44 +01:00
|
|
|
#include "shared/source/source_level_debugger/source_level_debugger.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
decltype(&PerformanceCounters::create) Device::createPerformanceCountersFunc = PerformanceCounters::create;
|
2019-11-05 13:38:20 +01:00
|
|
|
extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-11-05 13:38:20 +01:00
|
|
|
Device::Device(ExecutionEnvironment *executionEnvironment)
|
|
|
|
: executionEnvironment(executionEnvironment) {
|
2018-07-10 17:14:20 +02:00
|
|
|
this->executionEnvironment->incRefInternal();
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Device::~Device() {
|
2018-07-11 16:47:49 +02:00
|
|
|
DEBUG_BREAK_IF(nullptr == executionEnvironment->memoryManager.get());
|
2017-12-21 00:45:38 +01:00
|
|
|
if (performanceCounters) {
|
|
|
|
performanceCounters->shutdown();
|
|
|
|
}
|
2018-07-16 13:01:10 +02:00
|
|
|
|
2018-11-21 09:57:51 +01:00
|
|
|
for (auto &engine : engines) {
|
2019-01-10 13:57:40 +01:00
|
|
|
engine.commandStreamReceiver->flushBatchedSubmissions();
|
2018-03-09 14:48:42 +01:00
|
|
|
}
|
|
|
|
|
2019-11-05 13:38:20 +01:00
|
|
|
commandStreamReceivers.clear();
|
2019-02-19 08:55:11 +01:00
|
|
|
executionEnvironment->memoryManager->waitForDeletions();
|
2018-07-10 17:14:20 +02:00
|
|
|
executionEnvironment->decRefInternal();
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
bool Device::createDeviceImpl() {
|
2020-02-11 10:15:21 +01:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo);
|
|
|
|
|
|
|
|
if (!getDebugger()) {
|
2020-03-11 08:56:55 +01:00
|
|
|
this->executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->initDebugger();
|
2020-02-11 10:15:21 +01:00
|
|
|
}
|
|
|
|
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
|
|
|
hwHelper.setupHardwareCapabilities(&this->hardwareCapabilities, hwInfo);
|
2020-02-25 16:38:47 +01:00
|
|
|
executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->initGmm();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
if (!createEngines()) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-06 19:02:24 +01:00
|
|
|
|
|
|
|
getDefaultEngine().osContext->setDefaultContext(true);
|
|
|
|
|
|
|
|
for (auto &engine : engines) {
|
|
|
|
auto commandStreamReceiver = engine.commandStreamReceiver;
|
|
|
|
auto osContext = engine.osContext;
|
|
|
|
if (!commandStreamReceiver->initDirectSubmission(*this, *osContext)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 09:36:39 +01:00
|
|
|
executionEnvironment->memoryManager->setDefaultEngineIndex(defaultEngineIndex);
|
2018-11-28 09:02:55 +01:00
|
|
|
|
2020-01-07 07:42:40 +01:00
|
|
|
auto osInterface = getRootDeviceEnvironment().osInterface.get();
|
2018-11-21 09:57:51 +01:00
|
|
|
|
2019-02-07 09:36:39 +01:00
|
|
|
if (!osTime) {
|
|
|
|
osTime = OSTime::create(osInterface);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
2018-07-16 17:11:43 +02:00
|
|
|
|
2019-02-07 09:36:39 +01:00
|
|
|
initializeCaps();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-02-07 09:36:39 +01:00
|
|
|
if (osTime->getOSInterface()) {
|
2019-05-06 12:33:44 +02:00
|
|
|
if (hwInfo.capabilityTable.instrumentationEnabled) {
|
2019-05-20 11:19:27 +02:00
|
|
|
performanceCounters = createPerformanceCountersFunc(this);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 09:36:39 +01:00
|
|
|
executionEnvironment->memoryManager->setForce32BitAllocations(getDeviceInfo().force32BitAddressess);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-06-27 21:33:05 +02:00
|
|
|
if (DebugManager.flags.EnableExperimentalCommandBuffer.get() > 0) {
|
|
|
|
for (auto &engine : engines) {
|
|
|
|
auto csr = engine.commandStreamReceiver;
|
2019-02-07 09:36:39 +01:00
|
|
|
csr->setExperimentalCmdBuffer(std::make_unique<ExperimentalCommandBuffer>(csr, getDeviceInfo().profilingTimerResolution));
|
2018-11-28 09:02:55 +01:00
|
|
|
}
|
2018-07-05 11:23:28 +02:00
|
|
|
}
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
bool Device::createEngines() {
|
|
|
|
auto &hwInfo = getHardwareInfo();
|
2020-02-21 15:25:04 +01:00
|
|
|
auto gpgpuEngines = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getGpgpuEngineInstances(hwInfo);
|
2018-11-28 09:02:55 +01:00
|
|
|
|
2020-07-28 01:36:52 -07:00
|
|
|
this->engineGroups.resize(static_cast<uint32_t>(EngineGroupType::MaxEngineGroups));
|
2019-01-10 13:57:40 +01:00
|
|
|
for (uint32_t deviceCsrIndex = 0; deviceCsrIndex < gpgpuEngines.size(); deviceCsrIndex++) {
|
2019-10-24 13:34:25 +02:00
|
|
|
if (!createEngine(deviceCsrIndex, gpgpuEngines[deviceCsrIndex])) {
|
2018-11-28 09:02:55 +01:00
|
|
|
return false;
|
|
|
|
}
|
2019-07-16 09:23:02 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-28 09:02:55 +01:00
|
|
|
|
2019-11-05 13:38:20 +01:00
|
|
|
std::unique_ptr<CommandStreamReceiver> Device::createCommandStreamReceiver() const {
|
|
|
|
return std::unique_ptr<CommandStreamReceiver>(createCommandStream(*executionEnvironment, getRootDeviceIndex()));
|
|
|
|
}
|
|
|
|
|
2020-09-15 17:29:02 +02:00
|
|
|
bool Device::createEngine(uint32_t deviceCsrIndex, EngineTypeUsage engineTypeUsage) {
|
2019-07-16 09:23:02 +02:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
auto defaultEngineType = getChosenEngineType(hwInfo);
|
2019-02-18 13:59:16 +01:00
|
|
|
|
2019-11-05 13:38:20 +01:00
|
|
|
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver = createCommandStreamReceiver();
|
|
|
|
if (!commandStreamReceiver) {
|
2019-07-16 09:23:02 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-10 09:44:00 +01:00
|
|
|
|
2020-09-15 17:29:02 +02:00
|
|
|
auto engineType = engineTypeUsage.first;
|
|
|
|
|
|
|
|
bool internalUsage = (engineTypeUsage.second == EngineUsage::Internal);
|
2020-09-04 16:18:12 -07:00
|
|
|
if (internalUsage) {
|
|
|
|
commandStreamReceiver->initializeDefaultsForInternalEngine();
|
|
|
|
}
|
2020-02-10 09:44:00 +01:00
|
|
|
|
2019-12-27 11:32:12 +01:00
|
|
|
if (commandStreamReceiver->needsPageTableManager(engineType)) {
|
2019-11-05 13:38:20 +01:00
|
|
|
commandStreamReceiver->createPageTableManager();
|
|
|
|
}
|
2018-11-28 09:02:55 +01:00
|
|
|
|
2020-09-15 17:29:02 +02:00
|
|
|
bool lowPriority = (engineTypeUsage.second == EngineUsage::LowPriority);
|
2019-11-05 13:38:20 +01:00
|
|
|
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(), engineType,
|
2020-03-03 23:33:31 +01:00
|
|
|
getDeviceBitfield(), preemptionMode,
|
|
|
|
lowPriority, internalUsage, false);
|
2019-07-16 09:23:02 +02:00
|
|
|
commandStreamReceiver->setupContext(*osContext);
|
|
|
|
|
|
|
|
if (!commandStreamReceiver->initializeTagAllocation()) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-05 20:00:08 +01:00
|
|
|
|
|
|
|
if (!commandStreamReceiver->createGlobalFenceAllocation()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-21 09:35:12 +01:00
|
|
|
if (engineType == defaultEngineType && !lowPriority && !internalUsage) {
|
2019-07-16 09:23:02 +02:00
|
|
|
defaultEngineIndex = deviceCsrIndex;
|
|
|
|
}
|
2019-06-27 21:33:05 +02:00
|
|
|
|
2020-02-10 15:57:49 +01:00
|
|
|
if ((preemptionMode == PreemptionMode::MidThread || isDebuggerActive()) && !commandStreamReceiver->createPreemptionAllocation()) {
|
2019-07-16 09:23:02 +02:00
|
|
|
return false;
|
2018-11-28 09:02:55 +01:00
|
|
|
}
|
2019-07-16 09:23:02 +02:00
|
|
|
|
2020-07-28 01:36:52 -07:00
|
|
|
EngineControl engine{commandStreamReceiver.get(), osContext};
|
|
|
|
engines.push_back(engine);
|
|
|
|
if (!lowPriority && !internalUsage) {
|
|
|
|
const auto &hardwareInfo = this->getHardwareInfo();
|
|
|
|
auto &hwHelper = NEO::HwHelper::get(hardwareInfo.platform.eRenderCoreFamily);
|
|
|
|
hwHelper.addEngineToEngineGroup(engineGroups, engine, hwInfo);
|
|
|
|
}
|
|
|
|
|
2019-11-05 13:38:20 +01:00
|
|
|
commandStreamReceivers.push_back(std::move(commandStreamReceiver));
|
2019-07-16 09:23:02 +02:00
|
|
|
|
2018-11-28 09:02:55 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-12 11:27:28 +01:00
|
|
|
const HardwareInfo &Device::getHardwareInfo() const { return *getRootDeviceEnvironment().getHardwareInfo(); }
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
const DeviceInfo &Device::getDeviceInfo() const {
|
|
|
|
return deviceInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Device::getProfilingTimerResolution() {
|
2019-05-06 12:33:44 +02:00
|
|
|
return osTime->getDynamicDeviceTimerResolution(getHardwareInfo());
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
2018-07-11 10:32:17 +02:00
|
|
|
bool Device::isSimulation() const {
|
2019-05-06 12:33:44 +02:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
|
2019-05-08 16:00:24 +02:00
|
|
|
bool simulation = hwInfo.capabilityTable.isSimulation(hwInfo.platform.usDeviceID);
|
2020-05-14 13:12:17 +02:00
|
|
|
for (const auto &engine : engines) {
|
|
|
|
if (engine.commandStreamReceiver->getType() != CommandStreamReceiverType::CSR_HW) {
|
|
|
|
simulation = true;
|
|
|
|
}
|
2018-06-06 10:34:51 +02:00
|
|
|
}
|
2020-05-14 13:12:17 +02:00
|
|
|
|
2019-05-08 16:00:24 +02:00
|
|
|
if (hwInfo.featureTable.ftrSimulationMode) {
|
2018-07-11 10:32:17 +02:00
|
|
|
simulation = true;
|
|
|
|
}
|
2018-06-06 10:34:51 +02:00
|
|
|
return simulation;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
double Device::getPlatformHostTimerResolution() const {
|
|
|
|
if (osTime.get())
|
|
|
|
return osTime->getHostTimerResolution();
|
|
|
|
return 0.0;
|
|
|
|
}
|
2019-11-19 16:54:47 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
GFXCORE_FAMILY Device::getRenderCoreFamily() const {
|
2019-05-08 16:00:24 +02:00
|
|
|
return this->getHardwareInfo().platform.eRenderCoreFamily;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
2018-04-06 14:25:22 +02:00
|
|
|
|
2020-02-10 15:57:49 +01:00
|
|
|
bool Device::isDebuggerActive() const {
|
|
|
|
return deviceInfo.debuggerActive;
|
2018-04-06 14:25:22 +02:00
|
|
|
}
|
2018-11-22 13:57:10 +01:00
|
|
|
|
2020-09-15 17:29:02 +02:00
|
|
|
EngineControl &Device::getEngine(aub_stream::EngineType engineType, bool lowPriority, bool internalUsage) {
|
2019-03-23 14:26:06 +01:00
|
|
|
for (auto &engine : engines) {
|
|
|
|
if (engine.osContext->getEngineType() == engineType &&
|
2020-09-15 17:29:02 +02:00
|
|
|
engine.osContext->isLowPriority() == lowPriority &&
|
|
|
|
engine.osContext->isInternalEngine() == internalUsage) {
|
2019-03-23 14:26:06 +01:00
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
}
|
2019-04-09 17:46:23 +02:00
|
|
|
if (DebugManager.flags.OverrideInvalidEngineWithDefault.get()) {
|
|
|
|
return engines[0];
|
|
|
|
}
|
2019-03-23 14:26:06 +01:00
|
|
|
UNRECOVERABLE_IF(true);
|
|
|
|
}
|
2020-02-06 18:57:00 +01:00
|
|
|
|
2020-05-03 12:33:11 -07:00
|
|
|
EngineControl &Device::getEngine(uint32_t index) {
|
|
|
|
UNRECOVERABLE_IF(index >= engines.size());
|
|
|
|
return engines[index];
|
|
|
|
}
|
|
|
|
|
2020-02-06 18:57:00 +01:00
|
|
|
bool Device::getDeviceAndHostTimer(uint64_t *deviceTimestamp, uint64_t *hostTimestamp) const {
|
|
|
|
TimeStampData queueTimeStamp;
|
|
|
|
bool retVal = getOSTime()->getCpuGpuTime(&queueTimeStamp);
|
|
|
|
if (retVal) {
|
|
|
|
uint64_t resolution = (uint64_t)getOSTime()->getDynamicDeviceTimerResolution(getHardwareInfo());
|
|
|
|
*deviceTimestamp = queueTimeStamp.GPUTimeStamp * resolution;
|
|
|
|
}
|
|
|
|
|
|
|
|
retVal = getOSTime()->getCpuTime(hostTimestamp);
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Device::getHostTimer(uint64_t *hostTimestamp) const {
|
|
|
|
return getOSTime()->getCpuTime(hostTimestamp);
|
|
|
|
}
|
|
|
|
|
2020-02-24 18:04:30 +01:00
|
|
|
GmmClientContext *Device::getGmmClientContext() const {
|
|
|
|
return getGmmHelper()->getClientContext();
|
|
|
|
}
|
|
|
|
|
2020-04-16 14:44:03 +02:00
|
|
|
uint64_t Device::getGlobalMemorySize() const {
|
|
|
|
|
|
|
|
auto globalMemorySize = getMemoryManager()->isLocalMemorySupported(this->getRootDeviceIndex())
|
|
|
|
? getMemoryManager()->getLocalMemorySize(this->getRootDeviceIndex())
|
|
|
|
: getMemoryManager()->getSystemSharedMemory(this->getRootDeviceIndex());
|
|
|
|
globalMemorySize = std::min(globalMemorySize, getMemoryManager()->getMaxApplicationAddress() + 1);
|
|
|
|
globalMemorySize = static_cast<uint64_t>(static_cast<double>(globalMemorySize) * 0.8);
|
|
|
|
return globalMemorySize;
|
|
|
|
}
|
|
|
|
|
2020-06-18 17:08:55 +02:00
|
|
|
NEO::SourceLevelDebugger *Device::getSourceLevelDebugger() {
|
|
|
|
auto debugger = getDebugger();
|
|
|
|
if (debugger) {
|
|
|
|
return debugger->isLegacy() ? static_cast<NEO::SourceLevelDebugger *>(debugger) : nullptr;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-07-02 11:49:46 +02:00
|
|
|
const std::vector<EngineControl> &Device::getEngines() const {
|
|
|
|
return this->engines;
|
|
|
|
}
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|