2018-09-18 22:31:47 +08:00
|
|
|
/*
|
2023-01-03 18:27:35 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2018-09-18 22:31:47 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-09-18 22:31:47 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/device_factory.h"
|
|
|
|
|
2020-10-16 18:10:52 +08:00
|
|
|
#include "shared/source/aub/aub_center.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
|
|
|
#include "shared/source/device/root_device.h"
|
2022-12-16 01:32:03 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2023-02-02 22:25:08 +08:00
|
|
|
#include "shared/source/helpers/compiler_product_helper.h"
|
2023-02-02 00:23:01 +08:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2023-02-07 20:53:53 +08:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2022-07-20 18:13:10 +08:00
|
|
|
#include "shared/source/helpers/product_config_helper.h"
|
2021-04-29 16:58:16 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/aub_memory_operations_handler.h"
|
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2023-03-10 20:28:11 +08:00
|
|
|
#include "shared/source/os_interface/product_helper.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-13 20:26:40 +08:00
|
|
|
#include "hw_device_id.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-09-18 22:31:47 +08:00
|
|
|
|
2020-03-23 16:13:25 +08:00
|
|
|
bool DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(ExecutionEnvironment &executionEnvironment) {
|
2019-10-23 22:17:06 +08:00
|
|
|
auto numRootDevices = 1u;
|
2019-10-17 22:00:12 +08:00
|
|
|
if (DebugManager.flags.CreateMultipleRootDevices.get()) {
|
2019-10-23 22:17:06 +08:00
|
|
|
numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get();
|
2018-09-18 22:31:47 +08:00
|
|
|
}
|
2019-11-15 16:59:48 +08:00
|
|
|
executionEnvironment.prepareRootDeviceEnvironments(numRootDevices);
|
2019-10-22 17:44:06 +08:00
|
|
|
|
2018-09-18 22:31:47 +08:00
|
|
|
auto productFamily = DebugManager.flags.ProductFamilyOverride.get();
|
2022-07-20 18:13:10 +08:00
|
|
|
|
|
|
|
auto configStr = productFamily;
|
2023-04-18 00:11:43 +08:00
|
|
|
auto productConfigHelper = std::make_unique<ProductConfigHelper>();
|
2022-07-20 18:13:10 +08:00
|
|
|
ProductConfigHelper::adjustDeviceName(configStr);
|
2023-05-12 21:46:58 +08:00
|
|
|
uint32_t productConfig = productConfigHelper->getProductConfigFromDeviceName(configStr);
|
|
|
|
|
|
|
|
if (DebugManager.flags.OverrideHwIpVersion.get() != -1 && productConfigHelper->isSupportedProductConfig(DebugManager.flags.OverrideHwIpVersion.get())) {
|
|
|
|
productConfig = DebugManager.flags.OverrideHwIpVersion.get();
|
|
|
|
}
|
2022-07-20 18:13:10 +08:00
|
|
|
|
2022-02-04 21:41:04 +08:00
|
|
|
const HardwareInfo *hwInfoConst = getDefaultHwInfo();
|
2022-07-20 18:13:10 +08:00
|
|
|
DeviceAotInfo aotInfo{};
|
|
|
|
auto productConfigFound = productConfigHelper->getDeviceAotInfoForProductConfig(productConfig, aotInfo);
|
|
|
|
if (productConfigFound) {
|
|
|
|
hwInfoConst = aotInfo.hwInfo;
|
|
|
|
} else {
|
|
|
|
getHwInfoForPlatformString(productFamily, hwInfoConst);
|
|
|
|
}
|
2020-01-25 00:19:06 +08:00
|
|
|
std::string hwInfoConfigStr;
|
|
|
|
uint64_t hwInfoConfig = 0x0;
|
|
|
|
DebugManager.getHardwareInfoOverride(hwInfoConfigStr);
|
2019-03-19 22:09:33 +08:00
|
|
|
|
2020-03-04 15:51:02 +08:00
|
|
|
for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
|
2022-11-07 22:47:17 +08:00
|
|
|
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex].get();
|
2023-06-06 19:41:57 +08:00
|
|
|
rootDeviceEnvironment.setHwInfo(hwInfoConst);
|
|
|
|
|
|
|
|
rootDeviceEnvironment.initProductHelper();
|
|
|
|
rootDeviceEnvironment.initGfxCoreHelper();
|
|
|
|
rootDeviceEnvironment.initApiGfxCoreHelper();
|
|
|
|
rootDeviceEnvironment.initCompilerProductHelper();
|
|
|
|
|
2022-11-07 22:47:17 +08:00
|
|
|
auto hardwareInfo = rootDeviceEnvironment.getMutableHardwareInfo();
|
2019-03-19 22:09:33 +08:00
|
|
|
|
2023-02-28 21:26:21 +08:00
|
|
|
if (DebugManager.flags.OverrideRevision.get() != -1) {
|
|
|
|
hardwareInfo->platform.usRevId = static_cast<unsigned short>(DebugManager.flags.OverrideRevision.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DebugManager.flags.ForceDeviceId.get() != "unk") {
|
|
|
|
hardwareInfo->platform.usDeviceID = static_cast<unsigned short>(std::stoi(DebugManager.flags.ForceDeviceId.get(), nullptr, 16));
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &compilerProductHelper = rootDeviceEnvironment.getHelper<CompilerProductHelper>();
|
2020-03-04 15:51:02 +08:00
|
|
|
if (hwInfoConfigStr == "default") {
|
2023-02-28 21:26:21 +08:00
|
|
|
hwInfoConfig = compilerProductHelper.getHwInfoConfig(*hwInfoConst);
|
2020-03-04 15:51:02 +08:00
|
|
|
} else if (!parseHwInfoConfigString(hwInfoConfigStr, hwInfoConfig)) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-02-28 21:26:21 +08:00
|
|
|
|
2020-03-04 15:51:02 +08:00
|
|
|
setHwInfoValuesFromConfig(hwInfoConfig, *hardwareInfo);
|
2023-03-08 17:30:38 +08:00
|
|
|
hardwareInfoSetup[hwInfoConst->platform.eProductFamily](hardwareInfo, true, hwInfoConfig, compilerProductHelper);
|
2019-04-09 19:37:17 +08:00
|
|
|
|
2022-12-13 00:43:41 +08:00
|
|
|
auto &productHelper = rootDeviceEnvironment.getProductHelper();
|
|
|
|
productHelper.configureHardwareCustom(hardwareInfo, nullptr);
|
2019-03-28 22:34:26 +08:00
|
|
|
|
2022-07-20 18:13:10 +08:00
|
|
|
if (productConfigFound) {
|
2022-11-30 22:28:39 +08:00
|
|
|
compilerProductHelper.setProductConfigForHwInfo(*hardwareInfo, aotInfo.aotConfig);
|
2023-05-12 21:46:58 +08:00
|
|
|
if (DebugManager.flags.ForceDeviceId.get() == "unk") {
|
|
|
|
hardwareInfo->platform.usDeviceID = aotInfo.deviceIds->front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DebugManager.flags.OverrideHwIpVersion.get() != -1) {
|
|
|
|
hardwareInfo->ipVersion = DebugManager.flags.OverrideHwIpVersion.get();
|
2022-07-20 18:13:10 +08:00
|
|
|
}
|
|
|
|
|
2023-06-06 19:41:57 +08:00
|
|
|
rootDeviceEnvironment.initReleaseHelper();
|
|
|
|
|
2020-03-31 20:59:02 +08:00
|
|
|
if (DebugManager.flags.OverrideGpuAddressSpace.get() != -1) {
|
|
|
|
hardwareInfo->capabilityTable.gpuAddressSpace = maxNBitValue(static_cast<uint64_t>(DebugManager.flags.OverrideGpuAddressSpace.get()));
|
|
|
|
}
|
|
|
|
|
2022-11-07 22:47:17 +08:00
|
|
|
[[maybe_unused]] bool result = rootDeviceEnvironment.initAilConfiguration();
|
2021-08-09 16:38:18 +08:00
|
|
|
DEBUG_BREAK_IF(!result);
|
|
|
|
|
2020-03-04 15:51:02 +08:00
|
|
|
auto csrType = DebugManager.flags.SetCommandStreamReceiver.get();
|
|
|
|
if (csrType > 0) {
|
2022-12-12 20:39:04 +08:00
|
|
|
auto &gfxCoreHelper = rootDeviceEnvironment.getHelper<GfxCoreHelper>();
|
2022-12-08 20:22:35 +08:00
|
|
|
auto localMemoryEnabled = gfxCoreHelper.getEnableLocalMemory(*hardwareInfo);
|
2022-11-07 22:47:17 +08:00
|
|
|
rootDeviceEnvironment.initGmm();
|
|
|
|
rootDeviceEnvironment.initAubCenter(localMemoryEnabled, "", static_cast<CommandStreamReceiverType>(csrType));
|
|
|
|
auto aubCenter = rootDeviceEnvironment.aubCenter.get();
|
|
|
|
rootDeviceEnvironment.memoryOperationsInterface = std::make_unique<AubMemoryOperationsHandler>(aubCenter->getAubManager());
|
2019-11-15 16:59:48 +08:00
|
|
|
}
|
2020-02-14 23:37:48 +08:00
|
|
|
}
|
|
|
|
|
2021-01-25 17:24:00 +08:00
|
|
|
executionEnvironment.parseAffinityMask();
|
2022-07-25 20:13:27 +08:00
|
|
|
executionEnvironment.adjustCcsCount();
|
2020-03-04 15:51:02 +08:00
|
|
|
executionEnvironment.calculateMaxOsContextCount();
|
2018-09-18 22:31:47 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-07 16:00:25 +08:00
|
|
|
bool DeviceFactory::isHwModeSelected() {
|
|
|
|
int32_t csr = DebugManager.flags.SetCommandStreamReceiver.get();
|
|
|
|
switch (csr) {
|
|
|
|
case CSR_AUB:
|
|
|
|
case CSR_TBX:
|
|
|
|
case CSR_TBX_WITH_AUB:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-02-13 20:26:40 +08:00
|
|
|
|
2021-10-11 23:34:03 +08:00
|
|
|
static bool initHwDeviceIdResources(ExecutionEnvironment &executionEnvironment,
|
|
|
|
std::unique_ptr<NEO::HwDeviceId> &&hwDeviceId, uint32_t rootDeviceIndex) {
|
|
|
|
if (!executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->initOsInterface(std::move(hwDeviceId), rootDeviceIndex)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DebugManager.flags.OverrideGpuAddressSpace.get() != -1) {
|
|
|
|
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getMutableHardwareInfo()->capabilityTable.gpuAddressSpace =
|
|
|
|
maxNBitValue(static_cast<uint64_t>(DebugManager.flags.OverrideGpuAddressSpace.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DebugManager.flags.OverrideRevision.get() != -1) {
|
|
|
|
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getMutableHardwareInfo()->platform.usRevId =
|
|
|
|
static_cast<unsigned short>(DebugManager.flags.OverrideRevision.get());
|
|
|
|
}
|
2022-04-20 03:24:19 +08:00
|
|
|
|
|
|
|
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->initGmm();
|
|
|
|
|
2021-10-11 23:34:03 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-23 16:13:25 +08:00
|
|
|
bool DeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnvironment) {
|
2020-02-13 20:26:40 +08:00
|
|
|
using HwDeviceIds = std::vector<std::unique_ptr<HwDeviceId>>;
|
|
|
|
|
2020-03-17 14:26:46 +08:00
|
|
|
HwDeviceIds hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
2020-03-20 23:54:09 +08:00
|
|
|
if (hwDeviceIds.empty()) {
|
2020-02-13 20:26:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-20 23:54:09 +08:00
|
|
|
executionEnvironment.prepareRootDeviceEnvironments(static_cast<uint32_t>(hwDeviceIds.size()));
|
2020-02-13 20:26:40 +08:00
|
|
|
|
|
|
|
uint32_t rootDeviceIndex = 0u;
|
|
|
|
|
|
|
|
for (auto &hwDeviceId : hwDeviceIds) {
|
2021-10-11 23:34:03 +08:00
|
|
|
if (initHwDeviceIdResources(executionEnvironment, std::move(hwDeviceId), rootDeviceIndex) == false) {
|
2020-02-13 20:26:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rootDeviceIndex++;
|
|
|
|
}
|
|
|
|
|
2021-07-11 08:12:15 +08:00
|
|
|
executionEnvironment.sortNeoDevices();
|
2021-01-25 17:24:00 +08:00
|
|
|
executionEnvironment.parseAffinityMask();
|
2023-07-11 18:55:25 +08:00
|
|
|
executionEnvironment.adjustRootDeviceEnvironments();
|
2022-07-25 20:13:27 +08:00
|
|
|
executionEnvironment.adjustCcsCount();
|
2020-02-13 20:26:40 +08:00
|
|
|
executionEnvironment.calculateMaxOsContextCount();
|
2020-02-14 23:37:48 +08:00
|
|
|
|
2020-02-13 20:26:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-11 23:34:03 +08:00
|
|
|
bool DeviceFactory::prepareDeviceEnvironment(ExecutionEnvironment &executionEnvironment, std::string &osPciPath, const uint32_t rootDeviceIndex) {
|
|
|
|
using HwDeviceIds = std::vector<std::unique_ptr<HwDeviceId>>;
|
|
|
|
|
|
|
|
HwDeviceIds hwDeviceIds = OSInterface::discoverDevice(executionEnvironment, osPciPath);
|
|
|
|
if (hwDeviceIds.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
executionEnvironment.prepareRootDeviceEnvironment(rootDeviceIndex);
|
|
|
|
|
|
|
|
// HwDeviceIds should contain only one entry corresponding to osPciPath
|
|
|
|
UNRECOVERABLE_IF(hwDeviceIds.size() > 1);
|
2022-09-22 16:48:55 +08:00
|
|
|
if (!initHwDeviceIdResources(executionEnvironment, std::move(hwDeviceIds[0]), rootDeviceIndex)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
executionEnvironment.adjustCcsCount(rootDeviceIndex);
|
|
|
|
return true;
|
2021-10-11 23:34:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Device> DeviceFactory::createDevice(ExecutionEnvironment &executionEnvironment, std::string &osPciPath, const uint32_t rootDeviceIndex) {
|
|
|
|
std::unique_ptr<Device> device;
|
|
|
|
if (!NEO::prepareDeviceEnvironment(executionEnvironment, osPciPath, rootDeviceIndex)) {
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
executionEnvironment.memoryManager->createDeviceSpecificMemResources(rootDeviceIndex);
|
|
|
|
executionEnvironment.memoryManager->reInitLatestContextId();
|
|
|
|
device = createRootDeviceFunc(executionEnvironment, rootDeviceIndex);
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
std::vector<std::unique_ptr<Device>> DeviceFactory::createDevices(ExecutionEnvironment &executionEnvironment) {
|
|
|
|
std::vector<std::unique_ptr<Device>> devices;
|
2020-09-18 22:19:41 +08:00
|
|
|
|
|
|
|
if (!NEO::prepareDeviceEnvironments(executionEnvironment)) {
|
2020-02-15 00:36:30 +08:00
|
|
|
return devices;
|
|
|
|
}
|
2020-09-18 22:19:41 +08:00
|
|
|
|
2021-01-13 05:39:04 +08:00
|
|
|
if (!DeviceFactory::createMemoryManagerFunc(executionEnvironment)) {
|
2020-09-18 22:19:41 +08:00
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
for (uint32_t rootDeviceIndex = 0u; rootDeviceIndex < executionEnvironment.rootDeviceEnvironments.size(); rootDeviceIndex++) {
|
|
|
|
auto device = createRootDeviceFunc(executionEnvironment, rootDeviceIndex);
|
|
|
|
if (device) {
|
|
|
|
devices.push_back(std::move(device));
|
|
|
|
}
|
|
|
|
}
|
2021-04-29 16:58:16 +08:00
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Device> (*DeviceFactory::createRootDeviceFunc)(ExecutionEnvironment &, uint32_t) = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr<Device> {
|
|
|
|
return std::unique_ptr<Device>(Device::create<RootDevice>(&executionEnvironment, rootDeviceIndex));
|
|
|
|
};
|
2020-11-20 19:04:46 +08:00
|
|
|
|
2021-01-13 05:39:04 +08:00
|
|
|
bool (*DeviceFactory::createMemoryManagerFunc)(ExecutionEnvironment &) = [](ExecutionEnvironment &executionEnvironment) -> bool {
|
|
|
|
return executionEnvironment.initializeMemoryManager();
|
2020-11-20 19:04:46 +08:00
|
|
|
};
|
|
|
|
|
2022-02-01 01:43:42 +08:00
|
|
|
bool DeviceFactory::isAllowedDeviceId(uint32_t deviceId, const std::string &deviceIdString) {
|
|
|
|
if (deviceIdString != "unk") {
|
|
|
|
char *endptr = nullptr;
|
|
|
|
auto reqDeviceId = strtoul(deviceIdString.c_str(), &endptr, 16);
|
|
|
|
return (static_cast<uint32_t>(reqDeviceId) == deviceId);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|