Files
compute-runtime/level_zero/tools/source/sysman/ras/ras.cpp
Mayank Raghuwanshi 2ec2d514ec Update create Handle mechanism for sysman RAS
Use set instead of vector to get the supported error types,
using vector may cause duplication of error types when quering
supported error types from different interfaces which in turn
may cause duplication of handles.

Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
2021-12-02 12:39:30 +01:00

55 lines
1.5 KiB
C++

/*
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/basic_math.h"
#include "level_zero/tools/source/sysman/ras/ras_imp.h"
namespace L0 {
void RasHandleContext::releaseRasHandles() {
for (Ras *pRas : handleList) {
delete pRas;
}
handleList.clear();
}
RasHandleContext::~RasHandleContext() {
releaseRasHandles();
}
void RasHandleContext::createHandle(zes_ras_error_type_t type, ze_device_handle_t deviceHandle) {
Ras *pRas = new RasImp(pOsSysman, type, deviceHandle);
handleList.push_back(pRas);
}
void RasHandleContext::init(std::vector<ze_device_handle_t> &deviceHandles) {
for (const auto &deviceHandle : deviceHandles) {
std::set<zes_ras_error_type_t> errorType = {};
OsRas::getSupportedRasErrorTypes(errorType, pOsSysman, deviceHandle);
for (const auto &type : errorType) {
createHandle(type, deviceHandle);
}
}
}
ze_result_t RasHandleContext::rasGet(uint32_t *pCount,
zes_ras_handle_t *phRas) {
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
uint32_t numToCopy = std::min(*pCount, handleListSize);
if (0 == *pCount || *pCount > handleListSize) {
*pCount = handleListSize;
}
if (nullptr != phRas) {
for (uint32_t i = 0; i < numToCopy; i++) {
phRas[i] = handleList[i]->toHandle();
}
}
return ZE_RESULT_SUCCESS;
}
} // namespace L0