#include "include/errorcode.h"//文件名
#include <map>//导入map
#include <string>//导入string
namespace mindspore {
namespace lite {
std::string GetErrorInfo(STATUS status) {//定义一个返回值为String的函数
std::map<int, std::string> info_map = {{RET_OK, "No error occurs."},//储存了各种错误类型
{RET_ERROR, "Common error code."},//复制错误
{RET_NULL_PTR, "NULL pointer returned."},//返回空指针
{RET_PARAM_INVALID, "Invalid parameter."},//无效参数
{RET_NO_CHANGE, "No change."},
{RET_SUCCESS_EXIT, "No error but exit."},
{RET_MEMORY_FAILED, "Fail to create memory."},
{RET_NOT_SUPPORT, "Fail to support."},
{RET_THREAD_POOL_ERROR, "Thread pool error."},
{RET_OUT_OF_TENSOR_RANGE, "Failed to check range."},
{RET_INPUT_TENSOR_ERROR, "Failed to check input tensor."},
{RET_REENTRANT_ERROR, "Exist executor running."},
{RET_GRAPH_FILE_ERR, "Failed to verify graph file."},
{RET_NOT_FIND_OP, "Failed to find operator."},
{RET_INVALID_OP_NAME, "Invalid operator name."},
{RET_INVALID_OP_ATTR, "Invalid operator attr."},
{RET_OP_EXECUTE_FAILURE, "Failed to execution operator."},
{RET_FORMAT_ERR, "Failed to checking tensor format."},
{RET_INFER_ERR, "Failed to infer shape."},
{RET_INFER_INVALID, "Invalid infer shape before runtime."},
{RET_INPUT_PARAM_INVALID, "Invalid input param by user."}};
return info_map.find(status) == info_map.end() ? "Unknown error" : info_map[status];//若是都不是这些错误则输出“UnKnown error”
}
} // namespace lite
} // namespace mindspore
inner_context.cc中的init成员函数
int InnerContext::Init() {//定义一个Init函数
if (RET_OK != this->IsValid()) {//判断Ret_OK与this的IsValid
MS_LOG(ERROR) << "Context is not valid";//不等于则输出 Context is not valid错误
return RET_NOT_SUPPORT;//返回
}
if (this->thread_pool_ == nullptr && this->IsCpuEnabled()) {//判断thread_pool是否等于
this->thread_pool_ =
CreateLiteThreadPool(this->thread_num_, this->device_list_[0].device_info_.cpu_device_info_.cpu_bind_mode_);
if (this->thread_pool_ == nullptr) {//如果 thread_pool_ 无效
MS_LOG(ERROR) << "Create ThreadPool failed";//输出创建失败错误
return RET_NULL_PTR;//返回 这个引用错误
}
}
if (this->allocator == nullptr) {//判断 Allocator是否为空
this->allocator = mindspore::Allocator::Create();//为空则creat一个
if (this->allocator == nullptr) {//再次判断是否为空
MS_LOG(ERROR) << "Create Allocator failed";//仍含为空则输出错误 则为创建失败
return RET_NULL_PTR;//返回错误
}
}
if (IsNpuEnabled()) {//判断Npu是否 启用
MS_LOG(DEBUG) << "NPU enabled.";//启用Npu
}
if (IsGpuEnabled()) {//判断Gpu是否启用
MS_LOG(DEBUG) << "GPU enabled.";//启用Gpu
}
return RET_OK;
}