| @@ -42,6 +42,11 @@ | |||||
| #undef protected | #undef protected | ||||
| #undef private | #undef private | ||||
| #include <google/protobuf/compiler/importer.h> | |||||
| #include <google/protobuf/io/coded_stream.h> | |||||
| #include <google/protobuf/io/zero_copy_stream_impl.h> | |||||
| #include <google/protobuf/text_format.h> | |||||
| using namespace domi::caffe; | using namespace domi::caffe; | ||||
| using namespace ge; | using namespace ge; | ||||
| @@ -739,6 +744,16 @@ TEST_F(UtestCaffeParser, CaffeModelParser_GetCustomOp_test) | |||||
| Status ret = model_parser.GetCustomOp(*layer, operators); | Status ret = model_parser.GetCustomOp(*layer, operators); | ||||
| EXPECT_EQ(ret, SUCCESS); | EXPECT_EQ(ret, SUCCESS); | ||||
| ge::Operator ops2("Conv", "Convolution"); | |||||
| model_parser.custom_operator_.push_back(ops2); | |||||
| ret = model_parser.GetCustomOp(*layer, operators); | |||||
| EXPECT_EQ(ret, SUCCESS); | |||||
| ge::Operator ops("Data", "Input"); | |||||
| model_parser.custom_operator_.push_back(ops); | |||||
| ret = model_parser.GetCustomOp(*layer, operators); | |||||
| EXPECT_EQ(ret, SUCCESS); | |||||
| } | } | ||||
| TEST_F(UtestCaffeParser, CaffeModelParser_AddTensorDescToOpDesc_test) | TEST_F(UtestCaffeParser, CaffeModelParser_AddTensorDescToOpDesc_test) | ||||
| @@ -986,4 +1001,104 @@ TEST_F(UtestCaffeParser, CaffeOpParser_ParseParams_test) | |||||
| EXPECT_EQ(ret, SUCCESS); | EXPECT_EQ(ret, SUCCESS); | ||||
| } | } | ||||
| TEST_F(UtestCaffeParser, CaffeModelParser_FindShareParamLayers_test) | |||||
| { | |||||
| CaffeModelParser modelParser; | |||||
| std::map<std::string, std::vector<std::string>> layer_params_map; | |||||
| std::vector<std::string> layer_params; | |||||
| layer_params.emplace_back("Conv"); | |||||
| layer_params.emplace_back("Data"); | |||||
| layer_params.emplace_back("Abs"); | |||||
| layer_params_map.insert(std::make_pair("Abs", layer_params)); | |||||
| layer_params_map.insert(std::make_pair("Data", layer_params)); | |||||
| layer_params_map.insert(std::make_pair("Conv", layer_params)); | |||||
| Status ret = modelParser.FindShareParamLayers(layer_params_map); | |||||
| EXPECT_EQ(ret, SUCCESS); | |||||
| } | |||||
| TEST_F(UtestCaffeParser, CaffeWeightsParser_ParseLayerParameter_test) | |||||
| { | |||||
| CaffeWeightsParser weightParser; | |||||
| domi::caffe::NetParameter net; | |||||
| GetParserContext().type = domi::CAFFE; | |||||
| domi::caffe::LayerParameter *layer = net.add_layer(); | |||||
| layer->set_name("Abs"); | |||||
| layer->set_type("AbsVal"); | |||||
| ge::ComputeGraphPtr compute_graph = build_graph(true); | |||||
| const google::protobuf::Descriptor *descriptor = net.GetDescriptor(); | |||||
| Status ret = weightParser.ParseLayerParameter(descriptor, &net, compute_graph); | |||||
| EXPECT_EQ(ret, PARAM_INVALID); | |||||
| } | |||||
| TEST_F(UtestCaffeParser, CaffeModelParser_ParseLayerParameter_test) | |||||
| { | |||||
| CaffeModelParser modelParser; | |||||
| domi::caffe::NetParameter net; | |||||
| GetParserContext().type = domi::CAFFE; | |||||
| domi::caffe::LayerParameter *layer = net.add_layer(); | |||||
| layer->set_name("Abs"); | |||||
| layer->set_type("AbsVal"); | |||||
| vector<ge::Operator> operators; | |||||
| ge::OpDescPtr op_desc_src = std::make_shared<ge::OpDesc>("Data", "Input"); | |||||
| ge::Operator op_src = ge::OpDescUtils::CreateOperatorFromOpDesc(op_desc_src); | |||||
| operators.emplace_back(op_src); | |||||
| const google::protobuf::Descriptor *descriptor = net.GetDescriptor(); | |||||
| Status ret = modelParser.ParseLayerParameter(descriptor, &net, operators); | |||||
| EXPECT_EQ(ret, PARAM_INVALID); | |||||
| } | |||||
| TEST_F(UtestCaffeParser, CaffeModelParser_ReadModelWithoutWarning_test) | |||||
| { | |||||
| CaffeModelParser modelParser; | |||||
| std::string case_dir = __FILE__; | |||||
| case_dir = case_dir.substr(0, case_dir.find_last_of("/")); | |||||
| std::string model_file = case_dir + "/caffe_model/caffe.pbtxt"; | |||||
| const char *model_path = model_file.c_str(); | |||||
| domi::caffe::NetParameter net; | |||||
| domi::caffe::LayerParameter *layer = net.add_layer(); | |||||
| layer->set_name("Abs"); | |||||
| layer->set_type("AbsVal"); | |||||
| Status ret = modelParser.ReadModelWithoutWarning(model_path, &net); | |||||
| EXPECT_EQ(ret, FAILED); | |||||
| } | |||||
| TEST_F(UtestCaffeParser, CaffeModelParser_AddBlobsToMap_test) | |||||
| { | |||||
| CaffeModelParser modelParser; | |||||
| domi::caffe::NetParameter net; | |||||
| domi::caffe::LayerParameter *layer = net.add_layer(); | |||||
| layer->set_name("Abs"); | |||||
| layer->set_type("AbsVal"); | |||||
| std::map<std::string, std::string> inplace_blob_name_remapping{{"bottom", "AbsVal"}}; | |||||
| layer->add_top("top"); | |||||
| layer->add_bottom("bottom"); | |||||
| modelParser.AddBlobsToMap(*layer, inplace_blob_name_remapping); | |||||
| } | |||||
| TEST_F(UtestCaffeParser, CaffeWeightsParser_ParseWeightByFusionProto_test2) | |||||
| { | |||||
| std::string case_dir = __FILE__; | |||||
| case_dir = case_dir.substr(0, case_dir.find_last_of("/")); | |||||
| std::string model_file = case_dir + "/caffe_model/caffe_abs.pbtxt"; | |||||
| const char *weight_path = model_file.c_str(); | |||||
| std::string fusion_proto_path = case_dir + "/caffe_model/custom.proto"; | |||||
| string fusion_proto_name = "domi.caffe.NetParameter"; | |||||
| vector<ge::Operator> operators; | |||||
| ge::OpDescPtr op_desc_src = std::make_shared<ge::OpDesc>("Data", "Input"); | |||||
| ge::Operator op_src = ge::OpDescUtils::CreateOperatorFromOpDesc(op_desc_src); | |||||
| operators.emplace_back(op_src); | |||||
| CaffeModelParser modelParser; | |||||
| modelParser.ParseNetModelByCustomProto(weight_path, fusion_proto_path, fusion_proto_name, operators); | |||||
| } | |||||
| } // namespace ge | } // namespace ge | ||||
| @@ -30,11 +30,16 @@ | |||||
| #include "parser/common/proto_file_parser.h" | #include "parser/common/proto_file_parser.h" | ||||
| #include "omg/parser/parser_factory.h" | #include "omg/parser/parser_factory.h" | ||||
| #include "parser/caffe/caffe_parser.h" | #include "parser/caffe/caffe_parser.h" | ||||
| #include "register/register.h" | |||||
| #include "parser/common/pass_manager.h" | |||||
| #include "parser/common/tbe_plugin_loader.h" | |||||
| #undef protected | #undef protected | ||||
| #undef private | #undef private | ||||
| #include <dlfcn.h> | |||||
| using namespace domi; | using namespace domi; | ||||
| using namespace testing; | using namespace testing; | ||||
| using namespace ge; | |||||
| namespace ge { | namespace ge { | ||||
| class UtestAclGraphParser : public testing::Test { | class UtestAclGraphParser : public testing::Test { | ||||
| @@ -119,16 +124,15 @@ TEST_F(UtestAclGraphParser, test_CheckConflictOp) | |||||
| op.CheckConflictOp(caffe_proto_file, custom_proto_file, caffe_op_identifier_map, custom_op_identifier_map); | op.CheckConflictOp(caffe_proto_file, custom_proto_file, caffe_op_identifier_map, custom_op_identifier_map); | ||||
| caffe_op_identifier_map.clear(); | caffe_op_identifier_map.clear(); | ||||
| caffe_op_identifier_map.insert(std::make_pair("ge", std::make_pair(2, "ge"))); | |||||
| caffe_op_identifier_map.insert(std::make_pair("ge", std::make_pair(2, "ge"))); | |||||
| op.CheckConflictOp(caffe_proto_file, custom_proto_file, caffe_op_identifier_map, custom_op_identifier_map); | op.CheckConflictOp(caffe_proto_file, custom_proto_file, caffe_op_identifier_map, custom_op_identifier_map); | ||||
| } | } | ||||
| TEST_F(UtestAclGraphParser, test_CheckConflictIdentifier) | TEST_F(UtestAclGraphParser, test_CheckConflictIdentifier) | ||||
| { | { | ||||
| ge::ProtoFileParser op; | ge::ProtoFileParser op; | ||||
| std::string custom_file = "/dev/null"; | |||||
| const char *caffe_proto_file = custom_file.c_str(); | |||||
| const char *custom_proto_file = custom_file.c_str(); | |||||
| char *caffe_proto_file = "/dev/null"; | |||||
| char *custom_proto_file = "/dev/null"; | |||||
| std::map<int, std::pair<string, string>> caffe_op_identifier_map; | std::map<int, std::pair<string, string>> caffe_op_identifier_map; | ||||
| std::map<int, std::pair<string, string>> custom_op_identifier_map; | std::map<int, std::pair<string, string>> custom_op_identifier_map; | ||||
| custom_op_identifier_map.insert(std::make_pair(1, std::make_pair("ge", "ge"))); | custom_op_identifier_map.insert(std::make_pair(1, std::make_pair("ge", "ge"))); | ||||
| @@ -143,12 +147,15 @@ TEST_F(UtestAclGraphParser, test_CheckConflictIdentifier) | |||||
| TEST_F(UtestAclGraphParser, test_AddCustomAndConflictLayer) | TEST_F(UtestAclGraphParser, test_AddCustomAndConflictLayer) | ||||
| { | { | ||||
| Status ret; | Status ret; | ||||
| std::string custom_file = "/dev/null"; | |||||
| const char *custom_proto_file = custom_file.c_str(); | |||||
| char *custom_proto_file = "../parser/caffe/caffe_parser.h"; | |||||
| ge::ProtoFileParser op; | ge::ProtoFileParser op; | ||||
| std::ofstream write_tmp; | std::ofstream write_tmp; | ||||
| ret = op.ProtoFileParser::AddCustomAndConflictLayer(custom_proto_file, write_tmp); | ret = op.ProtoFileParser::AddCustomAndConflictLayer(custom_proto_file, write_tmp); | ||||
| EXPECT_EQ(ret, SUCCESS); | EXPECT_EQ(ret, SUCCESS); | ||||
| custom_proto_file = "/dev/ge"; | |||||
| ret = op.ProtoFileParser::AddCustomAndConflictLayer(custom_proto_file, write_tmp); | |||||
| EXPECT_EQ(ret, FAILED); | |||||
| } | } | ||||
| TEST_F(UtestAclGraphParser, test_FindConflictLine) | TEST_F(UtestAclGraphParser, test_FindConflictLine) | ||||
| @@ -157,10 +164,14 @@ TEST_F(UtestAclGraphParser, test_FindConflictLine) | |||||
| ProtoFileParser op; | ProtoFileParser op; | ||||
| int identifier = 0; | int identifier = 0; | ||||
| std::string dest_line; | std::string dest_line; | ||||
| std::string file = "../parser/caffe/caffe_parser.h"; | |||||
| const char *proto_file = file.c_str(); | |||||
| ret = op.FindConflictLine(proto_file, identifier, dest_line); | |||||
| string search_string("message=1,LayerParameter=1"); | |||||
| string search_string1("optional=1 repeated=2 required=3 "); | |||||
| ret = op.FindConflictLine("../tests/ut/parser/testcase/common/acl_graph_parser_unittest.cc", identifier, dest_line); | |||||
| EXPECT_EQ(ret, FAILED); | EXPECT_EQ(ret, FAILED); | ||||
| identifier = 1; | |||||
| ret = op.FindConflictLine("../tests/ut/parser/testcase/common/acl_graph_parser_unittest.cc", identifier, dest_line); | |||||
| EXPECT_EQ(ret, SUCCESS); | |||||
| } | } | ||||
| TEST_F(UtestAclGraphParser, test_ParseProtoFile) | TEST_F(UtestAclGraphParser, test_ParseProtoFile) | ||||
| @@ -170,7 +181,7 @@ TEST_F(UtestAclGraphParser, test_ParseProtoFile) | |||||
| std::string dest_line; | std::string dest_line; | ||||
| std::map<int, std::pair<string, string>> identifier_op_map; | std::map<int, std::pair<string, string>> identifier_op_map; | ||||
| std::map<std::string, std::pair<int, string>> op_identifier_map; | std::map<std::string, std::pair<int, string>> op_identifier_map; | ||||
| string proto_file = "../parser/caffe/caffe_parser.h"; | |||||
| string proto_file = "../tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc"; | |||||
| ret = op.ParseProtoFile(proto_file, identifier_op_map, op_identifier_map); | ret = op.ParseProtoFile(proto_file, identifier_op_map, op_identifier_map); | ||||
| EXPECT_EQ(ret, SUCCESS); | EXPECT_EQ(ret, SUCCESS); | ||||
| } | } | ||||
| @@ -218,5 +229,45 @@ TEST_F(UtestAclGraphParser, test_CreatProtoFile) | |||||
| EXPECT_EQ(ret, FAILED); | EXPECT_EQ(ret, FAILED); | ||||
| } | } | ||||
| TEST_F(UtestAclGraphParser, test_Finalize) | |||||
| { | |||||
| bool ret; | |||||
| bool is_train = true; | |||||
| ge::OpRegistrationTbe op; | |||||
| ge::OpRegistrationData reg_data("c"); | |||||
| ret = op.Finalize(reg_data, is_train); | |||||
| EXPECT_EQ(ret, false); | |||||
| } | |||||
| TEST_F(UtestAclGraphParser, test_WriteProtoFile) | |||||
| { | |||||
| Status ret; | |||||
| ProtoFileParser op; | |||||
| char *caffe_proto_file = "/dev/null"; | |||||
| char *custom_proto_file = "/ge/ge/ge/ge.c"; | |||||
| ret = op.WriteProtoFile(caffe_proto_file, custom_proto_file); | |||||
| EXPECT_EQ(ret, FAILED); | |||||
| } | |||||
| TEST_F(UtestAclGraphParser, test_GraphPasses) | |||||
| { | |||||
| std::vector<std::pair<std::string, GraphPass *>> v; | |||||
| ge::parser::PassManager manager; | |||||
| v = manager.GraphPasses(); | |||||
| } | |||||
| TEST_F(UtestAclGraphParser, test_ClearHandles_) | |||||
| { | |||||
| Status ret; | |||||
| TBEPluginLoader loader; | |||||
| void *handle = dlopen("/lib/libdmmp.so", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); | |||||
| if (handle == nullptr) { | |||||
| return; | |||||
| } | |||||
| loader.handles_vec_.push_back(handle); | |||||
| dlclose(handle); | |||||
| ret = loader.ClearHandles_(); | |||||
| EXPECT_EQ(ret, SUCCESS); | |||||
| } | |||||
| } // namespace ge | } // namespace ge | ||||
| @@ -387,4 +387,39 @@ TEST_F(UtestOnnxParser, onnx_test_ModelParseToGraph) | |||||
| EXPECT_EQ(ret, FAILED); | EXPECT_EQ(ret, FAILED); | ||||
| } | } | ||||
| TEST_F(UtestOnnxParser, onnx_test_ParseFromMemory) | |||||
| { | |||||
| OnnxModelParser modelParser; | |||||
| char *data = nullptr; | |||||
| uint32_t size = 1; | |||||
| ge::Graph graph; | |||||
| Status ret = modelParser.ParseFromMemory(data, size, graph); | |||||
| EXPECT_EQ(ret, FAILED); | |||||
| } | |||||
| TEST_F(UtestOnnxParser, onnx_test_Parse) | |||||
| { | |||||
| OnnxModelParser modelParser; | |||||
| const char *file = nullptr; | |||||
| ge::Graph graph; | |||||
| Status ret = modelParser.Parse(file, graph); | |||||
| EXPECT_EQ(ret, FAILED); | |||||
| } | |||||
| TEST_F(UtestOnnxParser, onnx_test_GetModelFromMemory) | |||||
| { | |||||
| OnnxModelParser modelParser; | |||||
| const char *data = "ut/parser/testcase/onnx_parser_testcase"; | |||||
| uint32_t size = 1; | |||||
| ge::onnx::ModelProto model_proto; | |||||
| Status ret = modelParser.GetModelFromMemory(data, size, model_proto); | |||||
| EXPECT_EQ(ret, FAILED); | |||||
| ret = modelParser.GetModelFromFile(data, model_proto); | |||||
| EXPECT_EQ(ret, FAILED); | |||||
| } | |||||
| } // namespace ge | } // namespace ge | ||||
| @@ -97,6 +97,11 @@ struct DelTransposeInfo { | |||||
| int inputIdx; | int inputIdx; | ||||
| }; | }; | ||||
| /* | |||||
| message=1,LayerParameter=1 | |||||
| optional =1 repeated =1 required =1 | |||||
| */ | |||||
| Status GetTransposeInfo(GraphDef *graph_def, std::map<std::string, std::string> &softmaxInfo, | Status GetTransposeInfo(GraphDef *graph_def, std::map<std::string, std::string> &softmaxInfo, | ||||
| std::map<std::string, DelTransposeInfo> &transposeInfo); | std::map<std::string, DelTransposeInfo> &transposeInfo); | ||||