From 350a0024fa59e624ebc74d46d8c96579f75d0be5 Mon Sep 17 00:00:00 2001 From: xujiuxu Date: Fri, 26 Aug 2022 15:47:49 +0800 Subject: [PATCH] clean code --- CMakeLists.txt | 1 + inc/external/parser/caffe_parser.h | 19 +---- inc/external/parser/onnx_parser.h | 18 +---- inc/external/parser/parser_common.h | 34 +++++++++ inc/external/parser/tensorflow_parser.h | 17 +---- parser/caffe/caffe_custom_parser_adapter.cc | 57 +++++++++------ parser/caffe/caffe_custom_parser_adapter.h | 16 +++- parser/caffe/caffe_data_parser.cc | 48 ++++++------ parser/caffe/caffe_data_parser.h | 6 +- parser/caffe/caffe_op_parser.cc | 85 ++++++++-------------- parser/caffe/caffe_op_parser.h | 15 +++- parser/caffe/caffe_parser.cc | 7 +- parser/caffe/caffe_parser.h | 4 +- parser/caffe/caffe_reshape_parser.cc | 10 +-- parser/caffe/caffe_reshape_parser.h | 2 +- parser/onnx/onnx_constant_parser.cc | 48 ++++++------ parser/onnx/onnx_custom_parser_adapter.cc | 2 +- parser/onnx/onnx_custom_parser_adapter.h | 2 +- parser/onnx/onnx_data_parser.cc | 7 +- parser/onnx/onnx_data_parser.h | 2 +- parser/onnx/onnx_file_constant_parser.cc | 4 +- parser/onnx/onnx_file_constant_parser.h | 2 +- parser/onnx/onnx_op_parser.h | 2 +- parser/onnx/onnx_parser.cc | 4 +- parser/onnx/onnx_parser.h | 4 +- parser/onnx/onnx_util.cc | 2 +- parser/onnx/onnx_util.h | 2 +- tests/st/testcase/test_caffe_parser.cc | 8 +- .../caffe_parser_testcase/caffe_parser_unittest.cc | 8 +- 29 files changed, 224 insertions(+), 212 deletions(-) create mode 100644 inc/external/parser/parser_common.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f46a1e..83d24c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -253,6 +253,7 @@ install(TARGETS _caffe_parser parser_common fmk_onnx_parser fmk_parser parser_he install(FILES ${PARSER_DIR}/inc/external/parser/onnx_parser.h ${PARSER_DIR}/inc/external/parser/caffe_parser.h ${PARSER_DIR}/inc/external/parser/tensorflow_parser.h + ${PARSER_DIR}/inc/external/parser/parser_common.h DESTINATION ${INSTALL_INCLUDE_DIR}/parser/external/parser COMPONENT opensdk EXCLUDE_FROM_ALL ) diff --git a/inc/external/parser/caffe_parser.h b/inc/external/parser/caffe_parser.h index 32b5e66..90a7987 100644 --- a/inc/external/parser/caffe_parser.h +++ b/inc/external/parser/caffe_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,27 +17,14 @@ #ifndef INC_EXTERNAL_ACL_GRAPH_CAFFE_H_ #define INC_EXTERNAL_ACL_GRAPH_CAFFE_H_ -#if defined(_MSC_VER) -#ifdef FUNC_VISIBILITY -#define PARSER_FUNC_VISIBILITY _declspec(dllexport) -#else -#define PARSER_FUNC_VISIBILITY -#endif -#else -#ifdef FUNC_VISIBILITY -#define PARSER_FUNC_VISIBILITY __attribute__((visibility("default"))) -#else -#define PARSER_FUNC_VISIBILITY -#endif -#endif - #include #include #include - +#include #include "graph/ascend_string.h" #include "graph/ge_error_codes.h" #include "graph/graph.h" +#include "parser_common.h" namespace ge { PARSER_FUNC_VISIBILITY graphStatus aclgrphParseCaffe(const char *model_file, const char *weights_file, diff --git a/inc/external/parser/onnx_parser.h b/inc/external/parser/onnx_parser.h index 1205034..12be388 100644 --- a/inc/external/parser/onnx_parser.h +++ b/inc/external/parser/onnx_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,23 +17,11 @@ #ifndef INC_EXTERNAL_PARSER_ONNX_PARSER_H_ #define INC_EXTERNAL_PARSER_ONNX_PARSER_H_ -#if defined(_MSC_VER) -#ifdef FUNC_VISIBILITY -#define PARSER_FUNC_VISIBILITY _declspec(dllexport) -#else -#define PARSER_FUNC_VISIBILITY -#endif -#else -#ifdef FUNC_VISIBILITY -#define PARSER_FUNC_VISIBILITY __attribute__((visibility("default"))) -#else -#define PARSER_FUNC_VISIBILITY -#endif -#endif - +#include #include "graph/ascend_string.h" #include "graph/ge_error_codes.h" #include "graph/graph.h" +#include "parser_common.h" namespace ge { PARSER_FUNC_VISIBILITY graphStatus aclgrphParseONNX(const char *model_file, diff --git a/inc/external/parser/parser_common.h b/inc/external/parser/parser_common.h new file mode 100644 index 0000000..25fa3bf --- /dev/null +++ b/inc/external/parser/parser_common.h @@ -0,0 +1,34 @@ +/** + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INC_EXTERNAL_ACL_PARSER_COMMON_H_ +#define INC_EXTERNAL_ACL_PARSER_COMMON_H_ + +#if defined(_MSC_VER) +#ifdef FUNC_VISIBILITY +#define PARSER_FUNC_VISIBILITY _declspec(dllexport) +#else +#define PARSER_FUNC_VISIBILITY +#endif +#else +#ifdef FUNC_VISIBILITY +#define PARSER_FUNC_VISIBILITY __attribute__((visibility("default"))) +#else +#define PARSER_FUNC_VISIBILITY +#endif +#endif + +#endif // INC_EXTERNAL_ACL_PARSER_COMMON_H_ \ No newline at end of file diff --git a/inc/external/parser/tensorflow_parser.h b/inc/external/parser/tensorflow_parser.h index d85b46a..705b022 100644 --- a/inc/external/parser/tensorflow_parser.h +++ b/inc/external/parser/tensorflow_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,20 +17,6 @@ #ifndef INC_EXTERNAL_ACL_PARSER_TENSORFLOW_H_ #define INC_EXTERNAL_ACL_PARSER_TENSORFLOW_H_ -#if defined(_MSC_VER) -#ifdef FUNC_VISIBILITY -#define PARSER_FUNC_VISIBILITY _declspec(dllexport) -#else -#define PARSER_FUNC_VISIBILITY -#endif -#else -#ifdef FUNC_VISIBILITY -#define PARSER_FUNC_VISIBILITY __attribute__((visibility("default"))) -#else -#define PARSER_FUNC_VISIBILITY -#endif -#endif - #include #include #include @@ -39,6 +25,7 @@ #include "graph/ascend_string.h" #include "graph/ge_error_codes.h" #include "graph/graph.h" +#include "parser_common.h" namespace ge { PARSER_FUNC_VISIBILITY graphStatus aclgrphParseTensorFlow(const char *model_file, ge::Graph &graph); diff --git a/parser/caffe/caffe_custom_parser_adapter.cc b/parser/caffe/caffe_custom_parser_adapter.cc index 9ea831a..fc74db1 100644 --- a/parser/caffe/caffe_custom_parser_adapter.cc +++ b/parser/caffe/caffe_custom_parser_adapter.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ const int kBlobIndexOne = 1; Status CaffeCustomParserAdapter::ParseParams(const Message *op_src, ge::OpDescPtr &op_dest) { GE_CHECK_NOTNULL(op_src); - const LayerParameter *layer = reinterpret_cast(op_src); + const LayerParameter *layer = PtrToPtr(op_src); GELOGD("Caffe layer name = %s, layer type= %s, parse params", layer->name().c_str(), layer->type().c_str()); GE_CHECK_NOTNULL(op_dest); @@ -78,12 +78,37 @@ Status CaffeCustomParserAdapter::ParseParams(const Operator &op_src, const ge::O return SUCCESS; } +Status CaffeCustomParserAdapter::AddEdgeFromConstNode(const NodePtr &const_node, const int32_t index, + const bool update_in_turn, ge::NodePtr &node) const { + GE_CHECK_NOTNULL(const_node); + GE_CHECK_NOTNULL(node); + auto op = node->GetOpDesc(); + GE_CHECK_NOTNULL(op); + auto valid_input_name = op->GetValidInputNameByIndex(index); + if (update_in_turn || valid_input_name.empty()) { + if (node->AddLinkFrom(static_cast(index), const_node) != GRAPH_SUCCESS) { + REPORT_CALL_ERROR("E19999", "AddEdge failed of from Node %s output to Node %s input %d", + const_node->GetName().c_str(), node->GetName().c_str(), index); + GELOGE(GRAPH_FAILED, "[Invoke][AddLinkFrom] AddEdge failed of from Node %s output to Node %s input %d", + const_node->GetName().c_str(), node->GetName().c_str(), index); + } + } else { + if (node->AddLinkFrom(valid_input_name, const_node) != GRAPH_SUCCESS) { + REPORT_CALL_ERROR("E19999", "AddEdge failed of from Node %s output to Node %s input %s", + const_node->GetName().c_str(), node->GetName().c_str(), valid_input_name.c_str()); + GELOGE(GRAPH_FAILED, "[Invoke][AddLinkFrom] AddEdge failed of from Node %s output to Node %s input %s", + const_node->GetName().c_str(), node->GetName().c_str(), valid_input_name.c_str()); + } + } + return SUCCESS; +} + Status CaffeCustomParserAdapter::ParseWeights(const Message *op_src, ge::NodePtr &node) { GE_CHECK_NOTNULL(node); auto op = node->GetOpDesc(); GE_CHECK_NOTNULL(op_src); GE_CHECK_NOTNULL(op); - const LayerParameter *layer = reinterpret_cast(op_src); + const LayerParameter *layer = PtrToPtr(op_src); GE_CHK_BOOL_RET_STATUS(layer != nullptr, FAILED, "[Convert][Type]Dynamic cast op_src to LayerParameter failed"); GELOGI("layer: %s blobs_size: %d bottom_size: %d", layer->name().c_str(), layer->blobs_size(), layer->bottom_size()); @@ -100,11 +125,11 @@ Status CaffeCustomParserAdapter::ParseWeights(const Message *op_src, ge::NodePtr GE_CHK_STATUS_RET(ConvertWeight(layer->blobs(i), layer->name(), weight), "[Convert][Blobs] (%d) for layer %s failed", i, layer->name().c_str()); GE_IF_BOOL_EXEC(layer->type() == kConvolution && i == kBlobIndexOne, - const ConvolutionParameter &conv_params_src = layer->convolution_param(); - bias_en = conv_params_src.bias_term();); + bias_en = layer->convolution_param().bias_term(); + ); GE_IF_BOOL_EXEC(layer->type() == kInnerProduct && i == kBlobIndexOne, - const InnerProductParameter &fc_params_src = layer->inner_product_param(); - bias_en = fc_params_src.bias_term();); + bias_en = layer->inner_product_param().bias_term(); + ); auto bias_shape = weight->MutableTensorDesc().GetShape(); // The num 0, 1, 2, 3 represet the dim index. bool matched = bias_en && bias_shape.GetDimNum() == static_cast(ge::parser::DIM_DEFAULT_SIZE) && @@ -127,24 +152,8 @@ Status CaffeCustomParserAdapter::ParseWeights(const Message *op_src, ge::NodePtr // add edge from const to current node auto const_node = owner_graph->AddNodeFront(const_opdesc); - GE_CHECK_NOTNULL(const_node); auto index = start_pos + i; - auto valid_input_name = op->GetValidInputNameByIndex(static_cast(index)); - if (update_in_turn || valid_input_name.empty()) { - if (node->AddLinkFrom(static_cast(index), const_node) != GRAPH_SUCCESS) { - REPORT_CALL_ERROR("E19999", "AddEdge failed of from Node %s output to Node %s input %d", - const_node->GetName().c_str(), node->GetName().c_str(), index); - GELOGE(GRAPH_FAILED, "[Invoke][AddLinkFrom] AddEdge failed of from Node %s output to Node %s input %d", - const_node->GetName().c_str(), node->GetName().c_str(), index); - } - } else { - if (node->AddLinkFrom(valid_input_name, const_node) != GRAPH_SUCCESS) { - REPORT_CALL_ERROR("E19999", "AddEdge failed of from Node %s output to Node %s input %s", - const_node->GetName().c_str(), node->GetName().c_str(), valid_input_name.c_str()); - GELOGE(GRAPH_FAILED, "[Invoke][AddLinkFrom] AddEdge failed of from Node %s output to Node %s input %s", - const_node->GetName().c_str(), node->GetName().c_str(), valid_input_name.c_str()); - } - } + GE_CHK_STATUS_RET_NOLOG(AddEdgeFromConstNode(const_node, static_cast(index), update_in_turn, node)); std::vector original_nodes; ge::GraphUtils::RecordOriginalNames(original_nodes, const_node); diff --git a/parser/caffe/caffe_custom_parser_adapter.h b/parser/caffe/caffe_custom_parser_adapter.h index 9c3dd71..2a821c9 100644 --- a/parser/caffe/caffe_custom_parser_adapter.h +++ b/parser/caffe/caffe_custom_parser_adapter.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,20 @@ class PARSER_FUNC_VISIBILITY CaffeCustomParserAdapter : public CaffeOpParser { * @author */ Status ParseWeights(const Message *op_src, ge::NodePtr &node) override; + + /** + * @ingroup domi_omg + * @brief parse weight of the operation + * @param [in] const_node const node to add link edge + * @param [in] index index of current node to add link + * @param [in] update_in_turn flag of update in turn + * @param [out] node params after parsing + * @return SUCCESS parse successfullyparse failed + * @return FAILED + * @author + */ +Status AddEdgeFromConstNode(const NodePtr &const_node, const int32_t index, + const bool update_in_turn, ge::NodePtr &node) const; }; } // namespace ge diff --git a/parser/caffe/caffe_data_parser.cc b/parser/caffe/caffe_data_parser.cc index 75fe56c..b6eb131 100644 --- a/parser/caffe/caffe_data_parser.cc +++ b/parser/caffe/caffe_data_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,9 @@ using namespace ge::parser; using domi::CAFFE; namespace ge { +namespace { + const char *kData = "Data"; +} Status CaffeDataParser::GetOutputDesc(const string &name, const std::vector &input_dims, const ge::OpDescPtr &op) const { GE_CHECK_NOTNULL(op); @@ -51,10 +54,10 @@ Status CaffeDataParser::ParseParams(const Message *op_src, ge::OpDescPtr &op) { GELOGD("Caffe layer name = %s, layer type= %s, parse params", layer->name().c_str(), layer->type().c_str()); if (layer->type() == ge::parser::INPUT_TYPE) { - GE_CHK_STATUS_RET(ParseParamsForInput(layer, op), "[Parse][Params] failed, Caffe layer name = %s, " + GE_CHK_STATUS_RET(ParseParamsForInput(*layer, op), "[Parse][Params] failed, Caffe layer name = %s, " "layer type= %s", layer->name().c_str(), layer->type().c_str()); } else if (layer->type() == ge::parser::DUMMY_DATA) { - GE_CHK_STATUS_RET(ParseParamsForDummyData(layer, op), "[Parse][Params] failed, Caffe layer name = %s, " + GE_CHK_STATUS_RET(ParseParamsForDummyData(*layer, op), "[Parse][Params] failed, Caffe layer name = %s, " "layer type= %s", layer->name().c_str(), layer->type().c_str()); } else { REPORT_INNER_ERROR("E19999", "layer:%s(%s) type is not %s or %s, check invalid", @@ -66,14 +69,14 @@ Status CaffeDataParser::ParseParams(const Message *op_src, ge::OpDescPtr &op) { return SUCCESS; } -Status CaffeDataParser::ParseParamsForInput(const domi::caffe::LayerParameter *layer, ge::OpDescPtr &op) { - if (layer->has_input_param()) { - const domi::caffe::InputParameter &input_param = layer->input_param(); +Status CaffeDataParser::ParseParamsForInput(const domi::caffe::LayerParameter &layer, ge::OpDescPtr &op) const { + if (layer.has_input_param()) { + const domi::caffe::InputParameter &input_param = layer.input_param(); if (input_param.shape_size() == 0) { ErrorManager::GetInstance().ATCReportErrMessage( - "E11027", {"layername", "layertype"}, {layer->name(), layer->type()}); + "E11027", {"layername", "layertype"}, {layer.name(), layer.type()}); GELOGE(PARAM_INVALID, "[Check][Param]input_param shape size is zero, check invalid, " - "caffe layer name [%s], layer type [%s].", layer->name().c_str(), layer->type().c_str()); + "caffe layer name [%s], layer type [%s].", layer.name().c_str(), layer.type().c_str()); return FAILED; } for (int i = 0; i < input_param.shape_size(); i++) { @@ -84,7 +87,7 @@ Status CaffeDataParser::ParseParamsForInput(const domi::caffe::LayerParameter *l for (auto &blob_shape_dim_temp : blob_shape.dim()) { model_dims.push_back(blob_shape_dim_temp); } - string name = layer->name(); + string name = layer.name(); GE_IF_BOOL_EXEC(shape_map.count(name) != 0, model_dims = shape_map.at(name)); GE_CHK_STATUS_RET(GetOutputDesc(name, model_dims, op), "[Get][OutputDesc] failed in layer %s", name.c_str()); @@ -93,13 +96,13 @@ Status CaffeDataParser::ParseParamsForInput(const domi::caffe::LayerParameter *l // Get from external input const ge::ParserContext &ctx = GetParserContext(); std::map> input_dims = ctx.input_dims; - string name = layer->name(); + string name = layer.name(); std::map>::const_iterator search = input_dims.find(name); if (search == input_dims.end()) { - REPORT_INPUT_ERROR("E11005", std::vector({"input"}), std::vector({layer->name()})); + REPORT_INPUT_ERROR("E11005", std::vector({"input"}), std::vector({layer.name()})); GELOGE(PARAM_INVALID, "[Check][Param] Caffe prototxt has no input_param or user " "should set --input_shape in atc parameter, caffe layer name [%s], layer type [%s].", - layer->name().c_str(), layer->type().c_str()); + layer.name().c_str(), layer.type().c_str()); return FAILED; } std::vector dims = search->second; @@ -109,14 +112,14 @@ Status CaffeDataParser::ParseParamsForInput(const domi::caffe::LayerParameter *l return SUCCESS; } -Status CaffeDataParser::ParseParamsForDummyData(const domi::caffe::LayerParameter *layer, ge::OpDescPtr &op) { - if (layer->has_dummy_data_param()) { - const domi::caffe::DummyDataParameter &dummy_data_param = layer->dummy_data_param(); +Status CaffeDataParser::ParseParamsForDummyData(const domi::caffe::LayerParameter &layer, ge::OpDescPtr &op) const { + if (layer.has_dummy_data_param()) { + const domi::caffe::DummyDataParameter &dummy_data_param = layer.dummy_data_param(); if (dummy_data_param.shape_size() == 0) { ErrorManager::GetInstance().ATCReportErrMessage( - "E11027", {"layername", "layertype"}, {layer->name(), layer->type()}); + "E11027", {"layername", "layertype"}, {layer.name(), layer.type()}); GELOGE(PARAM_INVALID, "[Check][Param] input_param shape size is zero, caffe layer name [%s], layer type [%s].", - layer->name().c_str(), layer->type().c_str()); + layer.name().c_str(), layer.type().c_str()); return FAILED; } for (int i = 0; i < dummy_data_param.shape_size(); i++) { @@ -129,7 +132,7 @@ Status CaffeDataParser::ParseParamsForDummyData(const domi::caffe::LayerParamete model_dims.push_back(blob_shape_dim_temp); } - string name = layer->name(); + string name = layer.name(); GE_IF_BOOL_EXEC(shape_map.count(name) != 0, model_dims = shape_map.at(name)); GE_CHK_STATUS_RET(GetOutputDesc(name, model_dims, op), "[Get][OutputDesc] failed in layer %s", name.c_str()); @@ -138,13 +141,13 @@ Status CaffeDataParser::ParseParamsForDummyData(const domi::caffe::LayerParamete // Get from external input const ge::ParserContext &ctx = GetParserContext(); std::map> input_dims = ctx.input_dims; - string name = layer->name(); + string name = layer.name(); std::map>::const_iterator search = input_dims.find(name); if (search == input_dims.end()) { - REPORT_INPUT_ERROR("E11005", std::vector({"input"}), std::vector({layer->name()})); + REPORT_INPUT_ERROR("E11005", std::vector({"input"}), std::vector({layer.name()})); GELOGE(PARAM_INVALID, "[Check][Param] Caffe prototxt has no input_param or user " "should set --input_shape in atc parameter, caffe layer name [%s], layer type [%s].", - layer->name().c_str(), layer->type().c_str()); + layer.name().c_str(), layer.type().c_str()); return FAILED; } std::vector dims = search->second; @@ -153,6 +156,5 @@ Status CaffeDataParser::ParseParamsForDummyData(const domi::caffe::LayerParamete } return SUCCESS; } - -REGISTER_OP_PARSER_CREATOR(CAFFE, DATA, CaffeDataParser); +REGISTER_OP_PARSER_CREATOR(CAFFE, kData, CaffeDataParser); } // namespace ge diff --git a/parser/caffe/caffe_data_parser.h b/parser/caffe/caffe_data_parser.h index b592f50..dfa5d5c 100644 --- a/parser/caffe/caffe_data_parser.h +++ b/parser/caffe/caffe_data_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,8 +48,8 @@ class PARSER_FUNC_VISIBILITY CaffeDataParser : public CaffeOpParser, public Data Status GetOutputDesc(const std::string &name, const std::vector &input_dims, const ge::OpDescPtr &op) const; // caffe data layer type could be type of `Input` or `DummyData` - Status ParseParamsForInput(const domi::caffe::LayerParameter *layer, ge::OpDescPtr &op); - Status ParseParamsForDummyData(const domi::caffe::LayerParameter *layer, ge::OpDescPtr &op); + Status ParseParamsForInput(const domi::caffe::LayerParameter &layer, ge::OpDescPtr &op) const; + Status ParseParamsForDummyData(const domi::caffe::LayerParameter &layer, ge::OpDescPtr &op) const; }; } // namespace ge diff --git a/parser/caffe/caffe_op_parser.cc b/parser/caffe/caffe_op_parser.cc index f2e6612..fe58086 100644 --- a/parser/caffe/caffe_op_parser.cc +++ b/parser/caffe/caffe_op_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,10 @@ using domi::caffe::BlobProto; using domi::CAFFE; namespace ge { +namespace { + const char *kNetOutput = "NetOutput"; + const char *kDropout = "Dropout"; +} Status CaffeOpParser::ParseParams(const Message *op_src, ge::OpDescPtr &op_dest) { (void)op_src; (void)op_dest; @@ -88,6 +92,18 @@ Status CaffeOpParser::ConvertWeight(const BlobProto &proto, const string &lay_na return ParseWeightType(proto, shape, count, lay_name, weight); } +Status CaffeOpParser::CheckSizeInvalid(const string &lay_name, const int32_t blob_size, const int32_t size) { + if (blob_size == size) { + return SUCCESS; + } + ErrorManager::GetInstance().ATCReportErrMessage("E11033", {"opname", "blobsize", "reason"}, + {lay_name, std::to_string(blob_size), + "it does not match shape size[" + std::to_string(size) + "]"}); + GELOGE(FAILED, "[Check][Param]Convert weight fail, Blob size does not match shape size, " + "shape size:%d, blob size:%d, layer name:%s", size, blob_size, lay_name.c_str()); + return FAILED; +} + Status CaffeOpParser::ParseWeightType(const BlobProto &proto, const ge::GeShape &shape, int size, const string &lay_name, ge::GeTensorPtr &weight) { // Extract weight data and store it in weightdef by float type @@ -95,14 +111,7 @@ Status CaffeOpParser::ParseWeightType(const BlobProto &proto, const ge::GeShape ge::DataType dtype = ge::DT_FLOAT; if (proto.double_data_size() > 0) { // Convert by double type - if (size != proto.double_data_size()) { - ErrorManager::GetInstance().ATCReportErrMessage("E11033", {"opname", "blobsize", "reason"}, - {lay_name, std::to_string(proto.double_data_size()), - "it does not match shape size[" + std::to_string(size) + "]"}); - GELOGE(FAILED, "[Check][Param]Convert weight fail, Blob size does not match shape size, " - "shape size:%d, blob size:%d, layer name:%s", size, proto.double_data_size(), lay_name.c_str()); - return FAILED; - } + GE_CHK_STATUS_RET_NOLOG(CheckSizeInvalid(lay_name, proto.double_data_size(), size)); std::unique_ptr buf(new (std::nothrow) float[size]()); GE_CHECK_NOTNULL(buf); for (int i = 0; i < size; ++i) { @@ -111,71 +120,39 @@ Status CaffeOpParser::ParseWeightType(const BlobProto &proto, const ge::GeShape GE_IF_BOOL_EXEC(weight->SetData(PtrToPtr(buf.get()), size * sizeof(float)) != ge::GRAPH_SUCCESS, GELOGW("SetData failed for GeTensor.");); // no need to return } else if (proto.int8_data().length() > 0) { - if (size != static_cast(proto.int8_data().length())) { - ErrorManager::GetInstance().ATCReportErrMessage("E11033", {"opname", "blobsize", "reason"}, - {lay_name, std::to_string(proto.int8_data().length()), - "it does not match shape size[" + std::to_string(size) + "]"}); - GELOGE(FAILED, "[Check][Param]Convert weight failed, Blob size does not match shape size, " - "shape size:%d, blob size:%ld, layer name:%s", size, proto.int8_data().length(), lay_name.c_str()); - return FAILED; - } + GE_CHK_STATUS_RET_NOLOG(CheckSizeInvalid(lay_name, static_cast(proto.int8_data().length()), size)); const char *data_ptr = proto.int8_data().data(); GE_CHECK_NOTNULL(data_ptr); - GE_IF_BOOL_EXEC( - weight->SetData(PtrToPtr(data_ptr), size * sizeof(int8_t)) != ge::GRAPH_SUCCESS, - GELOGW("SetData failed for GeTensor.");); // no need to return + GE_IF_BOOL_EXEC(weight->SetData(PtrToPtr(data_ptr), size * sizeof(int8_t)) != + ge::GRAPH_SUCCESS, GELOGW("SetData failed for GeTensor.");); // no need to return dtype = ge::DT_INT8; } else if (proto.int32_data_size() > 0) { - if (size != proto.int32_data_size()) { - ErrorManager::GetInstance().ATCReportErrMessage("E11033", {"opname", "blobsize", "reason"}, - {lay_name, std::to_string(proto.int32_data_size()), - "it does not match shape size[" + std::to_string(size) + "]"}); - GELOGE(FAILED, "[Check][Param]Convert weight failed, Blob size does not match shape size, " - "shape size:%d, blob size:%d, layer name:%s", size, proto.int32_data_size(), lay_name.c_str()); - return FAILED; - } + GE_CHK_STATUS_RET_NOLOG(CheckSizeInvalid(lay_name, static_cast(proto.int32_data_size()), size)); std::unique_ptr int32_weight_buf(new (std::nothrow) int32_t[size]()); GE_CHECK_NOTNULL(int32_weight_buf); for (int i = 0; i < size; ++i) { int32_weight_buf[i] = proto.int32_data(i); } - GE_IF_BOOL_EXEC( - weight->SetData(PtrToPtr(int32_weight_buf.get()), size * sizeof(int32_t)) != ge::GRAPH_SUCCESS, - GELOGW("SetData failed for GeTensor.");); // no need to return + GE_IF_BOOL_EXEC(weight->SetData(PtrToPtr(int32_weight_buf.get()), size * sizeof(int32_t)) != + ge::GRAPH_SUCCESS, GELOGW("SetData failed for GeTensor.");); // no need to return dtype = ge::DT_INT32; } else if (proto.uint64_data_size() > 0) { - if (size != proto.uint64_data_size()) { - ErrorManager::GetInstance().ATCReportErrMessage("E11033", {"opname", "blobsize", "reason"}, - {lay_name, std::to_string(proto.uint64_data_size()), - "it does not match shape size[" + std::to_string(size) + "]"}); - GELOGE(FAILED, "[Check][Param]Convert weight failed, Blob size does not match shape size, " - "shape size:%d, blob size:%d, layer name:%s", size, proto.uint64_data_size(), lay_name.c_str()); - return FAILED; - } + GE_CHK_STATUS_RET_NOLOG(CheckSizeInvalid(lay_name, static_cast(proto.uint64_data_size()), size)); std::unique_ptr uint64_weight_buf(new (std::nothrow) uint64_t[size]()); GE_CHECK_NOTNULL(uint64_weight_buf); for (int i = 0; i < size; ++i) { uint64_weight_buf[i] = proto.uint64_data(i); } GE_IF_BOOL_EXEC(weight->SetData(PtrToPtr(uint64_weight_buf.get()), size * sizeof(uint64_t)) != - ge::GRAPH_SUCCESS, - GELOGW("SetData failed for GeTensor.");); // no need to return + ge::GRAPH_SUCCESS, GELOGW("SetData failed for GeTensor.");); // no need to return dtype = ge::DT_UINT64; } else { // Convert by float type - if (size != proto.data_size()) { - ErrorManager::GetInstance().ATCReportErrMessage("E11033", {"opname", "blobsize", "reason"}, - {lay_name, std::to_string(proto.data_size()), - "it does not match shape size[" + std::to_string(size) + "]"}); - GELOGE(FAILED, "[Check][Param]Convert weight fail, Blob size does not match shape size, " - "shape size:%d, blob.data_size:%d, layer name:%s", size, proto.data_size(), lay_name.c_str()); - return FAILED; - } + GE_CHK_STATUS_RET_NOLOG(CheckSizeInvalid(lay_name, static_cast(proto.data_size()), size)); const float *data_ptr = proto.data().data(); GE_CHECK_NOTNULL(data_ptr); - GE_IF_BOOL_EXEC( - weight->SetData(PtrToPtr(data_ptr), size * sizeof(float)) != ge::GRAPH_SUCCESS, - GELOGW("SetData failed for GeTensor.");); // no need to return + GE_IF_BOOL_EXEC(weight->SetData(PtrToPtr(data_ptr), size * sizeof(float)) != + ge::GRAPH_SUCCESS, GELOGW("SetData failed for GeTensor.");); // no need to return } ge::GeTensorDesc weight_desc = ge::GeTensorDesc(); weight_desc.Update(shape, ge::FORMAT_NCHW, dtype); @@ -184,11 +161,11 @@ Status CaffeOpParser::ParseWeightType(const BlobProto &proto, const ge::GeShape } // Dropout's corresponding op_parser is registered as caffeopparser, optimized in optimization stage. -REGISTER_OP_PARSER_CREATOR(CAFFE, DROPOUT, CaffeOpParser); +REGISTER_OP_PARSER_CREATOR(CAFFE, kDropout, CaffeOpParser); // A new operator added by framework in OM model is used to // collect and arrange all outputs in the order of the original model's output // Net output operator does not need special processing in the parse stage, // and directly registers in the op_parser file -REGISTER_OP_PARSER_CREATOR(CAFFE, NETOUTPUT, CaffeOpParser); +REGISTER_OP_PARSER_CREATOR(CAFFE, kNetOutput, CaffeOpParser); } // namespace ge diff --git a/parser/caffe/caffe_op_parser.h b/parser/caffe/caffe_op_parser.h index 8f5345f..5cb87d8 100644 --- a/parser/caffe/caffe_op_parser.h +++ b/parser/caffe/caffe_op_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,6 @@ #include "graph/ge_tensor.h" #include "graph/op_desc.h" #include "graph/operator.h" -#include "graph/types.h" #include "graph/utils/attr_utils.h" #include "graph/utils/tensor_utils.h" #include "omg/parser/op_parser.h" @@ -112,6 +111,18 @@ class PARSER_FUNC_VISIBILITY CaffeOpParser : public OpParser { */ static Status ParseWeightType(const domi::caffe::BlobProto &proto, const ge::GeShape &shape, int size, const string &lay_name, ge::GeTensorPtr &weight); + + private: + /** + * @ingroup ge_omg + * @brief Convert blob proto to weight definition + * @param [in] lay_name op name + * @param [in] blob_size blob size + * @param [in] size input size + * @return SUCCESS check size invalid + * @return FAILED parse failed + */ + static Status CheckSizeInvalid(const string &lay_name, const int32_t blob_size, const int32_t size); }; } // namespace ge diff --git a/parser/caffe/caffe_parser.cc b/parser/caffe/caffe_parser.cc index 6ce8af7..6e28a8e 100644 --- a/parser/caffe/caffe_parser.cc +++ b/parser/caffe/caffe_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -389,7 +389,8 @@ Status CaffeModelParser::ParseInput(domi::caffe::NetParameter &proto_message, bo Status CaffeModelParser::ParseNetModelByCustomProto(const char *model_path, const string &custom_proto_path, - const string &custom_proto_name, vector &operators) { + const string &custom_proto_name, + vector &operators) const { google::protobuf::compiler::DiskSourceTree source_tree; source_tree.MapPath(kProjectRoot, custom_proto_path); google::protobuf::compiler::Importer importer(&source_tree, nullptr); @@ -1926,7 +1927,7 @@ Status CaffeWeightsParser::ConvertLayerProto(const google::protobuf::Message *me Status CaffeWeightsParser::ParseLayerField(const google::protobuf::Reflection *reflection, const google::protobuf::Message *message, const google::protobuf::FieldDescriptor *field, - google::protobuf::Message *layer) { + google::protobuf::Message *layer) const { GELOGD("Start to parse field: %s.", field->name().c_str()); domi::caffe::LayerParameter *layer_proto = PtrToPtr(layer); string filed_name = field->name(); diff --git a/parser/caffe/caffe_parser.h b/parser/caffe/caffe_parser.h index 3b4491d..542aca6 100644 --- a/parser/caffe/caffe_parser.h +++ b/parser/caffe/caffe_parser.h @@ -181,7 +181,7 @@ class PARSER_FUNC_VISIBILITY CaffeModelParser : public domi::ModelParser { * @return FAILED parse failed */ Status ParseNetModelByCustomProto(const char *model_path, const string &custom_proto_path, - const string &custom_proto_name, std::vector &operators); + const string &custom_proto_name, std::vector &operators) const; /* * @ingroup domi_omg @@ -401,7 +401,7 @@ class PARSER_FUNC_VISIBILITY CaffeWeightsParser : public domi::WeightsParser { Status ParseLayerField(const google::protobuf::Reflection *reflection, const google::protobuf::Message *message, const google::protobuf::FieldDescriptor *field, - google::protobuf::Message *layer); + google::protobuf::Message *layer) const; Status ConvertBlobsProto(const google::protobuf::Message *message, google::protobuf::Message *blobs) const; diff --git a/parser/caffe/caffe_reshape_parser.cc b/parser/caffe/caffe_reshape_parser.cc index 7175b09..44cce1d 100644 --- a/parser/caffe/caffe_reshape_parser.cc +++ b/parser/caffe/caffe_reshape_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ const int kAnchorIndexZero = 0; const int kAnchorIndexOne = 1; const int32_t RESHAPE_AXIS_DEFAULT_VALUE = 0; const int32_t RESHAPE_NUM_AXES_DEFAULT_VALUE = -1; +const char *kReshape = "Reshape"; } // namespace Status CaffeReshapeParser::ParseParams(const Message *op_src, ge::OpDescPtr &op) { @@ -127,9 +128,8 @@ Status CaffeReshapeParser::AddConstInput(ge::NodePtr &node) { for (size_t i = 0; i < dims_size; ++i) { data[i] = attr_shape[i]; } - GE_IF_BOOL_EXEC( - constTensor->SetData(PtrToPtr(data.get()), dims_size * sizeof(int64_t)) != ge::GRAPH_SUCCESS, - GELOGW("SetData failed for GeTensor.");); // no need to return + GE_IF_BOOL_EXEC(constTensor->SetData(PtrToPtr(data.get()), dims_size * sizeof(int64_t)) != + ge::GRAPH_SUCCESS, GELOGW("SetData failed for GeTensor.");); // no need to return // construct const node and add edge auto const_opdesc = ge::OpDescUtils::CreateConstOp(constTensor); @@ -151,5 +151,5 @@ Status CaffeReshapeParser::AddConstInput(ge::NodePtr &node) { return SUCCESS; } -REGISTER_OP_PARSER_CREATOR(CAFFE, RESHAPE, CaffeReshapeParser); +REGISTER_OP_PARSER_CREATOR(CAFFE, kReshape, CaffeReshapeParser); } // namespace ge diff --git a/parser/caffe/caffe_reshape_parser.h b/parser/caffe/caffe_reshape_parser.h index da423ee..9be90b6 100644 --- a/parser/caffe/caffe_reshape_parser.h +++ b/parser/caffe/caffe_reshape_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/onnx/onnx_constant_parser.cc b/parser/onnx/onnx_constant_parser.cc index bb01e0e..06ba0bf 100644 --- a/parser/onnx/onnx_constant_parser.cc +++ b/parser/onnx/onnx_constant_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,9 @@ using GeTensorDesc = ge::GeTensorDesc; using namespace ge::parser; namespace ge { +namespace { + const char *kConstant = "Const"; +} Status OnnxConstantParser::ParseConvertData(const ge::onnx::TensorProto &tensor_proto, ge::Tensor &tensor, int count) { int64_t data_type = tensor_proto.data_type(); if (ge::OnnxUtil::ConvertOnnxDataType(data_type) == ge::DataType::DT_UNDEFINED) { @@ -47,27 +50,22 @@ Status OnnxConstantParser::ParseConvertData(const ge::onnx::TensorProto &tensor_ } std::map datatype_val_size_map = { - // for int32, uint8, int8, uint16, int16, bool, and float16 values - {OnnxDataType::INT32, tensor_proto.int32_data_size()}, - {OnnxDataType::UINT8, tensor_proto.int32_data_size()}, - {OnnxDataType::INT8, tensor_proto.int32_data_size()}, - {OnnxDataType::UINT16, tensor_proto.int32_data_size()}, - {OnnxDataType::INT16, tensor_proto.int32_data_size()}, - {OnnxDataType::BOOL, tensor_proto.int32_data_size()}, - {OnnxDataType::FLOAT16, tensor_proto.int32_data_size()}, - // for int64 values - {OnnxDataType::INT64, tensor_proto.int64_data_size()}, - // for string values - {OnnxDataType::STRING, tensor_proto.string_data_size()}, - // for float and complex64 values - {OnnxDataType::FLOAT, tensor_proto.float_data_size()}, - {OnnxDataType::COMPLEX64, tensor_proto.float_data_size()}, - // for double and complex128 values - {OnnxDataType::DOUBLE, tensor_proto.double_data_size()}, - {OnnxDataType::COMPLEX128, tensor_proto.double_data_size()}, - // for uint64 and uint32 values - {OnnxDataType::UINT64, tensor_proto.uint64_data_size()}, - {OnnxDataType::UINT32, tensor_proto.uint64_data_size()}, + // for int32, uint8, int8, uint16, int16, bool, and float16 values + {OnnxDataType::INT32, tensor_proto.int32_data_size()}, {OnnxDataType::UINT8, tensor_proto.int32_data_size()}, + {OnnxDataType::INT8, tensor_proto.int32_data_size()}, {OnnxDataType::UINT16, tensor_proto.int32_data_size()}, + {OnnxDataType::INT16, tensor_proto.int32_data_size()}, {OnnxDataType::BOOL, tensor_proto.int32_data_size()}, + {OnnxDataType::FLOAT16, tensor_proto.int32_data_size()}, + // for int64 values + {OnnxDataType::INT64, tensor_proto.int64_data_size()}, + // for string values + {OnnxDataType::STRING, tensor_proto.string_data_size()}, + // for float and complex64 values + {OnnxDataType::FLOAT, tensor_proto.float_data_size()}, {OnnxDataType::COMPLEX64, tensor_proto.float_data_size()}, + // for double and complex128 values + {OnnxDataType::DOUBLE, tensor_proto.double_data_size()}, + {OnnxDataType::COMPLEX128, tensor_proto.double_data_size()}, + // for uint64 and uint32 values + {OnnxDataType::UINT64, tensor_proto.uint64_data_size()}, {OnnxDataType::UINT32, tensor_proto.uint64_data_size()}, }; int32_t datatype_val_size = 0; @@ -199,7 +197,7 @@ Status OnnxConstantParser::ParseConvertDataType(const ge::onnx::TensorProto &ten Status OnnxConstantParser::ParseConstFromInput(const ge::onnx::NodeProto *op_src, ge::Operator &op_def) { GE_CHECK_NOTNULL(op_src); - const NodeProto *node = reinterpret_cast(op_src); + const NodeProto *node = PtrToPtr(op_src); // Get const Tensor from node Tensor tensor; @@ -226,7 +224,7 @@ Status OnnxConstantParser::ParseConstFromInput(const ge::onnx::NodeProto *op_src Status OnnxConstantParser::ParseParams(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); GELOGD("Onnx op node name = %s, op type= %s, parse params", node->name().c_str(), node->op_type().c_str()); @@ -237,5 +235,5 @@ Status OnnxConstantParser::ParseParams(const Message *op_src, ge::Operator &op_d return SUCCESS; } -REGISTER_OP_PARSER_CREATOR(ONNX, CONSTANT, OnnxConstantParser); +REGISTER_OP_PARSER_CREATOR(ONNX, kConstant, OnnxConstantParser); } // namespace ge diff --git a/parser/onnx/onnx_custom_parser_adapter.cc b/parser/onnx/onnx_custom_parser_adapter.cc index 0ba1b4d..d634daf 100644 --- a/parser/onnx/onnx_custom_parser_adapter.cc +++ b/parser/onnx/onnx_custom_parser_adapter.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/onnx/onnx_custom_parser_adapter.h b/parser/onnx/onnx_custom_parser_adapter.h index 8ac1df9..e22dda7 100644 --- a/parser/onnx/onnx_custom_parser_adapter.h +++ b/parser/onnx/onnx_custom_parser_adapter.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/onnx/onnx_data_parser.cc b/parser/onnx/onnx_data_parser.cc index a2ac1e1..927e618 100644 --- a/parser/onnx/onnx_data_parser.cc +++ b/parser/onnx/onnx_data_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,9 @@ using domi::ONNX; using namespace ge::parser; namespace ge { +namespace { + const char *kData = "Data"; +} Status OnnxDataParser::ParseParams(const Message *op_src, ge::Operator &op_def) { GE_CHECK_NOTNULL(op_src); const ge::onnx::NodeProto *node_src = PtrToPtr(op_src); @@ -140,5 +143,5 @@ Status OnnxDataParser::ParseInputFromUser(const ge::Operator &op_def) { return SUCCESS; } -REGISTER_OP_PARSER_CREATOR(ONNX, DATA, OnnxDataParser); +REGISTER_OP_PARSER_CREATOR(ONNX, kData, OnnxDataParser); } // namespace ge diff --git a/parser/onnx/onnx_data_parser.h b/parser/onnx/onnx_data_parser.h index 994b956..4d51e2f 100644 --- a/parser/onnx/onnx_data_parser.h +++ b/parser/onnx/onnx_data_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/onnx/onnx_file_constant_parser.cc b/parser/onnx/onnx_file_constant_parser.cc index 35b808d..f12539f 100644 --- a/parser/onnx/onnx_file_constant_parser.cc +++ b/parser/onnx/onnx_file_constant_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright 2022 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -147,4 +147,4 @@ Status OnnxFileConstantParser::SetPathAttr(const ge::onnx::StringStringEntryProt } REGISTER_OP_PARSER_CREATOR(ONNX, kFileConstant, OnnxFileConstantParser); -} // namespace ge +} // namespace ge \ No newline at end of file diff --git a/parser/onnx/onnx_file_constant_parser.h b/parser/onnx/onnx_file_constant_parser.h index 6acbb87..e46ce0f 100644 --- a/parser/onnx/onnx_file_constant_parser.h +++ b/parser/onnx/onnx_file_constant_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2022 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/onnx/onnx_op_parser.h b/parser/onnx/onnx_op_parser.h index f1a2680..2ab3c38 100644 --- a/parser/onnx/onnx_op_parser.h +++ b/parser/onnx/onnx_op_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/onnx/onnx_parser.cc b/parser/onnx/onnx_parser.cc index 0f88ab3..3a88315 100644 --- a/parser/onnx/onnx_parser.cc +++ b/parser/onnx/onnx_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ #include "mmpa/mmpa_api.h" namespace { -const std::string kLocation = "location"; +const char *kLocation = "location"; } namespace ge { diff --git a/parser/onnx/onnx_parser.h b/parser/onnx/onnx_parser.h index 7e4e833..586d925 100644 --- a/parser/onnx/onnx_parser.h +++ b/parser/onnx/onnx_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ namespace ge { class PARSER_FUNC_VISIBILITY OnnxModelParser : public domi::ModelParser { public: OnnxModelParser() {} - virtual ~OnnxModelParser() {} + ~OnnxModelParser() override {} Status Parse(const char *file, ge::Graph &graph) override; diff --git a/parser/onnx/onnx_util.cc b/parser/onnx/onnx_util.cc index 040b134..fa84174 100644 --- a/parser/onnx/onnx_util.cc +++ b/parser/onnx/onnx_util.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/onnx/onnx_util.h b/parser/onnx/onnx_util.h index 65bff85..52fc2b3 100644 --- a/parser/onnx/onnx_util.h +++ b/parser/onnx/onnx_util.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/st/testcase/test_caffe_parser.cc b/tests/st/testcase/test_caffe_parser.cc index 0d460f3..42c9c8d 100644 --- a/tests/st/testcase/test_caffe_parser.cc +++ b/tests/st/testcase/test_caffe_parser.cc @@ -292,18 +292,18 @@ TEST_F(STestCaffeParser, caffe_parser_ParseParamsForDummyData_test) domi::caffe::NetParameter net; ge::OpDescPtr op = std::make_shared("conv", "Convolution"); domi::caffe::LayerParameter *lay = net.add_layer(); - Status ret = caffe_parser.ParseParamsForDummyData(lay, op); + Status ret = caffe_parser.ParseParamsForDummyData(*lay, op); EXPECT_EQ(ret, FAILED); - ret = caffe_parser.ParseParamsForInput(lay, op); + ret = caffe_parser.ParseParamsForInput(*lay, op); EXPECT_EQ(ret, FAILED); domi::caffe::DummyDataParameter *dummyData = lay->mutable_dummy_data_param(); - ret = caffe_parser.ParseParamsForDummyData(lay, op); + ret = caffe_parser.ParseParamsForDummyData(*lay, op); EXPECT_EQ(ret, FAILED); domi::caffe::BlobShape* dummpShape = dummyData->add_shape(); - ret = caffe_parser.ParseParamsForDummyData(lay, op); + ret = caffe_parser.ParseParamsForDummyData(*lay, op); EXPECT_EQ(ret, SUCCESS); } diff --git a/tests/ut/parser/testcase/caffe_parser_testcase/caffe_parser_unittest.cc b/tests/ut/parser/testcase/caffe_parser_testcase/caffe_parser_unittest.cc index e4b4351..55fc538 100755 --- a/tests/ut/parser/testcase/caffe_parser_testcase/caffe_parser_unittest.cc +++ b/tests/ut/parser/testcase/caffe_parser_testcase/caffe_parser_unittest.cc @@ -352,18 +352,18 @@ TEST_F(UtestCaffeParser, caffe_parser_ParseParamsForDummyData_test) domi::caffe::NetParameter net; ge::OpDescPtr op = std::make_shared("conv", "Convolution"); domi::caffe::LayerParameter *lay = net.add_layer(); - Status ret = caffe_parser.ParseParamsForDummyData(lay, op); + Status ret = caffe_parser.ParseParamsForDummyData(*lay, op); EXPECT_EQ(ret, FAILED); - ret = caffe_parser.ParseParamsForInput(lay, op); + ret = caffe_parser.ParseParamsForInput(*lay, op); EXPECT_EQ(ret, FAILED); domi::caffe::DummyDataParameter *dummyData = lay->mutable_dummy_data_param(); - ret = caffe_parser.ParseParamsForDummyData(lay, op); + ret = caffe_parser.ParseParamsForDummyData(*lay, op); EXPECT_EQ(ret, FAILED); domi::caffe::BlobShape* dummpShape = dummyData->add_shape(); - ret = caffe_parser.ParseParamsForDummyData(lay, op); + ret = caffe_parser.ParseParamsForDummyData(*lay, op); EXPECT_EQ(ret, SUCCESS); }