!26495 [MSLITE][DEVELOP] fix bug of status << override

Merge pull request !26495 from yangruoqi713/master_status
This commit is contained in:
i-robot 2021-11-19 08:23:02 +00:00 committed by Gitee
commit 968d855623
2 changed files with 62 additions and 56 deletions

View File

@ -32,6 +32,59 @@ struct Status::Data {
std::string err_description; std::string err_description;
}; };
static std::map<enum StatusCode, std::string> status_info_map = {
{kSuccess, "No error occurs."},
// Core
{kCoreFailed, "Common error code."},
// MD
{kMDOutOfMemory, "Out of memory"},
{kMDShapeMisMatch, "Shape is incorrect"},
{kMDInterrupted, "Interrupted system call"},
{kMDNoSpace, "No space left on device"},
{kMDPyFuncException, "Exception thrown from PyFunc"},
{kMDDuplicateKey, "Duplicate key"},
{kMDPythonInterpreterFailure, ""},
{kMDTDTPushFailure, "Unexpected error"},
{kMDFileNotExist, "Unexpected error"},
{kMDProfilingError, "Error encountered while profiling"},
{kMDBoundingBoxOutOfBounds, "Unexpected error"},
{kMDBoundingBoxInvalidShape, "Unexpected error"},
{kMDSyntaxError, "Syntax error"},
{kMDTimeOut, "Unexpected error"},
{kMDBuddySpaceFull, "BuddySpace full"},
{kMDNetWorkError, "Network error"},
{kMDNotImplementedYet, "Unexpected error"},
{kMDUnexpectedError, "Unexpected error"},
// ME
{kMEFailed, "Common error code."},
{kMEInvalidInput, "Invalid input."},
// MC
{kMCFailed, "Common error code."},
{kMCDeviceError, "Device error."},
{kMCInvalidInput, "Invalid input."},
{kMCInvalidArgs, "Invalid arguments."},
// Lite
{kLiteError, "Common error code."},
{kLiteNullptr, "NULL pointer returned."},
{kLiteParamInvalid, "Invalid parameter."},
{kLiteNoChange, "No change."},
{kLiteSuccessExit, "No error but exit."},
{kLiteMemoryFailed, "Fail to create memory."},
{kLiteNotSupport, "Fail to support."},
{kLiteThreadPoolError, "Thread pool error."},
{kLiteOutOfTensorRange, "Failed to check range."},
{kLiteInputTensorError, "Failed to check input tensor."},
{kLiteReentrantError, "Exist executor running."},
{kLiteGraphFileError, "Failed to verify graph file."},
{kLiteNotFindOp, "Failed to find operator."},
{kLiteInvalidOpName, "Invalid operator name."},
{kLiteInvalidOpAttr, "Invalid operator attr."},
{kLiteOpExecuteFailure, "Failed to execution operator."},
{kLiteFormatError, "Failed to checking tensor format."},
{kLiteInferError, "Failed to infer shape."},
{kLiteInferInvalid, "Invalid infer shape before runtime."},
{kLiteInputParamInvalid, "Invalid input param by user."}};
Status::Status() : data_(std::make_shared<Data>()) {} Status::Status() : data_(std::make_shared<Data>()) {}
Status::Status(enum StatusCode status_code, const std::vector<char> &status_msg) : data_(std::make_shared<Data>()) { Status::Status(enum StatusCode status_code, const std::vector<char> &status_msg) : data_(std::make_shared<Data>()) {
@ -40,7 +93,11 @@ Status::Status(enum StatusCode status_code, const std::vector<char> &status_msg)
} }
data_->err_description = CharToString(status_msg); data_->err_description = CharToString(status_msg);
data_->status_msg = CharToString(status_msg); if (!status_msg.empty()) {
data_->status_msg = CharToString(status_msg);
} else {
data_->status_msg = CodeAsString(status_code);
}
data_->status_code = status_code; data_->status_code = status_code;
} }
@ -105,59 +162,8 @@ std::vector<char> Status::GetErrDescriptionChar() const {
} }
std::vector<char> Status::CodeAsCString(enum StatusCode c) { std::vector<char> Status::CodeAsCString(enum StatusCode c) {
static std::map<enum StatusCode, std::string> info_map = {{kSuccess, "No error occurs."}, auto iter = status_info_map.find(c);
// Core return StringToChar(iter == status_info_map.end() ? "Unknown error" : iter->second);
{kCoreFailed, "Common error code."},
// MD
{kMDOutOfMemory, "Out of memory"},
{kMDShapeMisMatch, "Shape is incorrect"},
{kMDInterrupted, "Interrupted system call"},
{kMDNoSpace, "No space left on device"},
{kMDPyFuncException, "Exception thrown from PyFunc"},
{kMDDuplicateKey, "Duplicate key"},
{kMDPythonInterpreterFailure, ""},
{kMDTDTPushFailure, "Unexpected error"},
{kMDFileNotExist, "Unexpected error"},
{kMDProfilingError, "Error encountered while profiling"},
{kMDBoundingBoxOutOfBounds, "Unexpected error"},
{kMDBoundingBoxInvalidShape, "Unexpected error"},
{kMDSyntaxError, "Syntax error"},
{kMDTimeOut, "Unexpected error"},
{kMDBuddySpaceFull, "BuddySpace full"},
{kMDNetWorkError, "Network error"},
{kMDNotImplementedYet, "Unexpected error"},
{kMDUnexpectedError, "Unexpected error"},
// ME
{kMEFailed, "Common error code."},
{kMEInvalidInput, "Invalid input."},
// MC
{kMCFailed, "Common error code."},
{kMCDeviceError, "Device error."},
{kMCInvalidInput, "Invalid input."},
{kMCInvalidArgs, "Invalid arguments."},
// Lite
{kLiteError, "Common error code."},
{kLiteNullptr, "NULL pointer returned."},
{kLiteParamInvalid, "Invalid parameter."},
{kLiteNoChange, "No change."},
{kLiteSuccessExit, "No error but exit."},
{kLiteMemoryFailed, "Fail to create memory."},
{kLiteNotSupport, "Fail to support."},
{kLiteThreadPoolError, "Thread pool error."},
{kLiteOutOfTensorRange, "Failed to check range."},
{kLiteInputTensorError, "Failed to check input tensor."},
{kLiteReentrantError, "Exist executor running."},
{kLiteGraphFileError, "Failed to verify graph file."},
{kLiteNotFindOp, "Failed to find operator."},
{kLiteInvalidOpName, "Invalid operator name."},
{kLiteInvalidOpAttr, "Invalid operator attr."},
{kLiteOpExecuteFailure, "Failed to execution operator."},
{kLiteFormatError, "Failed to checking tensor format."},
{kLiteInferError, "Failed to infer shape."},
{kLiteInferInvalid, "Invalid infer shape before runtime."},
{kLiteInputParamInvalid, "Invalid input param by user."}};
auto iter = info_map.find(c);
return StringToChar(iter == info_map.end() ? "Unknown error" : iter->second);
} }
std::ostream &operator<<(std::ostream &os, const Status &s) { std::ostream &operator<<(std::ostream &os, const Status &s) {

View File

@ -154,7 +154,7 @@ int QuickStart(int argc, const char **argv) {
delete[](model_buf); delete[](model_buf);
if (build_ret != mindspore::kSuccess) { if (build_ret != mindspore::kSuccess) {
delete model; delete model;
std::cerr << "Build model error " << build_ret.StatusCode() << std::endl; std::cerr << "Build model error " << build_ret << std::endl;
return -1; return -1;
} }
@ -174,7 +174,7 @@ int QuickStart(int argc, const char **argv) {
auto predict_ret = model->Predict(inputs, &outputs); auto predict_ret = model->Predict(inputs, &outputs);
if (predict_ret != mindspore::kSuccess) { if (predict_ret != mindspore::kSuccess) {
delete model; delete model;
std::cerr << "Predict error " << predict_ret.StatusCode() << std::endl; std::cerr << "Predict error " << predict_ret << std::endl;
return -1; return -1;
} }