2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-01-10 16:37:56 +08:00
|
|
|
* Copyright (C) 2017-2019 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
|
|
|
|
2018-03-05 16:25:40 +08:00
|
|
|
#include "runtime/built_ins/built_ins.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/command_stream/command_stream_receiver.h"
|
|
|
|
#include "runtime/command_stream/device_command_stream.h"
|
2018-07-05 17:23:28 +08:00
|
|
|
#include "runtime/command_stream/experimental_command_buffer.h"
|
2018-02-06 18:58:05 +08:00
|
|
|
#include "runtime/command_stream/preemption.h"
|
2018-01-30 23:49:01 +08:00
|
|
|
#include "runtime/compiler_interface/compiler_interface.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/device/device_vector.h"
|
2018-04-18 20:59:28 +08:00
|
|
|
#include "runtime/device/driver_info.h"
|
2018-06-27 17:35:37 +08:00
|
|
|
#include "runtime/execution_environment/execution_environment.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/debug_helpers.h"
|
2019-02-13 00:27:13 +08:00
|
|
|
#include "runtime/helpers/hw_helper.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/options.h"
|
|
|
|
#include "runtime/memory_manager/memory_manager.h"
|
2018-08-27 21:48:29 +08:00
|
|
|
#include "runtime/os_interface/os_context.h"
|
2018-04-23 20:26:03 +08:00
|
|
|
#include "runtime/os_interface/os_interface.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/os_interface/os_time.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
|
|
|
|
|
|
|
#include "hw_cmds.h"
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstring>
|
|
|
|
#include <map>
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
DeviceVector::DeviceVector(const cl_device_id *devices,
|
|
|
|
cl_uint numDevices) {
|
|
|
|
for (cl_uint i = 0; i < numDevices; i++) {
|
|
|
|
this->push_back(castToObject<Device>(devices[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceVector::toDeviceIDs(std::vector<cl_device_id> &devIDs) {
|
|
|
|
int i = 0;
|
|
|
|
devIDs.resize(this->size());
|
|
|
|
|
|
|
|
for (auto &it : *this) {
|
|
|
|
devIDs[i] = it;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:06:14 +08:00
|
|
|
CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// Global table of hardware prefixes
|
|
|
|
const char *hardwarePrefix[IGFX_MAX_PRODUCT] = {
|
|
|
|
nullptr,
|
|
|
|
};
|
|
|
|
// Global table of family names
|
|
|
|
const char *familyName[IGFX_MAX_CORE] = {
|
|
|
|
nullptr,
|
|
|
|
};
|
|
|
|
// Global table of family names
|
|
|
|
bool familyEnabled[IGFX_MAX_CORE] = {
|
|
|
|
false,
|
|
|
|
};
|
|
|
|
|
2019-05-06 18:33:44 +08:00
|
|
|
Device::Device(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
|
|
|
: executionEnvironment(executionEnvironment), deviceIndex(deviceIndex) {
|
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-02-19 15:55:11 +08:00
|
|
|
executionEnvironment->memoryManager->waitForDeletions();
|
|
|
|
alignedFree(this->slmWindowStartAddress);
|
2019-06-28 03:33:05 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
auto osInterface = executionEnvironment->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() {
|
2019-06-28 03:33:05 +08:00
|
|
|
|
2019-05-06 18:33:44 +08:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
auto defaultEngineType = getChosenEngineType(hwInfo);
|
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-01-23 18:59:54 +08:00
|
|
|
if (!executionEnvironment->initializeCommandStreamReceiver(getDeviceIndex(), deviceCsrIndex)) {
|
2018-11-28 16:02:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:36:39 +08:00
|
|
|
auto commandStreamReceiver = executionEnvironment->commandStreamReceivers[getDeviceIndex()][deviceCsrIndex].get();
|
2019-02-18 20:59:16 +08:00
|
|
|
|
2019-03-13 22:00:07 +08:00
|
|
|
DeviceBitfield deviceBitfield;
|
|
|
|
deviceBitfield.set(getDeviceIndex());
|
2019-03-25 20:21:48 +08:00
|
|
|
bool lowPriority = deviceCsrIndex == HwHelper::lowPriorityGpgpuEngineIndex;
|
2019-02-18 20:59:16 +08:00
|
|
|
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver, gpgpuEngines[deviceCsrIndex],
|
2019-03-18 20:57:59 +08:00
|
|
|
deviceBitfield, preemptionMode, lowPriority);
|
2019-01-10 16:37:56 +08:00
|
|
|
commandStreamReceiver->setupContext(*osContext);
|
2019-02-18 20:59:16 +08:00
|
|
|
|
2018-11-28 16:02:55 +08:00
|
|
|
if (!commandStreamReceiver->initializeTagAllocation()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-03-20 17:56:22 +08:00
|
|
|
if (gpgpuEngines[deviceCsrIndex] == defaultEngineType && !lowPriority) {
|
2019-02-07 16:36:39 +08:00
|
|
|
defaultEngineIndex = deviceCsrIndex;
|
2018-11-28 16:02:55 +08:00
|
|
|
}
|
|
|
|
|
2019-06-28 03:33:05 +08:00
|
|
|
if ((preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) && !commandStreamReceiver->createPreemptionAllocation()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:36:39 +08:00
|
|
|
engines.push_back({commandStreamReceiver, osContext});
|
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
|
|
|
|
2019-05-08 22:00:24 +08:00
|
|
|
const WorkaroundTable *Device::getWaTable() const { return &getHardwareInfo().workaroundTable; }
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
const DeviceInfo &Device::getDeviceInfo() const {
|
|
|
|
return deviceInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceInfo *Device::getMutableDeviceInfo() {
|
|
|
|
return &deviceInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Device::getSLMWindowStartAddress() {
|
|
|
|
prepareSLMWindow();
|
|
|
|
return this->slmWindowStartAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Device::prepareSLMWindow() {
|
|
|
|
if (this->slmWindowStartAddress == nullptr) {
|
2018-07-11 22:47:49 +08:00
|
|
|
this->slmWindowStartAddress = executionEnvironment->memoryManager->allocateSystemMemory(MemoryConstants::slmWindowSize, MemoryConstants::slmWindowAlignment);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Device::getProductAbbrev() const {
|
2019-05-08 22:00:24 +08:00
|
|
|
return hardwarePrefix[executionEnvironment->getHardwareInfo()->platform.eProductFamily];
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-04-18 00:11:50 +08:00
|
|
|
const std::string Device::getFamilyNameWithType() const {
|
2019-05-06 18:33:44 +08:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
2019-05-08 22:00:24 +08:00
|
|
|
std::string platformName = familyName[hwInfo.platform.eRenderCoreFamily];
|
2018-04-18 00:11:50 +08:00
|
|
|
platformName.append(getPlatformType(hwInfo));
|
|
|
|
return platformName;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* We hide the retain and release function of BaseObject. */
|
|
|
|
void Device::retain() {
|
|
|
|
DEBUG_BREAK_IF(!isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr_if_unused<Device> Device::release() {
|
|
|
|
DEBUG_BREAK_IF(!isValid());
|
|
|
|
return unique_ptr_if_unused<Device>(this, false);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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
|