1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
* Copyright (C) 2023-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/debug_env_reader.h"
#include "shared/source/os_interface/os_interface.h"
#include "level_zero/core/source/driver/driver.h"
#include "level_zero/sysman/source/device/sysman_hw_device_id.h"
#include "level_zero/sysman/source/driver/sysman_driver_handle_imp.h"
#include "level_zero/sysman/source/driver/sysman_driver_imp.h"
#include "level_zero/sysman/source/driver/sysman_os_driver.h"
#include <cstring>
#include <vector>
namespace L0 {
namespace Sysman {
_ze_driver_handle_t *globalSysmanDriverHandle = nullptr;
uint32_t driverCount = 0;
bool sysmanOnlyInit = false;
void SysmanDriverImp::initialize(ze_result_t *result) {
*result = ZE_RESULT_ERROR_UNINITIALIZED;
auto executionEnvironment = new NEO::ExecutionEnvironment();
UNRECOVERABLE_IF(nullptr == executionEnvironment);
executionEnvironment->incRefInternal();
using HwDeviceIds = std::vector<std::unique_ptr<NEO::HwDeviceId>>;
HwDeviceIds hwDeviceIds = NEO::OSInterface::discoverDevices(*executionEnvironment);
if (!hwDeviceIds.empty()) {
executionEnvironment->prepareRootDeviceEnvironments(static_cast<uint32_t>(hwDeviceIds.size()));
uint32_t rootDeviceIndex = 0u;
for (auto &hwDeviceId : hwDeviceIds) {
auto sysmanHwDeviceId = createSysmanHwDeviceId(hwDeviceId);
auto initStatus = sysmanHwDeviceId != nullptr &&
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->initOsInterface(std::move(sysmanHwDeviceId), rootDeviceIndex);
if (!initStatus) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr,
"OsInterface initialization failed for device : %d\n", rootDeviceIndex);
*result = ZE_RESULT_ERROR_UNINITIALIZED;
executionEnvironment->decRefInternal();
return;
}
rootDeviceIndex++;
}
globalSysmanDriverHandle = SysmanDriverHandle::create(*executionEnvironment, result);
driverCount = 1;
} else {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr,
"%s\n", "No devices found");
*result = ZE_RESULT_ERROR_UNINITIALIZED;
}
executionEnvironment->decRefInternal();
std::unique_ptr<OsDriver> pOsDriverInterface = OsDriver::create();
if (globalSysmanDriverHandle != nullptr) {
pOsDriverInterface->initSurvivabilityDevices(globalSysmanDriverHandle, result);
} else {
globalSysmanDriverHandle = pOsDriverInterface->initSurvivabilityDevicesWithDriver(result, &driverCount);
}
}
ze_result_t SysmanDriverImp::initStatus(ZE_RESULT_ERROR_UNINITIALIZED);
ze_result_t SysmanDriverImp::driverInit() {
std::call_once(initDriverOnce, [this]() {
ze_result_t result;
this->initialize(&result);
initStatus = result;
if (result == ZE_RESULT_SUCCESS) {
sysmanOnlyInit = true;
}
});
return initStatus;
}
ze_result_t driverHandleGet(uint32_t *pCount, zes_driver_handle_t *phDriverHandles) {
if (driverCount == 0) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
if (*pCount == 0) {
*pCount = driverCount;
return ZE_RESULT_SUCCESS;
}
if (*pCount > driverCount) {
*pCount = driverCount;
}
if (phDriverHandles == nullptr) {
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
}
for (uint32_t i = 0; i < *pCount; i++) {
phDriverHandles[i] = globalSysmanDriverHandle;
}
return ZE_RESULT_SUCCESS;
}
static SysmanDriverImp driverImp;
SysmanDriver *SysmanDriver::driver = &driverImp;
ze_result_t init(zes_init_flags_t flags) {
if (flags && !(flags & ZE_INIT_FLAG_GPU_ONLY)) {
return ZE_RESULT_ERROR_UNINITIALIZED;
} else {
return SysmanDriver::get()->driverInit();
}
}
} // namespace Sysman
} // namespace L0
|