mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-11 16:45:25 +08:00
feature: refactor and rewrite setErrorDescription
Related-To: NEO-8379 Signed-off-by: Winston Zhang <winston.zhang@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
60711a169e
commit
0590b34cfa
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
* Copyright (C) 2020-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -11,7 +11,9 @@
|
||||
#include <level_zero/zes_api.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct _ze_driver_handle_t {
|
||||
virtual ~_ze_driver_handle_t() = default;
|
||||
};
|
||||
@@ -78,7 +80,7 @@ struct DriverHandle : BaseDriver {
|
||||
virtual ze_result_t createRTASParallelOperation(ze_rtas_parallel_operation_exp_handle_t *phParallelOperation) = 0;
|
||||
virtual ze_result_t formatRTASCompatibilityCheck(ze_rtas_format_exp_t rtasFormatA, ze_rtas_format_exp_t rtasFormatB) = 0;
|
||||
|
||||
virtual int setErrorDescription(const char *fmt, ...) = 0;
|
||||
virtual int setErrorDescription(const std::string &str) = 0;
|
||||
virtual ze_result_t getErrorDescription(const char **ppString) = 0;
|
||||
virtual ze_result_t clearErrorDescription() = 0;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "shared/source/memory_manager/unified_memory_manager.h"
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
#include "shared/source/utilities/logger.h"
|
||||
|
||||
#include "level_zero/api/driver_experimental/public/zex_common.h"
|
||||
#include "level_zero/core/source/builtin/builtin_functions_lib.h"
|
||||
@@ -1059,51 +1060,17 @@ uint32_t DriverHandleImp::getEventMaxKernelCount(uint32_t numDevices, ze_device_
|
||||
return maxCount;
|
||||
}
|
||||
|
||||
int DriverHandleImp::setErrorDescription(const char *fmt, ...) {
|
||||
int result = 0;
|
||||
int size = -1;
|
||||
va_list args;
|
||||
|
||||
auto threadId = std::this_thread::get_id();
|
||||
{
|
||||
std::lock_guard<std::mutex> errorDescsLock(errorDescsMutex);
|
||||
if (errorDescs.find(threadId) == errorDescs.end()) {
|
||||
errorDescs[threadId] = std::string();
|
||||
}
|
||||
}
|
||||
errorDescs[threadId].clear();
|
||||
va_start(args, fmt);
|
||||
size = vsnprintf(nullptr, 0, fmt, args); // NOLINT(clang-analyzer-valist.Uninitialized)
|
||||
va_end(args);
|
||||
if (size > 0) {
|
||||
va_start(args, fmt);
|
||||
errorDescs[threadId].resize(size + 1); // to temporarilly copy \0
|
||||
result = vsnprintf(errorDescs[threadId].data(), size + 1, fmt, args);
|
||||
errorDescs[threadId].resize(size); // to remove \0
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
return result;
|
||||
int DriverHandleImp::setErrorDescription(const std::string &str) {
|
||||
return this->devices[0]->getNEODevice()->getExecutionEnvironment()->setErrorDescription(str);
|
||||
}
|
||||
|
||||
ze_result_t DriverHandleImp::getErrorDescription(const char **ppString) {
|
||||
auto threadId = std::this_thread::get_id();
|
||||
{
|
||||
std::lock_guard<std::mutex> errorDescsLock(errorDescsMutex);
|
||||
if (errorDescs.find(threadId) == errorDescs.end()) {
|
||||
errorDescs[threadId] = std::string();
|
||||
}
|
||||
}
|
||||
*ppString = errorDescs[threadId].c_str();
|
||||
this->devices[0]->getNEODevice()->getExecutionEnvironment()->getErrorDescription(ppString);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t DriverHandleImp::clearErrorDescription() {
|
||||
auto threadId = std::this_thread::get_id();
|
||||
if (errorDescs.find(threadId) != errorDescs.end()) {
|
||||
errorDescs[threadId].clear();
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
return static_cast<ze_result_t>(this->devices[0]->getNEODevice()->getExecutionEnvironment()->clearErrorDescription());
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -173,7 +173,7 @@ struct DriverHandleImp : public DriverHandle {
|
||||
// not based on the lifetime of the object of a class.
|
||||
std::unordered_map<std::thread::id, std::string> errorDescs;
|
||||
std::mutex errorDescsMutex;
|
||||
int setErrorDescription(const char *fmt, ...) override;
|
||||
int setErrorDescription(const std::string &str) override;
|
||||
ze_result_t getErrorDescription(const char **ppString) override;
|
||||
ze_result_t clearErrorDescription() override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user