From c08216f2969e2ea91f843d2588ab88796fa20729 Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Wed, 20 Jan 2021 11:48:54 +0800 Subject: [PATCH] modified: ge/graph/load/model_manager/model_manager.cc modified: ge/graph/preprocess/graph_preprocess.cc modified: tests/ut/ge/CMakeLists.txt modified: tests/ut/ge/graph/load/new_model_manager_model_manager_unittest.cc new file: tests/ut/ge/graph/preprocess/graph_preprocess_unittest.cc --- ge/graph/load/model_manager/model_manager.cc | 1 + ge/graph/preprocess/graph_preprocess.cc | 43 +++++------ tests/ut/ge/CMakeLists.txt | 3 +- ...ew_model_manager_model_manager_unittest.cc | 40 ++++++---- .../preprocess/graph_preprocess_unittest.cc | 77 +++++++++++++++++++ 5 files changed, 124 insertions(+), 40 deletions(-) create mode 100644 tests/ut/ge/graph/preprocess/graph_preprocess_unittest.cc diff --git a/ge/graph/load/model_manager/model_manager.cc b/ge/graph/load/model_manager/model_manager.cc index 7cf869ac..8be8b60f 100755 --- a/ge/graph/load/model_manager/model_manager.cc +++ b/ge/graph/load/model_manager/model_manager.cc @@ -527,6 +527,7 @@ Status ModelManager::DataInputTensor(uint32_t model_id, const std::vector right_range)) { + GELOGE(PARAM_INVALID, "Given shape range is [%ld~%ld], current dim shape is %ld, out of range.Pleace Check.", + left_range, right_range, curr_dim); + return PARAM_INVALID; + } + } + origin_shape.SetDim(i, UNKNOWN_DIM); } } desc.SetShape(origin_shape); desc.SetShapeRange(current_shape_range_vec); - int64_t dynamic_shape_size = 1; - for (const auto range_pair : range_vec.at(index)) { - FMK_INT64_MULCHECK(dynamic_shape_size, range_pair.second); - dynamic_shape_size *= range_pair.second; - } - auto data_type_size = GetSizeByDataType(desc.GetDataType()); - if (data_type_size < 0) { - GELOGE(PARAM_INVALID, "Input data type is %s, is not supported.", - TypeUtils::DataTypeToSerialString(desc.GetDataType()).c_str()); - return PARAM_INVALID; - } - FMK_INT64_MULCHECK(dynamic_shape_size, data_type_size); - dynamic_shape_size *= data_type_size; - GELOGI("In dynamic_execute mode ,set input %s shape range size %ld", op->GetName().c_str(), dynamic_shape_size); - ge::TensorUtils::SetSize(desc, dynamic_shape_size); graphStatus graph_ret = op->UpdateInputDesc(0, desc); GE_CHK_STATUS_RET(graph_ret, "UpdateInputDesc fail, graph ret: %u", graph_ret); graph_ret = op->UpdateOutputDesc(0, desc); diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index dafb97e0..abff433c 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -573,7 +573,7 @@ set(DISTINCT_GRAPH_LOAD_TEST_FILES "graph/load/data_dumper_unittest.cc" #"graph/load/new_model_manager_data_inputer_unittest.cc" #"graph/load/new_model_manager_davinci_model_unittest.cc" - #"graph/load/new_model_manager_model_manager_unittest.cc" + "graph/load/new_model_manager_model_manager_unittest.cc" #"graph/load/new_model_manager_task_build_unittest.cc" "graph/load/new_model_manager_model_manager_aicpu_unittest.cc" "graph/load/end_graph_task_unittest.cc" @@ -697,6 +697,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/load/new_model_manager_model_manager_unittest.cc b/tests/ut/ge/graph/load/new_model_manager_model_manager_unittest.cc index 8750610a..3cffd2ed 100644 --- a/tests/ut/ge/graph/load/new_model_manager_model_manager_unittest.cc +++ b/tests/ut/ge/graph/load/new_model_manager_model_manager_unittest.cc @@ -15,24 +15,18 @@ */ #include - -#include +#include #include "common/debug/log.h" -#include "common/model_parser/base.h" -#include "common/properties_manager.h" #include "common/types.h" -#include "common/l2_cache_optimize.h" - +#include "graph/utils/graph_utils.h" #define private public #define protected public #include "graph/load/model_manager/model_manager.h" - #include "common/helper/om_file_helper.h" #include "common/op/ge_op_utils.h" #include "graph/load/graph_loader.h" -#include "graph/load/model_manager/davinci_model.h" -#include "graph/load/model_manager/davinci_model_parser.h" -#include "new_op_test_utils.h" +#include "graph/load/new_model_manager/davinci_model.h" +#include "graph/load/new_model_manager/davinci_model_parser.h" #undef private #undef protected @@ -87,7 +81,6 @@ class UtestModelManagerModelManager : public testing::Test { data.model_data = new uint8_t[data.model_len]; uint8_t data_ori[model_len]; memset(data_ori, 10, model_len); - uint32_t out_len; ModelFileHeader *header = (ModelFileHeader *)data.model_data; header->magic = MODEL_FILE_MAGIC_NUM; header->version = MODEL_VERSION; @@ -97,7 +90,7 @@ class UtestModelManagerModelManager : public testing::Test { void LoadStandardModelData(ge::ModelData &data) { static const std::string STANDARD_MODEL_DATA_PATH = - "llt/framework/domi/ut/ome/test/data/standard_partition_model.txt"; + "llt/framework/domi/ut/ome/test/data/standard_partition_model.txt"; ge::proto::ModelDef model_def; ReadProtoFromText(STANDARD_MODEL_DATA_PATH.c_str(), &model_def); @@ -113,9 +106,8 @@ class DModelListener : public ge::ModelListener { uint32_t OnComputeDone(uint32_t model_id, uint32_t data_index, uint32_t resultCode) { return 0; } }; -shared_ptr UTEST_CALL_BACK_FUN(new DModelListener()); -TEST_F(UtestModelManagerModelManager, case_load_incorrect_param) { +/*TEST_F(UtestModelManagerModelManager, case_load_incorrect_param) { ModelManager mm; uint32_t model_id = 0; ge::ModelData model; @@ -307,7 +299,7 @@ TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_fail) { } -/* +*//* // test GetInputOutputDescInfo fail TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_zero_copy_fail) { ModelManager manager; @@ -316,7 +308,7 @@ TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_zero_copy_fail) vector output_shape; EXPECT_EQ(ge::PARAM_INVALID, manager.GetInputOutputDescInfoForZeroCopy(2, input_shape, output_shape)); } -*/ +*//* // test Stop TEST_F(UtestModelManagerModelManager, stop_fail) { @@ -347,6 +339,20 @@ TEST_F(UtestModelManagerModelManager, destroy_aicpu_session) { manager.sess_ids_.insert(0); manager.DestroyAicpuSession(0); +}*/ +// test DataInputTensor +TEST_F(UtestModelManagerModelManager, test_data_input_tensor) { + shared_ptr g_label_call_back(nullptr); + auto model = std::make_shared(0, g_label_call_back); + ModelManager mm; + uint32_t model_id = 1; + mm.model_map_[1] = model; + mm.hybrid_model_map_[1] = std::make_shared(); + + auto input_tensor = InputTensorInfo(); + vector inputs; + inputs.emplace_back(input_tensor); + auto ret = mm.DataInputTensor(model_id,inputs); + EXPECT_EQ(ge::UNSUPPORTED, ret); } - } // namespace ge 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..2f149761 --- /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 "graph/passes/graph_builder_utils.h" +#include "graph/utils/attr_utils.h" +#include "graph/debug/ge_attr_define.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() { + } + void TearDown() { + } +}; + +ComputeGraphPtr BuildGraph1(){ + auto builder = ut::GraphBuilder("g1"); + auto data1 = builder.AddNode("data1",DATA,1,1); + auto data_opdesc = data1->GetOpDesc(); + AttrUtils::SetInt(data_opdesc, ATTR_NAME_INDEX, 0); + data1->UpdateOpDesc(data_opdesc); + 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; + tensor1.SetFormat(ge::FORMAT_NCHW); + tensor1.SetShape(ge::GeShape({3, 12, 5, 5})); + tensor1.SetDataType(ge::DT_FLOAT); + GeTensor input1(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(user_input, 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