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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/device/device.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08: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-25 01:04:30 +08:00
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2020-03-16 19:41:25 +08:00
|
|
|
#include "shared/source/os_interface/driver_info.h"
|
2020-02-24 05:44:01 +08: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 17:11:44 +08:00
|
|
|
#include "shared/source/source_level_debugger/source_level_debugger.h"
|
2020-02-24 17:22:30 +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) {
|
2018-07-10 23:14:20 +08:00
|
|
|
this->executionEnvironment->incRefInternal();
|
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
|
|
|
}
|
|
|
|
|
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() {
|
2020-02-11 17:15:21 +08:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo);
|
|
|
|
|
|
|
|
if (!getDebugger()) {
|
2020-03-11 15:56:55 +08:00
|
|
|
this->executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->initDebugger();
|
2020-02-11 17:15:21 +08:00
|
|
|
}
|
|
|
|
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
|
|
|
hwHelper.setupHardwareCapabilities(&this->hardwareCapabilities, hwInfo);
|
2020-02-25 23:38:47 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->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;
|
|
|
|
}
|
2020-03-07 02:02:24 +08: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 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
|
|
|
}
|
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-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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
2020-02-21 22:25:04 +08:00
|
|
|
auto gpgpuEngines = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getGpgpuEngineInstances(hwInfo);
|
2018-11-28 16:02:55 +08:00
|
|
|
|
2020-07-28 16:36:52 +08:00
|
|
|
this->engineGroups.resize(static_cast<uint32_t>(EngineGroupType::MaxEngineGroups));
|
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()));
|
|
|
|
}
|
|
|
|
|
2020-09-15 23:29:02 +08:00
|
|
|
bool Device::createEngine(uint32_t deviceCsrIndex, EngineTypeUsage engineTypeUsage) {
|
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;
|
|
|
|
}
|
2020-02-10 16:44:00 +08:00
|
|
|
|
2020-09-15 23:29:02 +08:00
|
|
|
auto engineType = engineTypeUsage.first;
|
|
|
|
|
|
|
|
bool internalUsage = (engineTypeUsage.second == EngineUsage::Internal);
|
2020-09-05 07:18:12 +08:00
|
|
|
if (internalUsage) {
|
|
|
|
commandStreamReceiver->initializeDefaultsForInternalEngine();
|
|
|
|
}
|
2020-02-10 16:44:00 +08:00
|
|
|
|
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
|
|
|
|
2020-09-15 23:29:02 +08:00
|
|
|
bool lowPriority = (engineTypeUsage.second == EngineUsage::LowPriority);
|
2019-11-05 20:38:20 +08:00
|
|
|
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(), engineType,
|
2020-03-04 06:33:31 +08:00
|
|
|
getDeviceBitfield(), preemptionMode,
|
|
|
|
lowPriority, internalUsage, false);
|
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
|
|
|
|
2020-02-10 22:57:49 +08:00
|
|
|
if ((preemptionMode == PreemptionMode::MidThread || isDebuggerActive()) && !commandStreamReceiver->createPreemptionAllocation()) {
|
2019-07-16 15:23:02 +08:00
|
|
|
return false;
|
2018-11-28 16:02:55 +08:00
|
|
|
}
|
2019-07-16 15:23:02 +08:00
|
|
|
|
2020-07-28 16:36:52 +08: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 20:38:20 +08:00
|
|
|
commandStreamReceivers.push_back(std::move(commandStreamReceiver));
|
2019-07-16 15:23:02 +08:00
|
|
|
|
2018-11-28 16:02:55 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-12 18:27:28 +08:00
|
|
|
const HardwareInfo &Device::getHardwareInfo() const { return *getRootDeviceEnvironment().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
|
|
|
}
|
|
|
|
|
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);
|
2020-05-14 19:12:17 +08:00
|
|
|
for (const auto &engine : engines) {
|
|
|
|
if (engine.commandStreamReceiver->getType() != CommandStreamReceiverType::CSR_HW) {
|
|
|
|
simulation = true;
|
|
|
|
}
|
2018-06-06 16:34:51 +08:00
|
|
|
}
|
2020-05-14 19:12:17 +08:00
|
|
|
|
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
|
|
|
|
2020-02-10 22:57:49 +08:00
|
|
|
bool Device::isDebuggerActive() const {
|
|
|
|
return deviceInfo.debuggerActive;
|
2018-04-06 20:25:22 +08:00
|
|
|
}
|
2018-11-22 20:57:10 +08:00
|
|
|
|
2020-09-15 23:29:02 +08:00
|
|
|
EngineControl &Device::getEngine(aub_stream::EngineType engineType, bool lowPriority, bool internalUsage) {
|
2019-03-23 21:26:06 +08:00
|
|
|
for (auto &engine : engines) {
|
|
|
|
if (engine.osContext->getEngineType() == engineType &&
|
2020-09-15 23:29:02 +08:00
|
|
|
engine.osContext->isLowPriority() == lowPriority &&
|
|
|
|
engine.osContext->isInternalEngine() == internalUsage) {
|
2019-03-23 21:26:06 +08:00
|
|
|
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);
|
|
|
|
}
|
2020-02-07 01:57:00 +08:00
|
|
|
|
2020-05-04 03:33:11 +08:00
|
|
|
EngineControl &Device::getEngine(uint32_t index) {
|
|
|
|
UNRECOVERABLE_IF(index >= engines.size());
|
|
|
|
return engines[index];
|
|
|
|
}
|
|
|
|
|
2020-02-07 01:57:00 +08: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-25 01:04:30 +08:00
|
|
|
GmmClientContext *Device::getGmmClientContext() const {
|
|
|
|
return getGmmHelper()->getClientContext();
|
|
|
|
}
|
|
|
|
|
2020-04-16 20:44:03 +08: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 23:08:55 +08:00
|
|
|
NEO::SourceLevelDebugger *Device::getSourceLevelDebugger() {
|
|
|
|
auto debugger = getDebugger();
|
|
|
|
if (debugger) {
|
|
|
|
return debugger->isLegacy() ? static_cast<NEO::SourceLevelDebugger *>(debugger) : nullptr;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-07-02 17:49:46 +08:00
|
|
|
const std::vector<EngineControl> &Device::getEngines() const {
|
|
|
|
return this->engines;
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|