From 78d1dc4e9c7968f9dc416b4a9b1960ba7fb07ac1 Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Mon, 18 Jan 2021 10:54:11 +0800 Subject: [PATCH] modified: tests/ut/ge/CMakeLists.txt new file: tests/ut/ge/graph/preprocess/graph_preprocess_unittest.cc --- tests/ut/ge/CMakeLists.txt | 3 +- .../preprocess/graph_preprocess_unittest.cc | 77 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/ut/ge/graph/preprocess/graph_preprocess_unittest.cc diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 2ebe9fc9..8b9bb188 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -36,7 +36,7 @@ set(PROTO_LIST "${GE_CODE_DIR}/metadef/proto/proto_inner/ge_onnx.proto" ) -protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST}) +protobuf_generate((ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST}) # include directories include_directories(${CMAKE_CURRENT_LIST_DIR}) @@ -694,6 +694,7 @@ set(MULTI_PARTS_TEST_FILES "graph/variable_accelerate_ctrl_unittest.cc" "graph/build/logical_stream_allocator_unittest.cc" "graph/build/mem_assigner_unittest.cc" + "graph/preprocess/graph_preprocess_unittest.cc" "session/omg_omg_unittest.cc" ) diff --git a/tests/ut/ge/graph/preprocess/graph_preprocess_unittest.cc b/tests/ut/ge/graph/preprocess/graph_preprocess_unittest.cc new file mode 100644 index 00000000..dae20f89 --- /dev/null +++ b/tests/ut/ge/graph/preprocess/graph_preprocess_unittest.cc @@ -0,0 +1,77 @@ +/** + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include + +#include "common/ge_inner_error_codes.h" +#include "common/types.h" +#include "common/util.h" +#include "passes/graph_builder_utils.h" + +#define private public +#define protected public +#include "graph/preprocess/graph_preprocess.h" +#include "ge/ge_api.h" +#undef private +#undef protected + +using namespace std; +namespace ge { +class UtestGraphPreproces : public testing::Test { + protected: + void SetUp() { + map options; + ge::Status ret = ge::GEInitialize(); + EXPECT_EQ(ret, ge::SUCCESS); + } + void TearDown() { + ge::Status ret = ge::GEFinalize(); + EXPECT_EQ(ret, ge::SUCCESS); + } +}; + +ComputeGraphPtr BuildGraph1(){ + auto builder = ut::GraphBuilder("g1"); + auto data1 = builder.AddNode("data1",DATA,0,1); + return builder.GetGraph(); +} + +TEST_F(UtestGraphPreproces, test_dynamic_input_shape_parse) { + ge::GraphPrepare graph_prepare; + graph_prepare.compute_graph_ = BuildGraph1(); + // prepare user_input & graph option + ge::GeTensorDesc tensor1; + tensor.SetFormat(ge::FORMAT_NCHW); + tensor.SetShape(ge::GeShape({3, 12, 5, 5})); + tensor.SetDataType(ge::DT_FLOAT); + GeTensor input1 = std::make_shared(tensor1); + std::vector user_input = {input1}; + std::map graph_option = {{"ge.exec.dynamicGraphExecuteMode","dynamic_execute"}, + {"ge.exec.dataInputsShapeRange","[3,1~20,2~10,5]"}}; + auto ret = graph_prepare.UpdateInput(input1, graph_option); + EXPECT_EQ(ret, ge::SUCCESS); + // check data node output shape_range and shape + auto data_node = graph_prepare.compute_graph_->FindNode("data1"); + auto data_output_desc = data_node->GetOpDesc()->GetOutputDescPtr(0); + vector expect_shape = {3,-1,-1,5}; + auto result_shape = data_output_desc->GetShape(); + EXPECT_EQ(result_shape.GetDimNum(), expect_shape.size()); + for(size_t i =0; i< expect_shape.size(); ++i){ + EXPECT_EQ(result_shape.GetDim(i), expect_shape.at(i)); + } +} +} \ No newline at end of file