Browse Source

Split library of operator.

pull/606/head
张晓昆 3 years ago
parent
commit
021bd2998a
14 changed files with 65 additions and 61 deletions
  1. +5
    -4
      parser/caffe/caffe_parser.cc
  2. +3
    -2
      parser/common/acl_graph_parser_util.cc
  3. +2
    -1
      parser/common/auto_mapping_subgraph_io_index_func.cc
  4. +3
    -2
      parser/common/parser_utils.cc
  5. +5
    -14
      parser/onnx/onnx_parser.cc
  6. +9
    -8
      parser/tensorflow/tensorflow_parser.cc
  7. +1
    -0
      tests/st/CMakeLists.txt
  8. +4
    -3
      tests/st/testcase/test_caffe_parser.cc
  9. +2
    -1
      tests/st/testcase/test_onnx_parser.cc
  10. +9
    -8
      tests/st/testcase/test_tensorflow_parser.cc
  11. +1
    -0
      tests/ut/parser/CMakeLists.txt
  12. +6
    -5
      tests/ut/parser/testcase/caffe_parser_testcase/caffe_parser_unittest.cc
  13. +4
    -3
      tests/ut/parser/testcase/onnx_parser_testcase/onnx_parser_unittest.cc
  14. +11
    -10
      tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc

+ 5
- 4
parser/caffe/caffe_parser.cc View File

@@ -54,6 +54,7 @@
#include "register/register_fmk_types.h"
#include "mmpa/mmpa_api.h"
#include "parser/common/parser_utils.h"
#include "graph/utils/oper_utils.h"

using domi::caffe::ConvolutionParameter;
using domi::caffe::InnerProductParameter;
@@ -98,7 +99,7 @@ graphStatus aclgrphParseCaffe(const char *model_file, const char *weights_file,
ge::ComputeGraphPtr compute_graph = ge::parser::MakeShared<ge::ComputeGraph>("tmpGraph");
GE_CHECK_NOTNULL(compute_graph);

graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);
auto model_parser = domi::ModelParserFactory::Instance()->CreateModelParser(domi::CAFFE);
GE_CHECK_NOTNULL(model_parser);

@@ -162,7 +163,7 @@ graphStatus aclgrphParseCaffe(const char *model_file, const char *weights_file,
ge::ComputeGraphPtr compute_graph = ge::parser::MakeShared<ge::ComputeGraph>(graph_name);
GE_CHECK_NOTNULL(compute_graph);

graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);
auto model_parser = domi::ModelParserFactory::Instance()->CreateModelParser(domi::CAFFE);
GE_CHECK_NOTNULL(model_parser);

