diff --git a/metadef b/metadef index 326ecbb..0b63956 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit 326ecbb2b4837699aa674cc30e9b9956e4fd364d +Subproject commit 0b6395643fd358080d8d2a80868d09154d47b7e9 diff --git a/parser/caffe/caffe_parser.cc b/parser/caffe/caffe_parser.cc index 9b8bd2b..d4d556c 100644 --- a/parser/caffe/caffe_parser.cc +++ b/parser/caffe/caffe_parser.cc @@ -78,6 +78,10 @@ using std::ifstream; } \ } while (0) +namespace { +const size_t kMaxErrStrLen = 128U; +} // namespace + namespace ge { graphStatus aclgrphParseCaffe(const char *model_file, const char *weights_file, ge::Graph &graph) { ErrorManager::GetInstance().SetStage(error_message::kModelCompile, error_message::kParser); @@ -247,7 +251,9 @@ Status CheckPathValid(const char *model_path, const string &custom_proto, string string &custom_proto_name) { string path_model = ge::parser::RealPath(model_path); if (path_model.empty()) { - ErrorManager::GetInstance().ATCReportErrMessage("E19000", {"path", "errmsg"}, {model_path, strerror(errno)}); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + ErrorManager::GetInstance().ATCReportErrMessage("E19000", {"path", "errmsg"}, {model_path, err_msg}); GELOGE(FAILED, "[Check][Param]ModelPath %s is Invalid path of model", model_path); return FAILED; } @@ -447,24 +453,30 @@ Status CaffeModelParser::CustomProtoParse(const char *model_path, const string & Status CaffeModelParser::ReadModelWithoutWarning(const char *model_path, google::protobuf::Message *message) { int32_t copy_fd = mmDup(STDERR_FILENO); if (copy_fd < 0) { - REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", strerror(errno)); - GELOGE(FAILED, "[Invoke][Dup] failed:%d, reason:%s", copy_fd, strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", err_msg); + GELOGE(FAILED, "[Invoke][Dup] failed:%d, reason:%s", copy_fd, err_msg); return FAILED; } int32_t fd = mmOpen(kDevNull, M_RDWR); if (fd < 0) { (void)mmClose(copy_fd); - ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {kDevNull, strerror(errno)}); - GELOGE(FAILED, "[Open][File] %s failed. reason:%s", kDevNull, strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {kDevNull, err_msg}); + GELOGE(FAILED, "[Open][File] %s failed. reason:%s", kDevNull, err_msg); return FAILED; } if (mmDup2(fd, STDERR_FILENO) < 0) { (void)mmClose(fd); (void)mmClose(copy_fd); - REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", strerror(errno)); - GELOGE(FAILED, "[Invoke][Dup2] Re-orient failed. reason:%s", strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", err_msg); + GELOGE(FAILED, "[Invoke][Dup2] Re-orient failed. reason:%s", err_msg); return FAILED; } @@ -478,8 +490,10 @@ Status CaffeModelParser::ReadModelWithoutWarning(const char *model_path, google: if (mmDup2(copy_fd, STDERR_FILENO) < 0) { (void)mmClose(fd); (void)mmClose(copy_fd); - REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", strerror(errno)); - GELOGE(FAILED, "[Invoke][Dup2] Re-orient failed. reason:%s", strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", err_msg); + GELOGE(FAILED, "[Invoke][Dup2] Re-orient failed. reason:%s", err_msg); return FAILED; } (void)mmClose(fd); diff --git a/parser/common/acl_graph_parser_util.cc b/parser/common/acl_graph_parser_util.cc index dd30d46..815791e 100644 --- a/parser/common/acl_graph_parser_util.cc +++ b/parser/common/acl_graph_parser_util.cc @@ -46,6 +46,7 @@ using google::protobuf::io::ZeroCopyInputStream; using namespace ge::parser; namespace { +const size_t kMaxErrStrLen = 128U; const std::string kGraphDefaultName = "domi_default"; /// The maximum length of the file. /// Based on the security coding specification and the current actual (protobuf) model size, it is determined as 2G-1 @@ -692,16 +693,17 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY long GetFileLength(const std::s return -1, "[Check][Param] input_file path is null."); std::string real_path = RealPath(input_file.c_str()); - + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(real_path.empty(), REPORT_INPUT_ERROR("E19000", std::vector({"path", "errmsg"}), - std::vector({real_path, strerror(errno)})); + std::vector({real_path, err_msg})); return -1, "[Get][Path] input_file path '%s' not valid", input_file.c_str()); unsigned long long file_length = 0; GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(mmGetFileSize(input_file.c_str(), &file_length) != EN_OK, ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, - {input_file, strerror(errno)}); - return -1, "[Open][File] [%s] failed. %s", input_file.c_str(), strerror(errno)); + {input_file, err_msg}); + return -1, "[Open][File] [%s] failed. %s", input_file.c_str(), err_msg); GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((file_length == 0 || file_length > kMaxFileSizeLimit), REPORT_INPUT_ERROR( @@ -829,11 +831,13 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromText(const ch "[Check][Param]incorrect parameter. nullptr == file || nullptr == message"); std::string real_path = RealPath(file); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(real_path.empty(), ErrorManager::GetInstance().ATCReportErrMessage("E19000", {"path", "errmsg"}, - {file, strerror(errno)}); + {file, err_msg}); return false, "[Check][Param]Path[%s]'s realpath is empty, errmsg[%s]", file, - strerror(errno)); + err_msg); GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(GetFileLength(real_path) == -1, return false, "[Check][Param] file size not valid."); diff --git a/parser/common/model_saver.cc b/parser/common/model_saver.cc index 9af4fa8..08a7f82 100644 --- a/parser/common/model_saver.cc +++ b/parser/common/model_saver.cc @@ -25,6 +25,7 @@ #include "mmpa/mmpa_api.h" namespace { +const size_t kMaxErrStrLen = 128U; const int kFileOpSuccess = 0; } // namespace @@ -65,8 +66,10 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelSaver::SaveJsonToFi mode_t mode = S_IRUSR | S_IWUSR; int32_t fd = mmOpen2(real_path, O_RDWR | O_CREAT | O_TRUNC, mode); if (fd == EN_ERROR || fd == EN_INVALID_PARAM) { - ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {file_path, strerror(errno)}); - GELOGE(FAILED, "[Open][File] [%s] failed. %s", file_path, strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {file_path, err_msg}); + GELOGE(FAILED, "[Open][File] [%s] failed. %s", file_path, err_msg); return FAILED; } const char *model_char = model_str.c_str(); @@ -74,16 +77,20 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelSaver::SaveJsonToFi // Write data to file mmSsize_t mmpa_ret = mmWrite(fd, const_cast((const void *)model_char), len); if (mmpa_ret == EN_ERROR || mmpa_ret == EN_INVALID_PARAM) { + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); ErrorManager::GetInstance().ATCReportErrMessage( - "E19004", {"file", "errmsg"}, {file_path, strerror(errno)}); + "E19004", {"file", "errmsg"}, {file_path, err_msg}); // Need to both print the error info of mmWrite and mmClose, so return ret after mmClose - GELOGE(FAILED, "[WriteTo][File] %s failed. errno = %ld, %s", file_path, mmpa_ret, strerror(errno)); + GELOGE(FAILED, "[WriteTo][File] %s failed. errno = %ld, %s", file_path, mmpa_ret, err_msg); ret = FAILED; } // Close file if (mmClose(fd) != EN_OK) { - REPORT_INNER_ERROR("E19999", "close file:%s failed. errmsg:%s", file_path, strerror(errno)); - GELOGE(FAILED, "[Close][File] %s failed. errmsg:%s", file_path, strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + REPORT_INNER_ERROR("E19999", "close file:%s failed. errmsg:%s", file_path, err_msg); + GELOGE(FAILED, "[Close][File] %s failed. errmsg:%s", file_path, err_msg); ret = FAILED; } return ret; @@ -137,11 +144,13 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY int ModelSaver::CreateDirectory int32_t ret = mmMkdir(tmp_dir_path, S_IRUSR | S_IWUSR | S_IXUSR); // 700 if (ret != 0) { if (errno != EEXIST) { + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); REPORT_CALL_ERROR("E19999", "Can not create directory %s. Make sure the directory exists and writable. errmsg:%s", - directory_path.c_str(), strerror(errno)); + directory_path.c_str(), err_msg); GELOGW("Can not create directory %s. Make sure the directory exists and writable. errmsg:%s", - directory_path.c_str(), strerror(errno)); + directory_path.c_str(), err_msg); return ret; } } @@ -151,11 +160,13 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY int ModelSaver::CreateDirectory int32_t ret = mmMkdir(const_cast(directory_path.c_str()), S_IRUSR | S_IWUSR | S_IXUSR); // 700 if (ret != 0) { if (errno != EEXIST) { + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); REPORT_CALL_ERROR("E19999", "Can not create directory %s. Make sure the directory exists and writable. errmsg:%s", - directory_path.c_str(), strerror(errno)); + directory_path.c_str(), err_msg); GELOGW("Can not create directory %s. Make sure the directory exists and writable. errmsg:%s", - directory_path.c_str(), strerror(errno)); + directory_path.c_str(), err_msg); return ret; } } diff --git a/parser/onnx/onnx_custom_parser_adapter.cc b/parser/onnx/onnx_custom_parser_adapter.cc index 1534dff..d441a03 100644 --- a/parser/onnx/onnx_custom_parser_adapter.cc +++ b/parser/onnx/onnx_custom_parser_adapter.cc @@ -20,6 +20,8 @@ #include "framework/common/debug/ge_log.h" #include "parser/common/op_parser_factory.h" #include "register/op_registry.h" +#include "parser/common/parser_utils.h" +#include "graph/def_types.h" using domi::ONNX; using domi::ParseParamByOpFunc; @@ -28,7 +30,7 @@ using domi::ParseParamFunc; namespace ge { Status OnnxCustomParserAdapter::ParseParams(const Message *op_src, ge::Operator &op_dest) { GE_CHECK_NOTNULL(op_src); - const ge::onnx::NodeProto *node_src = reinterpret_cast(op_src); + const ge::onnx::NodeProto *node_src = PtrToPtr(op_src); GE_CHECK_NOTNULL(node_src); GELOGI("Onnx op node name = %s, op type= %s, parse params.", node_src->name().c_str(), node_src->op_type().c_str()); diff --git a/parser/onnx/onnx_data_parser.cc b/parser/onnx/onnx_data_parser.cc index 9ac3c47..67fabb2 100644 --- a/parser/onnx/onnx_data_parser.cc +++ b/parser/onnx/onnx_data_parser.cc @@ -18,6 +18,7 @@ #include #include "common/util.h" #include "graph/debug/ge_attr_define.h" +#include "graph/def_types.h" #include "parser/common/op_parser_factory.h" #include "framework/omg/parser/parser_inner_ctx.h" #include "parser/onnx/onnx_util.h" @@ -28,7 +29,7 @@ using namespace ge::parser; namespace ge { Status OnnxDataParser::ParseParams(const Message *op_src, ge::Operator &op_def) { GE_CHECK_NOTNULL(op_src); - const ge::onnx::NodeProto *node_src = reinterpret_cast(op_src); + const ge::onnx::NodeProto *node_src = PtrToPtr(op_src); GE_CHECK_NOTNULL(node_src); GELOGD("Onnx op node name = %s, op type= %s, parse params", node_src->name().c_str(), node_src->op_type().c_str()); if (ParseInputFromModel(op_src, op_def) != SUCCESS) { @@ -72,7 +73,7 @@ int64_t OnnxDataParser::ParseInputTensor(const ge::onnx::AttributeProto &attribu Status OnnxDataParser::ParseInputFromModel(const Message *op_src, ge::Operator &op_def) { GE_CHECK_NOTNULL(op_src); - const ge::onnx::NodeProto *node = reinterpret_cast(op_src); + const ge::onnx::NodeProto *node = PtrToPtr(op_src); GE_CHECK_NOTNULL(node); // Get attr t:'input_tensor' form NodeProto diff --git a/parser/tensorflow/tensorflow_auto_mapping_parser_adapter.cc b/parser/tensorflow/tensorflow_auto_mapping_parser_adapter.cc index bdd525d..ea8aef1 100644 --- a/parser/tensorflow/tensorflow_auto_mapping_parser_adapter.cc +++ b/parser/tensorflow/tensorflow_auto_mapping_parser_adapter.cc @@ -19,6 +19,7 @@ #include "framework/omg/parser/parser_types.h" #include "common/util.h" #include "framework/common/debug/ge_log.h" +#include "graph/def_types.h" #include "parser/common/op_parser_factory.h" #include "register/op_registry.h" #include "register/register.h" @@ -42,7 +43,7 @@ Status TensorFlowAutoMappingParserAdapter::ParseParams(const Message *op_src, ge GELOGE(PARAM_INVALID, "Op src is null"); return PARAM_INVALID; } - const NodeDef *node = reinterpret_cast(op_src); + const NodeDef *node = PtrToPtr(op_src); GELOGD("TF op node name = %s, op type= %s, parse params", node->name().c_str(), node->op().c_str()); if (op_dest == nullptr) { REPORT_INNER_ERROR("E19999", "Param op_dest is nullptr, check invalid"); diff --git a/parser/tensorflow/tensorflow_enter_parser.cc b/parser/tensorflow/tensorflow_enter_parser.cc index 13427be..be7d4b4 100644 --- a/parser/tensorflow/tensorflow_enter_parser.cc +++ b/parser/tensorflow/tensorflow_enter_parser.cc @@ -31,7 +31,7 @@ Status TensorFlowEnterParser::ParseParams(const Message *op_src, ge::OpDescPtr & GE_CHECK_NOTNULL(op_desc); const std::string name = op_desc->GetName(); - const NodeDef *node = reinterpret_cast(op_src); + const NodeDef *node = PtrToPtr(op_src); domi::tensorflow::AttrValue str_attr; if (!TensorFlowUtil::FindAttrValue(node, ENTER_ATTR_FRAME_NAME, str_attr)) { REPORT_CALL_ERROR("E19999", "In NodeDef:%s attr:%s not exist, check invalid", diff --git a/parser/tensorflow/tensorflow_merge_parser.cc b/parser/tensorflow/tensorflow_merge_parser.cc index a13cc5b..fda3499 100644 --- a/parser/tensorflow/tensorflow_merge_parser.cc +++ b/parser/tensorflow/tensorflow_merge_parser.cc @@ -21,6 +21,7 @@ #include "graph/debug/ge_attr_define.h" #include "parser/common/op_parser_factory.h" #include "framework/omg/parser/parser_types.h" +#include "graph/def_types.h" using domi::TENSORFLOW; using ge::parser::MERGE; @@ -30,7 +31,7 @@ Status TensorFlowMergeParser::ParseParams(const Message *op_src, ge::OpDescPtr & GE_CHECK_NOTNULL(op_src); GE_CHECK_NOTNULL(op_desc); - const NodeDef *node = reinterpret_cast(op_src); + const NodeDef *node = PtrToPtr(op_src); domi::tensorflow::AttrValue attr_num; if (!(TensorFlowUtil::FindAttrValue(node, ATTR_NAME_N, attr_num))) { GELOGW("In NodeDef %s dynamic attr [%s] is not exist.", op_desc->GetName().c_str(), ATTR_NAME_N.c_str()); diff --git a/parser/tensorflow/tensorflow_reshape_parser.cc b/parser/tensorflow/tensorflow_reshape_parser.cc index a0df1f6..a3d5b1d 100644 --- a/parser/tensorflow/tensorflow_reshape_parser.cc +++ b/parser/tensorflow/tensorflow_reshape_parser.cc @@ -42,10 +42,9 @@ Status TensorFlowReshapeParser::ParseDesc(const domi::tensorflow::AttrValue &att ge::TypeUtils::DataTypeToSerialString(data_type).c_str()); return PARAM_INVALID); // calculate size - int64_t tmp_dim = 0; int64_t real_size = 1; for (uint32_t j = 0; j < ge_desc.GetShape().GetDimNum(); ++j) { - tmp_dim = ge_desc.GetShape().GetDim(j); + int64_t tmp_dim = ge_desc.GetShape().GetDim(j); GE_IF_BOOL_EXEC(tmp_dim < 0, real_size = tmp_dim * (-1) * real_size; continue;); real_size *= tmp_dim; } diff --git a/parser/tensorflow/tensorflow_squeeze_parser.cc b/parser/tensorflow/tensorflow_squeeze_parser.cc index 4d1601e..b9a1513 100644 --- a/parser/tensorflow/tensorflow_squeeze_parser.cc +++ b/parser/tensorflow/tensorflow_squeeze_parser.cc @@ -47,9 +47,8 @@ Status TensorFlowSqueezeParser::ParseDesc(const domi::tensorflow::AttrValue &att return domi::PARAM_INVALID); // calculate size int64_t real_size = 1; - int64_t tmp_dim = 0; for (uint32_t j = 0; j < ge_desc.GetShape().GetDimNum(); ++j) { - tmp_dim = ge_desc.GetShape().GetDim(j); + int64_t tmp_dim = ge_desc.GetShape().GetDim(j); GE_IF_BOOL_EXEC(tmp_dim < 0, real_size = tmp_dim * (-1) * real_size; continue;); PARSER_INT64_MULCHECK(real_size, tmp_dim); real_size *= tmp_dim; diff --git a/parser/tensorflow/tensorflow_util.cc b/parser/tensorflow/tensorflow_util.cc index 697881c..e68a79e 100644 --- a/parser/tensorflow/tensorflow_util.cc +++ b/parser/tensorflow/tensorflow_util.cc @@ -271,9 +271,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY domi::Status TensorFlowUtil::Tr GE_CHK_BOOL_RET_STATUS(ge::TypeUtils::GetDataTypeLength(data_type, size_type), PARAM_INVALID, "dataType no define size , parse ge_desc failed."); // get size - int64_t tmp_dim = 0; for (uint32_t j = 0; j < ge_desc.GetShape().GetDimNum(); ++j) { - tmp_dim = ge_desc.GetShape().GetDim(j); + int64_t tmp_dim = ge_desc.GetShape().GetDim(j); // The shape infered by fusedbatchnormgrad and mean calling tensorflow is not accurate. // Here, special treatment is given to the two operators.