From 58a3e06c173d8d3d895c6dfe0df0b6cb8e900151 Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Fri, 5 Mar 2021 16:13:26 +0800 Subject: [PATCH 1/9] modified: ge/graph/build/graph_builder.cc modified: ge/graph/load/model_manager/model_manager.cc modified: ge/host_kernels/identity_kernel.cc modified: ge/hybrid/model/hybrid_model.h modified: ge/hybrid/model/hybrid_model_builder.cc modified: ge/hybrid/node_executor/task_context.cc --- ge/graph/build/graph_builder.cc | 4 + ge/graph/load/model_manager/model_manager.cc | 4 +- ge/host_kernels/identity_kernel.cc | 1 + ge/hybrid/model/hybrid_model.h | 1 + ge/hybrid/model/hybrid_model_builder.cc | 115 +++++++++++++-------------- ge/hybrid/node_executor/task_context.cc | 2 +- 6 files changed, 63 insertions(+), 64 deletions(-) diff --git a/ge/graph/build/graph_builder.cc b/ge/graph/build/graph_builder.cc index 2731e076..57f0a126 100644 --- a/ge/graph/build/graph_builder.cc +++ b/ge/graph/build/graph_builder.cc @@ -394,6 +394,10 @@ static Status InsertMemcpyNode(const ComputeGraphPtr &graph, const OutDataAnchor } static Status GenerateTaskForConstant(const std::shared_ptr &graph) { + if (graph->GetGraphUnknownFlag()) { + GELOGI("Graph %s is unknown graph, ignore gen_task for constant.", graph->GetName().c_str()); + return SUCCESS; + } for (auto &node : graph->GetDirectNode()) { // CONSTANT not generate task, so insert IDENTITY between CONSTANT and NETOUTPUT auto op_desc = node->GetOpDesc(); diff --git a/ge/graph/load/model_manager/model_manager.cc b/ge/graph/load/model_manager/model_manager.cc index cfee9e6d..6a256ed0 100755 --- a/ge/graph/load/model_manager/model_manager.cc +++ b/ge/graph/load/model_manager/model_manager.cc @@ -297,10 +297,8 @@ Status ModelManager::LoadModelOnline(uint32_t &model_id, const shared_ptrCheckIsUnknownShape(is_shape_unknown), "CheckIsUnknownShape failed, model id:%u", - model_id); + bool is_shape_unknown = ge_root_model->GetRootGraph()->GetGraphUnknownFlag(); if (is_shape_unknown || GetContext().GetHostExecFlag()) { return DoLoadHybridModelOnline(model_id, model_name, ge_root_model, listener); } diff --git a/ge/host_kernels/identity_kernel.cc b/ge/host_kernels/identity_kernel.cc index 702f5c93..ef1446a8 100644 --- a/ge/host_kernels/identity_kernel.cc +++ b/ge/host_kernels/identity_kernel.cc @@ -61,4 +61,5 @@ Status IdentityKernel::Compute(const ge::OpDescPtr op_desc, const std::vector weight_buffer_; + std::map> weight_buffer_map_; RuntimeParam root_runtime_param_; string om_name_; }; diff --git a/ge/hybrid/model/hybrid_model_builder.cc b/ge/hybrid/model/hybrid_model_builder.cc index 48558e83..79ff75e8 100755 --- a/ge/hybrid/model/hybrid_model_builder.cc +++ b/ge/hybrid/model/hybrid_model_builder.cc @@ -996,70 +996,65 @@ Status HybridModelBuilder::InitVariableTensors() { Status HybridModelBuilder::InitWeights() { // For constant in root graph - const auto &root_graph = ge_root_model_->GetRootGraph(); - const auto &subgraph_models = ge_root_model_->GetSubgraphInstanceNameToModel(); - auto iter = subgraph_models.find(root_graph->GetName()); - if (iter == subgraph_models.end()) { - GELOGD("Root graph model not found"); - return SUCCESS; - } + for (const auto &subgraph_model : ge_root_model_->GetSubgraphInstanceNameToModel()) { + const auto &weight_buffer = subgraph_model.second->GetWeight(); + if (weight_buffer.GetSize() == 0) { + GELOGD("weight is empty"); + return SUCCESS; + } - auto &root_model = iter->second; - const auto &weight_buffer = root_model->GetWeight(); - if (weight_buffer.GetSize() == 0) { - GELOGD("weight is empty"); - return SUCCESS; - } + auto allocator = NpuMemoryAllocator::GetAllocator(); + GE_CHECK_NOTNULL(allocator); + auto sub_weight_buffer = TensorBuffer::Create(allocator, weight_buffer.size()); + GE_CHECK_NOTNULL(sub_weight_buffer); + auto weight_base = reinterpret_cast(sub_weight_buffer->GetData()); + GE_CHK_RT_RET(rtMemcpy(weight_base, + sub_weight_buffer->GetSize(), + weight_buffer.GetData(), + weight_buffer.GetSize(), + RT_MEMCPY_HOST_TO_DEVICE)); + + GELOGI("Init weight mem successfully, weight base %p, weight size = %zu", + weight_base, + sub_weight_buffer->GetSize()); + auto root_graph = GraphUtils::GetComputeGraph(subgraph_model.second->GetGraph()); + hybrid_model_.weight_buffer_map_.emplace(root_graph->GetName(),std::move(sub_weight_buffer)); + for (auto &node : root_graph->GetDirectNode()) { + if (node->GetType() != CONSTANT) { + continue; + } - auto allocator = NpuMemoryAllocator::GetAllocator(); - GE_CHECK_NOTNULL(allocator); - hybrid_model_.weight_buffer_ = TensorBuffer::Create(allocator, weight_buffer.size()); - GE_CHECK_NOTNULL(hybrid_model_.weight_buffer_); - auto weight_base = reinterpret_cast(hybrid_model_.weight_buffer_->GetData()); - GE_CHK_RT_RET(rtMemcpy(weight_base, - hybrid_model_.weight_buffer_->GetSize(), - weight_buffer.GetData(), - weight_buffer.GetSize(), - RT_MEMCPY_HOST_TO_DEVICE)); - - GELOGI("Init weight mem successfully, weight base %p, weight size = %zu", - weight_base, - hybrid_model_.weight_buffer_->GetSize()); - for (auto &node : root_graph->GetDirectNode()) { - if (node->GetType() != CONSTANT) { - continue; - } + auto op_desc = node->GetOpDesc(); + auto v_weights = ModelUtils::GetWeights(op_desc); + if (v_weights.empty()) { + GELOGE(INTERNAL_ERROR, "[%s] Constant has no value", node->GetName().c_str()); + return INTERNAL_ERROR; + } + auto *ge_tensor = const_cast(v_weights[0].get()); + GE_CHECK_NOTNULL(ge_tensor); + const GeTensorDesc &tensor_desc = ge_tensor->GetTensorDesc(); + int64_t tensor_size = 0; + GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetSize(*op_desc->MutableOutputDesc(0), tensor_size), + "[%s] Failed to get tensor size", + node->GetName().c_str()); + int64_t data_offset = 0; + GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetDataOffset(tensor_desc, data_offset), + "[%s] Failed to get data offset", + node->GetName().c_str()); + GELOGD("[%s] Start to init Constant node [%s], size = %ld, offset = %ld", + GetGraphName(), + node->GetName().c_str(), + tensor_size, + data_offset); - auto op_desc = node->GetOpDesc(); - auto v_weights = ModelUtils::GetWeights(op_desc); - if (v_weights.empty()) { - GELOGE(INTERNAL_ERROR, "[%s] Constant has no value", node->GetName().c_str()); - return INTERNAL_ERROR; + auto tensor_buffer = TensorBuffer::Create(weight_base + data_offset, tensor_size); + GE_CHECK_NOTNULL(tensor_buffer); + std::unique_ptr constant_tensor(new (std::nothrow)TensorValue(std::move(tensor_buffer))); + GE_CHECK_NOTNULL(constant_tensor); + constant_tensor->SetName("Constant_" + op_desc->GetName()); + hybrid_model_.constant_tensors_.emplace(node, std::move(constant_tensor)); + GELOGD("[%s] Constant node [%s] added, size = %ld", GetGraphName(), node->GetName().c_str(), tensor_size); } - auto *ge_tensor = const_cast(v_weights[0].get()); - GE_CHECK_NOTNULL(ge_tensor); - const GeTensorDesc &tensor_desc = ge_tensor->GetTensorDesc(); - int64_t tensor_size = 0; - GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetSize(*op_desc->MutableOutputDesc(0), tensor_size), - "[%s] Failed to get tensor size", - node->GetName().c_str()); - int64_t data_offset = 0; - GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetDataOffset(tensor_desc, data_offset), - "[%s] Failed to get data offset", - node->GetName().c_str()); - GELOGD("[%s] Start to init Constant node [%s], size = %ld, offset = %ld", - GetGraphName(), - node->GetName().c_str(), - tensor_size, - data_offset); - - auto tensor_buffer = TensorBuffer::Create(weight_base + data_offset, tensor_size); - GE_CHECK_NOTNULL(tensor_buffer); - std::unique_ptr constant_tensor(new (std::nothrow)TensorValue(std::move(tensor_buffer))); - GE_CHECK_NOTNULL(constant_tensor); - constant_tensor->SetName("Constant_" + op_desc->GetName()); - hybrid_model_.constant_tensors_.emplace(node, std::move(constant_tensor)); - GELOGD("[%s] Constant node [%s] added, size = %ld", GetGraphName(), node->GetName().c_str(), tensor_size); } return SUCCESS; } diff --git a/ge/hybrid/node_executor/task_context.cc b/ge/hybrid/node_executor/task_context.cc index 08cce30c..ac8bba16 100644 --- a/ge/hybrid/node_executor/task_context.cc +++ b/ge/hybrid/node_executor/task_context.cc @@ -236,7 +236,7 @@ Status TaskContext::AllocateOutput(int index, ref_node->GetName().c_str(), ref_node->GetType().c_str()); - TensorValue *ref_tensor = execution_context_->model->GetVariable(ref_node->GetName()); + TensorValue *ref_tensor = execution_context_->model->GetTensor(ref_node); GE_CHECK_NOTNULL(ref_tensor); outputs_start_[index] = *ref_tensor; } else { From 5fe85f3f85b19ef4741a466c7a0b7569689e6e07 Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Fri, 5 Mar 2021 16:19:43 +0800 Subject: [PATCH 2/9] modified: ge/graph/partition/dynamic_shape_partition.cc --- ge/graph/partition/dynamic_shape_partition.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ge/graph/partition/dynamic_shape_partition.cc b/ge/graph/partition/dynamic_shape_partition.cc index 2a60765f..623d7604 100755 --- a/ge/graph/partition/dynamic_shape_partition.cc +++ b/ge/graph/partition/dynamic_shape_partition.cc @@ -57,6 +57,17 @@ static bool IsInExperimentalMode(const ComputeGraphPtr &root_graph) { if (is_singleop) { return false; } + // if input_node in root_graph is dynamic shape, skip dynamic partition + // whole graph as one unknown graph + if (node->GetType() == DATA && node->GetOwnerComputeGraph()->GetParentNode() == nullptr) { + auto op_desc = node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + auto data_output_desc = op_desc->GetOutputDescPtr(0); + GE_CHECK_NOTNULL(data_output_desc); + if (data_output_desc->GetShape().IsUnknownShape()) { + return false; + } + } for (const auto &input_desc : node->GetOpDesc()->GetAllInputsDesc()) { auto type = input_desc.GetDataType(); From 3d0a83a45585d1438009408b72ad3a7ddcfb8119 Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Tue, 9 Mar 2021 17:17:58 +0800 Subject: [PATCH 3/9] modified: tests/ut/ge/hybrid/ge_hybrid_unittest.cc --- tests/ut/ge/hybrid/ge_hybrid_unittest.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc index 0b6ca271..6789f0b1 100644 --- a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc +++ b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc @@ -190,4 +190,34 @@ TEST_F(UtestGeHybrid, index_taskdefs_success) { HybridModelBuilder hybrid_model_builder(hybrid_model); ASSERT_EQ(hybrid_model_builder.IndexTaskDefs(graph, ge_model), SUCCESS); +} + +TEST_F(UtestGeHybrid, init_weight_success) { + // make graph with sub_graph + ComputeGraphPtr graph = std::make_shared("root_graph"); + OpDescPtr op_desc = CreateOpDesc("if", IF); + /*std::vector kernelBin; + TBEKernelPtr tbe_kernel = std::make_shared("name/Add", std::move(kernelBin));*/ + //op_desc->SetExtAttr(ge::OP_EXTATTR_NAME_TBE_KERNEL, tbe_kernel); + //std::string kernel_name("kernel/Add"); + //AttrUtils::SetStr(op_desc, op_desc->GetName() + "_kernelname", kernel_name); + NodePtr node = graph->AddNode(op_desc); + // make sub graph + ComputeGraphPtr sub_graph = std::make_shared("if_sub_graph"); + OpDescPtr const_op_desc = CreateOpDesc("const", CONSTANT); + vector dims_vec_0 = {2, 1, 4, 1, 2}; + vector data_vec_0 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + GeTensorDesc tensor_desc_0(GeShape(dims_vec_0), FORMAT_NCHW, DT_INT32); + (void)TensorUtils::SetRealDimCnt(tensor_desc_0, dims_vec_0.size()); + ConstGeTensorPtr constTensor_0 = + std::make_shared(tensor_desc_0, (uint8_t *)&data_vec_0[0], data_vec_0.size() * sizeof(int32_t)); + AttrUtils::SetTensor(const_op_desc, ge::ATTR_NAME_WEIGHTS, constTensor_0); + const_op_desc->AddOutputDesc(constTensor_0); + NodePtr const_node = sub_graph->AddNode(const_op_desc); + graph->AddSubgraph("sub", sub_graph); + + GeRootModelPtr ge_root_model = make_shared(graph); + HybridModel hybrid_model(ge_root_model); + HybridModelBuilder hybrid_model_builder(hybrid_model); + auto ret = hybrid_model_builder.InitWeights(); } \ No newline at end of file From 612463e08970dc15eddaf18247a62a17746313c2 Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Tue, 9 Mar 2021 20:18:48 +0800 Subject: [PATCH 4/9] modified: tests/ut/ge/hybrid/ge_hybrid_unittest.cc --- tests/ut/ge/hybrid/ge_hybrid_unittest.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc index 6789f0b1..659d11c6 100644 --- a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc +++ b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc @@ -34,6 +34,7 @@ #include "hybrid/node_executor/aicore/aicore_task_builder.h" #include "graph/load/model_manager/tbe_handle_store.h" #include "graph/types.h" +#include "graph/utils/tensor_utils.h" #undef private #undef protected @@ -212,7 +213,7 @@ TEST_F(UtestGeHybrid, init_weight_success) { ConstGeTensorPtr constTensor_0 = std::make_shared(tensor_desc_0, (uint8_t *)&data_vec_0[0], data_vec_0.size() * sizeof(int32_t)); AttrUtils::SetTensor(const_op_desc, ge::ATTR_NAME_WEIGHTS, constTensor_0); - const_op_desc->AddOutputDesc(constTensor_0); + const_op_desc->AddOutputDesc(tensor_desc_0); NodePtr const_node = sub_graph->AddNode(const_op_desc); graph->AddSubgraph("sub", sub_graph); From ce83b1569db73c2d36a3e6c3b0faa8bdf057594a Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Thu, 11 Mar 2021 11:39:08 +0800 Subject: [PATCH 5/9] modified: tests/ut/ge/hybrid/ge_hybrid_unittest.cc --- tests/ut/ge/hybrid/ge_hybrid_unittest.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc index 659d11c6..c6f9f4f1 100644 --- a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc +++ b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc @@ -218,6 +218,8 @@ TEST_F(UtestGeHybrid, init_weight_success) { graph->AddSubgraph("sub", sub_graph); GeRootModelPtr ge_root_model = make_shared(graph); + GeModelPtr ge_sub_model = make_shared(sub_graph); + ge_root_model->SetSubgraphInstanceNameToModel("sub",ge_sub_model); HybridModel hybrid_model(ge_root_model); HybridModelBuilder hybrid_model_builder(hybrid_model); auto ret = hybrid_model_builder.InitWeights(); From bab9bca59689195ba1bfc7c25aceb9bee6cd795a Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Thu, 11 Mar 2021 11:42:02 +0800 Subject: [PATCH 6/9] modified: ge/graph/partition/dynamic_shape_partition.cc --- ge/graph/partition/dynamic_shape_partition.cc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/ge/graph/partition/dynamic_shape_partition.cc b/ge/graph/partition/dynamic_shape_partition.cc index 623d7604..2a60765f 100755 --- a/ge/graph/partition/dynamic_shape_partition.cc +++ b/ge/graph/partition/dynamic_shape_partition.cc @@ -57,17 +57,6 @@ static bool IsInExperimentalMode(const ComputeGraphPtr &root_graph) { if (is_singleop) { return false; } - // if input_node in root_graph is dynamic shape, skip dynamic partition - // whole graph as one unknown graph - if (node->GetType() == DATA && node->GetOwnerComputeGraph()->GetParentNode() == nullptr) { - auto op_desc = node->GetOpDesc(); - GE_CHECK_NOTNULL(op_desc); - auto data_output_desc = op_desc->GetOutputDescPtr(0); - GE_CHECK_NOTNULL(data_output_desc); - if (data_output_desc->GetShape().IsUnknownShape()) { - return false; - } - } for (const auto &input_desc : node->GetOpDesc()->GetAllInputsDesc()) { auto type = input_desc.GetDataType(); From 801a1e0fcaa051d6d85c99110918906fe44b2607 Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Fri, 12 Mar 2021 10:45:47 +0800 Subject: [PATCH 7/9] modified: gather_v2_kernel.cc modified: strided_slice_kernel.cc modified: ../../tests/ut/ge/hybrid/ge_hybrid_unittest.cc --- ge/host_kernels/gather_v2_kernel.cc | 40 ++++++++++++++++----------------- ge/host_kernels/strided_slice_kernel.cc | 40 ++++++++++++++++----------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/ge/host_kernels/gather_v2_kernel.cc b/ge/host_kernels/gather_v2_kernel.cc index ee73626b..610d2c3b 100644 --- a/ge/host_kernels/gather_v2_kernel.cc +++ b/ge/host_kernels/gather_v2_kernel.cc @@ -208,7 +208,7 @@ Status GatherV2Kernel::GenData(const int64_t data_num, ConstGeTensorPtr tensor_x ret = ProcessAxis3(tensor_x, output); break; default: - GELOGI("Only support 4 dims and below but input axis is %ld", axis); + GELOGI("Only support 4 dims and below but input axis is %ld.", axis); return NOT_CHANGED; } return ret; @@ -267,7 +267,7 @@ Status GatherV2Kernel::Process(int64_t axis, DataType data_type, ConstGeTensorPt ret = GenData(data_num, input_tensor_ptr, axis, output_ptr); break; default: - GELOGI("GatherV2Kernel does not support this Data type:%s", TypeUtils::DataTypeToSerialString(data_type).c_str()); + GELOGI("GatherV2Kernel does not support this Data type:%s.", TypeUtils::DataTypeToSerialString(data_type).c_str()); return NOT_CHANGED; } return ret; @@ -278,7 +278,7 @@ Status GatherV2Kernel::SaveIndicesByDataType(ConstGeTensorPtr indices_tensor_ptr auto indices_ptr = const_cast(reinterpret_cast(indices_tensor_ptr->GetData().data())); for (int64_t i = 0; i < indices_shape.GetShapeSize(); i++) { if (*(indices_ptr + i) < 0 || *(indices_ptr + i) >= x_shape.GetDim(axis)) { - GELOGW("indices %ld value is not in range [0, %ld)", i, x_shape.GetDim(axis)); + GELOGW("indices %ld value is not in range [0, %ld).", i, x_shape.GetDim(axis)); return NOT_CHANGED; } indicates_.push_back(*(indices_ptr + i)); @@ -288,7 +288,7 @@ Status GatherV2Kernel::SaveIndicesByDataType(ConstGeTensorPtr indices_tensor_ptr auto indices_ptr = const_cast(reinterpret_cast(indices_tensor_ptr->GetData().data())); for (int64_t i = 0; i < indices_shape.GetShapeSize(); i++) { if (*(indices_ptr + i) < 0 || *(indices_ptr + i) >= x_shape.GetDim(axis)) { - GELOGW("indices %ld value is not in range [0, %ld)", i, x_shape.GetDim(axis)); + GELOGW("indices %ld value is not in range [0, %ld).", i, x_shape.GetDim(axis)); return NOT_CHANGED; } indicates_.push_back(*(indices_ptr + i)); @@ -330,13 +330,13 @@ Status GatherV2Kernel::Check(const OpDescPtr &op_desc_ptr, const vectorGetTensorDesc().GetShape(); // axis must be scalar if (axis_shape.GetDimNum() != 0) { - GELOGW("axis must be scalar but its shape is %zu", axis_shape.GetDimNum()); + GELOGW("axis must be scalar but its shape is %zu.", axis_shape.GetDimNum()); return NOT_CHANGED; } auto axis_data_type = tensor2->GetTensorDesc().GetDataType(); bool is_valid_axis_data_type = axis_data_type == DT_INT32 || axis_data_type == DT_INT64; if (!is_valid_axis_data_type) { - GELOGW("axis datatype must be DT_INT32 or DT_INT64"); + GELOGW("axis datatype must be DT_INT32 or DT_INT64."); return NOT_CHANGED; } @@ -344,42 +344,42 @@ Status GatherV2Kernel::Check(const OpDescPtr &op_desc_ptr, const vectorGetTensorDesc().GetDataType(); bool is_valid_indices_data_type = indices_data_type == DT_INT32 || indices_data_type == DT_INT64; if (!is_valid_indices_data_type) { - GELOGW("indices datatype must be DT_INT32 or DT_INT64"); + GELOGW("indices datatype must be DT_INT32 or DT_INT64."); return NOT_CHANGED; } if (indices_shape.GetDimNum() > kMaxIndicatesDims) { - GELOGW("indices input only support 0 or 1 dims"); + GELOGW("indices input only support 0 or 1 dims."); return NOT_CHANGED; } return SUCCESS; } void GatherV2Kernel::DebugPrint(int64_t axis, const GeShape &x_shape, const GeShape &indices_shape, const std::vector &y_shape) { - GELOGD("GatherV2Kernel axis:%ld x_shape:%zu indices_shape:%zu y_shape:%zu", axis, x_shape.GetDimNum(), + GELOGD("GatherV2Kernel axis:%ld x_shape:%zu indices_shape:%zu y_shape:%zu.", axis, x_shape.GetDimNum(), indices_shape.GetDimNum(), y_shape.size()); for (size_t i = 0; i < x_shape.GetDimNum(); i++) { - GELOGD("GatherV2Kernel x_shape[%zu]: %ld", i, x_shape.GetDim(i)); + GELOGD("GatherV2Kernel x_shape[%zu]: %ld.", i, x_shape.GetDim(i)); } for (size_t i = 0; i < indices_shape.GetDimNum(); i++) { - GELOGD("GatherV2Kernel indices_shape[%zu]: %ld", i, indices_shape.GetDim(i)); + GELOGD("GatherV2Kernel indices_shape[%zu]: %ld.", i, indices_shape.GetDim(i)); } for (size_t i = 0; i < y_shape.size(); i++) { - GELOGD("GatherV2Kernel y_shape[%zu]: %ld", i, y_shape[i]); + GELOGD("GatherV2Kernel y_shape[%zu]: %ld.", i, y_shape[i]); } for (auto ele : indicates_) { - GELOGD("GatherV2Kernel indices:%ld", ele); + GELOGD("GatherV2Kernel indices:%ld.", ele); } } Status GatherV2Kernel::Compute(const OpDescPtr op_desc_ptr, const vector &input, vector &v_output) { - GELOGI("Enter GatherV2Kernel Process."); + GELOGI("Enter GatherV2Kernel Process"); Status ret = Check(op_desc_ptr, input, v_output); if (ret != SUCCESS) { - GELOGW("param check failed."); + GELOGW("param check failed"); return NOT_CHANGED; } - GELOGI("GatherV2Kernel[%s] start Process.", op_desc_ptr->GetName().c_str()); + GELOGI("GatherV2Kernel[%s] start Process", op_desc_ptr->GetName().c_str()); ConstGeTensorPtr tensor0 = input.at(kGatherV2InputIndexZero); ConstGeTensorPtr tensor1 = input.at(kGatherV2InputIndexOne); ConstGeTensorPtr tensor2 = input.at(kGatherV2InputIndexTwo); @@ -394,7 +394,7 @@ Status GatherV2Kernel::Compute(const OpDescPtr op_desc_ptr, const vector= 0 ? axis : axis + x_shape.GetDimNum(); // check axis value if (axis < 0 || (axis + 1) > static_cast(x_shape.GetDimNum())) { - GELOGW("axis is invalid"); + GELOGW("axis is invalid!"); return NOT_CHANGED; } auto indices_data_type = tensor1->GetTensorDesc().GetDataType(); @@ -407,7 +407,7 @@ Status GatherV2Kernel::Compute(const OpDescPtr op_desc_ptr, const vectorGetTensorDesc().GetDataType(); if (supported_type.find(x_data_type) == supported_type.end()) { - GELOGI("GatherV2Kernel does not support this Data type:%s", TypeUtils::DataTypeToSerialString(x_data_type).c_str()); + GELOGI("GatherV2Kernel does not support this Data type:%s.", TypeUtils::DataTypeToSerialString(x_data_type).c_str()); return NOT_CHANGED; } // calc output shape @@ -442,13 +442,13 @@ Status GatherV2Kernel::Compute(const OpDescPtr op_desc_ptr, const vector 1) { - GELOGW("Only one non-zero bit is allowed in ellipsis_mask."); + GELOGW("Only one non-zero bit is allowed in ellipsis_mask"); return false; } } @@ -84,14 +84,14 @@ void GetOriginStrideVec(const std::vector &input, vector &input, vector &v_output) { - GELOGD("StridedSliceKernel in."); + GELOGD("StridedSliceKernel in"); // 1.Check input and attrs if (CheckAndGetAttr(attr) != SUCCESS) { - GELOGW("Check and get attrs failed.Ignore kernel."); + GELOGW("Check and get attrs failed.Ignore kernel"); return NOT_CHANGED; } if (CheckInputParam(input) != SUCCESS) { - GELOGW("Check input params failed.Ignore kernel."); + GELOGW("Check input params failed.Ignore kernel"); return NOT_CHANGED; } // 2.Init param with mask attrs. @@ -100,7 +100,7 @@ Status StridedSliceKernel::Compute(const ge::OpDescPtr attr, const std::vector output_dims; std::vector stride_vec; if (InitParamWithAttrs(input, input_dims, begin_vec, output_dims, stride_vec) != SUCCESS) { - GELOGW("Init param with mask attrs failed.Ignore kernel."); + GELOGW("Init param with mask attrs failed.Ignore kernel"); return NOT_CHANGED; } @@ -114,13 +114,13 @@ Status StridedSliceKernel::Compute(const ge::OpDescPtr attr, const std::vectorGetOutputDesc(0); GeTensorPtr output_ptr = MakeShared(output_tensor_desc); if (output_ptr == nullptr) { - GELOGE(MEMALLOC_FAILED, "MakeShared GeTensor failed, node name %s.", attr->GetName().c_str()); + GELOGE(MEMALLOC_FAILED, "MakeShared GeTensor failed, node name %s", attr->GetName().c_str()); return NOT_CHANGED; } auto ret = OpUtils::SetOutputSliceData(data, static_cast(data_size), data_type, input_dims, begin_vec, output_dims, output_ptr.get(), stride_vec); if (ret != SUCCESS) { - GELOGE(INTERNAL_ERROR, "SetOutputSliceData failed."); + GELOGE(INTERNAL_ERROR, "SetOutputSliceData failed"); return NOT_CHANGED; } @@ -133,18 +133,18 @@ Status StridedSliceKernel::Compute(const ge::OpDescPtr attr, const std::vector &input) { if (input.size() != kStridedSliceInputSize) { - GELOGE(PARAM_INVALID, "The number of input for strided slice must be %zu.", kStridedSliceInputSize); + GELOGE(PARAM_INVALID, "The number of input for strided slice must be %zu", kStridedSliceInputSize); return PARAM_INVALID; } @@ -178,11 +178,11 @@ Status StridedSliceKernel::CheckInputParam(const std::vector & auto stride_tensor_desc = begin_tensor->GetTensorDesc(); if (begin_tensor_desc.GetDataType() != end_tensor_desc.GetDataType() || end_tensor_desc.GetDataType() != stride_tensor_desc.GetDataType()) { - GELOGW("Data type of StridedSlice OP(begin,end,strides) must be same."); + GELOGW("Data type of StridedSlice OP(begin,end,strides) must be same"); return PARAM_INVALID; } if (kIndexNumberType.find(begin_tensor_desc.GetDataType()) == kIndexNumberType.end()) { - GELOGW("Data type of StridedSlice OP(begin,end,strides) must be int32 or int64."); + GELOGW("Data type of StridedSlice OP(begin,end,strides) must be int32 or int64"); return PARAM_INVALID; } @@ -190,7 +190,7 @@ Status StridedSliceKernel::CheckInputParam(const std::vector & auto x_data_type = weight0->GetTensorDesc().GetDataType(); auto x_data_size = GetSizeByDataType(x_data_type); if (x_data_size < 0) { - GELOGW("Data type of x input %s is not supported.", TypeUtils::DataTypeToSerialString(x_data_type).c_str()); + GELOGW("Data type of x input %s is not supported", TypeUtils::DataTypeToSerialString(x_data_type).c_str()); return PARAM_INVALID; } size_t weight0_size = weight0->GetData().size() / x_data_size; @@ -198,12 +198,12 @@ Status StridedSliceKernel::CheckInputParam(const std::vector & size_t end_data_size = end_tensor->GetData().size(); size_t stride_data_size = stride_tensor->GetData().size(); if ((weight0_size == 0) || (begin_data_size == 0) || (end_data_size == 0) || (stride_data_size == 0)) { - GELOGW("Data size of inputs is 0."); + GELOGW("Data size of inputs is 0"); return PARAM_INVALID; } // check dim size if (!((begin_data_size == end_data_size) && (end_data_size == stride_data_size))) { - GELOGW("The sizes of begin, end and stride is not supported."); + GELOGW("The sizes of begin, end and stride is not supported"); return PARAM_INVALID; } return SUCCESS; @@ -250,15 +250,15 @@ Status StridedSliceKernel::InitParamWithAttrs(const std::vector &x_dims) { auto begin_data_type_size = GetSizeByDataType(begin_tensor->GetTensorDesc().GetDataType()); if (begin_data_type_size == 0) { - GELOGW("Param begin_data_type_size should not be zero."); + GELOGW("Param begin_data_type_size should not be zero"); return; } size_t begin_vec_size = begin_tensor->GetData().size() / begin_data_type_size; From 56ff720fac6ed23db72d57c6a3634701ce923adc Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Fri, 12 Mar 2021 11:23:16 +0800 Subject: [PATCH 8/9] modified: ../../tests/ut/ge/hybrid/ge_hybrid_unittest.cc --- tests/ut/ge/hybrid/ge_hybrid_unittest.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc index c6f9f4f1..5e754810 100644 --- a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc +++ b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc @@ -15,8 +15,8 @@ */ #include +#include #include - #include "runtime/rt.h" #define protected public @@ -25,7 +25,6 @@ #include "hybrid/model/hybrid_model.h" #include "model/ge_model.h" #include "model/ge_root_model.h" - #include "hybrid/node_executor/aicore/aicore_op_task.h" #include "framework/common/taskdown_common.h" #include "framework/common/debug/log.h" @@ -33,6 +32,8 @@ #include "hybrid/executor/hybrid_execution_context.h" #include "hybrid/node_executor/aicore/aicore_task_builder.h" #include "graph/load/model_manager/tbe_handle_store.h" +#include "graph/manager/graph_mem_allocator.h" +#include "hybrid/common/npu_memory_allocator.h" #include "graph/types.h" #include "graph/utils/tensor_utils.h" @@ -44,6 +45,7 @@ using namespace testing; using namespace ge; using namespace hybrid; + class UtestGeHybrid : public testing::Test { protected: void SetUp() {} @@ -194,14 +196,10 @@ TEST_F(UtestGeHybrid, index_taskdefs_success) { } TEST_F(UtestGeHybrid, init_weight_success) { + NpuMemoryAllocator::allocators_.emplace(make_pair(0, nullptr)); // make graph with sub_graph ComputeGraphPtr graph = std::make_shared("root_graph"); OpDescPtr op_desc = CreateOpDesc("if", IF); - /*std::vector kernelBin; - TBEKernelPtr tbe_kernel = std::make_shared("name/Add", std::move(kernelBin));*/ - //op_desc->SetExtAttr(ge::OP_EXTATTR_NAME_TBE_KERNEL, tbe_kernel); - //std::string kernel_name("kernel/Add"); - //AttrUtils::SetStr(op_desc, op_desc->GetName() + "_kernelname", kernel_name); NodePtr node = graph->AddNode(op_desc); // make sub graph ComputeGraphPtr sub_graph = std::make_shared("if_sub_graph"); @@ -218,9 +216,16 @@ TEST_F(UtestGeHybrid, init_weight_success) { graph->AddSubgraph("sub", sub_graph); GeRootModelPtr ge_root_model = make_shared(graph); - GeModelPtr ge_sub_model = make_shared(sub_graph); + GeModelPtr ge_sub_model = make_shared(); + //Buffer weight_buffer = Buffer(128,0); + //ge_sub_model->SetWeight(weight_buffer); ge_root_model->SetSubgraphInstanceNameToModel("sub",ge_sub_model); HybridModel hybrid_model(ge_root_model); HybridModelBuilder hybrid_model_builder(hybrid_model); auto ret = hybrid_model_builder.InitWeights(); + ASSERT_EQ(ret,SUCCESS); + Buffer weight_buffer = Buffer(128,0); + ge_sub_model->SetWeight(weight_buffer); + ret = hybrid_model_builder.InitWeights(); + ASSERT_EQ(ret,PARAM_INVALID); } \ No newline at end of file From 5acba132615d8ece4031acd62ca47c083aba2703 Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Fri, 12 Mar 2021 14:16:06 +0800 Subject: [PATCH 9/9] modified: concat_offset_kernel.cc modified: gather_v2_kernel.cc modified: strided_slice_kernel.cc --- ge/host_kernels/concat_offset_kernel.cc | 12 ++++++------ ge/host_kernels/gather_v2_kernel.cc | 12 ++++++------ ge/host_kernels/strided_slice_kernel.cc | 22 +++++++++++----------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ge/host_kernels/concat_offset_kernel.cc b/ge/host_kernels/concat_offset_kernel.cc index ff597873..b6940eb4 100644 --- a/ge/host_kernels/concat_offset_kernel.cc +++ b/ge/host_kernels/concat_offset_kernel.cc @@ -33,7 +33,7 @@ const int kNumOne = 1; } // namespace Status ConcatOffsetKernel::Compute(const OpDescPtr op_desc_ptr, const vector &input, vector &v_output) { - GELOGI("ConcatOffsetKernel in."); + GELOGD("ConcatOffsetKernel in"); if (op_desc_ptr == nullptr) { GELOGE(PARAM_INVALID, "input opdesc is nullptr."); return PARAM_INVALID; @@ -41,7 +41,7 @@ Status ConcatOffsetKernel::Compute(const OpDescPtr op_desc_ptr, const vector(reinterpret_cast(input_0->GetData().data()))); // validate inputs if ((static_cast(input.size()) != (N + kNumOne)) || (input.size() <= kConcatOffsetInputIndexOne)) { - GELOGW("The number of input for concat offset must be equal to %d, and must be more than one.", (N + kNumOne)); + GELOGW("The number of input for concat offset must be equal to %d, and must be more than one", (N + kNumOne)); return NOT_CHANGED; } @@ -61,7 +61,7 @@ Status ConcatOffsetKernel::Compute(const OpDescPtr op_desc_ptr, const vectorMutableTensorDesc().SetShape(output_shape); GE_IF_BOOL_EXEC(output_ptr->SetData(reinterpret_cast(buf.get()), static_cast(sizeof(DT_INT32) * output_size)) != GRAPH_SUCCESS, - GELOGW("set data failed"); + GELOGW("set data failed."); return NOT_CHANGED); v_output.push_back(output_ptr); // caculate offset @@ -99,7 +99,7 @@ Status ConcatOffsetKernel::Compute(const OpDescPtr op_desc_ptr, const vector(tensor_x, output); break; default: - GELOGI("Only support 4 dims and below but input axis is %ld.", axis); + GELOGI("Only support 4 dims and below but input axis is %ld", axis); return NOT_CHANGED; } return ret; @@ -267,7 +267,7 @@ Status GatherV2Kernel::Process(int64_t axis, DataType data_type, ConstGeTensorPt ret = GenData(data_num, input_tensor_ptr, axis, output_ptr); break; default: - GELOGI("GatherV2Kernel does not support this Data type:%s.", TypeUtils::DataTypeToSerialString(data_type).c_str()); + GELOGI("GatherV2Kernel does not support this Data type:%s", TypeUtils::DataTypeToSerialString(data_type).c_str()); return NOT_CHANGED; } return ret; @@ -330,13 +330,13 @@ Status GatherV2Kernel::Check(const OpDescPtr &op_desc_ptr, const vectorGetTensorDesc().GetShape(); // axis must be scalar if (axis_shape.GetDimNum() != 0) { - GELOGW("axis must be scalar but its shape is %zu.", axis_shape.GetDimNum()); + GELOGW("axis must be scalar but its shape is %zu", axis_shape.GetDimNum()); return NOT_CHANGED; } auto axis_data_type = tensor2->GetTensorDesc().GetDataType(); bool is_valid_axis_data_type = axis_data_type == DT_INT32 || axis_data_type == DT_INT64; if (!is_valid_axis_data_type) { - GELOGW("axis datatype must be DT_INT32 or DT_INT64."); + GELOGW("axis datatype must be DT_INT32 or DT_INT64"); return NOT_CHANGED; } @@ -442,13 +442,13 @@ Status GatherV2Kernel::Compute(const OpDescPtr op_desc_ptr, const vector 1) { - GELOGW("Only one non-zero bit is allowed in ellipsis_mask"); + GELOGW("Only one non-zero bit is allowed in ellipsis_mask."); return false; } } @@ -100,7 +100,7 @@ Status StridedSliceKernel::Compute(const ge::OpDescPtr attr, const std::vector output_dims; std::vector stride_vec; if (InitParamWithAttrs(input, input_dims, begin_vec, output_dims, stride_vec) != SUCCESS) { - GELOGW("Init param with mask attrs failed.Ignore kernel"); + GELOGW("Init param with mask attrs failed.Ignore kernel."); return NOT_CHANGED; } @@ -114,7 +114,7 @@ Status StridedSliceKernel::Compute(const ge::OpDescPtr attr, const std::vectorGetOutputDesc(0); GeTensorPtr output_ptr = MakeShared(output_tensor_desc); if (output_ptr == nullptr) { - GELOGE(MEMALLOC_FAILED, "MakeShared GeTensor failed, node name %s", attr->GetName().c_str()); + GELOGE(MEMALLOC_FAILED, "MakeShared GeTensor failed, node name %s.", attr->GetName().c_str()); return NOT_CHANGED; } auto ret = OpUtils::SetOutputSliceData(data, static_cast(data_size), data_type, input_dims, begin_vec, @@ -138,7 +138,7 @@ Status StridedSliceKernel::Compute(const ge::OpDescPtr attr, const std::vector &input) { if (input.size() != kStridedSliceInputSize) { - GELOGE(PARAM_INVALID, "The number of input for strided slice must be %zu", kStridedSliceInputSize); + GELOGE(PARAM_INVALID, "The number of input for strided slice must be %zu.", kStridedSliceInputSize); return PARAM_INVALID; } @@ -178,7 +178,7 @@ Status StridedSliceKernel::CheckInputParam(const std::vector & auto stride_tensor_desc = begin_tensor->GetTensorDesc(); if (begin_tensor_desc.GetDataType() != end_tensor_desc.GetDataType() || end_tensor_desc.GetDataType() != stride_tensor_desc.GetDataType()) { - GELOGW("Data type of StridedSlice OP(begin,end,strides) must be same"); + GELOGW("Data type of StridedSlice OP(begin,end,strides) must be same."); return PARAM_INVALID; } if (kIndexNumberType.find(begin_tensor_desc.GetDataType()) == kIndexNumberType.end()) { @@ -190,7 +190,7 @@ Status StridedSliceKernel::CheckInputParam(const std::vector & auto x_data_type = weight0->GetTensorDesc().GetDataType(); auto x_data_size = GetSizeByDataType(x_data_type); if (x_data_size < 0) { - GELOGW("Data type of x input %s is not supported", TypeUtils::DataTypeToSerialString(x_data_type).c_str()); + GELOGW("Data type of x input %s is not supported.", TypeUtils::DataTypeToSerialString(x_data_type).c_str()); return PARAM_INVALID; } size_t weight0_size = weight0->GetData().size() / x_data_size; @@ -198,12 +198,12 @@ Status StridedSliceKernel::CheckInputParam(const std::vector & size_t end_data_size = end_tensor->GetData().size(); size_t stride_data_size = stride_tensor->GetData().size(); if ((weight0_size == 0) || (begin_data_size == 0) || (end_data_size == 0) || (stride_data_size == 0)) { - GELOGW("Data size of inputs is 0"); + GELOGW("Data size of inputs is 0."); return PARAM_INVALID; } // check dim size if (!((begin_data_size == end_data_size) && (end_data_size == stride_data_size))) { - GELOGW("The sizes of begin, end and stride is not supported"); + GELOGW("The sizes of begin, end and stride is not supported."); return PARAM_INVALID; } return SUCCESS; @@ -254,7 +254,7 @@ Status StridedSliceKernel::InitParamWithAttrs(const std::vector &x_dims) { auto begin_data_type_size = GetSizeByDataType(begin_tensor->GetTensorDesc().GetDataType()); if (begin_data_type_size == 0) { - GELOGW("Param begin_data_type_size should not be zero"); + GELOGW("Param begin_data_type_size should not be zero."); return; } size_t begin_vec_size = begin_tensor->GetData().size() / begin_data_type_size;