@@ -1377,7 +1378,7 @@ Status CaffeModelParser::ParseFromMemory(const char *data, uint32_t size, ge::Co
Status CaffeModelParser::Parse(const char *model_path, ge::Graph &graph) {
ErrorManager::GetInstance().SetStage(error_message::kModelCompile, error_message::kParser);
GE_CHECK_NOTNULL(model_path);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
GE_CHECK_NOTNULL(compute_graph);

Status ret = Parse(model_path, compute_graph);
@@ -1705,7 +1706,7 @@ Status CaffeWeightsParser::ParseFromMemory(const char *data, uint32_t size, ge::
Status CaffeWeightsParser::Parse(const char *file, ge::Graph &graph) {
ErrorManager::GetInstance().SetStage(error_message::kModelCompile, error_message::kParser);
GE_CHECK_NOTNULL(file);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
GE_CHECK_NOTNULL(compute_graph);

Status ret = Parse(file, compute_graph);


+ 3
- 2
parser/common/acl_graph_parser_util.cc View File

@@ -40,6 +40,7 @@
#include "parser/common/register_tbe.h"
#include "tbe_plugin_loader.h"
#include "mmpa/mmpa_api.h"
#include "graph/utils/oper_utils.h"

using google::protobuf::io::CodedInputStream;
using google::protobuf::io::FileInputStream;
@@ -524,7 +525,7 @@ domi::Status AclGrphParseUtil::GetDefaultOutInfo(ge::ComputeGraphPtr &compute_gr
domi::Status AclGrphParseUtil::SetOutputNodeInfo(ge::Graph &graph,
const std::map<AscendString, AscendString> &parser_params) {
(void)parser_params;
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
GE_CHECK_NOTNULL(compute_graph);

std::vector<std::pair<std::string, int32_t>> user_out_nodes = ge::GetParserContext().user_out_nodes;
@@ -656,7 +657,7 @@ domi::Status AclGrphParseUtil::ParseParamsBeforeGraph(const std::map<AscendStrin
domi::Status AclGrphParseUtil::ParseParamsAfterGraph(ge::Graph &graph,
const std::map<AscendString, AscendString> &parser_params) const {
// support paragrams: input_fp16_nodes, is_input_adjust_hw_layout,
ComputeGraphPtr compute_graph = GraphUtils::GetComputeGraph(graph);
ComputeGraphPtr compute_graph = OperUtils::GetComputeGraph(graph);
GE_CHECK_NOTNULL(compute_graph);

string input_fp16_nodes;


+ 2
- 1
parser/common/auto_mapping_subgraph_io_index_func.cc View File

@@ -26,6 +26,7 @@
#include "register/register_fmk_types.h"
#include "framework/common/debug/ge_log.h"
#include "framework/common/util.h"
#include "graph/utils/oper_utils.h"

namespace ge {
namespace {
@@ -125,7 +126,7 @@ Status AutoMappingSubgraphIndexByDataNodeAndOutputNodesInfo(
const std::function<Status(int netoutput_index, int &parent_output_index)> &output) {
GE_CHECK_NOTNULL(input);
GE_CHECK_NOTNULL(output);
auto compute_graph = ge::GraphUtils::GetComputeGraph(graph);
auto compute_graph = ge::OperUtils::GetComputeGraph(graph);
GE_CHECK_NOTNULL(compute_graph);

auto ret = AutoMappingSubgraphIndexByDataNode(compute_graph, input);


+ 3
- 2
parser/common/parser_utils.cc View File

@@ -26,6 +26,7 @@
#include "graph/utils/node_adapter.h"
#include "graph/utils/op_desc_utils.h"
#include "register/op_registry.h"
#include "graph/utils/oper_utils.h"

namespace ge {
namespace {
@@ -109,9 +110,9 @@ Status ParserUtils::ExpandOneToManyGraph(const Graph &graph, OutputMapping &outp

Status ParserUtils::ExpandNodeToSubgraph(const Graph &subgraph, const NodePtr &node, const Graph &graph,
OutputMapping &output_mapping) {
ComputeGraphPtr sub_compute_graph = GraphUtils::GetComputeGraph(subgraph);
ComputeGraphPtr sub_compute_graph = OperUtils::GetComputeGraph(subgraph);
GE_CHECK_NOTNULL(sub_compute_graph);
ComputeGraphPtr compute_graph = GraphUtils::GetComputeGraph(graph);
ComputeGraphPtr compute_graph = OperUtils::GetComputeGraph(graph);
GE_CHECK_NOTNULL(compute_graph);

// add subgraph node to graph.


+ 5
- 14
parser/onnx/onnx_parser.cc View File

@@ -15,36 +15,27 @@
*/

#include "onnx_parser.h"

#include <algorithm>
#include <iostream>
#include <queue>
#include "common/convert/message2operator.h"
#include "common/convert/pb2json.h"
#include "common/util.h"
#include "common/util/error_manager/error_manager.h"
#include "external/graph/operator_factory.h"
#include "external/register/register_error_codes.h"
#include "external/parser/onnx_parser.h"
#include "external/ge/ge_api_types.h"
#include "framework/omg/parser/parser_inner_ctx.h"
#include "framework/omg/parser/parser_types.h"
#include "omg/parser/parser_factory.h"
#include "onnx_op_parser.h"
#include "onnx_util.h"
#include "parser/common/op_parser_factory.h"
#include "parser/common/acl_graph_parser_util.h"
#include "parser/common/model_saver.h"
#include "parser/common/parser_utils.h"
#include "parser/common/prototype_pass_manager.h"
#include "parser/onnx/onnx_custom_parser_adapter.h"
#include "parser/onnx/onnx_util.h"
#include "register/op_registry.h"
#include "register/register_fmk_types.h"
#include "graph/utils/graph_utils.h"
#include "graph/utils/node_utils.h"
#include "graph/utils/type_utils.h"
#include "graph/utils/oper_utils.h"
#include "subgraph_adapter/subgraph_adapter_factory.h"
#include "framework/common/types.h"
#include "mmpa/mmpa_api.h"

namespace {
@@ -76,7 +67,7 @@ graphStatus PrepareBeforeParse(AclGrphParseUtil &acl_graph_parse_util,
ge::ComputeGraphPtr compute_graph = ge::parser::MakeShared<ge::ComputeGraph>(graph_name);
GE_CHECK_NOTNULL(compute_graph);

graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);
model_parser = domi::ModelParserFactory::Instance()->CreateModelParser(domi::ONNX);
GE_CHECK_NOTNULL(model_parser);
return ge::SUCCESS;
@@ -249,7 +240,7 @@ Status PostOpProcessForSubgraph(const ParseArg &arg, ge::ComputeGraphPtr sub_gra
node->GetOpDesc()->SetName(OnnxUtil::GenUniqueNodeName(sub_graph->GetName(), node->GetName()));
}

auto graph = ge::GraphUtils::CreateGraphFromComputeGraph(sub_graph);
auto graph = ge::OperUtils::CreateGraphFromComputeGraph(sub_graph);
Status ret = FAILED;
if (post_func != nullptr) {
ret = post_func(arg.graph_name, graph);
@@ -908,7 +899,7 @@ Status OnnxModelParser::ModelParseToGraph(const ge::onnx::ModelProto &onnx_model
root_graph = tmp_graph;
}

ge::ComputeGraphPtr cur_compute_graph = ge::GraphUtils::GetComputeGraph(tmp_graph);
ge::ComputeGraphPtr cur_compute_graph = ge::OperUtils::GetComputeGraph(tmp_graph);
GE_CHECK_NOTNULL(cur_compute_graph);

ret = PostOpProcessForSubgraph(arg, cur_compute_graph);


+ 9
- 8
parser/tensorflow/tensorflow_parser.cc View File

@@ -54,6 +54,7 @@
#include "register/scope/scope_pass_registry_impl.h"
#include "parser/common/auto_mapping_subgraph_io_index_func.h"
#include "graph/def_types.h"
#include "graph/utils/oper_utils.h"

using ge::OpParserFactory;
using ge::Pb2Json;
@@ -108,7 +109,7 @@ graphStatus aclgrphParseTensorFlow(const char *model_file, ge::Graph &graph) {
return FAILED;
}

graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);
auto model_parser = domi::ModelParserFactory::Instance()->CreateModelParser(domi::TENSORFLOW);
if (model_parser == nullptr) {
REPORT_CALL_ERROR("E19999", "No Model Parser for tensorflow, check invalid");
@@ -162,7 +163,7 @@ graphStatus aclgrphParseTensorFlow(const char *model_file, const std::map<Ascend
return FAILED;
}

graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);
auto model_parser = domi::ModelParserFactory::Instance()->CreateModelParser(domi::TENSORFLOW);
if (model_parser == nullptr) {
REPORT_CALL_ERROR("E19999", "No Model Parser for tensorflow, check invalid");
@@ -299,7 +300,7 @@ Status PostOpProcessForSubgraph(const ParseArg &arg) {
node->GetOpDesc()->SetName(node->GetOwnerComputeGraph()->GetName() + "/" + node->GetName());
}

auto graph = ge::GraphUtils::CreateGraphFromComputeGraph(arg.graph);
auto graph = ge::OperUtils::CreateGraphFromComputeGraph(arg.graph);
Status ret = FAILED;
if (post_func != nullptr) {
ret = post_func(arg.subgraph_name, graph);
@@ -337,7 +338,7 @@ Status MappingAndAddSubGraph(const NodePtr &node, const Graph &graph, const Comp
return INTERNAL_ERROR;
}

ComputeGraphPtr compute_graph = GraphUtils::GetComputeGraph(graph);
ComputeGraphPtr compute_graph = OperUtils::GetComputeGraph(graph);
GE_CHECK_NOTNULL(compute_graph);
// Inner function, GetOpDesc has been checked by caller
(void)node->GetOpDesc()->AddSubgraphName("f");
@@ -1355,7 +1356,7 @@ Status TensorFlowModelParser::GetFunctionProto(const string &file,
Status TensorFlowModelParser::Parse(const char *file, ge::Graph &graph) {
ErrorManager::GetInstance().SetStage(error_message::kModelCompile, error_message::kParser);
GE_CHECK_NOTNULL(file);
ge::ComputeGraphPtr root_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr root_graph = ge::OperUtils::GetComputeGraph(graph);
GE_CHECK_NOTNULL(root_graph);

Status ret = Parse(file, root_graph);
@@ -1575,7 +1576,7 @@ Status TensorFlowModelParser::ParseAllGraph(const google::protobuf::Message *pro
DeleteFuisonNodeDef();

GE_RETURN_IF_ERROR(AddEdges(graph));
Graph dest_graph = GraphUtils::CreateGraphFromComputeGraph(graph);
Graph dest_graph = OperUtils::CreateGraphFromComputeGraph(graph);
ParserUtils::OutputMapping final_output_nodes;
GE_RETURN_IF_ERROR(ParserUtils::ExpandOneToManyGraph(dest_graph, final_output_nodes));
GE_RETURN_IF_ERROR(UpdateOutputsInfo(final_output_nodes));
@@ -2319,7 +2320,7 @@ Status TensorFlowModelParser::ParseProto(const google::protobuf::Message *proto,

ret = AddEdges(graph);

Graph dest_graph = GraphUtils::CreateGraphFromComputeGraph(graph);
Graph dest_graph = OperUtils::CreateGraphFromComputeGraph(graph);
ParserUtils::OutputMapping final_output_nodes;
GE_RETURN_IF_ERROR(ParserUtils::ExpandOneToManyGraph(dest_graph, final_output_nodes));
GE_RETURN_IF_ERROR(UpdateOutputsInfo(final_output_nodes));
@@ -4002,7 +4003,7 @@ Status TensorFlowModelParser::AddExternalGraph(const ComputeGraphPtr &root_graph
REPORT_CALL_ERROR("E19999", "Failed to parse external model, node:%s.", node->GetName().c_str());
return INTERNAL_ERROR;
}
Graph graph = model.GetGraph();
Graph graph = ge::OperUtils::CreateGraphFromComputeGraph(model.GetGraph());
GELOGD("Get subgraph[%s] from model[%s].", ParserUtils::GetGraphName(graph).c_str(), node->GetName().c_str());
Status ret = MappingAndAddSubGraph(node, graph, root_graph);
if (ret != SUCCESS) {


+ 1
- 0
tests/st/CMakeLists.txt View File

@@ -125,6 +125,7 @@ set(MATEDEF_SRC_FILES
"${PARSER_DIR}/metadef/graph/utils/graph_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/node_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/op_desc_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/oper_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/tensor_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/transformer_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/tuning_utils.cc"


+ 4
- 3
tests/st/testcase/test_caffe_parser.cc View File

@@ -20,6 +20,7 @@
#define private public
#include "parser/common/op_parser_factory.h"
#include "graph/operator_reg.h"
#include "graph/utils/oper_utils.h"
#include "register/op_registry.h"
#include "parser/common/register_tbe.h"
#include "framework/omg/parser/model_parser.h"
@@ -188,7 +189,7 @@ TEST_F(STestCaffeParser, caffe_parser_user_output_with_default) {
ASSERT_NE(model_parser, nullptr);
ge::ComputeGraphPtr compute_graph = ge::parser::MakeShared<ge::ComputeGraph>("tmp_graph");
ASSERT_NE(compute_graph, nullptr);
ge::Graph graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
ge::Graph graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);
auto ret = model_parser->Parse(model_file.c_str(), graph);
ASSERT_EQ(ret, GRAPH_SUCCESS);
AclGrphParseUtil acl_graph_parse_util;
@@ -258,7 +259,7 @@ TEST_F(STestCaffeParser, modelparser_parsefrommemory_success)
const char* tmp_tf_pb_model = modelFile.c_str();
ge::Graph graph;

ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
CaffeModelParser modelParser;
MemBuffer* memBuffer = ParerSTestsUtils::MemBufferFromFile(tmp_tf_pb_model);
auto ret = modelParser.ParseFromMemory((char*)memBuffer->data, memBuffer->size, compute_graph);
@@ -672,7 +673,7 @@ TEST_F(STestCaffeParser, CaffeWeightsParser_ParseGraph_test)
{
CaffeWeightsParser weightParser;
ge::ComputeGraphPtr compute_graph = ge::parser::MakeShared<ge::ComputeGraph>("tmp_graph");
ge::Graph graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
ge::Graph graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);

std::string case_dir = __FILE__;
case_dir = case_dir.substr(0, case_dir.find_last_of("/"));


+ 2
- 1
tests/st/testcase/test_onnx_parser.cc View File

@@ -18,6 +18,7 @@
#include <iostream>
#include "parser/common/op_parser_factory.h"
#include "graph/operator_reg.h"
#include "graph/utils/oper_utils.h"
#include "register/op_registry.h"
#include "parser/common/register_tbe.h"
#include "external/parser/onnx_parser.h"
@@ -111,7 +112,7 @@ TEST_F(STestOnnxParser, onnx_parser_user_output_with_default) {
ge::Graph graph;
auto ret = ge::aclgrphParseONNX(model_file.c_str(), parser_params, graph);
ASSERT_EQ(ret, GRAPH_SUCCESS);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
auto output_nodes_info = compute_graph->GetGraphOutNodesInfo();
ASSERT_EQ(output_nodes_info.size(), 1);
EXPECT_EQ((output_nodes_info.at(0).first->GetName()), "Conv_0");


+ 9
- 8
tests/st/testcase/test_tensorflow_parser.cc View File

@@ -21,6 +21,7 @@
#include "parser/common/op_parser_factory.h"
#include "parser/tensorflow/tensorflow_parser.h"
#include "graph/operator_reg.h"
#include "graph/utils/oper_utils.h"
#include "register/op_registry.h"
#include "external/register/register.h"
#include "parser/common/register_tbe.h"
@@ -1022,7 +1023,7 @@ TEST_F(STestTensorflowParser, tensorflow_parser_success) {
ge::Graph graph;
auto ret = ge::aclgrphParseTensorFlow(model_file.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
auto output_nodes_info = compute_graph->GetGraphOutNodesInfo();
ASSERT_EQ(output_nodes_info.size(), 1);
EXPECT_EQ((output_nodes_info.at(0).first->GetName()), "add_test_1");
@@ -1125,7 +1126,7 @@ TEST_F(STestTensorflowParser, tensorflow_parserfrommemory_failed)
modelFile = caseDir + "/origin_models/tf_add.pb";
parser_params = {{AscendString(ge::ir_option::OUT_NODES), AscendString("Placeholder:0;Placeholder_1:0")}};
ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
ret = modelParser.ParseFromMemory(data, size, compute_graph);
EXPECT_NE(ret, SUCCESS);
}
@@ -1142,7 +1143,7 @@ TEST_F(STestTensorflowParser, modelparser_parsefrommemory_success)
Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);

ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
TensorFlowModelParser modelParser;
MemBuffer* memBuffer = MemBufferFromFile(tmp_tf_pb_model);
PreChecker::Instance().HasError() == false;
@@ -1163,7 +1164,7 @@ TEST_F(STestTensorflowParser, weightsparser_parsefrommemory_success)
Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);

ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
auto weights_parser = domi::WeightsParserFactory::Instance()->CreateWeightsParser(domi::TENSORFLOW);
MemBuffer* memBuffer = MemBufferFromFile(tmp_tf_pb_model);
ret = weights_parser->ParseFromMemory((char*)memBuffer->data, memBuffer->size, compute_graph);
@@ -1192,7 +1193,7 @@ TEST_F(STestTensorflowParser, parser_ParseProtoWithSubgraphV2)
Status ret = ge::aclgrphParseTensorFlow(root_proto.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);

ge::ComputeGraphPtr root_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr root_graph = ge::OperUtils::GetComputeGraph(graph);
domi::GetGraphCallbackV2 callback(&getGraphCallbackV2);
TensorFlowModelParser parser;
ret = parser.ParseProtoWithSubgraph(root_proto, callback, root_graph);
@@ -1223,7 +1224,7 @@ TEST_F(STestTensorflowParser, tensorflow_ParserProto_failed)
Status ret = ge::aclgrphParseTensorFlow(root_proto.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);

ge::ComputeGraphPtr root_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr root_graph = ge::OperUtils::GetComputeGraph(graph);
TensorFlowModelParser tensorflow_parser;
ret = tensorflow_parser.ParseProto(reinterpret_cast<google::protobuf::Message *>(&graphDef), root_graph);
EXPECT_EQ(PARAM_INVALID, ret);
@@ -1259,7 +1260,7 @@ TEST_F(STestTensorflowParser, tensorflow_parserAllGraph_failed)
Status ret = ge::aclgrphParseTensorFlow(root_proto.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);

ge::ComputeGraphPtr root_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr root_graph = ge::OperUtils::GetComputeGraph(graph);
TensorFlowModelParser tensorflow_parser;
ret = tensorflow_parser.ParseAllGraph(reinterpret_cast<google::protobuf::Message *>(&graphDef), root_graph);
ASSERT_NE(ret, SUCCESS);
@@ -1504,7 +1505,7 @@ TEST_F(STestTensorflowParser, parse_AddScopeInnerNode)
std::string modelFile = caseDir + "/origin_models/tf_add.pb";
std::string op_name = "ge_ascend_irgraph";
ge::Graph graph(op_name);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
std::map<ge::AscendString, ge::AscendString> parser_params = {
{AscendString(ge::ir_option::OUT_NODES), AscendString("Placeholder:0;Placeholder_1:0")}};
Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph);


+ 1
- 0
tests/ut/parser/CMakeLists.txt View File

@@ -126,6 +126,7 @@ set(MATEDEF_SRC_FILES
"${PARSER_DIR}/metadef/graph/utils/cycle_detector.cc"
"${PARSER_DIR}/metadef/graph/utils/node_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/op_desc_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/oper_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/tensor_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/transformer_utils.cc"
"${PARSER_DIR}/metadef/graph/utils/tuning_utils.cc"


+ 6
- 5
tests/ut/parser/testcase/caffe_parser_testcase/caffe_parser_unittest.cc View File

@@ -21,6 +21,7 @@
#include <iostream>
#include "parser/common/op_parser_factory.h"
#include "graph/operator_reg.h"
#include "graph/utils/oper_utils.h"
#include "external/graph/types.h"
#include "register/op_registry.h"
#include "parser/common/register_tbe.h"
@@ -184,7 +185,7 @@ TEST_F(UtestCaffeParser, caffe_parser_user_output_with_name_and_index) {
ASSERT_NE(model_parser, nullptr);
ge::ComputeGraphPtr compute_graph = ge::parser::MakeShared<ge::ComputeGraph>("tmpGraph");
ASSERT_NE(compute_graph, nullptr);
ge::Graph graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
ge::Graph graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);

ge::GetParserContext().user_out_nodes.push_back({"abs", 0});
auto ret = model_parser->Parse(model_file.c_str(), graph);
@@ -211,7 +212,7 @@ TEST_F(UtestCaffeParser, caffe_parser_user_output_with_top_name) {
ASSERT_NE(model_parser, nullptr);
ge::ComputeGraphPtr compute_graph = ge::parser::MakeShared<ge::ComputeGraph>("tmpGraph");
ASSERT_NE(compute_graph, nullptr);
ge::Graph graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
ge::Graph graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);

ge::GetParserContext().user_out_tensors.push_back("abs_out");
auto ret = model_parser->Parse(model_file.c_str(), graph);
@@ -238,7 +239,7 @@ TEST_F(UtestCaffeParser, caffe_parser_user_output_with_default) {
ASSERT_NE(model_parser, nullptr);
ge::ComputeGraphPtr compute_graph = ge::parser::MakeShared<ge::ComputeGraph>("tmpGraph");
ASSERT_NE(compute_graph, nullptr);
ge::Graph graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
ge::Graph graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);
auto ret = model_parser->Parse(model_file.c_str(), graph);
ASSERT_EQ(ret, GRAPH_SUCCESS);
AclGrphParseUtil acl_graph_parse_util;
@@ -312,7 +313,7 @@ TEST_F(UtestCaffeParser, ParseFromMemory_success)
ge::Graph graph;

Status ret = ge::aclgrphParseCaffe(modelFile.c_str(), weight_file.c_str(), graph);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
CaffeModelParser modelParser;
MemBuffer* memBuffer1 = ParerUTestsUtils::MemBufferFromFile(tmp_tf_pb_model);
ret = modelParser.ParseFromMemory((char*)memBuffer1->data, memBuffer1->size, compute_graph);
@@ -751,7 +752,7 @@ TEST_F(UtestCaffeParser, CaffeWeightsParser_ParseGraph_test)
{
CaffeWeightsParser weightParser;
ge::ComputeGraphPtr compute_graph = ge::parser::MakeShared<ge::ComputeGraph>("tmp_graph");
ge::Graph graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
ge::Graph graph = ge::OperUtils::CreateGraphFromComputeGraph(compute_graph);

std::string case_dir = __FILE__;
case_dir = case_dir.substr(0, case_dir.find_last_of("/"));


+ 4
- 3
tests/ut/parser/testcase/onnx_parser_testcase/onnx_parser_unittest.cc View File

@@ -18,6 +18,7 @@
#include <iostream>
#include "parser/common/op_parser_factory.h"
#include "graph/operator_reg.h"
#include "graph/utils/oper_utils.h"
#include "external/graph/types.h"
#include "register/op_registry.h"
#include "parser/common/register_tbe.h"
@@ -130,7 +131,7 @@ TEST_F(UtestOnnxParser, onnx_parser_user_output_with_name_and_index) {
ge::Graph graph;
auto ret = ge::aclgrphParseONNX(model_file.c_str(), parser_params, graph);
ASSERT_EQ(ret, GRAPH_SUCCESS);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
auto output_nodes_info = compute_graph->GetGraphOutNodesInfo();
ASSERT_EQ(output_nodes_info.size(), 1);
EXPECT_EQ((output_nodes_info.at(0).first->GetName()), "Conv_0");
@@ -149,7 +150,7 @@ TEST_F(UtestOnnxParser, onnx_parser_user_output_with_tensor) {
ge::Graph graph;
auto ret = ge::aclgrphParseONNX(model_file.c_str(), parser_params, graph);
ASSERT_EQ(ret, GRAPH_SUCCESS);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
auto output_nodes_info = compute_graph->GetGraphOutNodesInfo();
ASSERT_EQ(output_nodes_info.size(), 1);
EXPECT_EQ((output_nodes_info.at(0).first->GetName()), "Conv_0");
@@ -167,7 +168,7 @@ TEST_F(UtestOnnxParser, onnx_parser_user_output_with_default) {
ge::Graph graph;
auto ret = ge::aclgrphParseONNX(model_file.c_str(), parser_params, graph);
ASSERT_EQ(ret, GRAPH_SUCCESS);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
auto output_nodes_info = compute_graph->GetGraphOutNodesInfo();
ASSERT_EQ(output_nodes_info.size(), 1);
EXPECT_EQ((output_nodes_info.at(0).first->GetName()), "Conv_0");


+ 11
- 10
tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc View File

@@ -22,6 +22,7 @@
#include "parser/tensorflow/tensorflow_parser.h"
#include "framework/omg/parser/parser_factory.h"
#include "graph/operator_reg.h"
#include "graph/utils/oper_utils.h"
#include "external/graph/types.h"
#include "register/op_registry.h"
#include "external/register/register.h"
@@ -1036,7 +1037,7 @@ TEST_F(UtestTensorflowParser, tensorflow_parser_success) {
ge::Graph graph;
auto ret = ge::aclgrphParseTensorFlow(model_file.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
auto output_nodes_info = compute_graph->GetGraphOutNodesInfo();
ASSERT_EQ(output_nodes_info.size(), 1);
EXPECT_EQ((output_nodes_info.at(0).first->GetName()), "add_test_1");
@@ -1173,7 +1174,7 @@ TEST_F(UtestTensorflowParser, tensorflow_parser_with_external_graph) {
// 3. Serialize ONNX graph to string
// 3.1 normal
ge::Model model("model", "");
model.SetGraph(GraphUtils::CreateGraphFromComputeGraph(sub_graph));
model.SetGraph(sub_graph);
Buffer buffer;
graphStatus save_ret = model.Save(buffer, false);
ASSERT_EQ(save_ret, GRAPH_SUCCESS);
@@ -1181,7 +1182,7 @@ TEST_F(UtestTensorflowParser, tensorflow_parser_with_external_graph) {
// model will failed
input1->GetOpDesc()->DelAttr(ATTR_NAME_INDEX);
ge::Model model_will_fail("model_will_fail", "");
model_will_fail.SetGraph(GraphUtils::CreateGraphFromComputeGraph(sub_graph));
model_will_fail.SetGraph(sub_graph);
Buffer buffer_fail;
save_ret = model_will_fail.Save(buffer_fail, false);
ASSERT_EQ(save_ret, GRAPH_SUCCESS);
@@ -1288,7 +1289,7 @@ TEST_F(UtestTensorflowParser, tensorflow_parserfrommemory_failed)
modelFile = caseDir + "/tensorflow_model/tf_add.pb";
parser_params = {{AscendString(ge::ir_option::OUT_NODES), AscendString("Placeholder:0;Placeholder_1:0")}};
ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
ret = modelParser.ParseFromMemory(data, size, compute_graph);
EXPECT_NE(ret, SUCCESS);
}
@@ -1305,7 +1306,7 @@ TEST_F(UtestTensorflowParser, modelparser_parsefrommemory_success)
Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);

ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
TensorFlowModelParser modelParser;
MemBuffer* memBuffer = MemBufferFromFile(tmp_tf_pb_model);
PreChecker::Instance().HasError() == false;
@@ -1326,7 +1327,7 @@ TEST_F(UtestTensorflowParser, weightsparser_parsefrommemory_success)
Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);

ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
auto weights_parser = domi::WeightsParserFactory::Instance()->CreateWeightsParser(domi::TENSORFLOW);
MemBuffer* memBuffer = MemBufferFromFile(tmp_tf_pb_model);
ret = weights_parser->ParseFromMemory((char*)memBuffer->data, memBuffer->size, compute_graph);
@@ -1355,7 +1356,7 @@ TEST_F(UtestTensorflowParser, parser_ParseProtoWithSubgraphV2)
Status ret = ge::aclgrphParseTensorFlow(root_proto.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);

ge::ComputeGraphPtr root_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr root_graph = ge::OperUtils::GetComputeGraph(graph);
domi::GetGraphCallbackV2 callback(&getGraphCallbackV2);
TensorFlowModelParser parser;
ret = parser.ParseProtoWithSubgraph(root_proto, callback, root_graph);
@@ -1386,7 +1387,7 @@ TEST_F(UtestTensorflowParser, tensorflow_ParserProto_failed)
Status ret = ge::aclgrphParseTensorFlow(root_proto.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);

ge::ComputeGraphPtr root_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr root_graph = ge::OperUtils::GetComputeGraph(graph);
TensorFlowModelParser tensorflow_parser;
ret = tensorflow_parser.ParseProto(reinterpret_cast<google::protobuf::Message *>(&graphDef), root_graph);
EXPECT_EQ(PARAM_INVALID, ret);
@@ -1425,7 +1426,7 @@ TEST_F(UtestTensorflowParser, tensorflow_parserAllGraph_failed)
Status ret = ge::aclgrphParseTensorFlow(root_proto.c_str(), parser_params, graph);
ASSERT_EQ(ret, SUCCESS);

ge::ComputeGraphPtr root_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr root_graph = ge::OperUtils::GetComputeGraph(graph);
TensorFlowModelParser tensorflow_parser;
ret = tensorflow_parser.ParseAllGraph(reinterpret_cast<google::protobuf::Message *>(&graphDef), root_graph);
ASSERT_NE(ret, SUCCESS);
@@ -1677,7 +1678,7 @@ TEST_F(UtestTensorflowParser, parse_AddScopeInnerNode)
std::string modelFile = caseDir + "/tensorflow_model/tf_add.pb";
std::string op_name = "ge_ascend_irgraph";
ge::Graph graph(op_name);
ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
ge::ComputeGraphPtr compute_graph = ge::OperUtils::GetComputeGraph(graph);
std::map<ge::AscendString, ge::AscendString> parser_params = {
{AscendString(ge::ir_option::OUT_NODES), AscendString("Placeholder:0;Placeholder_1:0")}};
Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph);


Loading…
Cancel
Save