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-06 18:57:00 +01:00
|
|
|
#include "core/device/device.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2020-02-19 16:32:40 +01:00
|
|
|
#include "core/command_stream/experimental_command_buffer.h"
|
2019-11-15 16:20:45 +01:00
|
|
|
#include "core/command_stream/preemption.h"
|
2020-01-07 07:42:40 +01:00
|
|
|
#include "core/execution_environment/root_device_environment.h"
|
2019-11-13 10:01:19 +01:00
|
|
|
#include "core/helpers/hw_helper.h"
|
2020-02-07 17:00:20 +01:00
|
|
|
#include "core/memory_manager/memory_manager.h"
|
2020-01-13 14:47:05 +01:00
|
|
|
#include "core/os_interface/os_context.h"
|
2020-01-21 15:24:52 +01:00
|
|
|
#include "core/os_interface/os_interface.h"
|
|
|
|
#include "core/os_interface/os_time.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/command_stream/command_stream_receiver.h"
|
2018-04-18 14:59:28 +02:00
|
|
|
#include "runtime/device/driver_info.h"
|
2018-04-23 14:26:03 +02:00
|
|
|
#include "runtime/source_level_debugger/source_level_debugger.h"
|
2019-02-27 11:39:32 +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) {
|
2017-12-21 00:45:38 +01:00
|
|
|
deviceExtensions.reserve(1000);
|
2018-06-21 10:47:21 +02:00
|
|
|
name.reserve(100);
|
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()) {
|
|
|
|
this->executionEnvironment->initDebugger();
|
|
|
|
}
|
|
|
|
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
|
|
|
hwHelper.setupHardwareCapabilities(&this->hardwareCapabilities, hwInfo);
|
|
|
|
|
2019-01-23 11:59:54 +01:00
|
|
|
executionEnvironment->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;
|
|
|
|
}
|
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
|
|
|
}
|
2019-02-07 09:36:39 +01:00
|
|
|
driverInfo.reset(DriverInfo::create(osInterface));
|
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();
|
2019-05-08 16:00:24 +02:00
|
|
|
auto &gpgpuEngines = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getGpgpuEngineInstances();
|
2018-11-28 09:02:55 +01:00
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
2019-10-24 13:34:25 +02:00
|
|
|
bool Device::createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engineType) {
|
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
|
|
|
|
|
|
|
bool internalUsage = (deviceCsrIndex == HwHelper::internalUsageEngineIndex);
|
|
|
|
if (internalUsage) {
|
|
|
|
engineType = defaultEngineType;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-07-16 09:23:02 +02:00
|
|
|
bool lowPriority = (deviceCsrIndex == HwHelper::lowPriorityGpgpuEngineIndex);
|
2019-11-05 13:38:20 +01:00
|
|
|
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(), engineType,
|
2019-12-03 10:15:46 +01:00
|
|
|
getDeviceBitfield(), preemptionMode, lowPriority);
|
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-01-15 17:02:47 +01:00
|
|
|
if (!commandStreamReceiver->initDirectSubmission(*this, *osContext)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-05 13:38:20 +01:00
|
|
|
engines.push_back({commandStreamReceiver.get(), osContext});
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Device::getSupportedClVersion() const {
|
2019-05-06 12:33:44 +02:00
|
|
|
return getHardwareInfo().capabilityTable.clVersionSupport;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
2020-02-06 18:57:00 +01:00
|
|
|
void Device::appendOSExtensions(const std::string &newExtensions) {
|
|
|
|
deviceExtensions += newExtensions;
|
|
|
|
deviceInfo.deviceExtensions = deviceExtensions.c_str();
|
|
|
|
}
|
|
|
|
|
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);
|
2018-11-21 09:57:51 +01:00
|
|
|
if (engines[0].commandStreamReceiver->getType() != CommandStreamReceiverType::CSR_HW) {
|
2018-06-06 10:34:51 +02:00
|
|
|
simulation = true;
|
|
|
|
}
|
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
|
|
|
|
2019-03-27 10:06:29 +01:00
|
|
|
EngineControl &Device::getEngine(aub_stream::EngineType engineType, bool lowPriority) {
|
2019-03-23 14:26:06 +01:00
|
|
|
for (auto &engine : engines) {
|
|
|
|
if (engine.osContext->getEngineType() == engineType &&
|
|
|
|
engine.osContext->isLowPriority() == lowPriority) {
|
|
|
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|