2018-06-22 18:54:33 +08:00
|
|
|
/*
|
2020-01-07 14:42:40 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-09-20 11:54:29 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2018-06-27 17:35:37 +08:00
|
|
|
|
2020-02-05 15:30:17 +08:00
|
|
|
#include "core/execution_environment/execution_environment.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2019-10-22 18:09:08 +08:00
|
|
|
#include "core/compiler_interface/compiler_interface.h"
|
2020-02-05 15:30:17 +08:00
|
|
|
#include "core/compiler_interface/default_cache_config.h"
|
2020-02-10 22:57:49 +08:00
|
|
|
#include "core/debugger/debugger.h"
|
2019-11-15 16:59:48 +08:00
|
|
|
#include "core/execution_environment/root_device_environment.h"
|
2019-12-04 19:36:16 +08:00
|
|
|
#include "core/gmm_helper/gmm_helper.h"
|
2019-11-13 17:01:19 +08:00
|
|
|
#include "core/helpers/hw_helper.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "runtime/built_ins/built_ins.h"
|
2020-01-21 18:00:03 +08:00
|
|
|
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
|
2018-06-27 17:35:37 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2019-05-06 18:33:44 +08:00
|
|
|
ExecutionEnvironment::ExecutionEnvironment() {
|
2020-01-30 16:36:05 +08:00
|
|
|
hwInfo = std::make_unique<HardwareInfo>();
|
2019-05-06 18:33:44 +08:00
|
|
|
};
|
|
|
|
|
2019-10-24 19:34:25 +08:00
|
|
|
ExecutionEnvironment::~ExecutionEnvironment() {
|
2020-02-10 22:57:49 +08:00
|
|
|
debugger.reset();
|
2019-10-24 19:34:25 +08:00
|
|
|
compilerInterface.reset();
|
|
|
|
builtins.reset();
|
2020-02-12 00:48:40 +08:00
|
|
|
if (memoryManager) {
|
|
|
|
memoryManager->commonCleanup();
|
|
|
|
}
|
2019-10-24 19:34:25 +08:00
|
|
|
rootDeviceEnvironments.clear();
|
|
|
|
}
|
2018-07-16 23:11:43 +08:00
|
|
|
|
2019-01-23 18:59:54 +08:00
|
|
|
void ExecutionEnvironment::initGmm() {
|
2018-07-16 22:37:17 +08:00
|
|
|
if (!gmmHelper) {
|
2020-01-07 14:42:40 +08:00
|
|
|
gmmHelper.reset(new GmmHelper(rootDeviceEnvironments[0]->osInterface.get(), hwInfo.get()));
|
2018-07-16 22:37:17 +08:00
|
|
|
}
|
2018-07-03 16:00:12 +08:00
|
|
|
}
|
2019-12-17 15:11:16 +08:00
|
|
|
|
2019-01-23 18:59:54 +08:00
|
|
|
void ExecutionEnvironment::setHwInfo(const HardwareInfo *hwInfo) {
|
2019-05-06 18:33:44 +08:00
|
|
|
*this->hwInfo = *hwInfo;
|
2019-01-23 18:59:54 +08:00
|
|
|
}
|
2019-12-17 15:11:16 +08:00
|
|
|
|
2019-03-15 17:22:35 +08:00
|
|
|
void ExecutionEnvironment::initializeMemoryManager() {
|
2018-07-17 17:11:48 +08:00
|
|
|
if (this->memoryManager) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-20 15:01:58 +08:00
|
|
|
|
2019-02-19 15:55:11 +08:00
|
|
|
int32_t setCommandStreamReceiverType = CommandStreamReceiverType::CSR_HW;
|
|
|
|
if (DebugManager.flags.SetCommandStreamReceiver.get() >= 0) {
|
|
|
|
setCommandStreamReceiverType = DebugManager.flags.SetCommandStreamReceiver.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (setCommandStreamReceiverType) {
|
|
|
|
case CommandStreamReceiverType::CSR_TBX:
|
|
|
|
case CommandStreamReceiverType::CSR_TBX_WITH_AUB:
|
|
|
|
case CommandStreamReceiverType::CSR_AUB:
|
2019-03-15 17:22:35 +08:00
|
|
|
memoryManager = std::make_unique<OsAgnosticMemoryManager>(*this);
|
2019-02-19 15:55:11 +08:00
|
|
|
break;
|
|
|
|
case CommandStreamReceiverType::CSR_HW:
|
|
|
|
case CommandStreamReceiverType::CSR_HW_WITH_AUB:
|
|
|
|
default:
|
2019-03-15 17:22:35 +08:00
|
|
|
memoryManager = MemoryManager::createMemoryManager(*this);
|
2019-02-19 15:55:11 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-07-16 23:11:43 +08:00
|
|
|
DEBUG_BREAK_IF(!this->memoryManager);
|
|
|
|
}
|
2019-12-17 15:11:16 +08:00
|
|
|
|
2020-02-10 22:57:49 +08:00
|
|
|
void ExecutionEnvironment::initDebugger() {
|
|
|
|
debugger = Debugger::create(hwInfo.get());
|
2018-07-12 21:47:48 +08:00
|
|
|
}
|
2019-12-17 15:11:16 +08:00
|
|
|
|
|
|
|
void ExecutionEnvironment::calculateMaxOsContextCount() {
|
|
|
|
auto &hwHelper = HwHelper::get(this->hwInfo->platform.eRenderCoreFamily);
|
|
|
|
auto osContextCount = hwHelper.getGpgpuEngineInstances().size();
|
2020-01-20 22:46:03 +08:00
|
|
|
auto subDevicesCount = HwHelper::getSubDevicesCount(this->getHardwareInfo());
|
2020-01-20 14:02:07 +08:00
|
|
|
auto rootDevicesCount = this->rootDeviceEnvironments.size();
|
2019-12-17 15:11:16 +08:00
|
|
|
bool hasRootCsr = subDevicesCount > 1;
|
|
|
|
|
2020-01-20 14:02:07 +08:00
|
|
|
MemoryManager::maxOsContextCount = static_cast<uint32_t>(rootDevicesCount * (osContextCount * subDevicesCount + hasRootCsr));
|
2019-12-17 15:11:16 +08:00
|
|
|
}
|
|
|
|
|
2018-07-23 18:23:48 +08:00
|
|
|
GmmHelper *ExecutionEnvironment::getGmmHelper() const {
|
|
|
|
return gmmHelper.get();
|
|
|
|
}
|
2019-12-30 21:14:27 +08:00
|
|
|
GmmClientContext *ExecutionEnvironment::getGmmClientContext() const {
|
|
|
|
return gmmHelper->getClientContext();
|
|
|
|
}
|
2018-08-01 15:06:46 +08:00
|
|
|
CompilerInterface *ExecutionEnvironment::getCompilerInterface() {
|
|
|
|
if (this->compilerInterface.get() == nullptr) {
|
|
|
|
std::lock_guard<std::mutex> autolock(this->mtx);
|
|
|
|
if (this->compilerInterface.get() == nullptr) {
|
2020-02-05 15:30:17 +08:00
|
|
|
auto cache = std::make_unique<CompilerCache>(getDefaultCompilerCacheConfig());
|
2019-10-21 21:47:04 +08:00
|
|
|
this->compilerInterface.reset(CompilerInterface::createInstance(std::move(cache), true));
|
2018-08-01 15:06:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this->compilerInterface.get();
|
|
|
|
}
|
2019-12-17 15:11:16 +08:00
|
|
|
|
2018-08-21 21:47:21 +08:00
|
|
|
BuiltIns *ExecutionEnvironment::getBuiltIns() {
|
|
|
|
if (this->builtins.get() == nullptr) {
|
|
|
|
std::lock_guard<std::mutex> autolock(this->mtx);
|
|
|
|
if (this->builtins.get() == nullptr) {
|
|
|
|
this->builtins = std::make_unique<BuiltIns>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this->builtins.get();
|
|
|
|
}
|
2019-02-27 00:52:31 +08:00
|
|
|
|
2019-09-03 20:20:32 +08:00
|
|
|
bool ExecutionEnvironment::isFullRangeSvm() const {
|
2019-11-28 01:00:52 +08:00
|
|
|
return hwInfo->capabilityTable.gpuAddressSpace >= maxNBitValue(47);
|
2019-09-03 20:20:32 +08:00
|
|
|
}
|
2019-11-15 16:59:48 +08:00
|
|
|
|
|
|
|
void ExecutionEnvironment::prepareRootDeviceEnvironments(uint32_t numRootDevices) {
|
|
|
|
if (rootDeviceEnvironments.size() < numRootDevices) {
|
|
|
|
rootDeviceEnvironments.resize(numRootDevices);
|
|
|
|
}
|
|
|
|
for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
|
|
|
|
if (!rootDeviceEnvironments[rootDeviceIndex]) {
|
|
|
|
rootDeviceEnvironments[rootDeviceIndex] = std::make_unique<RootDeviceEnvironment>(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|