From fee49b798b19d91f161879a56d6b613f708f750e Mon Sep 17 00:00:00 2001 From: wangxiaotian22 Date: Thu, 4 Mar 2021 14:56:04 +0800 Subject: [PATCH] ut cov --- ge/graph/load/model_manager/davinci_model.cc | 36 +++--- ge/graph/manager/graph_manager.cc | 2 +- tests/ut/ge/CMakeLists.txt | 1 + .../ge/graph/build/graph_builder_unittest.cc | 108 ++++++++++++++++++ 4 files changed, 128 insertions(+), 19 deletions(-) create mode 100644 tests/ut/ge/graph/build/graph_builder_unittest.cc diff --git a/ge/graph/load/model_manager/davinci_model.cc b/ge/graph/load/model_manager/davinci_model.cc index 86d9d21e..e9d1528f 100755 --- a/ge/graph/load/model_manager/davinci_model.cc +++ b/ge/graph/load/model_manager/davinci_model.cc @@ -214,12 +214,12 @@ DavinciModel::~DavinciModel() { UnbindTaskSinkStream(); for (size_t i = 0; i < label_list_.size(); ++i) { if (label_list_[i] != nullptr) { - GE_LOGW_IF(rtLabelDestroy(label_list_[i]) != RT_ERROR_NONE, "Destroy label failed, index:%zu", i); + GE_LOGW_IF(rtLabelDestroy(label_list_[i]) != RT_ERROR_NONE, "Destroy label failed, index:%zu.", i); } } for (size_t i = 0; i < stream_list_.size(); ++i) { - GE_LOGW_IF(rtStreamDestroy(stream_list_[i]) != RT_ERROR_NONE, "Destroy stream failed, index:%zu", i); + GE_LOGW_IF(rtStreamDestroy(stream_list_[i]) != RT_ERROR_NONE, "Destroy stream failed, index:%zu.", i); } for (size_t i = 0; i < event_list_.size(); ++i) { @@ -278,7 +278,7 @@ void DavinciModel::UnbindHcomStream() { for (size_t i = 0; i < all_hccl_stream_list_.size(); i++) { GE_LOGW_IF(rtModelUnbindStream(rt_model_handle_, all_hccl_stream_list_[i]) != RT_ERROR_NONE, "Unbind hccl stream from model failed! Index: %zu", i); - GE_LOGW_IF(rtStreamDestroy(all_hccl_stream_list_[i]) != RT_ERROR_NONE, "Destroy hccl stream for rt_model failed!") + GE_LOGW_IF(rtStreamDestroy(all_hccl_stream_list_[i]) != RT_ERROR_NONE, "Destroy hccl stream for rt_model failed") } } return; @@ -364,7 +364,7 @@ Status DavinciModel::InitWeightMem(void *dev_ptr, void *weight_ptr, size_t weigh Status DavinciModel::InitFeatureMapAndP2PMem(void *dev_ptr, size_t mem_size) { if (is_feature_map_mem_has_inited_) { - GELOGE(PARAM_INVALID, "call InitFeatureMapMem more than once."); + GELOGE(PARAM_INVALID, "call InitFeatureMapMem more than once"); return PARAM_INVALID; } is_feature_map_mem_has_inited_ = true; @@ -387,7 +387,7 @@ Status DavinciModel::InitFeatureMapAndP2PMem(void *dev_ptr, size_t mem_size) { GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Alloc feature map memory failed. size: %zu", data_size); return ACL_ERROR_GE_MEMORY_ALLOCATION; } - GEEVENT("[IMAS]InitFeatureMapAndP2PMem graph_%u MallocMemory type[F] memaddr[%p] mem_size[%zu].", + GEEVENT("[IMAS]InitFeatureMapAndP2PMem graph_%u MallocMemory type[F] memaddr[%p] mem_size[%zu]", runtime_param_.graph_id, mem_base_, data_size); if (!is_inner_weight_base_) { @@ -408,7 +408,7 @@ Status DavinciModel::InitFeatureMapAndP2PMem(void *dev_ptr, size_t mem_size) { is_inner_p2p_mem_base_ = true; } - GE_CHK_STATUS_RET(InitVariableMem(), "Init variable memory failed"); + GE_CHK_STATUS_RET(InitVariableMem(), "Init variable memory failed."); runtime_param_.mem_base = mem_base_; runtime_param_.weight_base = weights_mem_base_; runtime_param_.memory_infos[RT_MEMORY_P2P_DDR].memory_base = p2p_mem_base_; @@ -480,7 +480,7 @@ void DavinciModel::CheckHasHcomOp(const ComputeGraphPtr &compute_graph) { for (const auto &node : compute_graph->GetAllNodes()) { OpDescPtr op_desc = node->GetOpDesc(); - GE_IF_BOOL_EXEC(op_desc == nullptr, GELOGW("Node OpDesc is nullptr"); continue); + GE_IF_BOOL_EXEC(op_desc == nullptr, GELOGW("Node OpDesc is nullptr."); continue); if (hcom_opp_types.count(op_desc->GetType()) > 0) { uint32_t stream_id = static_cast(op_desc->GetStreamId()); hcom_streams_.emplace(stream_id); @@ -527,25 +527,25 @@ Status DavinciModel::DoTaskSink() { } GE_CHK_RT_RET(rtGetAicpuDeploy(&deploy_type_)); - GELOGI("do task_sink. AiCpu deploy type is: %x", deploy_type_); + GELOGI("do task_sink. AiCpu deploy type is: %x.", deploy_type_); - GE_CHK_STATUS_RET(BindModelStream(), "Bind model stream failed."); + GE_CHK_STATUS_RET(BindModelStream(), "Bind model stream failed"); if (known_node_) { - GE_CHK_STATUS_RET(MallocKnownArgs(), "Mallloc known node args failed."); + GE_CHK_STATUS_RET(MallocKnownArgs(), "Mallloc known node args failed"); } - GE_CHK_STATUS_RET(InitTaskInfo(*model_task_def.get()), "InitTaskInfo failed."); + GE_CHK_STATUS_RET(InitTaskInfo(*model_task_def.get()), "InitTaskInfo failed"); - GE_CHK_STATUS_RET(ModelManager::GetInstance()->LaunchCustAicpuSo(), "Launch cust aicpu so failed."); + GE_CHK_STATUS_RET(ModelManager::GetInstance()->LaunchCustAicpuSo(), "Launch cust aicpu so failed"); - GE_CHK_STATUS_RET(ModelManager::GetInstance()->CheckAicpuOpList(ge_model_), "Check aicpu op type failed."); + GE_CHK_STATUS_RET(ModelManager::GetInstance()->CheckAicpuOpList(ge_model_), "Check aicpu op type failed"); - GE_CHK_STATUS_RET(InitEntryTask(), "InitEntryTask failed."); + GE_CHK_STATUS_RET(InitEntryTask(), "InitEntryTask failed"); - GE_CHK_STATUS_RET(InitL1DataDumperArgs(), "InitL1DataDumperArgs failed."); + GE_CHK_STATUS_RET(InitL1DataDumperArgs(), "InitL1DataDumperArgs failed"); - GE_CHK_STATUS_RET(DistributeTask(), "Distribute failed."); + GE_CHK_STATUS_RET(DistributeTask(), "Distribute failed"); GE_CHK_RT_RET(rtModelLoadComplete(rt_model_handle_)); @@ -558,7 +558,7 @@ Status DavinciModel::SetTSDevice() { int64_t value = 0; bool ret = ge::AttrUtils::GetInt(ge_model_, ATTR_MODEL_CORE_TYPE, value); uint32_t core_type = ret ? static_cast(value) : 0; - GELOGD("SetTSDevice: %u.", core_type); + GELOGD("SetTSDevice: %u", core_type); rtError_t rt_ret = rtSetTSDevice(core_type); if (rt_ret != RT_ERROR_NONE) { GELOGE(RT_FAILED, "SetTSDevice failed, ret: 0x%X", rt_ret); @@ -570,7 +570,7 @@ Status DavinciModel::SetTSDevice() { Status DavinciModel::OpDebugRegister() { bool is_op_debug = false; (void)ge::AttrUtils::GetBool(ge_model_, ATTR_OP_DEBUG_FLAG, is_op_debug); - GELOGD("The value of op debug in ge_model is %d.", is_op_debug); + GELOGD("The value of op debug in ge_model is %d", is_op_debug); if (is_op_debug) { debug_reg_mutex_.lock(); rtError_t rt_ret = rtMalloc(&op_debug_addr_, kOpDebugMemorySize, RT_MEMORY_DDR); diff --git a/ge/graph/manager/graph_manager.cc b/ge/graph/manager/graph_manager.cc index 7c214a0d..131765ed 100755 --- a/ge/graph/manager/graph_manager.cc +++ b/ge/graph/manager/graph_manager.cc @@ -1524,7 +1524,7 @@ Status GraphManager::ParseOptions(const std::map &opti Status GraphManager::ParseTrainGraphFlag(bool &options, bool &option) { std::shared_ptr ge_instance_ptr = ge::GELib::GetInstance(); if (ge_instance_ptr == nullptr) { - GELOGW("[Initialize] set train_graph_flag to 0 when GE is not initialized or finalized."); + GELOGW("[Initialize] set train_graph_flag to 0 when GE is not initialized or finalized"); option = false; } else if (!ge_instance_ptr->isTrainMode()) { option = false; diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 1df848d5..295e03f4 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -752,6 +752,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/build/graph_builder_unittest.cc" "graph/preprocess/graph_preprocess_unittest.cc" "graph/manager/hcom_util_unittest.cc" "graph/manager/graph_caching_allocator_unittest.cc" diff --git a/tests/ut/ge/graph/build/graph_builder_unittest.cc b/tests/ut/ge/graph/build/graph_builder_unittest.cc new file mode 100644 index 00000000..f44c23a6 --- /dev/null +++ b/tests/ut/ge/graph/build/graph_builder_unittest.cc @@ -0,0 +1,108 @@ +/** + * 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 + +#define protected public +#define private public +#include "graph/manager/graph_manager_utils.h" +#undef protected +#undef private + +#include "graph/build/logical_stream_allocator.h" + +#include "common/types.h" +#include "common/util.h" + +#include "graph/compute_graph.h" +#include "graph/utils/attr_utils.h" +#include "graph/utils/graph_utils.h" + +using namespace std; + + +class UtestGraphBuilder : public testing::Test { + protected: + void SetUp() {} + + void TearDown() {} + + void MakeGraph(ge::ComputeGraphPtr &graph) { + ge::OpDescPtr op_def_a = CreateOpWithWsSize("A", 6000); + op_def_a->SetStreamId(0); + ge::OpDescPtr op_def_b = CreateOpWithWsSize("B", 120000); + op_def_b->SetStreamId(0); + ge::OpDescPtr op_def_c = CreateOpWithWsSize("C", 16000); + op_def_c->SetStreamId(1); + ge::OpDescPtr op_def_d = CreateOpWithWsSize("D", 24000); + op_def_d->SetStreamId(2); + ge::OpDescPtr op_def_e = CreateOpWithWsSize("E", 24000); + op_def_e->SetStreamId(3); + ge::OpDescPtr op_def_f = CreateOpWithWsSize("F", 30000); + op_def_f->SetStreamId(2); + ge::OpDescPtr op_def_g = CreateOpWithWsSize("G", 32000); + op_def_g->SetStreamId(3); + ge::OpDescPtr op_def_h = CreateOpWithWsSize("H", 48000); + op_def_h->SetStreamId(2); + ge::OpDescPtr op_def_i = CreateOpWithWsSize("I", 60000); + op_def_i->SetStreamId(2); + ge::OpDescPtr op_def_j = CreateOpWithWsSize("J", 256000, NETOUTPUT); + op_def_j->SetStreamId(3); + + // add node + ge::NodePtr node_a = graph->AddNode(op_def_a); + ge::NodePtr node_b = graph->AddNode(op_def_b); + ge::NodePtr node_c = graph->AddNode(op_def_c); + ge::NodePtr node_d = graph->AddNode(op_def_d); + ge::NodePtr node_e = graph->AddNode(op_def_e); + ge::NodePtr node_f = graph->AddNode(op_def_f); + ge::NodePtr node_g = graph->AddNode(op_def_g); + ge::NodePtr node_h = graph->AddNode(op_def_h); + ge::NodePtr node_i = graph->AddNode(op_def_i); + ge::NodePtr node_j = graph->AddNode(op_def_j); + + // add edge + ge::GraphUtils::AddEdge(node_a->GetOutDataAnchor(0), node_b->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(node_a->GetOutDataAnchor(0), node_c->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(node_b->GetOutDataAnchor(0), node_d->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(node_b->GetOutDataAnchor(0), node_e->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(node_c->GetOutDataAnchor(0), node_g->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(node_d->GetOutDataAnchor(0), node_f->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(node_e->GetOutDataAnchor(0), node_g->GetInDataAnchor(1)); + ge::GraphUtils::AddEdge(node_f->GetOutDataAnchor(0), node_h->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(node_g->GetOutDataAnchor(0), node_j->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(node_h->GetOutDataAnchor(0), node_i->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(node_i->GetOutDataAnchor(0), node_j->GetInDataAnchor(1)); + + GetContext().out_nodes_map["H"] = {0}; + GetContext().out_nodes_map["I"] = {0}; + GetContext().out_nodes_map["J"] = {0}; + graph->TopologicalSorting(); + } +}; + + +TEST_F(UtestGraphBuilder, BuildForKnownShapeGraph_test) { + ge::ComputeGraphPtr graph = make_shared(""); + MakeGraph(graph); + + GraphBuilder builder; + GeModelPtr ge_model_ptr = nullptr; + builder.BuildForKnownShapeGraph(graph, ge_model_ptr, 0); + } +