2018-06-22 18:54:33 +08:00
|
|
|
/*
|
2021-01-18 16:27:50 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2018-09-20 11:54:29 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2018-06-27 17:35:37 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-12-02 18:22:27 +08:00
|
|
|
#include "shared/source/built_ins/built_ins.h"
|
2021-04-16 20:52:30 +08:00
|
|
|
#include "shared/source/built_ins/sip.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2021-05-05 16:07:53 +08:00
|
|
|
#include "shared/source/helpers/affinity_mask.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-03-19 21:26:08 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2020-11-02 22:54:01 +08:00
|
|
|
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
|
2020-03-17 14:26:46 +08:00
|
|
|
#include "shared/source/os_interface/os_environment.h"
|
2021-03-31 02:11:00 +08:00
|
|
|
#include "shared/source/utilities/wait_util.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2021-03-31 02:11:00 +08:00
|
|
|
ExecutionEnvironment::ExecutionEnvironment() {
|
|
|
|
WaitUtils::init();
|
|
|
|
}
|
2019-05-06 18:33:44 +08:00
|
|
|
|
2019-10-24 19:34:25 +08:00
|
|
|
ExecutionEnvironment::~ExecutionEnvironment() {
|
2020-02-12 00:48:40 +08:00
|
|
|
if (memoryManager) {
|
|
|
|
memoryManager->commonCleanup();
|
2020-12-02 18:22:27 +08:00
|
|
|
for (const auto &rootDeviceEnvironment : this->rootDeviceEnvironments) {
|
2021-04-16 20:52:30 +08:00
|
|
|
SipKernel::freeSipKernels(rootDeviceEnvironment.get(), memoryManager.get());
|
2020-12-02 18:22:27 +08:00
|
|
|
if (rootDeviceEnvironment->builtins.get()) {
|
|
|
|
rootDeviceEnvironment->builtins.get()->freeSipKernels(memoryManager.get());
|
|
|
|
}
|
|
|
|
}
|
2020-02-12 00:48:40 +08:00
|
|
|
}
|
2019-10-24 19:34:25 +08:00
|
|
|
rootDeviceEnvironments.clear();
|
|
|
|
}
|
2018-07-16 23:11:43 +08:00
|
|
|
|
2020-09-18 22:19:41 +08:00
|
|
|
bool ExecutionEnvironment::initializeMemoryManager() {
|
2018-07-17 17:11:48 +08:00
|
|
|
if (this->memoryManager) {
|
2020-09-18 22:19:41 +08:00
|
|
|
return memoryManager->isInitialized();
|
2018-07-17 17:11:48 +08:00
|
|
|
}
|
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;
|
|
|
|
}
|
2020-09-18 22:19:41 +08:00
|
|
|
|
|
|
|
return memoryManager->isInitialized();
|
2018-07-16 23:11:43 +08:00
|
|
|
}
|
2019-12-17 15:11:16 +08:00
|
|
|
|
|
|
|
void ExecutionEnvironment::calculateMaxOsContextCount() {
|
2020-08-17 19:41:48 +08:00
|
|
|
MemoryManager::maxOsContextCount = 0u;
|
2020-02-12 18:27:28 +08:00
|
|
|
for (const auto &rootDeviceEnvironment : this->rootDeviceEnvironments) {
|
2020-02-21 22:25:04 +08:00
|
|
|
auto hwInfo = rootDeviceEnvironment->getHardwareInfo();
|
|
|
|
auto &hwHelper = HwHelper::get(hwInfo->platform.eRenderCoreFamily);
|
|
|
|
auto osContextCount = hwHelper.getGpgpuEngineInstances(*hwInfo).size();
|
|
|
|
auto subDevicesCount = HwHelper::getSubDevicesCount(hwInfo);
|
2020-02-12 18:27:28 +08:00
|
|
|
bool hasRootCsr = subDevicesCount > 1;
|
2019-12-17 15:11:16 +08:00
|
|
|
|
2020-02-12 18:27:28 +08:00
|
|
|
MemoryManager::maxOsContextCount += static_cast<uint32_t>(osContextCount * subDevicesCount + hasRootCsr);
|
|
|
|
}
|
2019-12-17 15:11:16 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-25 17:24:00 +08:00
|
|
|
void ExecutionEnvironment::parseAffinityMask() {
|
|
|
|
auto affinityMaskString = DebugManager.flags.ZE_AFFINITY_MASK.get();
|
|
|
|
|
|
|
|
if (affinityMaskString.compare("default") == 0 ||
|
|
|
|
affinityMaskString.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-05 16:07:53 +08:00
|
|
|
const uint32_t numRootDevices = static_cast<uint32_t>(rootDeviceEnvironments.size());
|
|
|
|
|
|
|
|
std::vector<AffinityMaskHelper> affinityMaskHelper(numRootDevices);
|
2021-01-25 17:24:00 +08:00
|
|
|
|
|
|
|
size_t pos = 0;
|
|
|
|
while (pos < affinityMaskString.size()) {
|
|
|
|
size_t posNextDot = affinityMaskString.find_first_of(".", pos);
|
|
|
|
size_t posNextComma = affinityMaskString.find_first_of(",", pos);
|
|
|
|
std::string rootDeviceString = affinityMaskString.substr(pos, std::min(posNextDot, posNextComma) - pos);
|
|
|
|
uint32_t rootDeviceIndex = static_cast<uint32_t>(std::stoul(rootDeviceString, nullptr, 0));
|
2021-05-05 16:07:53 +08:00
|
|
|
if (rootDeviceIndex < numRootDevices) {
|
|
|
|
auto hwInfo = rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo();
|
|
|
|
auto subDevicesCount = HwHelper::getSubDevicesCount(hwInfo);
|
|
|
|
|
2021-01-25 17:24:00 +08:00
|
|
|
pos += rootDeviceString.size();
|
|
|
|
if (posNextDot != std::string::npos &&
|
|
|
|
affinityMaskString.at(pos) == '.' && posNextDot < posNextComma) {
|
|
|
|
pos++;
|
|
|
|
std::string subDeviceString = affinityMaskString.substr(pos, posNextComma - pos);
|
|
|
|
uint32_t subDeviceIndex = static_cast<uint32_t>(std::stoul(subDeviceString, nullptr, 0));
|
2021-05-05 16:07:53 +08:00
|
|
|
if (subDeviceIndex < subDevicesCount) {
|
|
|
|
affinityMaskHelper[rootDeviceIndex].enableGenericSubDevice(subDeviceIndex);
|
2021-01-25 17:24:00 +08:00
|
|
|
}
|
|
|
|
} else {
|
2021-05-05 16:07:53 +08:00
|
|
|
affinityMaskHelper[rootDeviceIndex].enableAllGenericSubDevices(subDevicesCount);
|
2021-01-25 17:24:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (posNextComma == std::string::npos) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos = posNextComma + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<RootDeviceEnvironment>> filteredEnvironments;
|
2021-05-05 16:07:53 +08:00
|
|
|
for (uint32_t i = 0u; i < numRootDevices; i++) {
|
|
|
|
if (!affinityMaskHelper[i].isDeviceEnabled()) {
|
2021-01-25 17:24:00 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-05-05 16:07:53 +08:00
|
|
|
rootDeviceEnvironments[i]->deviceAffinityMask = affinityMaskHelper[i];
|
2021-01-25 17:24:00 +08:00
|
|
|
filteredEnvironments.emplace_back(rootDeviceEnvironments[i].release());
|
|
|
|
}
|
|
|
|
|
|
|
|
rootDeviceEnvironments.swap(filteredEnvironments);
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|