From ecd5ef56e5310f31ebee4deb5c795ca61f26134c Mon Sep 17 00:00:00 2001 From: wangzhengjun Date: Wed, 23 Mar 2022 17:17:35 +0800 Subject: [PATCH 1/3] batch train for bert 2.x --- parser/tensorflow/tensorflow_auto_mapping_parser_adapter.cc | 3 +++ tests/st/testcase/test_tensorflow_parser.cc | 1 + .../testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc | 1 + 3 files changed, 5 insertions(+) diff --git a/parser/tensorflow/tensorflow_auto_mapping_parser_adapter.cc b/parser/tensorflow/tensorflow_auto_mapping_parser_adapter.cc index bc50850..76fc5ef 100644 --- a/parser/tensorflow/tensorflow_auto_mapping_parser_adapter.cc +++ b/parser/tensorflow/tensorflow_auto_mapping_parser_adapter.cc @@ -109,6 +109,9 @@ Status TensorFlowAutoMappingParserAdapter::ParseParams(const Message *op_src, ge return FAILED; } } + const auto out_desc = op_dest->MutableOutputDesc(0); + GE_CHECK_NOTNULL(out_desc); + out_desc->SetDataType(out_type); std::shared_ptr pkg_node = ge::parser::MakeShared(); GE_CHECK_NOTNULL(pkg_node); diff --git a/tests/st/testcase/test_tensorflow_parser.cc b/tests/st/testcase/test_tensorflow_parser.cc index 07346f9..7ed5ef8 100644 --- a/tests/st/testcase/test_tensorflow_parser.cc +++ b/tests/st/testcase/test_tensorflow_parser.cc @@ -1913,6 +1913,7 @@ TEST_F(STestTensorflowParser, tensorflow_auto_mapping_parser_adapter_test) EXPECT_EQ(ret, SUCCESS); op_dest->SetType(ge::parser::SHAPE); + op_dest->AddOutputDesc(GeTensorDesc()); ret = autoMappingParser.ParseParams(node_def, op_dest); EXPECT_EQ(ret, SUCCESS); } diff --git a/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc b/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc index 0afb636..710609e 100644 --- a/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc +++ b/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc @@ -2082,6 +2082,7 @@ TEST_F(UtestTensorflowParser, tensorflow_auto_mapping_parser_adapter_test) EXPECT_EQ(ret, SUCCESS); op_dest->SetType(ge::parser::SHAPE); + op_dest->AddOutputDesc(GeTensorDesc()); ret = autoMappingParser.ParseParams(node_def, op_dest); EXPECT_EQ(ret, SUCCESS); } From 232519892d2d2bf4a3685c55ca18809c9dd17028 Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Fri, 25 Mar 2022 09:12:54 +0800 Subject: [PATCH 2/3] Delete GE_CHK_*_EXEC_* like Macro --- parser/caffe/caffe_parser.cc | 181 +++++++++++++++--------------- parser/common/acl_graph_parser_util.cc | 197 ++++++++++++++++++++------------- parser/common/model_saver.cc | 8 +- parser/tensorflow/graph_functiondef.cc | 22 ++-- parser/tensorflow/graph_optimizer.cc | 25 +++-- parser/tensorflow/tensorflow_parser.cc | 191 +++++++++++++++++++------------- parser/tensorflow/tensorflow_util.cc | 5 +- 7 files changed, 355 insertions(+), 274 deletions(-) diff --git a/parser/caffe/caffe_parser.cc b/parser/caffe/caffe_parser.cc index 3bdd931..5e6b0b7 100644 --- a/parser/caffe/caffe_parser.cc +++ b/parser/caffe/caffe_parser.cc @@ -61,13 +61,7 @@ using domi::caffe::InnerProductParameter; using domi::caffe::LayerParameter; using domi::caffe::NetParameter; using domi::ParseParamByOpFunc; -using ge::caffe_op_map; -using ge::CaffeOpParser; using ge::parser::ModelSaver; -using ge::OpParser; -using ge::OpParserFactory; -using ge::Pb2Json; -using ge::PreChecker; using std::ifstream; #define CAFFE_CHECK_NULL_AND_REPROT_ERRORMSG(val, errormsg) \ @@ -299,16 +293,17 @@ Status CaffeModelParser::ParseInput(domi::caffe::NetParameter &proto_message, bo GELOGE(FAILED, "[Check][Size]input_dim and input_shape can not both exist!"); return FAILED; } - int input_dim_size = proto_message.input_dim_size(); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((input_dim_size / proto_message.input_size() != parser::DIM_DEFAULT_SIZE || - input_dim_size % proto_message.input_size() != 0), - ErrorManager::GetInstance().ATCReportErrMessage( - "E11003", {"input_dim_size", "input_size"}, - {std::to_string(input_dim_size), std::to_string(proto_message.input_size())}); - return FAILED, - "[Check][Size]Model input_dim size[%d] is not 4 times of input size[%d].", - input_dim_size, proto_message.input_size()) + const int32_t input_dim_size = proto_message.input_dim_size(); + const bool is_input_invalid = (((input_dim_size / proto_message.input_size()) != parser::DIM_DEFAULT_SIZE) || + ((input_dim_size % proto_message.input_size()) != 0)); + if (is_input_invalid) { + ErrorManager::GetInstance().ATCReportErrMessage("E11003", {"input_dim_size", "input_size"}, + {std::to_string(input_dim_size), std::to_string(proto_message.input_size())}); + GELOGE(FAILED, "[Check][Size]Model input_dim size[%d] is not 4 times of input size[%d].", + input_dim_size, proto_message.input_size()); + return FAILED; + } for (int i = 0; i < proto_message.input_size(); i++) { domi::caffe::LayerParameter *layer = proto_message.add_layer(); @@ -329,12 +324,14 @@ Status CaffeModelParser::ParseInput(domi::caffe::NetParameter &proto_message, bo input_data_flag = true; } } else if (proto_message.input_shape_size() > 0) { - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(proto_message.input_shape_size() != proto_message.input_size(), - ErrorManager::GetInstance().ATCReportErrMessage("E11004", {"input_shape_size", "input_size"}, - {std::to_string(proto_message.input_shape_size()), - std::to_string(proto_message.input_size())}); - return FAILED, "[Check][Size]caffe net input_shape size(%d) is not equal input size(%d).", - proto_message.input_shape_size(), proto_message.input_size()); + if (proto_message.input_shape_size() != proto_message.input_size()) { + ErrorManager::GetInstance().ATCReportErrMessage("E11004", {"input_shape_size", "input_size"}, + {std::to_string(proto_message.input_shape_size()), + std::to_string(proto_message.input_size())}); + GELOGE(FAILED, "[Check][Size]caffe net input_shape size(%d) is not equal input size(%d).", + proto_message.input_shape_size(), proto_message.input_size()); + return FAILED; + } for (int i = 0; i < proto_message.input_size(); i++) { int dim_size = proto_message.input_shape(i).dim_size(); @@ -839,11 +836,11 @@ Status CaffeModelParser::AddNode(const domi::caffe::LayerParameter &layer, ge::C std::shared_ptr factory = OpParserFactory::Instance(domi::CAFFE); GE_CHECK_NOTNULL(factory); std::shared_ptr op_parser = factory->CreateOpParser(op_type); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(op_parser == nullptr, - ErrorManager::GetInstance().ATCReportErrMessage("E11009", {"opname", "optype"}, - {layer.name(), op_type}); - return FAILED, "op_parser is null, op_type: %s.", - op_type.c_str()); + if (op_parser == nullptr) { + ErrorManager::GetInstance().ATCReportErrMessage("E11009", {"opname", "optype"}, {layer.name(), op_type}); + GELOGE(FAILED, "op_parser is null, op_type: %s.", op_type.c_str()); + return FAILED; + } ge::OpDescPtr op; // Process change of tensordesc initialization of opdesc, @@ -1229,12 +1226,14 @@ Status CaffeModelParser::PreCheck(const domi::caffe::NetParameter &net) { GE_RETURN_WITH_LOG_IF_ERROR(PreChecker::Instance().AddOp(&layer, layer.name(), layer.type()), "[Invoke][AddOp]Add layer to PreChecker failed, layer name: %s.", layer.name().c_str()); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(PreChecker::Instance().CheckName(&layer) != SUCCESS, return FAILED, - "[Invoke][CheckName]Check op[%s] failed, name repeat in caffe prototxt.", - layer.name().c_str()); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(PreChecker::Instance().CheckType(&layer) != SUCCESS, return FAILED, - "[Invoke][CheckType]Check op[%s]'s optype failed, type is not supported.", - layer.name().c_str()); + if (PreChecker::Instance().CheckName(&layer) != SUCCESS) { + GELOGE(FAILED, "[Invoke][CheckName]Check op[%s] failed, name repeat in caffe prototxt.", layer.name().c_str()); + return FAILED; + } + if (PreChecker::Instance().CheckType(&layer) != SUCCESS) { + GELOGE(FAILED, "[Invoke][CheckType]Check op[%s]'s optype failed, type is not supported.", layer.name().c_str()); + return FAILED; + } } return SUCCESS; @@ -1293,9 +1292,11 @@ Status CaffeModelParser::ParseFromMemory(const char *data, uint32_t size, ge::Co for (int32_t layer_index = 0; layer_index < layer_count; ++layer_index) { domi::caffe::LayerParameter &layer = const_cast(proto_message.layer(layer_index)); - GE_CHK_BOOL_EXEC_INFO(CheckValidLayer(layer), continue, - "[Check][Layer]layer phase is train, skip this layer, name:%s, type:%s.", - layer.name().c_str(), layer.type().c_str()); + if (!CheckValidLayer(layer)) { + GELOGI("[Check][Layer]layer phase is train, skip this layer, name:%s, type:%s.", + layer.name().c_str(), layer.type().c_str()); + continue; + } CHECK_FALSE_EXEC(!((layer.type() == ge::parser::DATA_TYPE) && input_data_flag), has_error = true; REPORT_INNER_ERROR("E19999", "net %s has input and data layer simultaneously, check invalid." @@ -1453,23 +1454,16 @@ Status CaffeModelParser::Parse(const char *model_path, ge::ComputeGraphPtr &grap // parse network model by custom proto and get custom operators string custom_proto_path = ge::GetParserContext().custom_proto_path + "custom.proto"; string caffe_proto_path = ge::GetParserContext().caffe_proto_path + "caffe.proto"; - Status result = CustomProtoParse(model_path, custom_proto_path, caffe_proto_path, custom_operator_); - if (result != SUCCESS) { - GELOGE(FAILED, "[Parse][Model] by custom proto failed, model path: %s.", model_path); + GE_CHK_STATUS(CustomProtoParse(model_path, custom_proto_path, caffe_proto_path, custom_operator_), + "[Parse][Model] by custom proto failed, model path: %s.", model_path); + + if (proto_message.layer_size() == 0) { + ErrorManager::GetInstance().ATCReportErrMessage("E11021", {"realpath"}, {model_path}); + GELOGE(FAILED, "[Check][Size]The model file[%s] is consisted of layers-structure which is deprecated in Caffe " + "and unsupported in ATC. The \"layers\" should be changed to \"layer\".", model_path); return FAILED; } - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - proto_message.layer_size() == 0 && proto_message.layers_size() > 0, - ErrorManager::GetInstance().ATCReportErrMessage("E11021", {"realpath"}, {model_path}); - return FAILED, - "[Check][Size]The model file[%s] is consisted of layers-structure which is deprecated in Caffe " - "and unsupported in ATC. The \"layers\" should be changed to \"layer\".", - model_path); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((proto_message.layer_size() == 0), - ErrorManager::GetInstance().ATCReportErrMessage("E11022"); - return FAILED, "[Check][Size]net layer num is zero, prototxt file may be invalid."); - GE_RETURN_WITH_LOG_IF_ERROR(ProtoTypePassManager::Instance().Run(&proto_message, domi::CAFFE), "Run ProtoType Pass Failed"); // Set network name @@ -1515,9 +1509,11 @@ Status CaffeModelParser::Parse(const char *model_path, ge::ComputeGraphPtr &grap for (int32_t layer_index = 0; layer_index < layer_count; ++layer_index) { domi::caffe::LayerParameter &layer = const_cast(proto_message.layer(layer_index)); SaveOrigionLayerTops(layer); - GE_CHK_BOOL_EXEC_INFO(CheckValidLayer(layer), continue, - "[Check][Layer]layer phase is train, skip this layer, name:%s, type:%s.", - layer.name().c_str(), layer.type().c_str()); + if (!CheckValidLayer(layer)) { + GELOGI("[Check][Layer]layer phase is train, skip this layer, name:%s, type:%s.", + layer.name().c_str(), layer.type().c_str()); + continue; + } CHECK_FALSE_EXEC(!((layer.type() == ge::parser::DATA_TYPE) && input_data_flag), has_error = true; GELOGE(FAILED, "[Check][Layer]net %s has input and data layer simultaneously, check invalid." @@ -2112,15 +2108,17 @@ Status CaffeWeightsParser::CheckLayersSize(const google::protobuf::Message *mess } } - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(num_layer == 0 && num_layers > 0, - ErrorManager::GetInstance().ATCReportErrMessage("E11023"); - return FAILED, - "[Check][Param]The weight file is consisted of layers-structure which is deprecated " - "in Caffe and unsupported in ATC. The \"layers\" should be changed to \"layer\"."); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((num_layer == 0), ErrorManager::GetInstance().ATCReportErrMessage("E11024"); - return FAILED, - "[Check][Param] Weight layer num is zero, weight file may be invalid."); - + if (num_layer == 0 && num_layers > 0) { + ErrorManager::GetInstance().ATCReportErrMessage("E11023"); + GELOGE(FAILED, "[Check][Param]The weight file is consisted of layers-structure which is deprecated " + "in Caffe and unsupported in ATC. The \"layers\" should be changed to \"layer\"."); + return FAILED; + } + if (num_layer == 0) { + ErrorManager::GetInstance().ATCReportErrMessage("E11024"); + GELOGE(FAILED, "[Check][Param] Weight layer num is zero, weight file may be invalid."); + return FAILED; + } return SUCCESS; } @@ -2175,20 +2173,20 @@ Status CaffeWeightsParser::ConvertLayerParameter(const google::protobuf::Message GE_CHECK_NOTNULL(factory); std::shared_ptr op_parser = factory->CreateOpParser(op_type); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - (op_parser.get() == nullptr), - REPORT_INPUT_ERROR("E11009", std::vector({"opname", "optype"}), - std::vector({layer_name, op_type})); - return FAILED, - "[Create][OpParser] failed for Op[%s], optype is %s", layer_name.c_str(), op_type.c_str()); + if (op_parser.get() == nullptr) { + REPORT_INPUT_ERROR("E11009", std::vector({"opname", "optype"}), + std::vector({layer_name, op_type})); + GELOGE(FAILED, "[Create][OpParser] failed for Op[%s], optype is %s", layer_name.c_str(), op_type.c_str()); + return FAILED; + } // Parsing weight information through op parser Status status = op_parser->ParseWeights(layer_message, node); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - (status != SUCCESS), - REPORT_CALL_ERROR("E19999", "Parse weight for op:%s(%s) failed", layer_name.c_str(), op_type.c_str()); - return status, - "[Parse][Weights] for op[%s] failed", layer_name.c_str()); + if (status != SUCCESS) { + REPORT_CALL_ERROR("E19999", "Parse weight for op:%s(%s) failed", layer_name.c_str(), op_type.c_str()); + GELOGE(FAILED, "[Parse][Weights] for op[%s] failed", layer_name.c_str()); + return status; + } } return SUCCESS; } @@ -2236,13 +2234,18 @@ Status CaffeWeightsParser::ConvertNetParameter(const NetParameter ¶m, ge::Co // Operator name and occurrence map, handle duplicate operators std::map layer_name_map; - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(num_layer == 0 && num_layers > 0, - ErrorManager::GetInstance().ATCReportErrMessage("E11023"); - return FAILED, "[Check][Param] The weight file is consisted of layers-structure " - "which is deprecated in Caffe and unsupported in ATC. " - "The \"layers\" should be changed to \"layer\"."); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((num_layer == 0), ErrorManager::GetInstance().ATCReportErrMessage("E11024"); - return FAILED, "weight layer num is zero, weight file may be invalid."); + if (num_layer == 0 && num_layers > 0) { + ErrorManager::GetInstance().ATCReportErrMessage("E11023"); + GELOGE(FAILED, "[Check][Param] The weight file is consisted of layers-structure " + "which is deprecated in Caffe and unsupported in ATC. " + "The \"layers\" should be changed to \"layer\"."); + return FAILED; + } + if (num_layer == 0) { + ErrorManager::GetInstance().ATCReportErrMessage("E11024"); + GELOGE(FAILED, "weight layer num is zero, weight file may be invalid."); + return FAILED; + } for (int i = 0; i < num_layer; ++i) { const LayerParameter &layer = param.layer(i); @@ -2301,18 +2304,20 @@ Status CaffeWeightsParser::ConvertNetParameter(const NetParameter ¶m, ge::Co GE_CHECK_NOTNULL(factory); std::shared_ptr op_parser = factory->CreateOpParser(op_type); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - (op_parser.get() == nullptr), - REPORT_INPUT_ERROR("E11009", std::vector({"opname", "optype"}), - std::vector({layer_name, op_type})); - return FAILED, "[Create][OpParser] failed for Op[%s], optype is %s", layer_name.c_str(), op_type.c_str()); + if (op_parser.get() == nullptr) { + REPORT_INPUT_ERROR("E11009", std::vector({"opname", "optype"}), + std::vector({layer_name, op_type})); + GELOGE(FAILED, "[Create][OpParser] failed for Op[%s], optype is %s", layer_name.c_str(), op_type.c_str()); + return FAILED; + } // Parsing weight information through op parser Status status = op_parser->ParseWeights(&layer, node); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - (status != SUCCESS), - REPORT_CALL_ERROR("E19999", "Parse weight for op:%s(%s) failed", layer_name.c_str(), op_type.c_str()); - return status, "[Parse][Weights] for op[%s] failed", layer_name.c_str()); + if (status != SUCCESS) { + REPORT_CALL_ERROR("E19999", "Parse weight for op:%s(%s) failed", layer_name.c_str(), op_type.c_str()); + GELOGE(FAILED, "[Parse][Weights] for op[%s] failed", layer_name.c_str()); + return status; + } } } diff --git a/parser/common/acl_graph_parser_util.cc b/parser/common/acl_graph_parser_util.cc index 6e8a753..2721c01 100644 --- a/parser/common/acl_graph_parser_util.cc +++ b/parser/common/acl_graph_parser_util.cc @@ -613,24 +613,27 @@ domi::Status AclGrphParseUtil::ParseParamsBeforeGraph(const std::mapGetName().c_str()); + if (ParseAclInputFp16Nodes(compute_graph, input_fp16_nodes, is_input_adjust_hw_layout) != SUCCESS) { + GELOGE(FAILED, "[Invoke][ParseAclInputFp16Nodes] Parse input_fp16_nodes failed, graph:%s", + compute_graph->GetName().c_str()); + return PARAM_INVALID; + } return SUCCESS; } @@ -689,30 +694,35 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY std::string RealPath(const char // Get file length FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY long GetFileLength(const std::string &input_file) { - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(input_file.empty(), - REPORT_INNER_ERROR("E19999", "input_file path is null, check invalid."); - return -1, "[Check][Param] input_file path is null."); + if (input_file.empty()) { + REPORT_INNER_ERROR("E19999", "input_file path is null, check invalid."); + GELOGE(FAILED, "[Check][Param] input_file path is null."); + return -1; + } 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, err_msg})); - return -1, "[Get][Path] input_file path '%s' not valid", input_file.c_str()); + if (real_path.empty()) { + REPORT_INPUT_ERROR("E19000", std::vector({"path", "errmsg"}), + std::vector({real_path, err_msg})); + GELOGE(FAILED, "[Get][Path] input_file path '%s' not valid", input_file.c_str()); + return -1; + } 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, 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( - "E19015", std::vector({"file", "size", "maxsize"}), - std::vector({input_file, std::to_string(file_length), - std::to_string(kMaxFileSizeLimit)})); - return -1, "[Check][Param] File[%s] size %lld is out of range(0,%d).", - input_file.c_str(), file_length, kMaxFileSizeLimit); + if (mmGetFileSize(input_file.c_str(), &file_length) != EN_OK) { + ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {input_file, err_msg}); + GELOGE(FAILED, "[Open][File] [%s] failed. %s", input_file.c_str(), err_msg); + return -1; + } + + if ((file_length == 0) || (file_length > kMaxFileSizeLimit)) { + REPORT_INPUT_ERROR("E19015", std::vector({ "file", "size", "maxsize" }), + std::vector({ input_file, std::to_string(file_length), std::to_string(kMaxFileSizeLimit) })); + GELOGE(FAILED, "[Check][Param] File[%s] size %lld is out of range(0,%d).", + input_file.c_str(), file_length, kMaxFileSizeLimit); + return -1; + } return static_cast(file_length); } @@ -725,9 +735,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY uint64_t GetCurrentTimestamp() } static bool ReadProtoFromCodedInputStream(CodedInputStream &coded_stream, Message *proto) { - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(proto == nullptr, - REPORT_INNER_ERROR("E19999", "param proto is nullptr, check invalid"); - return false, "[Check][Param] incorrect parameter. nullptr == proto"); + if (proto == nullptr) { + REPORT_INNER_ERROR("E19999", "param proto is nullptr, check invalid"); + GELOGE(FAILED, "[Check][Param] incorrect parameter. nullptr == proto"); + return false; + } coded_stream.SetTotalBytesLimit(kProtoReadBytesLimit); return proto->ParseFromCodedStream(&coded_stream); @@ -743,17 +755,23 @@ static bool ReadProtoFromCodedInputStream(CodedInputStream &coded_stream, Messag */ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadBytesFromBinaryFile(const char *file_name, char **buffer, int &length) { - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((file_name == nullptr), - REPORT_INNER_ERROR("E19999", "param file_name is nullptr, check invalid"); - return false, "[Check][Param] incorrect parameter. file is nullptr"); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((buffer == nullptr), - REPORT_INNER_ERROR("E19999", "param buffer is nullptr, check invalid"); - return false, "[Check][Param] incorrect parameter. buffer is nullptr"); + if (file_name == nullptr) { + REPORT_INNER_ERROR("E19999", "param file_name is nullptr, check invalid"); + GELOGE(FAILED, "[Check][Param] incorrect parameter. file is nullptr"); + return false; + } + if (buffer == nullptr) { + REPORT_INNER_ERROR("E19999", "param buffer is nullptr, check invalid"); + GELOGE(FAILED, "[Check][Param] incorrect parameter. buffer is nullptr"); + return false; + } std::string real_path = RealPath(file_name); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(real_path.empty(), - REPORT_INNER_ERROR("E19999", "file path '%s' not valid, realpath failed", file_name); - return false, "[Check][Param]file path '%s' not valid, realpath failed", file_name); + if (real_path.empty()) { + REPORT_INNER_ERROR("E19999", "file path '%s' not valid, realpath failed", file_name); + GELOGE(FAILED, "[Check][Param]file path '%s' not valid, realpath failed", file_name); + return false; + } std::ifstream file(real_path.c_str(), std::ios::binary | std::ios::ate); if (!file.is_open()) { @@ -763,16 +781,22 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadBytesFromBinaryFile(co } length = static_cast(file.tellg()); - - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((length <= 0), file.close(); REPORT_INNER_ERROR("E19999", "file length <= 0"); - return false, "[Check][Param] file length <= 0"); + if ((length <= 0)) { + file.close(); + REPORT_INNER_ERROR("E19999", "file length <= 0"); + GELOGE(FAILED, "[Check][Param] file length <= 0"); + return false; + } file.seekg(0, std::ios::beg); *buffer = new(std::nothrow) char[length](); - GE_CHK_BOOL_TRUE_EXEC_RET_STATUS(*buffer == nullptr, false, file.close(); - REPORT_CALL_ERROR("E19999", "new an object failed."), - "[Create][Buffer] new an object failed."); + if (*buffer == nullptr) { + REPORT_INNER_ERROR("E19999", "[Create][Buffer] new an object failed, length=%d.", length); + GELOGE(FAILED, "[Create][Buffer] new an object failed, length=%d.", length); + file.close(); + return false; + } file.read(*buffer, length); file.close(); @@ -780,16 +804,23 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadBytesFromBinaryFile(co } FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromBinaryFile(const char *file, Message *proto) { - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((file == nullptr || proto == nullptr), - REPORT_INNER_ERROR("E19999", "param file or proto is nullptr, check invalid"); - return false, "[Check][Param] Input parameter file or proto is nullptr!"); + if ((file == nullptr) || (proto == nullptr)) { + REPORT_INNER_ERROR("E19999", "param file or proto is nullptr, check invalid"); + GELOGE(FAILED, "[Check][Param] Input parameter file or proto is nullptr!"); + return false; + } std::string real_path = RealPath(file); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(real_path.empty(), - REPORT_INNER_ERROR("E19999", "file path '%s' not valid, realpath failed", file); - return false, "[Check][Param]pb file path '%s' not valid, realpath failed", file); + if (real_path.empty()) { + REPORT_INNER_ERROR("E19999", "file path '%s' not valid, realpath failed", file); + GELOGE(FAILED, "[Check][Param]pb file path '%s' not valid, realpath failed", file); + return false; + } - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(GetFileLength(real_path) == -1, return false, "[Get][FileLength]file size not valid."); + if (GetFileLength(real_path) == -1) { + GELOGE(FAILED, "[Get][FileLength]file size not valid."); + return false; + } std::ifstream fs(real_path, std::ifstream::in | std::ifstream::binary); if (!fs.is_open()) { @@ -815,10 +846,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromBinaryFile(co } FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromArray(const void *data, int size, Message *proto) { - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((proto == nullptr || data == nullptr || size == 0), - REPORT_INNER_ERROR("E19999", "param proto or data is nullptr " - "or size is 0, check invalid"); return false, - "[Check][Param]incorrect parameter. proto is nullptr || data is nullptr || size is 0"); + if ((proto == nullptr) || (data == nullptr) || (size == 0)) { + REPORT_INNER_ERROR("E19999", "param proto or data is nullptr or size is 0, check invalid"); + GELOGE(FAILED, "[Check][Param]incorrect parameter. proto is nullptr || data is nullptr || size is 0"); + return false; + } google::protobuf::io::CodedInputStream coded_stream(PtrToPtr(const_cast(data)), size); return ReadProtoFromCodedInputStream(coded_stream, proto); @@ -826,21 +858,25 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromArray(const v FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromText(const char *file, google::protobuf::Message *message) { - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((file == nullptr || message == nullptr), - REPORT_INNER_ERROR("E19999", "param file or message is nullptr, check invalid"); - return false, - "[Check][Param]incorrect parameter. nullptr == file || nullptr == message"); + if ((file == nullptr) || (message == nullptr)) { + REPORT_INNER_ERROR("E19999", "param file or message is nullptr, check invalid"); + GELOGE(FAILED, "[Check][Param]incorrect parameter. nullptr == file || nullptr == message"); + return false; + } 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, err_msg}); - return false, "[Check][Param]Path[%s]'s realpath is empty, errmsg[%s]", file, - err_msg); + if (real_path.empty()) { + ErrorManager::GetInstance().ATCReportErrMessage("E19000", {"path", "errmsg"}, {file, err_msg}); + GELOGE(FAILED, "[Check][Param]Path[%s]'s realpath is empty, errmsg[%s]", file, err_msg); + return false; + } - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(GetFileLength(real_path) == -1, return false, "[Check][Param] file size not valid."); + if (GetFileLength(real_path) == -1) { + GELOGE(FAILED, "[Check][Param] file size not valid."); + return false; + } std::ifstream fs(real_path.c_str(), std::ifstream::in); @@ -863,10 +899,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromText(const ch FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromMem(const char *data, int size, google::protobuf::Message *message) { - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((data == nullptr || message == nullptr), - REPORT_INNER_ERROR("E19999", "param data or message is nullptr,check invalid"); - return false, - "[Check][Param] incorrect parameter. data is nullptr || message is nullptr"); + if ((data == nullptr) || (message == nullptr)) { + REPORT_INNER_ERROR("E19999", "param data or message is nullptr,check invalid"); + GELOGE(FAILED, "[Check][Param] incorrect parameter. data is nullptr || message is nullptr"); + return false; + } std::string str(data, static_cast(size)); std::istringstream fs(str); diff --git a/parser/common/model_saver.cc b/parser/common/model_saver.cc index 0102848..2963ad3 100644 --- a/parser/common/model_saver.cc +++ b/parser/common/model_saver.cc @@ -55,9 +55,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelSaver::SaveJsonToFi } char real_path[PATH_MAX] = {0}; - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(file_path) >= PATH_MAX, - REPORT_INNER_ERROR("E19999", "file path %s is too long!", file_path); - return FAILED, "[Check][Param] file path %s is too long!", file_path); + if (strlen(file_path) >= PATH_MAX) { + REPORT_INNER_ERROR("E19999", "file path %s is too long!", file_path); + GELOGE(FAILED, "[Check][Param] file path %s is too long!", file_path); + return FAILED; + } if (realpath(file_path, real_path) == nullptr) { GELOGI("File %s does not exit, it will be created.", file_path); } diff --git a/parser/tensorflow/graph_functiondef.cc b/parser/tensorflow/graph_functiondef.cc index 51ebf37..0758b97 100644 --- a/parser/tensorflow/graph_functiondef.cc +++ b/parser/tensorflow/graph_functiondef.cc @@ -161,7 +161,6 @@ domi::Status RemapFunctionDef(FunctionDef *fdef, const string &name, NameMapHelp if (node_def->input(i).find("^") != string::npos) { // Control input const string normalized = node_names.Renormalize(node_def->input(i).substr(1)); - GE_IF_BOOL_EXEC(normalized.empty(), REPORT_INNER_ERROR("E19999", "Could not remap control input %s of node %s in function %s", node_def->input(i).c_str(), node_def->name().c_str(), name.c_str()); @@ -172,7 +171,6 @@ domi::Status RemapFunctionDef(FunctionDef *fdef, const string &name, NameMapHelp *node_def->mutable_input(i) = "^" + normalized; } else { const auto iter = tensor_renaming.find(node_def->input(i)); - GE_IF_BOOL_EXEC(iter == tensor_renaming.end(), REPORT_INNER_ERROR("E19999", "Could not remap input %s of node %s in function %s", node_def->input(i).c_str(), node_def->name().c_str(), name.c_str()); @@ -188,14 +186,12 @@ domi::Status RemapFunctionDef(FunctionDef *fdef, const string &name, NameMapHelp // Remap return values. for (int r = 0; r < fdef->signature().output_arg_size(); ++r) { const string &ret_name = fdef->signature().output_arg(r).name(); - GE_IF_BOOL_EXEC(ret_name.empty(), REPORT_INNER_ERROR("E19999", "Missing output %d to function %s", r, name.c_str()); GELOGE(domi::INTERNAL_ERROR, "Missing output %d to function %s .", r, name.c_str()); return domi::INTERNAL_ERROR); const string &return_value = return_values[ret_name]; - GE_IF_BOOL_EXEC(return_value.empty(), REPORT_INNER_ERROR("E19999", "Could not remap return value %d ,%s of %s in function %s", r, ret_name.c_str(), return_value.c_str(), name.c_str()); @@ -204,12 +200,11 @@ domi::Status RemapFunctionDef(FunctionDef *fdef, const string &name, NameMapHelp return domi::INTERNAL_ERROR); const auto iter = tensor_renaming.find(return_value); - - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(iter == tensor_renaming.end(), - REPORT_INNER_ERROR("E19999", "can not find value[%s] in tensor_renaming map", - return_value.c_str()); - return domi::INTERNAL_ERROR, - "can not find value[%s] in tensor_renaming map.", return_value.c_str()); + if (iter == tensor_renaming.end()) { + REPORT_INNER_ERROR("E19999", "can not find value[%s] in tensor_renaming map", return_value.c_str()); + GELOGE(FAILED, "can not find value[%s] in tensor_renaming map.", return_value.c_str()); + return domi::INTERNAL_ERROR; + } (*fdef->mutable_ret())[ret_name] = iter->second; } @@ -378,7 +373,6 @@ domi::Status GraphToFunctionDef::DavGraphToFunctionDef(ge::ComputeGraphPtr graph GE_CHECK_NOTNULL(node); if (node->GetOpDesc()->GetType() == ge::parser::DATA) { int64_t index = 0; - int64_t type = 1; GE_CHK_BOOL_RET_STATUS(ge::AttrUtils::GetInt(node->GetOpDesc(), "T", type), PARAM_INVALID, "Get type attr failed"); @@ -400,7 +394,6 @@ domi::Status GraphToFunctionDef::DavGraphToFunctionDef(ge::ComputeGraphPtr graph if (node->GetOpDesc()->GetType() == ge::parser::NETOUTPUT) { int64_t index = 0; int64_t type = 1; - GE_CHK_BOOL_RET_STATUS(ge::AttrUtils::GetInt(node->GetOpDesc(), "T", type), PARAM_INVALID, "Get type attr failed"); @@ -589,7 +582,10 @@ bool GraphToFunctionDef::FindAttrValue(const domi::tensorflow::NodeDef *node_def void GraphToFunctionDef::AddNodeAttr(const string &attr_name, const domi::tensorflow::AttrValue &value, domi::tensorflow::NodeDef *node_def) { - GE_CHK_BOOL_TRUE_EXEC_INFO(node_def == nullptr, return, "input parameter is null."); + if (node_def == nullptr) { + GELOGI("input parameter is null."); + return; + } node_def->mutable_attr()->insert(AttrValueMap::value_type(attr_name, value)); } } // namespace ge diff --git a/parser/tensorflow/graph_optimizer.cc b/parser/tensorflow/graph_optimizer.cc index bd6b6f5..ce56a6b 100644 --- a/parser/tensorflow/graph_optimizer.cc +++ b/parser/tensorflow/graph_optimizer.cc @@ -206,9 +206,11 @@ Status ParserGraphOptimizer::UpdateGraph(vector &nodes) { std::unique_ptr func_def_lib(new (std::nothrow) FunctionDefLibrary()); GE_CHECK_NOTNULL(func_def_lib); // convert graph to FunctionDef - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(nodes.size() == 0, - REPORT_INNER_ERROR("E19999", "Param nodes size must greater than 0"); - return PARAM_INVALID, "node size must greater than 0 ."); + if (nodes.size() == 0) { + REPORT_INNER_ERROR("E19999", "Param nodes size must greater than 0"); + GELOGE(FAILED, "node size must greater than 0 ."); + return PARAM_INVALID; + } GE_CHK_STATUS_RET(CollectNodeFuncs(nodes, func_def_lib.get()), "Collect functionDef in nodes failed."); GE_CHK_STATUS_RET(GraphToFunctionDef::BuildFunctionDef(sub_graph, nodes[0]->GetName(), func_def_lib.get(), node_def.get(), input_anchors, output_anchors), @@ -226,7 +228,10 @@ Status ParserGraphOptimizer::UpdateGraph(vector &nodes) { GELOGE(PARAM_INVALID, "Serialize func_def to string failed."); return PARAM_INVALID); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(nodes.size() == 0, return PARAM_INVALID, "nodes is empty."); + if (nodes.size() == 0) { + GELOGE(FAILED, "nodes is empty."); + return PARAM_INVALID; + } std::string fusion_op_name; for (auto node : nodes) { @@ -410,12 +415,12 @@ Status ParserGraphOptimizer::RebuildInputAnchors(vector &in auto tensorDescPtr = dst_node->GetOpDesc()->GetInputDescPtr(in_anchor->GetIdx()); GE_CHECK_NOTNULL_EXEC(tensorDescPtr, return domi::FAILED); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((fusion_op_desc->AddInputDesc(*tensorDescPtr)) != GRAPH_SUCCESS, - REPORT_CALL_ERROR("E19999", "Add input desc to op:%s(%s) failed", - fusion_op_desc->GetName().c_str(), - fusion_op_desc->GetType().c_str()); - return FAILED, - "Add fusion_op_desc AddInputDesc failed"); + if (fusion_op_desc->AddInputDesc(*tensorDescPtr) != GRAPH_SUCCESS) { + REPORT_CALL_ERROR("E19999", "Add input desc to op:%s(%s) failed", + fusion_op_desc->GetName().c_str(), fusion_op_desc->GetType().c_str()); + GELOGE(FAILED, "Add fusion_op_desc AddInputDesc failed"); + return FAILED; + } ge::DataType data_type = tensorDescPtr->GetDataType(); const std::map::const_iterator iter = GE_TENSORFLOW_DATA_TYPE_MAP.find((int32_t)data_type); GE_IF_BOOL_EXEC( diff --git a/parser/tensorflow/tensorflow_parser.cc b/parser/tensorflow/tensorflow_parser.cc index 2167dbf..70be97f 100644 --- a/parser/tensorflow/tensorflow_parser.cc +++ b/parser/tensorflow/tensorflow_parser.cc @@ -508,8 +508,11 @@ Status TensorFlowModelParser::AddNode(const domi::tensorflow::NodeDef *node_def, ge::NodePtr node = nullptr; node = graph->AddNode(op_desc); - - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((node == nullptr), DeleteFuisonNodeDef(); return INTERNAL_ERROR, "add node failed."); + if (node == nullptr) { + DeleteFuisonNodeDef(); + GELOGE(FAILED, "add node failed."); + return INTERNAL_ERROR; + } node_map_[node_name] = node; @@ -546,7 +549,11 @@ Status TensorFlowModelParser::AddNode(const domi::tensorflow::NodeDef *node_def, // checkout op input number with IR GE_RETURN_IF_ERROR(CheckoutInputNum(op, node_def)); ge::NodePtr node = graph->AddNode(op); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((node == nullptr), DeleteFuisonNodeDef(); return INTERNAL_ERROR, "add node failed."); + if (node == nullptr) { + DeleteFuisonNodeDef(); + GELOGE(FAILED, "add node failed."); + return INTERNAL_ERROR; + } node_map_[node_name] = node; @@ -795,22 +802,24 @@ Status TensorFlowModelParser::AddEdges(ge::ComputeGraphPtr &graph) { GE_CHECK_NOTNULL(out_archor_ptr); ge::InDataAnchorPtr in_archor_ptr = dest->GetInDataAnchor(outputpair.second); GE_CHECK_NOTNULL(in_archor_ptr); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ge::GraphUtils::AddEdge(out_archor_ptr, in_archor_ptr) != ge::GRAPH_SUCCESS, - REPORT_INNER_ERROR("E19999", "Add link from op:%s to op:%s failed", - src->GetName().c_str(), dest->GetName().c_str()); - return INTERNAL_ERROR, "Add link failed from op[%s] to op[%s].", - src->GetName().c_str(), dest->GetName().c_str()); + if (ge::GraphUtils::AddEdge(out_archor_ptr, in_archor_ptr) != ge::GRAPH_SUCCESS) { + REPORT_INNER_ERROR("E19999", "Add link from op:%s to op:%s failed", + src->GetName().c_str(), dest->GetName().c_str()); + GELOGE(FAILED, "Add link failed from op[%s] to op[%s].", src->GetName().c_str(), dest->GetName().c_str()); + return INTERNAL_ERROR; + } } else { GELOGD("Start add contorl edge: from %s to %s.", src->GetName().c_str(), dest->GetName().c_str()); ge::InControlAnchorPtr in_archor_ptr = dest->GetInControlAnchor(); GE_CHECK_NOTNULL(in_archor_ptr); ge::OutControlAnchorPtr out_archor_ptr = src->GetOutControlAnchor(); GE_CHECK_NOTNULL(out_archor_ptr); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ge::GraphUtils::AddEdge(out_archor_ptr, in_archor_ptr) != ge::GRAPH_SUCCESS, - REPORT_INNER_ERROR("E19999", "Add link from op:%s to op:%s failed", - src->GetName().c_str(), dest->GetName().c_str()); - return INTERNAL_ERROR, "Add link failed from op[%s] to op[%s].", - src->GetName().c_str(), dest->GetName().c_str()); + if (ge::GraphUtils::AddEdge(out_archor_ptr, in_archor_ptr) != ge::GRAPH_SUCCESS) { + REPORT_INNER_ERROR("E19999", "Add link from op:%s to op:%s failed", + src->GetName().c_str(), dest->GetName().c_str()); + GELOGE(FAILED, "Add link failed from op[%s] to op[%s].", src->GetName().c_str(), dest->GetName().c_str()); + return INTERNAL_ERROR; + } } } dest_input_map.erase(input_iter); @@ -922,10 +931,11 @@ Status TensorFlowModelParser::ParseNodeDef(TensorFlowModelParser *parser, ge::Co } std::map::const_iterator iterator = parser->adaptedOpTypeMap_.find(node_name); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - iterator == parser->adaptedOpTypeMap_.cend(), - REPORT_INNER_ERROR("E19999", "get adapted op type failed, node name = %s", node_name.c_str()); - return FAILED, "get adapted op type failed, node name = %s", node_name.c_str()); + if (iterator == parser->adaptedOpTypeMap_.cend()) { + REPORT_INNER_ERROR("E19999", "get adapted op type failed, node name = %s", node_name.c_str()); + GELOGE(FAILED, "get adapted op type failed, node name = %s", node_name.c_str()); + return FAILED; + } string op_type = iterator->second; // Log printing for determining operator type @@ -1018,10 +1028,12 @@ Status TensorFlowModelParser::ParseNodeDef(TensorFlowModelParser *parser, ge::Co node = graph->AddNode(op); } - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - (node == nullptr), REPORT_CALL_ERROR("E19999", "Add node:%s(%s) to graph:%s failed", op->GetName().c_str(), - op->GetType().c_str(), graph->GetName().c_str()); - return INTERNAL_ERROR, "add node failed."); + if (node == nullptr) { + REPORT_CALL_ERROR("E19999", "Add node:%s(%s) to graph:%s failed", op->GetName().c_str(), + op->GetType().c_str(), graph->GetName().c_str()); + GELOGE(FAILED, "add node failed."); + return INTERNAL_ERROR; + } if (needFusion) { shared_ptr fusion_op_parser = factory->CreateFusionOpParser(op_type); @@ -1117,10 +1129,11 @@ Status TensorFlowModelParser::AddNodeToGraphAndMarkFormat(ge::ComputeGraphPtr &g for (size_t j = 0; j < op_node_list_size; j++) { const string op_node_name = op_node_name_list[j]; auto iterator = node_map_.find(op_node_name); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - (iterator == node_map_.end()), - REPORT_INNER_ERROR("E19999", "node:%s can't find in node_map_, check invalid", op_node_name.c_str()); - return INTERNAL_ERROR, "add node failed."); + if (iterator == node_map_.end()) { + REPORT_INNER_ERROR("E19999", "node:%s can't find in node_map_, check invalid", op_node_name.c_str()); + GELOGE(FAILED, "add node failed."); + return INTERNAL_ERROR; + } GE_CHECK_NOTNULL(iterator->second); GE_CHK_STATUS_RET(iterator->second->SetOwnerComputeGraph(graph), "set owner compute graph failed"); graph->AddNode(iterator->second); @@ -1179,15 +1192,22 @@ Status TensorFlowModelParser::ParseFromMemory(const char *data, uint32_t size, g domi::tensorflow::GraphDef OriDef; bool read = ge::parser::ReadProtoFromArray(data, static_cast(size), &OriDef); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(!read, REPORT_INNER_ERROR("E19999", "read graph proto from binary failed"); - return INTERNAL_ERROR, "read_proto_from_binary failed."); + if (!read) { + REPORT_INNER_ERROR("E19999", "read graph proto from binary failed"); + GELOGE(FAILED, "read_proto_from_binary failed."); + return INTERNAL_ERROR; + } domi::tensorflow::GraphDef graph_def; - if (ge::GetParserContext().input_dims.empty() && ge::GetParserContext().out_nodes_map.empty()) { + const bool is_empty_input = GetParserContext().input_dims.empty() && GetParserContext().out_nodes_map.empty(); + if (is_empty_input) { graph_def = OriDef; } else { GELOGI("Before Trim, the Graph Node size is:%d", OriDef.node_size()); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(TrimGraph(OriDef, &graph_def), return INTERNAL_ERROR, "Trim Graph fail."); + if (TrimGraph(OriDef, &graph_def)) { + GELOGE(FAILED, "Trim Graph fail."); + return INTERNAL_ERROR; + } GELOGI("After Trim, The graph_def.node_size():%d", graph_def.node_size()); } @@ -1267,9 +1287,12 @@ Status TensorFlowModelParser::ParseFromMemory(const char *data, uint32_t size, g return INTERNAL_ERROR; } const string &node_op = node_def->op(); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((tensorflow_op_map.find(node_op) == tensorflow_op_map.cend()), DeleteFuisonNodeDef(); - REPORT_INNER_ERROR("E19999", "Op type %s unsupport", node_op.c_str()); - return INTERNAL_ERROR, "Unsupport op type %s", node_op.c_str()); + if (tensorflow_op_map.find(node_op) == tensorflow_op_map.cend()) { + DeleteFuisonNodeDef(); + REPORT_INNER_ERROR("E19999", "Op type %s unsupport", node_op.c_str()); + GELOGE(FAILED, "Unsupport op type %s", node_op.c_str()); + return INTERNAL_ERROR; + } ret = AddNode(node_def, graph, scope_graph); if (ret != SUCCESS) { @@ -1337,7 +1360,10 @@ Status TensorFlowModelParser::Parse(const char *model_path, ge::ComputeGraphPtr // Store objects parsed from pb files domi::tensorflow::GraphDef ori_def; bool read = ge::parser::ReadProtoFromBinaryFile(model_path, &ori_def); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(!read, return INTERNAL_ERROR, "read_proto_from_binary failed."); + if (!read) { + GELOGE(FAILED, "read_proto_from_binary failed."); + return INTERNAL_ERROR; + } // Trim graph by user input and output. domi::tensorflow::GraphDef graph_def; @@ -1345,7 +1371,10 @@ Status TensorFlowModelParser::Parse(const char *model_path, ge::ComputeGraphPtr graph_def = ori_def; } else { GELOGI("Before Trim, the Graph Node size is:%d", ori_def.node_size()); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(TrimGraph(ori_def, &graph_def), return INTERNAL_ERROR, "Trim Graph fail."); + if (TrimGraph(ori_def, &graph_def)) { + GELOGE(FAILED, "Trim Graph fail."); + return INTERNAL_ERROR; + } GELOGI("After Trim, The graph_def.node size is:%d", graph_def.node_size()); } @@ -1440,12 +1469,16 @@ Status TensorFlowModelParser::ParseAllGraph(const google::protobuf::Message *pro GE_RETURN_WITH_LOG_IF_ERROR(PreChecker::Instance().AddOp(&node, node.name(), node.op()), "Add node_def to PreChecker failed, node name: %s.", node.name().c_str()); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(PreChecker::Instance().CheckName(&node) != SUCCESS, return FAILED, - "Check op[%s] failed, name repeat in tensorflow pb file.", node.name().c_str()); - GE_CHK_BOOL_EXEC_NOLOG( - node.op() == TENSORFLOWF_NODE_OP_IDENTITY, - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(PreChecker::Instance().CheckType(&node, true) != SUCCESS, return FAILED, - "Check op[%s]'s optype failed, type is not supported.", node.name().c_str());) + if (PreChecker::Instance().CheckName(&node) != SUCCESS) { + GELOGE(FAILED, "Check op[%s] failed, name repeat in tensorflow pb file.", node.name().c_str()); + return FAILED; + } + if (node.op() != TENSORFLOWF_NODE_OP_IDENTITY) { + if (PreChecker::Instance().CheckType(&node, true) != SUCCESS) { + GELOGE(FAILED, "Check op[%s]'s optype failed, type is not supported.", node.name().c_str()); + return FAILED; + } + } } bool has_error = false; @@ -2441,17 +2474,19 @@ Status TensorFlowModelParser::ParseProtoWithSubgraph(const std::string &root_pro Status TensorFlowModelParser::OptimizeIdentityByOutput(map &nodedef_map, const string &curr_node_name, bool &clear_input_flag) { auto context_iter = op_node_context_map_.find(curr_node_name); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - (context_iter == op_node_context_map_.end()), - REPORT_INNER_ERROR("E19999", "Node:%s can't find in op_node_context_map_, check invalid", curr_node_name.c_str()); - return INTERNAL_ERROR, "Can't find op node context."); + if (context_iter == op_node_context_map_.end()) { + REPORT_INNER_ERROR("E19999", "Node:%s can't find in op_node_context_map_, check invalid", curr_node_name.c_str()); + GELOGE(FAILED, "Can't find op node context."); + return INTERNAL_ERROR; + } OpNodeContext op_node_context = context_iter->second; const std::map::const_iterator node_def_iter = nodedef_map.find(curr_node_name); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - (node_def_iter == nodedef_map.cend()), - REPORT_INNER_ERROR("E19999", "Node:%s can't find in nodedef_map, check invalid", curr_node_name.c_str()); - return INTERNAL_ERROR, "Can't find nodedef"); + if (node_def_iter == nodedef_map.cend()) { + REPORT_INNER_ERROR("E19999", "Node:%s can't find in nodedef_map, check invalid", curr_node_name.c_str()); + GELOGE(FAILED, "Can't find nodedef"); + return INTERNAL_ERROR; + } domi::tensorflow::NodeDef *curr_node_def = node_def_iter->second; GE_CHECK_NOTNULL(curr_node_def); bool has_out_retval = false; @@ -2516,17 +2551,13 @@ Status TensorFlowModelParser::OptimizeSnapShot(domi::tensorflow::NodeDef *curr_m const std::pair &input_data, const std::vector &control_list) { GE_CHECK_NOTNULL(curr_mode_def); - if (curr_mode_def == nullptr) { - REPORT_INNER_ERROR("E19999", "Param curr_mode_def is nullptr, check invalid"); - GELOGE(FAILED, "input param is nullptr."); - return PARAM_INVALID; - } string curr_node_name = curr_mode_def->name(); auto context_iter = op_node_context_map_.find(curr_node_name); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - (context_iter == op_node_context_map_.end()), - REPORT_INNER_ERROR("E19999", "Node:%s can't find in op_node_context_map_, check invalid", curr_node_name.c_str()); - return INTERNAL_ERROR, "Can't find op node context."); + if (context_iter == op_node_context_map_.end()) { + REPORT_INNER_ERROR("E19999", "Node:%s can't find in op_node_context_map_, check invalid", curr_node_name.c_str()); + GELOGE(FAILED, "Can't find op node context."); + return INTERNAL_ERROR; + } OpNodeContext op_node_context = context_iter->second; std::map>> output_map = op_node_context.output_map; @@ -3076,10 +3107,10 @@ Status TensorFlowModelParser::TrimGraphByInput(const domi::tensorflow::GraphDef std::set next_inputs; for (const string ¤t_input : current_inputs) { delete_nodes.insert(current_input); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(!node_lookup.count(current_input), - ErrorManager::GetInstance().ATCReportErrMessage("E10016", {"parameter", "opname"}, - {"input_shape", current_input}); - return FAILED, "Input op[%s] not found in graph.", current_input.c_str()); + GE_CHK_BOOL_EXEC(node_lookup.count(current_input) > 0U, + ErrorManager::GetInstance().ATCReportErrMessage("E10016", {"parameter", "opname"}, + {"input_shape", current_input}); + return FAILED, "Input op[%s] not found in graph.", current_input.c_str()); const NodeDef *current_node = node_lookup[current_input]; GE_CHECK_NOTNULL(current_node); for (const string &input_name : current_node->input()) { @@ -3152,10 +3183,10 @@ Status TensorFlowModelParser::TrimGraphByOutput(const domi::tensorflow::GraphDef for (const string ¤t_input : current_inputs) { required_nodes.insert(current_input); GE_IF_BOOL_EXEC(input_nodes.count(current_input), continue); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(!node_lookup.count(current_input), - ErrorManager::GetInstance().ATCReportErrMessage("E10016", {"parameter", "opname"}, - {"out_nodes", current_input}); - return FAILED, "Input op[%s] not found in graph.", current_input.c_str()); + GE_CHK_BOOL_EXEC(node_lookup.count(current_input) > 0U, + ErrorManager::GetInstance().ATCReportErrMessage("E10016", {"parameter", "opname"}, + {"out_nodes", current_input}); + return FAILED, "Input op[%s] not found in graph.", current_input.c_str()); const NodeDef *current_node = node_lookup[current_input]; GE_CHECK_NOTNULL(current_node); for (const string &input_name : current_node->input()) { @@ -3231,11 +3262,12 @@ Status TensorFlowModelParser::FusionNodeParseParams(shared_ptr &op_par // Find all children of the fusion operator auto iter = fusion_op_nodedef_map_.find(node_def->name()); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - iter == fusion_op_nodedef_map_.end(), - REPORT_INNER_ERROR("E19999", "Node:%s can't find in fusion_op_nodedef_map_, check invalid", - node_def->name().c_str()); - return INTERNAL_ERROR, "FusionOp node %s has no children node!", node_def->name().c_str()); + if (iter == fusion_op_nodedef_map_.end()) { + REPORT_INNER_ERROR("E19999", "Node:%s can't find in fusion_op_nodedef_map_, check invalid", + node_def->name().c_str()); + GELOGE(FAILED, "FusionOp node %s has no children node!", node_def->name().c_str()); + return INTERNAL_ERROR; + } (void)ge::AttrUtils::SetStr(node->GetOpDesc(), ge::ATTR_NAME_FUSIONOP_ORIGINAL_TYPE, node_def->op()); vector node_def_v = iter->second; @@ -3302,7 +3334,7 @@ Status TensorFlowModelParser::OptimizeConstNodes4CustomOp(domi::tensorflow::Grap string node_name = current_node->name(); all_nodedef_map[node_name] = current_node; } - GE_CHK_BOOL_EXEC_INFO(!all_nodedef_map.empty(), return SUCCESS, "all_nodedef_map is empty"); + GELOGD("node size is: %zu", all_nodedef_map.size()); // 2. move input to attr. for (auto &it_node_map : all_nodedef_map) { @@ -3313,14 +3345,14 @@ Status TensorFlowModelParser::OptimizeConstNodes4CustomOp(domi::tensorflow::Grap // 2.1. check whether the current op is register for move to attr. const std::vector &move_input_vec = domi::OpRegistry::Instance()->GetRemoveInputConfigure(current_op_name); - GE_CHK_BOOL_EXEC_NOLOG(!move_input_vec.empty(), continue); - GELOGD("Current op %s is registered for remove input.", current_op_name.c_str()); - // 2.2 check whether the current op is a TVM op. - GE_CHK_BOOL_EXEC_INFO( - domi::OpRegistry::Instance()->GetImplyTypeByOriOpType(current_op_name) == domi::ImplyType::TVM, continue, - "op %s is not TVM op", current_op_name.c_str()); - GELOGD("handle tvm op %s", current_op_name.c_str()); + const bool is_unknown_custom_op = move_input_vec.empty() || + (domi::OpRegistry::Instance()->GetImplyTypeByOriOpType(current_op_name) != domi::ImplyType::TVM); + if (is_unknown_custom_op) { + GELOGI("op %s is not TVM op, move input size: %zu", current_op_name.c_str(), move_input_vec.size()); + continue; + } + GELOGD("Current op %s is registered for remove input and tvm op", current_op_name.c_str()); // 2.3 copy input to attr set unused_inputs; @@ -3367,7 +3399,8 @@ Status TensorFlowModelParser::OptimizeConstNodes4CustomOp(domi::tensorflow::Grap } for (size_t i = 0; i < it.input_order.size(); ++i) { int new_index = it.input_order[i]; - if (new_index < 0 || new_index >= inputs.size()) { + const bool is_input_invalid = (new_index < 0) || (new_index >= inputs.size()); + if (is_input_invalid) { REPORT_INNER_ERROR("E19999", "New order of %s has invalid index %d, out of range(0, %d)", it_node_map.first.c_str(), new_index, inputs.size()); GELOGE(INTERNAL_ERROR, "New order of %s has invalid index %d.", it_node_map.first.c_str(), new_index); diff --git a/parser/tensorflow/tensorflow_util.cc b/parser/tensorflow/tensorflow_util.cc index e68a79e..256bbea 100644 --- a/parser/tensorflow/tensorflow_util.cc +++ b/parser/tensorflow/tensorflow_util.cc @@ -301,7 +301,10 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY domi::Status TensorFlowUtil::Tr } FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void TensorFlowUtil::AddNodeAttr( const std::string &attr_name, const domi::tensorflow::AttrValue &value, domi::tensorflow::NodeDef *const node_def) { - GE_CHK_BOOL_TRUE_EXEC_INFO(node_def == nullptr, return, "input parameter is null."); + if (node_def == nullptr) { + GELOGI("input parameter is null."); + return; + } node_def->mutable_attr()->insert(AttrValueMap::value_type(attr_name, value)); } } // namespace ge From 68e0ecd2540e5742f5b3e8d04db6057ccff14aa4 Mon Sep 17 00:00:00 2001 From: "tanghaojie1@huawei.com" Date: Wed, 13 Apr 2022 10:01:08 +0800 Subject: [PATCH 3/3] update metadef submodule --- metadef | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadef b/metadef index 0a4c051..b3374c1 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit 0a4c05147cf6e1aa62172636c271e625549f3778 +Subproject commit b3374c154d01a34e7173cd982c8eb46158f790aa