2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-13 21:47:05 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-07-16 23:11:43 +08:00
|
|
|
#include "runtime/device/device.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2019-11-15 23:20:45 +08:00
|
|
|
#include "core/command_stream/preemption.h"
|
2020-01-07 14:42:40 +08:00
|
|
|
#include "core/execution_environment/root_device_environment.h"
|
2019-11-13 17:01:19 +08:00
|
|
|
#include "core/helpers/hw_helper.h"
|
2020-01-13 21:47:05 +08:00
|
|
|
#include "core/os_interface/os_context.h"
|
2020-01-21 22:24:52 +08:00
|
|
|
#include "core/os_interface/os_interface.h"
|
|
|
|
#include "core/os_interface/os_time.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/command_stream/command_stream_receiver.h"
|
2018-07-05 17:23:28 +08:00
|
|
|
#include "runtime/command_stream/experimental_command_buffer.h"
|
2018-04-18 20:59:28 +08:00
|
|
|
#include "runtime/device/driver_info.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/memory_manager/memory_manager.h"
|
2018-04-23 20:26:03 +08:00
|
|
|
#include "runtime/source_level_debugger/source_level_debugger.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
decltype(&PerformanceCounters::create) Device::createPerformanceCountersFunc = PerformanceCounters::create;
|
2019-11-05 20:38:20 +08:00
|
|
|
extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-11-05 20:38:20 +08:00
|
|
|
Device::Device(ExecutionEnvironment *executionEnvironment)
|
|
|
|
: executionEnvironment(executionEnvironment) {
|
2017-12-21 07:45:38 +08:00
|
|
|
memset(&deviceInfo, 0, sizeof(deviceInfo));
|
|
|
|
deviceExtensions.reserve(1000);
|
2018-06-21 16:47:21 +08:00
|
|
|
name.reserve(100);
|
2019-05-06 18:33:44 +08:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
2018-02-06 18:58:05 +08:00
|
|
|
preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo);
|
2018-10-02 04:36:15 +08:00
|
|
|
|
2018-07-12 21:47:48 +08:00
|
|
|
if (!getSourceLevelDebugger()) {
|
2019-01-23 18:59:54 +08:00
|
|
|
this->executionEnvironment->initSourceLevelDebugger();
|
2018-04-23 20:26:03 +08:00
|
|
|
}
|
2018-07-10 23:14:20 +08:00
|
|
|
this->executionEnvironment->incRefInternal();
|
2019-05-08 22:00:24 +08:00
|
|
|
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
2018-08-23 23:42:35 +08:00
|
|
|
hwHelper.setupHardwareCapabilities(&this->hardwareCapabilities, hwInfo);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Device::~Device() {
|
2018-07-11 22:47:49 +08:00
|
|
|
DEBUG_BREAK_IF(nullptr == executionEnvironment->memoryManager.get());
|
2017-12-21 07:45:38 +08:00
|
|
|
if (performanceCounters) {
|
|
|
|
performanceCounters->shutdown();
|
|
|
|
}
|
2018-07-16 19:01:10 +08:00
|
|
|
|
2018-11-21 16:57:51 +08:00
|
|
|
for (auto &engine : engines) {
|
2019-01-10 20:57:40 +08:00
|
|
|
engine.commandStreamReceiver->flushBatchedSubmissions();
|
2018-03-09 21:48:42 +08:00
|
|
|
}
|
|
|
|
|
2018-07-12 21:47:48 +08:00
|
|
|
if (deviceInfo.sourceLevelDebuggerActive && executionEnvironment->sourceLevelDebugger) {
|
|
|
|
executionEnvironment->sourceLevelDebugger->notifyDeviceDestruction();
|
2018-05-02 20:27:55 +08:00
|
|
|
}
|
2019-11-05 20:38:20 +08:00
|
|
|
commandStreamReceivers.clear();
|
2019-02-19 15:55:11 +08:00
|
|
|
executionEnvironment->memoryManager->waitForDeletions();
|
2018-07-10 23:14:20 +08:00
|
|
|
executionEnvironment->decRefInternal();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-05-06 18:33:44 +08:00
|
|
|
bool Device::createDeviceImpl() {
|
2019-01-23 18:59:54 +08:00
|
|
|
executionEnvironment->initGmm();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-05-06 18:33:44 +08:00
|
|
|
if (!createEngines()) {
|
2017-12-21 07:45:38 +08:00
|
|
|
return false;
|
|
|
|
}
|
2019-02-07 16:36:39 +08:00
|
|
|
executionEnvironment->memoryManager->setDefaultEngineIndex(defaultEngineIndex);
|
2018-11-28 16:02:55 +08:00
|
|
|
|
2020-01-07 14:42:40 +08:00
|
|
|
auto osInterface = getRootDeviceEnvironment().osInterface.get();
|
2018-11-21 16:57:51 +08:00
|
|
|
|
2019-02-07 16:36:39 +08:00
|
|
|
if (!osTime) {
|
|
|
|
osTime = OSTime::create(osInterface);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2019-02-07 16:36:39 +08:00
|
|
|
driverInfo.reset(DriverInfo::create(osInterface));
|
2018-07-16 23:11:43 +08:00
|
|
|
|
2019-02-07 16:36:39 +08:00
|
|
|
initializeCaps();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-05-06 18:33:44 +08:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
2019-02-07 16:36:39 +08:00
|
|
|
if (osTime->getOSInterface()) {
|
2019-05-06 18:33:44 +08:00
|
|
|
if (hwInfo.capabilityTable.instrumentationEnabled) {
|
2019-05-20 17:19:27 +08:00
|
|
|
performanceCounters = createPerformanceCountersFunc(this);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 20:26:03 +08:00
|
|
|
uint32_t deviceHandle = 0;
|
2018-11-28 16:02:55 +08:00
|
|
|
if (osInterface) {
|
|
|
|
deviceHandle = osInterface->getDeviceHandle();
|
2018-04-23 20:26:03 +08:00
|
|
|
}
|
|
|
|
|
2019-02-07 16:36:39 +08:00
|
|
|
if (deviceInfo.sourceLevelDebuggerActive) {
|
|
|
|
executionEnvironment->sourceLevelDebugger->notifyNewDevice(deviceHandle);
|
2018-04-23 20:26:03 +08:00
|
|
|
}
|
|
|
|
|
2019-02-07 16:36:39 +08:00
|
|
|
executionEnvironment->memoryManager->setForce32BitAllocations(getDeviceInfo().force32BitAddressess);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-06-28 03:33:05 +08:00
|
|
|
if (DebugManager.flags.EnableExperimentalCommandBuffer.get() > 0) {
|
|
|
|
for (auto &engine : engines) {
|
|
|
|
auto csr = engine.commandStreamReceiver;
|
2019-02-07 16:36:39 +08:00
|
|
|
csr->setExperimentalCmdBuffer(std::make_unique<ExperimentalCommandBuffer>(csr, getDeviceInfo().profilingTimerResolution));
|
2018-11-28 16:02:55 +08:00
|
|
|
}
|
2018-07-05 17:23:28 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-06 18:33:44 +08:00
|
|
|
bool Device::createEngines() {
|
|
|
|
auto &hwInfo = getHardwareInfo();
|
2019-05-08 22:00:24 +08:00
|
|
|
auto &gpgpuEngines = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getGpgpuEngineInstances();
|
2018-11-28 16:02:55 +08:00
|
|
|
|
2019-01-10 20:57:40 +08:00
|
|
|
for (uint32_t deviceCsrIndex = 0; deviceCsrIndex < gpgpuEngines.size(); deviceCsrIndex++) {
|
2019-10-24 19:34:25 +08:00
|
|
|
if (!createEngine(deviceCsrIndex, gpgpuEngines[deviceCsrIndex])) {
|
2018-11-28 16:02:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
2019-07-16 15:23:02 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-28 16:02:55 +08:00
|
|
|
|
2019-11-05 20:38:20 +08:00
|
|
|
std::unique_ptr<CommandStreamReceiver> Device::createCommandStreamReceiver() const {
|
|
|
|
return std::unique_ptr<CommandStreamReceiver>(createCommandStream(*executionEnvironment, getRootDeviceIndex()));
|
|
|
|
}
|
|
|
|
|
2019-10-24 19:34:25 +08:00
|
|
|
bool Device::createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engineType) {
|
2019-07-16 15:23:02 +08:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
auto defaultEngineType = getChosenEngineType(hwInfo);
|
2019-02-18 20:59:16 +08:00
|
|
|
|
2019-11-05 20:38:20 +08:00
|
|
|
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver = createCommandStreamReceiver();
|
|
|
|
if (!commandStreamReceiver) {
|
2019-07-16 15:23:02 +08:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-27 18:32:12 +08:00
|
|
|
if (commandStreamReceiver->needsPageTableManager(engineType)) {
|
2019-11-05 20:38:20 +08:00
|
|
|
commandStreamReceiver->createPageTableManager();
|
|
|
|
}
|
2018-11-28 16:02:55 +08:00
|
|
|
|
2019-07-16 15:23:02 +08:00
|
|
|
bool lowPriority = (deviceCsrIndex == HwHelper::lowPriorityGpgpuEngineIndex);
|
2020-01-21 16:35:12 +08:00
|
|
|
bool internalUsage = (deviceCsrIndex == HwHelper::internalUsageEngineIndex);
|
2019-11-05 20:38:20 +08:00
|
|
|
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(), engineType,
|
2019-12-03 17:15:46 +08:00
|
|
|
getDeviceBitfield(), preemptionMode, lowPriority);
|
2019-07-16 15:23:02 +08:00
|
|
|
commandStreamReceiver->setupContext(*osContext);
|
|
|
|
|
|
|
|
if (!commandStreamReceiver->initializeTagAllocation()) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-06 03:00:08 +08:00
|
|
|
|
|
|
|
if (!commandStreamReceiver->createGlobalFenceAllocation()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-21 16:35:12 +08:00
|
|
|
if (engineType == defaultEngineType && !lowPriority && !internalUsage) {
|
2019-07-16 15:23:02 +08:00
|
|
|
defaultEngineIndex = deviceCsrIndex;
|
|
|
|
}
|
2019-06-28 03:33:05 +08:00
|
|
|
|
2019-07-16 15:23:02 +08:00
|
|
|
if ((preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) && !commandStreamReceiver->createPreemptionAllocation()) {
|
|
|
|
return false;
|
2018-11-28 16:02:55 +08:00
|
|
|
}
|
2019-07-16 15:23:02 +08:00
|
|
|
|
2019-11-05 20:38:20 +08:00
|
|
|
engines.push_back({commandStreamReceiver.get(), osContext});
|
|
|
|
commandStreamReceivers.push_back(std::move(commandStreamReceiver));
|
2019-07-16 15:23:02 +08:00
|
|
|
|
2018-11-28 16:02:55 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-06 18:33:44 +08:00
|
|
|
const HardwareInfo &Device::getHardwareInfo() const { return *executionEnvironment->getHardwareInfo(); }
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
const DeviceInfo &Device::getDeviceInfo() const {
|
|
|
|
return deviceInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Device::getProfilingTimerResolution() {
|
2019-05-06 18:33:44 +08:00
|
|
|
return osTime->getDynamicDeviceTimerResolution(getHardwareInfo());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Device::getSupportedClVersion() const {
|
2019-05-06 18:33:44 +08:00
|
|
|
return getHardwareInfo().capabilityTable.clVersionSupport;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-07-11 16:32:17 +08:00
|
|
|
bool Device::isSimulation() const {
|
2019-05-06 18:33:44 +08:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
|
2019-05-08 22:00:24 +08:00
|
|
|
bool simulation = hwInfo.capabilityTable.isSimulation(hwInfo.platform.usDeviceID);
|
2018-11-21 16:57:51 +08:00
|
|
|
if (engines[0].commandStreamReceiver->getType() != CommandStreamReceiverType::CSR_HW) {
|
2018-06-06 16:34:51 +08:00
|
|
|
simulation = true;
|
|
|
|
}
|
2019-05-08 22:00:24 +08:00
|
|
|
if (hwInfo.featureTable.ftrSimulationMode) {
|
2018-07-11 16:32:17 +08:00
|
|
|
simulation = true;
|
|
|
|
}
|
2018-06-06 16:34:51 +08:00
|
|
|
return simulation;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
double Device::getPlatformHostTimerResolution() const {
|
|
|
|
if (osTime.get())
|
|
|
|
return osTime->getHostTimerResolution();
|
|
|
|
return 0.0;
|
|
|
|
}
|
2019-11-19 23:54:47 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
GFXCORE_FAMILY Device::getRenderCoreFamily() const {
|
2019-05-08 22:00:24 +08:00
|
|
|
return this->getHardwareInfo().platform.eRenderCoreFamily;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-04-06 20:25:22 +08:00
|
|
|
|
2018-04-10 19:49:26 +08:00
|
|
|
bool Device::isSourceLevelDebuggerActive() const {
|
2018-04-06 20:25:22 +08:00
|
|
|
return deviceInfo.sourceLevelDebuggerActive;
|
|
|
|
}
|
2018-11-22 20:57:10 +08:00
|
|
|
|
2019-03-27 17:06:29 +08:00
|
|
|
EngineControl &Device::getEngine(aub_stream::EngineType engineType, bool lowPriority) {
|
2019-03-23 21:26:06 +08:00
|
|
|
for (auto &engine : engines) {
|
|
|
|
if (engine.osContext->getEngineType() == engineType &&
|
|
|
|
engine.osContext->isLowPriority() == lowPriority) {
|
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
}
|
2019-04-09 23:46:23 +08:00
|
|
|
if (DebugManager.flags.OverrideInvalidEngineWithDefault.get()) {
|
|
|
|
return engines[0];
|
|
|
|
}
|
2019-03-23 21:26:06 +08:00
|
|
|
UNRECOVERABLE_IF(true);
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|