Files
compute-runtime/level_zero/tools/source/sysman/sysman.cpp
Spruit, Neil R e1d9f92b94 Fixed Global Driver to be void * with library unload driver cleanup
- Changed Global Driver to be a void * to avoid auto add of Global
Driver Destructor to run before destruction of other L0 data structures
that might be enqueued to destory in static object destructors.
- Added register of library unload driverdestructor to cleanup
driver/device as the last destructor run.

Change-Id: I8ba6c5c27424b942a86a2613edd52fc682ab1c64
Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com>
2020-06-22 12:59:03 +02:00

55 lines
1.5 KiB
C++

/*
* Copyright (C) 2019-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/source/sysman/sysman.h"
#include "level_zero/core/source/driver/driver.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/tools/source/sysman/sysman_imp.h"
#include <vector>
namespace L0 {
static SysmanHandleContext *SysmanHandleContextInstance = nullptr;
void SysmanHandleContext::init(ze_init_flag_t flag) {
if (SysmanHandleContextInstance == nullptr) {
SysmanHandleContextInstance = new SysmanHandleContext();
}
}
SysmanHandleContext::SysmanHandleContext() {
DriverHandle *dH = L0::DriverHandle::fromHandle(GlobalDriverHandle);
uint32_t count = 0;
dH->getDevice(&count, nullptr);
std::vector<ze_device_handle_t> devices(count);
dH->getDevice(&count, devices.data());
for (auto device : devices) {
SysmanImp *sysman = new SysmanImp(device);
UNRECOVERABLE_IF(!sysman);
sysman->init();
handle_map[device] = sysman;
}
}
ze_result_t SysmanHandleContext::sysmanGet(zet_device_handle_t hDevice, zet_sysman_handle_t *phSysman) {
if (SysmanHandleContextInstance == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
auto got = SysmanHandleContextInstance->handle_map.find(hDevice);
if (got == SysmanHandleContextInstance->handle_map.end()) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
*phSysman = got->second;
return ZE_RESULT_SUCCESS;
}
} // namespace L0