From 96ecc01cbe7286888b57852226771d7a9e1f3e1a Mon Sep 17 00:00:00 2001 From: wjm Date: Thu, 10 Jun 2021 11:47:43 +0800 Subject: [PATCH 01/50] fix safe --- ge/common/dump/exception_dumper.cc | 1 + ge/graph/build/model_builder.cc | 2 +- ge/graph/load/model_manager/task_info/kernel_task_info.cc | 2 ++ ge/graph/preprocess/insert_op/util_insert_aipp_op.cc | 1 + ge/hybrid/model/hybrid_model_builder.cc | 1 + ge/plugin/engine/engine_manage.cc | 2 +- 6 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ge/common/dump/exception_dumper.cc b/ge/common/dump/exception_dumper.cc index c8ec3d35..c41da551 100644 --- a/ge/common/dump/exception_dumper.cc +++ b/ge/common/dump/exception_dumper.cc @@ -161,6 +161,7 @@ Status ExceptionDumper::DumpExceptionInfo(const std::vector &ex uint64_t proto_size = dump_data.ByteSizeLong(); std::unique_ptr proto_msg(new (std::nothrow) char[proto_size]); + GE_CHECK_NOTNULL(proto_msg); bool ret = dump_data.SerializeToArray(proto_msg.get(), proto_size); if (!ret || proto_size == 0) { REPORT_INNER_ERROR("E19999", "Serialize proto to string fail"); diff --git a/ge/graph/build/model_builder.cc b/ge/graph/build/model_builder.cc index d38e89fe..e35e4e7d 100755 --- a/ge/graph/build/model_builder.cc +++ b/ge/graph/build/model_builder.cc @@ -707,7 +707,7 @@ Status ModelBuilder::SaveDataToModel(ge::Model &model, ge::GeModel &ge_model) { if (!kernel_name.empty() && (kernel_buffer.GetSize() > 0)) { GE_CHECK_NOTNULL(kernel_buffer.GetData()); std::vector data(kernel_buffer.GetData(), kernel_buffer.GetData() + kernel_buffer.GetSize()); - tbe_kernel = std::make_shared(kernel_name, std::move(data)); + tbe_kernel = MakeShared(kernel_name, std::move(data)); GE_CHECK_NOTNULL(tbe_kernel); GELOGI("Node [%s][%s] start recovery extra attr %s from %s", node_op_desc->GetName().c_str(), node_op_desc->GetType().c_str(), ge::OP_EXTATTR_NAME_TBE_KERNEL, ATTR_NAME_TBE_KERNEL_NAME.c_str()); diff --git a/ge/graph/load/model_manager/task_info/kernel_task_info.cc b/ge/graph/load/model_manager/task_info/kernel_task_info.cc index bfb6e24b..07ad63ca 100755 --- a/ge/graph/load/model_manager/task_info/kernel_task_info.cc +++ b/ge/graph/load/model_manager/task_info/kernel_task_info.cc @@ -645,6 +645,7 @@ Status KernelTaskInfo::InitTVMTask(uint16_t offset, const domi::KernelDef &kerne GE_CHECK_NOTNULL(op_desc); args_addr = std::unique_ptr(new (std::nothrow) uint8_t[args_size_]); + GE_CHECK_NOTNULL(args_addr); errno_t sec_ret = memcpy_s(args_addr.get(), args_size_, kernel_def.args().data(), args_size_); if (sec_ret != EOK) { REPORT_CALL_ERROR("E19999", "Call memcpy_s fail, size:%u, ret:0x%X", args_size_, sec_ret); @@ -1000,6 +1001,7 @@ Status KernelTaskInfo::InitAicpuTask(uint32_t op_index, const domi::KernelDef &k // copy args to new host memory args_addr = std::unique_ptr(new (std::nothrow) uint8_t[args_size_]); + GE_CHECK_NOTNULL(args_addr); GE_PRINT_DYNAMIC_MEMORY(new, "cce task physical memory.", sizeof(uint8_t) * args_size_) errno_t sec_ret = memcpy_s(args_addr.get(), args_size_, kernel_def.args().data(), args_size_); if (sec_ret != EOK) { diff --git a/ge/graph/preprocess/insert_op/util_insert_aipp_op.cc b/ge/graph/preprocess/insert_op/util_insert_aipp_op.cc index 3cd26139..cc7f276e 100755 --- a/ge/graph/preprocess/insert_op/util_insert_aipp_op.cc +++ b/ge/graph/preprocess/insert_op/util_insert_aipp_op.cc @@ -568,6 +568,7 @@ Status InsertNewOpUtil::GetDataRelatedNode(NodePtr &node, std::map aipp_params(new (std::nothrow) domi::AippOpParams()); + GE_CHECK_NOTNULL(aipp_params); ge::GeAttrValue::NAMED_ATTRS aipp_attr; GE_CHK_BOOL_RET_STATUS(AttrUtils::GetNamedAttrs(data_op, ATTR_NAME_AIPP, aipp_attr), ACL_ERROR_GE_AIPP_NOT_EXIST, "[Get][Attr] %s from op:%s failed", ATTR_NAME_AIPP.c_str(), data_op->GetName().c_str()); diff --git a/ge/hybrid/model/hybrid_model_builder.cc b/ge/hybrid/model/hybrid_model_builder.cc index e80d9b90..554ddbbb 100755 --- a/ge/hybrid/model/hybrid_model_builder.cc +++ b/ge/hybrid/model/hybrid_model_builder.cc @@ -1044,6 +1044,7 @@ Status HybridModelBuilder::InitConstantOps() { } else { var_tensor.reset(new(std::nothrow)TensorValue(nullptr, 0)); } + GE_CHECK_NOTNULL(var_tensor); } else { GE_CHK_STATUS_RET_NOLOG(VarNodeToTensor(var_node, var_tensor)); GELOGD("Init const op tensor. name = %s, size = %ld", var_name.c_str(), var_tensor->GetSize()); diff --git a/ge/plugin/engine/engine_manage.cc b/ge/plugin/engine/engine_manage.cc index 0e129526..9cc37fd6 100644 --- a/ge/plugin/engine/engine_manage.cc +++ b/ge/plugin/engine/engine_manage.cc @@ -38,7 +38,7 @@ Status EngineManager::RegisterEngine(const std::string &engine_name, DNNEnginePt if (engine_map_ == nullptr) { engine_map_.reset(new (std::nothrow) std::map()); } - + GE_CHECK_NOTNULL(engine_map_); auto it = engine_map_->find(engine_name); if (it != engine_map_->end()) { GELOGW("engine %s already exist.", engine_name.c_str()); From 3e68c392878a9161d9a4ff291469e50487949c78 Mon Sep 17 00:00:00 2001 From: wjm Date: Thu, 10 Jun 2021 13:01:01 +0800 Subject: [PATCH 02/50] fix --- ge/plugin/engine/engine_manage.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ge/plugin/engine/engine_manage.cc b/ge/plugin/engine/engine_manage.cc index 9cc37fd6..0e129526 100644 --- a/ge/plugin/engine/engine_manage.cc +++ b/ge/plugin/engine/engine_manage.cc @@ -38,7 +38,7 @@ Status EngineManager::RegisterEngine(const std::string &engine_name, DNNEnginePt if (engine_map_ == nullptr) { engine_map_.reset(new (std::nothrow) std::map()); } - GE_CHECK_NOTNULL(engine_map_); + auto it = engine_map_->find(engine_name); if (it != engine_map_->end()) { GELOGW("engine %s already exist.", engine_name.c_str()); From 4c398c9f8b7f1259a67b0526b29c38cbc0692c32 Mon Sep 17 00:00:00 2001 From: wjm Date: Thu, 10 Jun 2021 18:34:11 +0800 Subject: [PATCH 03/50] update submodule --- metadef | 2 +- parser | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/metadef b/metadef index 9c9907b7..3e14f92d 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit 9c9907b76a457f456072af96b8cbcfb7943beccc +Subproject commit 3e14f92d47abc9a2e703be2171f047553f7597e0 diff --git a/parser b/parser index 15a27afe..4151e330 160000 --- a/parser +++ b/parser @@ -1 +1 @@ -Subproject commit 15a27afefe45f2abdb78787d629163aab9437599 +Subproject commit 4151e33028c518057289b569b36cd4069af362a4 From 18496bce86f7f55519b8c6bf5efd6b00ecb9a665 Mon Sep 17 00:00:00 2001 From: yskhhh Date: Thu, 17 Jun 2021 14:49:57 +0800 Subject: [PATCH 04/50] add debug task info --- .../aicore/aicore_node_executor.cc | 6 +++ .../node_executor/aicore/aicore_op_task.h | 2 + ge/single_op/single_op.cc | 5 ++ ge/single_op/task/build_task_utils.cc | 54 +++++++++++++++++-- ge/single_op/task/build_task_utils.h | 8 +++ ge/single_op/task/op_task.cc | 1 + ge/single_op/task/op_task.h | 2 + tests/ut/ge/hybrid/ge_hybrid_unittest.cc | 31 +++++++++++ tests/ut/ge/single_op/single_op_unittest.cc | 13 ++++- 9 files changed, 118 insertions(+), 4 deletions(-) diff --git a/ge/hybrid/node_executor/aicore/aicore_node_executor.cc b/ge/hybrid/node_executor/aicore/aicore_node_executor.cc index 7ebb9e39..efa864ed 100755 --- a/ge/hybrid/node_executor/aicore/aicore_node_executor.cc +++ b/ge/hybrid/node_executor/aicore/aicore_node_executor.cc @@ -18,6 +18,7 @@ #include "framework/common/taskdown_common.h" #include "hybrid/executor/hybrid_execution_context.h" #include "external/runtime/rt_error_codes.h" +#include "single_op/task/build_task_utils.h" namespace ge { namespace hybrid { @@ -196,6 +197,11 @@ Status AiCoreNodeTask::ExecuteAsync(TaskContext &context, std::function RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[AiCoreNodeLaunchKernel] Start"); GE_CHK_STATUS_RET_NOLOG((*it)->LaunchKernel(context.GetStream())); GE_CHK_STATUS_RET_NOLOG(CheckOverflow(context)); + GE_CHECK_NOTNULL(context.GetExecutionContext()->model); + GELOGD("[DEBUG_TASK_INFO : Executor Task] %s/%s %s", + context.GetExecutionContext()->model->GetModelName().c_str(), + (*it)->GetName().empty() ? (*it)->GetLogName().c_str() : (*it)->GetName().c_str(), + BuildTaskUtils::GetTaskInfo(context).c_str()); // save profiling data uint32_t task_id = 0; uint32_t stream_id = 0; diff --git a/ge/hybrid/node_executor/aicore/aicore_op_task.h b/ge/hybrid/node_executor/aicore/aicore_op_task.h index 8d7b7f1e..9db958d2 100755 --- a/ge/hybrid/node_executor/aicore/aicore_op_task.h +++ b/ge/hybrid/node_executor/aicore/aicore_op_task.h @@ -72,6 +72,8 @@ class AiCoreOpTask { const std::string& GetName() const; + const std::string& GetLogName() const {return log_name_;} + bool GetClearAtomic() const {return clear_atomic_;} uint32_t GetBlockDim() const {return block_dim_;} diff --git a/ge/single_op/single_op.cc b/ge/single_op/single_op.cc index d09e8398..fc34e513 100755 --- a/ge/single_op/single_op.cc +++ b/ge/single_op/single_op.cc @@ -297,6 +297,9 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status SingleOp::ExecuteAsync(c for (auto &task : tasks_) { ret = task->LaunchKernel(stream_); + GELOGD("[DEBUG_TASK_INFO : Static Task] %s %s", + task->GetTaskName().c_str(), + BuildTaskUtils::GetTaskInfo(task->GetOpdesc(), inputs, outputs).c_str()); if (ret != SUCCESS) { return ret; } @@ -447,6 +450,8 @@ Status DynamicSingleOp::ExecuteAsync(const vector &input_desc, } else { GE_CHK_STATUS_RET_NOLOG(op_task_->LaunchKernel(input_desc, input_buffers, output_desc, output_buffers, stream_)); } + GELOGD("[DEBUG_TASK_INFO : Dynamic Task] %s", + BuildTaskUtils::GetTaskInfo(op_task_->GetOpdesc(), input_buffers, output_buffers).c_str()); GE_CHK_STATUS_RET_NOLOG(op_task_->OpenDump(stream_)); GE_CHK_STATUS_RET_NOLOG(ProfilingTaskInfo(op_task_.get(), kShapeTypeDynamic)); return SUCCESS; diff --git a/ge/single_op/task/build_task_utils.cc b/ge/single_op/task/build_task_utils.cc index 9e4d55e1..b3a7ae09 100644 --- a/ge/single_op/task/build_task_utils.cc +++ b/ge/single_op/task/build_task_utils.cc @@ -70,7 +70,9 @@ std::vector BuildTaskUtils::GetKernelArgs(const OpDescPtr &op_desc, return JoinAddresses(addresses); } -std::string BuildTaskUtils::GetTaskInfo(const OpDescPtr &op_desc) { +std::string BuildTaskUtils::InnerGetTaskInfo(const OpDescPtr &op_desc, + const std::vector &input_addrs, + const std::vector &output_addrs) { std::stringstream ss; if (op_desc != nullptr) { auto op_type = op_desc->GetType(); @@ -87,7 +89,10 @@ std::string BuildTaskUtils::GetTaskInfo(const OpDescPtr &op_desc) { } ss << TypeUtils::DataTypeToSerialString(input->GetDataType()) << " "; ss << TypeUtils::FormatToSerialString(input->GetFormat()); - ss << VectorToString(input->GetShape().GetDims()); + ss << VectorToString(input->GetShape().GetDims()) << " "; + if (idx < input_addrs.size()) { + ss << input_addrs[idx]; + } if (idx < op_desc->GetInputsSize() - 1) { ss << ","; } @@ -101,7 +106,10 @@ std::string BuildTaskUtils::GetTaskInfo(const OpDescPtr &op_desc) { const GeShape &out_shape = output->GetShape(); const auto &dims = out_shape.GetDims(); ss << TypeUtils::FormatToSerialString(out_format); - ss << VectorToString(dims); + ss << VectorToString(dims) << " "; + if (idx < output_addrs.size()) { + ss << output_addrs[idx]; + } if (idx < op_desc->GetOutputsSize() - 1) { ss << ","; } @@ -110,4 +118,44 @@ std::string BuildTaskUtils::GetTaskInfo(const OpDescPtr &op_desc) { } return ss.str(); } + +std::string BuildTaskUtils::GetTaskInfo(const OpDescPtr &op_desc) { + vector input_addrs; + vector output_addrs; + return InnerGetTaskInfo(op_desc, input_addrs, output_addrs); +} + +std::string BuildTaskUtils::GetTaskInfo(const OpDescPtr &op_desc, + const std::vector &inputs, + const std::vector &outputs) { + vector input_addrs; + vector output_addrs; + GE_CHECK_NOTNULL_EXEC(op_desc, return ""); + if (op_desc->GetAllInputsSize() == inputs.size()) { + std::for_each(inputs.begin(), inputs.end(), [&](const DataBuffer &db) { input_addrs.push_back(db.data); }); + } + if (op_desc->GetOutputsSize() == outputs.size()) { + std::for_each(outputs.begin(), outputs.end(), [&](const DataBuffer &db) { output_addrs.push_back(db.data); }); + } + return InnerGetTaskInfo(op_desc, input_addrs, output_addrs); +} + +std::string BuildTaskUtils::GetTaskInfo(const hybrid::TaskContext &task_context) { + auto &node_item = task_context.GetNodeItem(); + auto op_desc = node_item.GetOpDesc(); + GE_CHECK_NOTNULL_EXEC(op_desc, return ""); + vector input_addrs; + vector output_addrs; + if (op_desc->GetAllInputsSize() == static_cast(task_context.NumInputs())) { + for (size_t i = 0; i < op_desc->GetAllInputsSize(); ++i) { + input_addrs.push_back(task_context.GetInput(i)->GetData()); + } + } + if (op_desc->GetOutputsSize() == static_cast(task_context.NumOutputs())) { + for (size_t i = 0; i < op_desc->GetOutputsSize(); ++i) { + output_addrs.push_back(task_context.GetOutput(i)->GetData()); + } + } + return InnerGetTaskInfo(op_desc, input_addrs, output_addrs); +} } // namespace ge diff --git a/ge/single_op/task/build_task_utils.h b/ge/single_op/task/build_task_utils.h index 7a2369e4..68894f5b 100644 --- a/ge/single_op/task/build_task_utils.h +++ b/ge/single_op/task/build_task_utils.h @@ -23,6 +23,7 @@ #include "graph/op_desc.h" #include "single_op/single_op.h" #include "single_op/single_op_model.h" +#include "hybrid/node_executor/task_context.h" namespace ge { class BuildTaskUtils { @@ -35,7 +36,14 @@ class BuildTaskUtils { bool keep_workspace = true); static std::vector JoinAddresses(const std::vector> &addresses); static std::vector GetKernelArgs(const OpDescPtr &op_desc, const SingleOpModelParam ¶m); + static std::string InnerGetTaskInfo(const OpDescPtr &op_desc, + const std::vector &input_addrs, + const std::vector &output_addrs); static std::string GetTaskInfo(const OpDescPtr &op_desc); + static std::string GetTaskInfo(const OpDescPtr &op_desc, + const std::vector &inputs, + const std::vector &outputs); + static std::string GetTaskInfo(const hybrid::TaskContext& task_context); template static std::string VectorToString(const std::vector &values) { std::stringstream ss; diff --git a/ge/single_op/task/op_task.cc b/ge/single_op/task/op_task.cc index e48677f8..02fc96f3 100755 --- a/ge/single_op/task/op_task.cc +++ b/ge/single_op/task/op_task.cc @@ -89,6 +89,7 @@ Status OpTask::OpenDump(rtStream_t stream) { void TbeOpTask::SetStubFunc(const std::string &name, const void *stub_func) { this->stub_name_ = name; this->stub_func_ = stub_func; + this->task_name_ = name; } void TbeOpTask::SetKernelArgs(std::unique_ptr &&args, size_t arg_size, uint32_t block_dim, diff --git a/ge/single_op/task/op_task.h b/ge/single_op/task/op_task.h index ed6cf40f..5efb4472 100644 --- a/ge/single_op/task/op_task.h +++ b/ge/single_op/task/op_task.h @@ -44,6 +44,7 @@ class OpTask { virtual Status UpdateArgTable(const SingleOpModelParam ¶m); void SetModelArgs(std::string model_name, uint32_t model_id); Status GetProfilingArgs(TaskDescInfo &task_desc_info, uint32_t &model_id); + const std::string &GetTaskName() const {return task_name_;} void SetOpDesc(const OpDescPtr &op_desc) { op_desc_ = op_desc; } @@ -66,6 +67,7 @@ class OpTask { std::string model_name_; uint32_t model_id_ = 0; uint32_t block_dim_ = 1; + std::string task_name_; }; class TbeOpTask : public OpTask { diff --git a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc index 228af832..24a60413 100644 --- a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc +++ b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc @@ -34,12 +34,14 @@ #include "hybrid/executor/hybrid_execution_context.h" #include "hybrid/executor/hybrid_model_executor.h" #include "hybrid/node_executor/aicore/aicore_task_builder.h" +#include "hybrid/node_executor/aicore/aicore_node_executor.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" #include "graph/testcase/ge_graph/graph_builder_utils.h" +#include "single_op/task/build_task_utils.h" #include "graph/op_desc_impl.h" #undef private #undef protected @@ -746,4 +748,33 @@ TEST_F(UtestGeHybrid, TestParseDependencies) { AttrUtils::SetTensor(tensor_desc, "_value", tensor); std::set dependent_for_shape_inference; ASSERT_EQ(builder.ParseDependencies(*node_item, deps, dependent_for_shape_inference), SUCCESS); +} + +TEST_F(UtestGeHybrid, TestTaskExecuteAsync) { + auto graph = make_shared("graph"); + OpDescPtr op_desc = CreateOpDesc("Add", "Add"); + GeShape shape({2, 16}); + GeTensorDesc tensor_desc(shape); + op_desc->AddInputDesc(tensor_desc); + op_desc->AddInputDesc(tensor_desc); + op_desc->AddOutputDesc(tensor_desc); + auto node = graph->AddNode(op_desc); + std::unique_ptr node_item; + NodeItem::Create(node, node_item); + node_item->input_start = 0; + node_item->output_start = 0; + + GraphExecutionContext execution_context; + GraphItem graph_item; + SubgraphContext subgraph_context(&graph_item, &execution_context); + ASSERT_EQ(subgraph_context.Init(), SUCCESS); + subgraph_context.all_inputs_.resize(2); + subgraph_context.all_outputs_.resize(1); + auto node_state = subgraph_context.GetOrCreateNodeState(node_item.get()); + auto task_context = *node_state->GetTaskContext(); + ASSERT_NE(BuildTaskUtils::GetTaskInfo(task_context), ""); + std::unique_ptr task1(new AiCoreOpTask()); + std::vector> tasks; + AiCoreNodeTask node_task(std::move(tasks)); + ASSERT_EQ(node_task.ExecuteAsync(task_context, nullptr), SUCCESS); } \ No newline at end of file diff --git a/tests/ut/ge/single_op/single_op_unittest.cc b/tests/ut/ge/single_op/single_op_unittest.cc index db3de7ec..831f3f16 100644 --- a/tests/ut/ge/single_op/single_op_unittest.cc +++ b/tests/ut/ge/single_op/single_op_unittest.cc @@ -23,6 +23,7 @@ #define private public #include "single_op/single_op.h" #include "single_op/single_op_manager.h" +#include "single_op/task/build_task_utils.h" #undef private #undef protected @@ -126,9 +127,19 @@ TEST_F(UtestSingleOp, test_singleop_execute_async1) { SingleOpModelParam model_params; single_op.running_param_.reset(new (std::nothrow)SingleOpModelParam(model_params)); single_op.args_.resize(1); + + auto *tbe_task = new (std::nothrow) TbeOpTask(); + ge::OpDescPtr op_desc = std::make_shared("Mul", MATMUL); + EXPECT_EQ(op_desc->AddInputDesc("x", GeTensorDesc(GeShape({2}), FORMAT_NCHW)), GRAPH_SUCCESS); + EXPECT_EQ(op_desc->AddOutputDesc("x", GeTensorDesc(GeShape({2}), FORMAT_NCHW)), GRAPH_SUCCESS); + EXPECT_NE(BuildTaskUtils::GetTaskInfo(op_desc), ""); + ge::ComputeGraphPtr graph = std::make_shared("default"); + ge::NodePtr node = graph->AddNode(op_desc); + tbe_task->node_ = node; + tbe_task->op_desc_ = op_desc; + single_op.tasks_.push_back(tbe_task); EXPECT_EQ(single_op.hybrid_model_executor_, nullptr); EXPECT_EQ(single_op.running_param_->mem_base, nullptr); - EXPECT_EQ(single_op.tasks_.size(), 0); EXPECT_EQ(single_op.ExecuteAsync(input_buffers, output_buffers), SUCCESS); } From 75429f81a033a9de1b975936948aa6310b68523c Mon Sep 17 00:00:00 2001 From: wqtshg Date: Fri, 25 Jun 2021 10:22:30 +0800 Subject: [PATCH 05/50] update submodule --- metadef | 2 +- parser | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/metadef b/metadef index 9e4a51a9..f3f137de 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit 9e4a51a9602195b82e326b853f5adbfefc3972b6 +Subproject commit f3f137de034885f0c7394d7f04b41b08d450d2d2 diff --git a/parser b/parser index 79536a19..15a27afe 160000 --- a/parser +++ b/parser @@ -1 +1 @@ -Subproject commit 79536a196f89cf7a1f5852ff7304b9a7d7b12eff +Subproject commit 15a27afefe45f2abdb78787d629163aab9437599 From ae488883304a78b6dc802a0f090a9d22ffa96af7 Mon Sep 17 00:00:00 2001 From: liudingyan Date: Thu, 24 Jun 2021 21:31:30 +0800 Subject: [PATCH 06/50] modify ge_log_error --- ge/executor/ge_executor.cc | 276 +++++++++++++++++++--------- ge/graph/build/label_allocator.cc | 3 +- inc/framework/common/debug/ge_log.h | 7 +- 3 files changed, 194 insertions(+), 92 deletions(-) diff --git a/ge/executor/ge_executor.cc b/ge/executor/ge_executor.cc index 486764bd..73cd7bb5 100755 --- a/ge/executor/ge_executor.cc +++ b/ge/executor/ge_executor.cc @@ -125,34 +125,41 @@ void SetDynamicInputDataFlag(const ge::RunModelData &input_data, const std::vect bool IsDynamicBatchSizeMatchModel(uint64_t batch_size, const vector> &batch_info) { if (batch_info.empty()) { - GELOGE(ge::FAILED, "Dynamic batch info is empty."); + REPORT_INNER_ERROR("E19999", "param Dynamic batch info is empty, check invalid."); + GELOGE(ge::FAILED, "[Check][Param] Dynamic batch info is empty."); return false; } for (auto batch : batch_info) { if (batch.size() != kDynamicBatchSizeVecSize) { - GELOGE(ge::FAILED, "Dynamic batch param num is %zu, current batch size is %zu.", kDynamicBatchSizeVecSize, - batch.size()); + REPORT_INNER_ERROR("E19999", "Dynamic batch param num is %zu, current batch size is %zu.", + kDynamicBatchSizeVecSize, batch.size()); + GELOGE(ge::FAILED, "[Check][Param] Dynamic batch param num is %zu, current batch size is %zu.", + kDynamicBatchSizeVecSize, batch.size()); return false; } if (batch[0] == static_cast(batch_size)) { return true; } } - GELOGE(ge::FAILED, "Dynamic batch %lu can not match the gear of model.", batch_size); + REPORT_INNER_ERROR("E19999", "Dynamic batch %lu can not match the gear of model.", batch_size); + GELOGE(ge::FAILED, "[Check][Param] Dynamic batch %lu can not match the gear of model.", batch_size); return false; } bool IsDynamicImageSizeMatchModel(uint64_t image_height, uint64_t image_width, const vector> &batch_info) { if (batch_info.empty()) { - GELOGE(ge::FAILED, "Dynamic batch info is empty."); + REPORT_INNER_ERROR("E19999", "ParamDynamic batch info is empty. check invalid"); + GELOGE(ge::FAILED, "[Check][Param] Dynamic batch info is empty."); return false; } for (auto resolution : batch_info) { if (resolution.size() != kDynamicImageSizeVecSize) { - GELOGE(ge::FAILED, "Dynamic resolution param num is %zu, current resolution size is %zu.", + REPORT_INNER_ERROR("E19999", "Dynamic resolution param num is %zu, current resolution size is %zu.", + kDynamicImageSizeVecSize, resolution.size()); + GELOGE(ge::FAILED, "[Check][Param] Dynamic resolution param num is %zu, current resolution size is %zu.", kDynamicImageSizeVecSize, resolution.size()); return false; } @@ -160,22 +167,28 @@ bool IsDynamicImageSizeMatchModel(uint64_t image_height, uint64_t image_width, return true; } } - - GELOGE(ge::FAILED, "Dynamic resolution (%lu,%lu) can not match the gear of model.", image_height, image_width); + REPORT_INNER_ERROR("E19999", "Dynamic resolution (%lu,%lu) can not match the gear of model.", + image_height, image_width); + GELOGE(ge::FAILED, "[Check][Param]Dynamic resolution (%lu,%lu) can not match the gear of model.", + image_height, image_width); return false; } bool IsDynmaicDimsSizeMatchModel(const vector cur_dynamic_dims, const vector> &batch_info) { if (batch_info.empty()) { - GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Dynamic batch info is empty."); + REPORT_INNER_ERROR("E19999", "param batch_info is empty, check invalid"); + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Param] Dynamic batch info is empty."); return false; } bool find_match = false; for (auto resolution : batch_info) { if (cur_dynamic_dims.size() != resolution.size()) { - GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Cur dynamic dims param num is %zu, current resolution size is %zu.", + REPORT_INNER_ERROR("E19999", "Cur dynamic dims param num is %zu, current resolution size is %zu.", + cur_dynamic_dims.size(), resolution.size()); + GELOGE(ACL_ERROR_GE_PARAM_INVALID, + "[Check][Param] Cur dynamic dims param num is %zu, current resolution size is %zu.", cur_dynamic_dims.size(), resolution.size()); return false; } @@ -192,7 +205,7 @@ bool IsDynmaicDimsSizeMatchModel(const vector cur_dynamic_dims, } } if (!find_match) { - GELOGE(ACL_ERROR_GE_PARAM_INVALID, "choose dynamic dims can not match the gear of model."); + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Param] choose dynamic dims can not match the gear of model."); } return find_match; } @@ -241,7 +254,7 @@ Status GeExecutor::Initialize() { Status init_hostcpu_engine_status = HostCpuEngine::GetInstance().Initialize(); if (init_hostcpu_engine_status != SUCCESS) { - GELOGE(init_hostcpu_engine_status, "Failed to initialize HostCpuEngine"); + GELOGE(init_hostcpu_engine_status, "[initialize][HostCpuEngine] failed"); return init_hostcpu_engine_status; } @@ -251,12 +264,12 @@ Status GeExecutor::Initialize() { mem_type.push_back(RT_MEMORY_P2P_DDR); auto ret = MemManager::Instance().Initialize(mem_type); if (ret != SUCCESS) { - GELOGE(ret, "Memory Manager init failed."); + GELOGE(ret, "[Initialize][MemManager] failed."); return ret; } GE_CHK_STATUS_RET(OpsKernelBuilderManager::Instance().Initialize({}, false), - "Failed to initialize OpsKernelBuilders."); + "[Initialize][OpsKernelBuilderManager] failed."); // Start profiling Options profiling_options; @@ -292,13 +305,18 @@ Status GeExecutor::Finalize() { Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length, uint64_t batch_size) { if (dynamic_input_addr == nullptr) { - GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, "Dynamic input addr is nullptr!"); + REPORT_INNER_ERROR("E19999", "param dynamic_input_addr is nullptr, check invalid, model id:%u", model_id); + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, + "[Check][Param] Dynamic input addr is nullptr, model id:%u", model_id); return ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID; } uint64_t size = sizeof(uint32_t); if (length < size) { - GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, "Dynamic input size [%lu] is less than [%lu]!", length, size); + REPORT_INNER_ERROR("E19999", "Dynamic input size [%lu] is less than [%lu], check invalid, model id:%u", + length, size, model_id); + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, + "[Check][Param] Dynamic input size [%lu] is less than [%lu], model id:%u", length, size, model_id); return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } if (length >= sizeof(uint64_t)) { @@ -311,24 +329,28 @@ Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_ad int32_t dynamic_type = static_cast(FIXED); Status ret = GraphExecutor::GetDynamicBatchInfo(model_id, batch_info, dynamic_type); if (ret != SUCCESS) { - GELOGE(ret, "Get dynamic input info failed."); + REPORT_CALL_ERROR("E19999", "get dynamic batch info failed, model id:%u", model_id); + GELOGE(ret, "[Get][DynamicBatchInfo] failed, model id:%u.", model_id); return ret; } if (!IsDynamicBatchSizeMatchModel(batch_size, batch_info)) { - GELOGE(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, "The current dynamic input does not match the gear of the model."); + GELOGE(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, + "[Check][Param] The current dynamic input does not match the gear of the model(id:%u).", model_id); return ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID; } ret = GraphExecutor::SetDynamicSize(model_id, batch_num, static_cast(DYNAMIC_BATCH)); if (ret != SUCCESS) { - GELOGE(ret, "Set dynamic size failed"); + REPORT_CALL_ERROR("E19999", "set dynamic size failed, model id:%u, dynamic_type:1", model_id); + GELOGE(ret, "[Set][DynamicSize] failed, model id:%u, dynamic_type:1", model_id); return ret; } // memcpy dynamic_batch_size from host to device rtError_t rt_ret = rtMemcpy(dynamic_input_addr, length, &batch_size, size, RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { - GELOGE(rt_ret, "memcpy dynamic batch input data failed! ret: 0x%X", rt_ret); + REPORT_CALL_ERROR("E19999", "Call rtMemcpy, size:%lu ret:0x%X", length, rt_ret); + GELOGE(rt_ret, "[Call][RtMemcpy] memcpy dynamic batch input data failed! size:%lu ret:0x%X", length, rt_ret); return RT_ERROR_TO_GE_STATUS(rt_ret); } return SUCCESS; @@ -337,14 +359,19 @@ Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_ad Status GeExecutor::SetDynamicImageSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length, uint64_t image_height, uint64_t image_width) { if (dynamic_input_addr == nullptr) { - GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, "Dynamic input addr is nullptr!"); + REPORT_INNER_ERROR("E19999", "param dynamic_input_addr is nullptr, check invalid, model id:%u", model_id); + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, + "[Check][Param] Dynamic input addr is nullptr, model id:%u", model_id); return ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID; } uint64_t dynamic_input_size = kDynamicImageSizeInputSize * sizeof(uint32_t); if (length < dynamic_input_size) { + REPORT_INNER_ERROR("E19999", "Dynamic input size [%lu] is less than [%lu], check invalid, model id:%u", + length, dynamic_input_size, model_id); GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, - "Dynamic input size [%lu] is less than [%lu]!", length, dynamic_input_size); + "[Check][Param] Dynamic input size [%lu] is less than [%lu], model id:%u", + length, dynamic_input_size, model_id); return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } uint64_t size = sizeof(uint32_t); @@ -357,18 +384,22 @@ Status GeExecutor::SetDynamicImageSize(uint32_t model_id, void *dynamic_input_ad int32_t dynamic_type = static_cast(FIXED); Status ret = GraphExecutor::GetDynamicBatchInfo(model_id, batch_info, dynamic_type); if (ret != SUCCESS) { - GELOGE(ret, "Get dynamic input info failed."); + REPORT_CALL_ERROR("E19999", "Get dynamic input info failed, model id:%u.", model_id); + GELOGE(ret, "[Get][DynamicBatchInfo] failed, model id:%u.", model_id); return ret; } if (!IsDynamicImageSizeMatchModel(image_height, image_width, batch_info)) { - GELOGE(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, "The current dynamic input does not match the gear of the model."); + GELOGE(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, + "[Check][Param] The current dynamic input does not match the gear of the model, " + "image_height:%lu, image_width:%lu.", image_height, image_width); return ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID; } ret = GraphExecutor::SetDynamicSize(model_id, batch_num, static_cast(DYNAMIC_IMAGE)); if (ret != SUCCESS) { - GELOGE(ret, "Set dynamic size failed"); + REPORT_CALL_ERROR("E19999", "Set dynamic size failed, model id:%u,", model_id); + GELOGE(ret, "[Set][DynamicSize] failed, model id:%u", model_id); return ret; } @@ -376,7 +407,9 @@ Status GeExecutor::SetDynamicImageSize(uint32_t model_id, void *dynamic_input_ad rtError_t rt_ret = rtMemcpy(dynamic_input_addr, size, &image_height, size, RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { - GELOGE(rt_ret, "memcpy dynamic resolution input data failed! ret: 0x%X", rt_ret); + REPORT_CALL_ERROR("E19999", "Call rtMemcpy failed! size:%lu, ret:0x%X, model id:%u", size, rt_ret, model_id); + GELOGE(rt_ret, "[Call][RtMemcpy] memcpy dynamic resolution input data failed! size:%lu, ret:0x%X, model id:%u", + size, rt_ret, model_id); return RT_ERROR_TO_GE_STATUS(rt_ret); } @@ -385,7 +418,10 @@ Status GeExecutor::SetDynamicImageSize(uint32_t model_id, void *dynamic_input_ad rt_ret = rtMemcpy(reinterpret_cast(reinterpret_cast(dynamic_input_addr) + size), remain_size, &image_width, size, RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { - GELOGE(rt_ret, "memcpy dynamic resolution input data failed!"); + REPORT_CALL_ERROR("E19999", "Call rtMemcpy failed! size:%lu, ret:0x%X, model id:%u", + remain_size, rt_ret, model_id); + GELOGE(rt_ret, "[Call][RtMemcpy] memcpy dynamic resolution input data failed! size:%lu, ret:0x%X, model id:%u", + remain_size, rt_ret, model_id); return RT_ERROR_TO_GE_STATUS(rt_ret); } return SUCCESS; @@ -394,40 +430,48 @@ Status GeExecutor::SetDynamicImageSize(uint32_t model_id, void *dynamic_input_ad Status GeExecutor::SetDynamicDims(uint32_t model_id, void *dynamic_input_addr, uint64_t length, const vector &dynamic_dims) { if (dynamic_input_addr == nullptr) { - GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, "Dynamic input addr is nullptr!"); + REPORT_INNER_ERROR("E19999", "Param dynamic_input_addr is nullptr, check invalid, model id:%u", model_id); + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, + "[Check][Param] Dynamic input addr is nullptr, model id:%u", model_id); return ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID; } vector cur_dynamic_dims; Status ret = GetCurDynamicDims(model_id, dynamic_dims, cur_dynamic_dims); if (ret != SUCCESS) { - GELOGE(ret, "Set cur gear dynamic dims failed"); + GELOGE(ret, "[Get][CurDynamicDims] failed, model id:%u", model_id); return ret; } std::vector> batch_info; int32_t dynamic_type = static_cast(FIXED); ret = GraphExecutor::GetDynamicBatchInfo(model_id, batch_info, dynamic_type); if (ret != SUCCESS) { - GELOGE(ret, "Get dynamic input info failed."); + REPORT_CALL_ERROR("E19999", "Get dynamic input info failed, model id:%u.", model_id); + GELOGE(ret, "[Get][DynamicBatchInfo] failed, model id:%u.", model_id); return ret; } if (!IsDynmaicDimsSizeMatchModel(cur_dynamic_dims, batch_info)) { - GELOGE(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, "The current dynamic input does not match the gear of the model."); + GELOGE(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, + "[Check][Param] The current dynamic input does not match the gear of the model, id:%u.", model_id); return ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID; } ret = GraphExecutor::SetDynamicSize(model_id, cur_dynamic_dims, static_cast(DYNAMIC_DIMS)); if (ret != SUCCESS) { - GELOGE(ret, "Set dynamic size failed"); + REPORT_CALL_ERROR("E19999", "Set dynamic size failed, model id:%u", model_id); + GELOGE(ret, "[Set][DynamicSize] failed, model id:%u", model_id); return ret; } size_t dynamic_dim_num = cur_dynamic_dims.size(); uint64_t dynamic_input_size = static_cast(dynamic_dim_num * sizeof(uint32_t)); if (length < dynamic_input_size) { + REPORT_INNER_ERROR("E19999", "input dynamic size [%lu] is less than [%lu], model id:%u", + length, dynamic_input_size, model_id); GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, - "Dynamic input size [%lu] is less than [%lu]!", length, dynamic_input_size); + "[Check][Param] Dynamic input size [%lu] is less than [%lu], model id:%u", + length, dynamic_input_size, model_id); return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } uint64_t size = sizeof(uint32_t); @@ -440,7 +484,9 @@ Status GeExecutor::SetDynamicDims(uint32_t model_id, void *dynamic_input_addr, u rt_ret = rtMemcpy(reinterpret_cast(reinterpret_cast(dynamic_input_addr) + size * i), length - size * i, &cur_dynamic_dims[i], size, RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { - GELOGE(rt_ret, "memcpy dynamic resolution input data failed!"); + REPORT_CALL_ERROR("E19999", "Call rtMemcpy failed, size:%lu, ret:0x%X", (length - size * i), rt_ret); + GELOGE(rt_ret, "[Call][RtMemcpy] memcpy dynamic resolution input data failed! size:%lu, ret:0x%X", + length - size * i, rt_ret); return RT_ERROR_TO_GE_STATUS(rt_ret); } } @@ -454,14 +500,14 @@ Status GeExecutor::GetCurDynamicDims(uint32_t model_id, const vector & vector output_desc; auto ret = GetModelDescInfo(model_id, input_desc, output_desc); if (ret != ge::SUCCESS) { - GELOGE(ret, "GetModelDescInfo failed."); + GELOGE(ret, "[Get][ModelDescInfo] failed, model id:%u.", model_id); return ret; } vector user_designate_shape_order; vector all_data_dims; ret = GetUserDesignateShapeOrder(model_id, user_designate_shape_order); if (ret != ge::SUCCESS) { - GELOGE(ret, "GetUserDesignateShapeOrder failed."); + GELOGE(ret, "[Call][GetUserDesignateShapeOrder] failed, model id:%u.", model_id); return ret; } for (auto &data_name : user_designate_shape_order) { @@ -475,8 +521,10 @@ Status GeExecutor::GetCurDynamicDims(uint32_t model_id, const vector & } } if (dynamic_dims.size() != all_data_dims.size()){ + REPORT_INNER_ERROR("E19999", "Dynamic input size [%lu] is not equal with all data dims size [%lu]!", + dynamic_dims.size(), all_data_dims.size()); GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, - "Dynamic input size [%lu] is not equal with all data dims size [%lu]!", + "[Check][Param] Dynamic input size [%lu] is not equal with all data dims size [%lu]!", dynamic_dims.size(), all_data_dims.size()); return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } @@ -484,8 +532,10 @@ Status GeExecutor::GetCurDynamicDims(uint32_t model_id, const vector & if (all_data_dims[i] < 0) { cur_dynamic_dims.push_back(dynamic_dims[i]); } else if (static_cast(all_data_dims[i]) != dynamic_dims[i]) { + REPORT_INNER_ERROR("E19999", "Static dims should be same, index:%zu value:%lu should be %ld", + i, dynamic_dims[i], all_data_dims[i]); GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, - "Static dims should be same, index: %zu value: %lu should be %ld", + "[Check][Param] Static dims should be same, index:%zu value:%lu should be %ld", i, dynamic_dims[i], all_data_dims[i]); return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } @@ -496,12 +546,14 @@ Status GeExecutor::GetCurDynamicDims(uint32_t model_id, const vector & Status GeExecutor::GetCurShape(const uint32_t model_id, std::vector &batch_info, int32_t &dynamic_type) { GELOGI("Begin to get current shape"); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized, model id:%u", model_id); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized, model id:%u", model_id); return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetCurShape(model_id, batch_info, dynamic_type); if (ret != SUCCESS) { - GELOGE(ret, "Get current shape failed"); + REPORT_CALL_ERROR("E19999", "Get Cur Shape failed, model id:%u", model_id); + GELOGE(ret, "[Get][CurShape] failed, model id:%u", model_id); return ret; } return SUCCESS; @@ -512,11 +564,14 @@ Status GeExecutor::SetDynamicAippData(uint32_t model_id, void *dynamic_input_add const kAippDynamicPara &aippParms) { GELOGI("Enter to SetDynamicAippData."); if (dynamic_input_addr == nullptr) { - GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, "Dynamic aipp input addr is nullptr!"); + REPORT_INNER_ERROR("E19999", "Param dynamic_input_addr is nullptr, check invalid, model id:%u", model_id); + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, + "[Check][Param] Dynamic aipp input addr is nullptr, model id:%u", model_id); return ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID; } if (aippBatchPara.empty()) { - GELOGE(ACL_ERROR_GE_AIPP_BATCH_EMPTY, "aippBatchPara is empty."); + REPORT_INNER_ERROR("E19999", "Param aippBatchPara is empty, check invalid, model id:%u", model_id); + GELOGE(ACL_ERROR_GE_AIPP_BATCH_EMPTY, "[Check][Param] aippBatchPara is empty, model id:%u", model_id); return ACL_ERROR_GE_AIPP_BATCH_EMPTY; } uint64_t batch_num = aippBatchPara.size(); @@ -527,14 +582,18 @@ Status GeExecutor::SetDynamicAippData(uint32_t model_id, void *dynamic_input_add "batch num is %lu, struct_len is %lu", model_id, length, batch_num, struct_len); if (struct_len > length) { + REPORT_INNER_ERROR("E19999", "input dynamic aipp param len:%lu is larger than aipp_data size:%lu", + struct_len, length); GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, - "input dynamic aipp param len [%lu] is larger than aipp_data size [%lu]", struct_len, length); + "[Check][Param] input dynamic aipp param len [%lu] is larger than aipp_data size [%lu]", + struct_len, length); return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } // Memcpy real kAippDynamicBatchPara from host to device rtError_t rt_ret = rtMemcpy(dynamic_input_addr, length, &aippParms, real_aippParms_size, RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { - GELOGE(rt_ret, "memcpy real_aippParms_size failed! ret: 0x%X", rt_ret); + REPORT_CALL_ERROR("E19999", "Call rtMemcpy failed, size:%lu, ret:0x%X", length, rt_ret); + GELOGE(rt_ret, "[Call][RtMemcpy] memcpy aippParms failed! size:%lu, ret:0x%X", length, rt_ret); return RT_ERROR_TO_GE_STATUS(rt_ret); } uint64_t remain_len = length - real_aippParms_size; @@ -545,7 +604,8 @@ Status GeExecutor::SetDynamicAippData(uint32_t model_id, void *dynamic_input_add (remain_len - i * sizeof(kAippDynamicBatchPara)), &(aippBatchPara[i]), sizeof(kAippDynamicBatchPara), RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { - GELOGE(rt_ret, "memcpy kAippDynamicBatchPara input data failed! ret: 0x%X", rt_ret); + REPORT_CALL_ERROR("E19999", "Call rtMemcpy failed, ret:0x%X", rt_ret); + GELOGE(rt_ret, "[Call][RtMemcpy] memcpy kAippDynamicBatchPara input data failed! ret:0x%X", rt_ret); return RT_ERROR_TO_GE_STATUS(rt_ret); } } @@ -555,12 +615,14 @@ Status GeExecutor::SetDynamicAippData(uint32_t model_id, void *dynamic_input_add Status GeExecutor::UnloadModel(uint32_t model_id) { GELOGD("unload model %u begin.", model_id); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphLoader::DestroyAicpuSessionForInfer(model_id); if (ret != SUCCESS) { - GELOGE(ret, "[GraphLoader] DestroyAicpuSessionForInfer failed. model id: %u", model_id); + REPORT_CALL_ERROR("E19999", "Destroy Aicpu Session For Infer failed, model id:%u", model_id); + GELOGE(ret, "[Destroy][AicpuSession] For Infer failed. model id:%u", model_id); return ret; } @@ -578,7 +640,8 @@ Status GeExecutor::UnloadModel(uint32_t model_id) { } ret = GraphLoader::UnloadModel(model_id); if (ret != SUCCESS) { - GELOGE(ret, "[GraphLoader] DestroyAicpuSessionForInfer failed. model id: %u", model_id); + REPORT_CALL_ERROR("E19999", "unload model failed, model id:%u", model_id); + GELOGE(ret, "[Unload][Model] failed. model id:%u", model_id); return ret; } return SUCCESS; @@ -588,7 +651,8 @@ Status GeExecutor::UnloadModel(uint32_t model_id) { Status GeExecutor::GetModelDescInfo(uint32_t model_id, std::vector &input_desc, std::vector &output_desc, bool new_model_desc) { if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized, model id:%u", model_id); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized, model id:%u", model_id); return ACL_ERROR_GE_EXEC_NOT_INIT; } @@ -600,20 +664,26 @@ Status GeExecutor::GetModelDescInfo(uint32_t model_id, std::vector> &batch_info, int32_t &dynamic_type) { if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetDynamicBatchInfo(model_id, batch_info, dynamic_type); if (ret != SUCCESS) { - GELOGE(ret, "GetDynamicBatchInfo failed."); + REPORT_CALL_ERROR("E19999", "Get Dynamic BatchInfo failed, model id:%u.", model_id); + GELOGE(ret, "[Get][DynamicBatchInfo] failed, model id:%u.", model_id); return ret; } return SUCCESS; @@ -657,13 +729,15 @@ Status GeExecutor::GetDynamicBatchInfo(uint32_t model_id, std::vector> &batch_info) { GELOGI("Begin to get combined dynamic dims info."); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetCombinedDynamicDims(model_id, batch_info); if (ret != SUCCESS) { - GELOGE(ret, "GetCombinedDynamicDims failed."); + REPORT_CALL_ERROR("E19999", "Get Combined DynamicDims failed, model id:%u.", model_id); + GELOGE(ret, "[Get][CombinedDynamicDims] failed, model id:%u.", model_id); return ret; } @@ -680,13 +754,15 @@ Status GeExecutor::GetCombinedDynamicDims(uint32_t model_id, vector &user_designate_shape_order) { if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetUserDesignateShapeOrder(model_id, user_designate_shape_order); if (ret != SUCCESS) { - GELOGE(ret, "GetUserDesignateShapeOrder failed."); + REPORT_CALL_ERROR("E19999", "GetUserDesignateShapeOrder failed, model id:%u.", model_id); + GELOGE(ret, "[Call][GetUserDesignateShapeOrder] failed, model id:%u.", model_id); return ret; } @@ -704,7 +780,8 @@ Status GeExecutor::GetUserDesignateShapeOrder(uint32_t model_id, vector Status GeExecutor::GetAIPPInfo(uint32_t model_id, uint32_t index, AippConfigInfo &aipp_info) { GELOGI("Begin to GetAIPPInfo."); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor not inited yet!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetAippInfo(model_id, index, aipp_info); @@ -719,7 +796,8 @@ Status GeExecutor::GetAIPPInfo(uint32_t model_id, uint32_t index, AippConfigInfo Status GeExecutor::GetAippType(uint32_t model_id, uint32_t index, InputAippType &type, size_t &aipp_index) { GELOGI("Begin to get aipp type."); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not inited yet!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetAippType(model_id, index, type, aipp_index); @@ -741,8 +819,10 @@ Status GeExecutor::GetOpAttr(uint32_t model_id, const std::string &op_name, cons } Status ret = GraphExecutor::GetOpAttr(model_id, op_name, attr_name, attr_value); if (ret != SUCCESS) { - GELOGE(ret, "[Get][OpAttr]Get op:%s attr:%s failed.", op_name.c_str(), attr_name.c_str()); - REPORT_CALL_ERROR("E19999", "Get op:%s attr:%s failed.", op_name.c_str(), attr_name.c_str()); + GELOGE(ret, "[Get][OpAttr]Get op:%s attr:%s failed, model id:%u.", + op_name.c_str(), attr_name.c_str(), model_id); + REPORT_CALL_ERROR("E19999", "Get op:%s attr:%s failed, model id:%u", + op_name.c_str(), attr_name.c_str(), model_id); return ret; } return SUCCESS; @@ -750,12 +830,14 @@ Status GeExecutor::GetOpAttr(uint32_t model_id, const std::string &op_name, cons Status GeExecutor::GetModelAttr(uint32_t model_id, std::vector &dynamic_output_shape_info) { if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not inited yet!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not inited yet!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetModelAttr(model_id, dynamic_output_shape_info); if (ret != SUCCESS) { - GELOGE(ret, "Get dynamic batch output shape info failed."); + REPORT_CALL_ERROR("E19999", "Get Model Attr failed, model id:%u.", model_id); + GELOGE(ret, "[Get][ModelAttr] failed, model id:%u.", model_id); return ret; } return SUCCESS; @@ -764,7 +846,8 @@ Status GeExecutor::GetModelAttr(uint32_t model_id, std::vector &dyn Status GeExecutor::CommandHandle(const Command &command) { Status ret = GraphLoader::CommandHandle(command); if (ret != SUCCESS) { - GELOGE(ACL_ERROR_GE_COMMAND_HANDLE, "CommandHandle: Command Handle failed."); + REPORT_CALL_ERROR("E19999", "call CommandHandle failed, ret:%u", ret); + GELOGE(ACL_ERROR_GE_COMMAND_HANDLE, "[Call][CommandHandle] failed, ret:%u", ret); return ACL_ERROR_GE_COMMAND_HANDLE; } return SUCCESS; @@ -773,7 +856,8 @@ Status GeExecutor::CommandHandle(const Command &command) { Status GeExecutor::GetMaxUsedMemory(uint32_t model_id, uint32_t &max_size) { GELOGI("Get max used memory begin."); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } @@ -793,14 +877,15 @@ Status GeExecutor::GetMaxUsedMemory(uint32_t model_id, uint32_t &max_size) { Status GeExecutor::LoadDataFromFile(const std::string &path, ModelData &model_data) { GELOGI("Load data from file begin."); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } string filePath = RealPath(path.c_str()); if (filePath.empty()) { GELOGE(ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID, - "File path is invalid. please check your text file '%s'.", path.c_str()); + "[Call][RealPath] File path is invalid. please check your text file '%s'.", path.c_str()); return ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID; } GELOGI("load modelData from file: %s.", path.c_str()); @@ -829,7 +914,8 @@ Status GeExecutor::LoadDataFromFile(const std::string &path, ModelData &model_da Status GeExecutor::LoadModelFromData(uint32_t &model_id, const ModelData &model_data, void *dev_ptr, size_t mem_size, void *weight_ptr, size_t weight_size) { if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not inited yet!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } @@ -850,7 +936,8 @@ Status GeExecutor::LoadModelWithQ(uint32_t &model_id, const ModelData &model_dat const std::vector &output_queue_ids) { GELOGI("Load model with queue begin."); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } return GraphLoader::LoadModelWithQ(model_id, model_data, input_queue_ids, output_queue_ids); @@ -889,7 +976,8 @@ Status GeExecutor::ExecModel(uint32_t model_id, void *stream, const ge::RunModel const std::vector &input_desc, ge::RunModelData &run_output_data, std::vector &output_desc, bool async_mode) { if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } @@ -904,7 +992,8 @@ Status GeExecutor::ExecModel(uint32_t model_id, void *stream, const ge::RunModel int32_t dynamic_type = static_cast(FIXED); Status ret = GraphExecutor::GetDynamicBatchInfo(model_id, batch_info, dynamic_type); if (ret != SUCCESS) { - GELOGE(ret, "Get dynamic input info failed."); + REPORT_CALL_ERROR("E19999", "get dynamic batch info failed, model id:%u.", model_id); + GELOGE(ret, "[Get][DynamicBatchInfo] failed, model id:%u.", model_id); return ret; } if (!batch_info.empty()) { @@ -926,14 +1015,16 @@ Status GeExecutor::ExecModel(uint32_t model_id, void *stream, const ge::RunModel Status GeExecutor::GetMemAndWeightSize(const std::string &path, size_t &mem_size, size_t &weight_size) { GELOGI("Get memory and weight size from file begin."); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } ModelData model; Status ret = ge::GraphLoader::LoadDataFromFile(path, 0, model); if ((ret != SUCCESS) || (model.model_data == nullptr)) { - GELOGE(ret, "Load data from file failed. ret = %d", ret); + REPORT_CALL_ERROR("E19999", "load data from file failed, ret = %d", ret); + GELOGE(ret, "[Load][Data] from file failed. ret = %d", ret); return ret; } @@ -958,12 +1049,14 @@ Status GeExecutor::GetMemAndWeightSize(const void *model_data, size_t model_size size_t &weight_size) { GELOGI("Get memory and weight size from data begin."); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } if (model_data == nullptr) { - GELOGE(ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID, "invalid model data!"); + REPORT_INNER_ERROR("E19999", "param model_data is nullptr, check invalid!"); + GELOGE(ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID, "[Check][Param] invalid model data!"); return ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID; } @@ -997,7 +1090,8 @@ Status GeExecutor::LoadDynamicSingleOpV2(const std::string &model_name, const ge Status GeExecutor::ExecuteAsync(SingleOp *executor, const std::vector &inputs, std::vector &outputs) { if (executor == nullptr) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "param is NULL"); + REPORT_INNER_ERROR("E19999", "Param executor is nullptr, check invalid"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] param executor is nullptr"); return ACL_ERROR_GE_EXEC_NOT_INIT; } @@ -1021,7 +1115,8 @@ Status GeExecutor::GetDeviceIdByModelId(uint32_t model_id, uint32_t &device_id) GE_CHECK_NOTNULL(model_manager); auto davinci_model = model_manager->GetModel(model_id); if (davinci_model == nullptr) { - GELOGE(ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, "Model id: %d is invaild or model is not loaded.", model_id); + GELOGE(ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, + "[Get][Model] failed, Model id:%u is invaild or model is not loaded.", model_id); return ACL_ERROR_GE_EXEC_MODEL_ID_INVALID; } @@ -1034,7 +1129,7 @@ Status GeExecutor::GetBatchInfoSize(uint32_t model_id, size_t &shape_count) { int32_t dynamic_type = static_cast(FIXED); Status ret = GetDynamicBatchInfo(model_id, batch_info, dynamic_type); if (ret != SUCCESS) { - GELOGE(ret, "Calc batch info size failed. ret = %d", ret); + GELOGE(ret, "[Get][DynamicBatchInfo] failed. ret = %d, model id:%u", ret, model_id); return ret; } if (batch_info.empty()) { @@ -1048,13 +1143,15 @@ Status GeExecutor::GetBatchInfoSize(uint32_t model_id, size_t &shape_count) { Status GeExecutor::GetOrigInputInfo(uint32_t model_id, uint32_t index, OriginInputInfo &orig_input_info) { GELOGI("Begin to GetOrigInputInfo."); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetOrigInputInfo(model_id, index, orig_input_info); if (ret != SUCCESS) { - GELOGE(ret, "GetOrigInputInfo failed."); + REPORT_CALL_ERROR("E19999", "Get Orig Input Info failed, model id:%u.", model_id); + GELOGE(ret, "[Get][OrigInputInfo] failed, model id:%u.", model_id); return ret; } @@ -1067,13 +1164,15 @@ Status GeExecutor::GetAllAippInputOutputDims(uint32_t model_id, uint32_t index, std::vector &output_dims) { GELOGI("Begin to GetAllAippInputOutputDims."); if (!isInit_) { - GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + REPORT_INNER_ERROR("E19999", "GeExecutor has not been initialized!"); + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Check][Param] GeExecutor has not been initialized!"); return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetAllAippInputOutputDims(model_id, index, input_dims, output_dims); if (ret != SUCCESS) { - GELOGE(ret, "GetAllAippInputOutputDims failed."); + REPORT_CALL_ERROR("E19999", "Get All Aipp Input Output Dims failed, model id:%u.", model_id); + GELOGE(ret, "[Get][AllAippInputOutputDims] failed, model id:%u.", model_id); return ret; } @@ -1085,7 +1184,10 @@ Status GeExecutor::GetOpDescInfo(uint32_t device_id, uint32_t stream_id, uint32_ GELOGI("Begin to GetOpDescInfo."); Status ret = GraphExecutor::GetOpDescInfo(device_id, stream_id, task_id, op_desc_info); if (ret != SUCCESS) { - GELOGE(ret, "GetOpDescInfo failed."); + REPORT_CALL_ERROR("E19999", "get opdesc info failed, device_id:%u, stream_id:%u, task_id:%u.", + device_id, stream_id, task_id); + GELOGE(ret, "[Get][OpDescInfo] failed, device_id:%u, stream_id:%u, task_id:%u.", + device_id, stream_id, task_id); return ret; } GELOGI("GetOpDescInfo succ."); @@ -1096,7 +1198,7 @@ Status GeExecutor::SetDump(const DumpConfig &dump_config) { GELOGI("Start to set dump config"); auto ret = DumpManager::GetInstance().SetDumpConf(dump_config); if (ret != SUCCESS) { - GELOGE(ret, "Set dump conf failed"); + GELOGE(ret, "[Set][DumpConf] failed, ret:%d", ret); return ret; } GELOGI("Set dump config successfully"); diff --git a/ge/graph/build/label_allocator.cc b/ge/graph/build/label_allocator.cc index 6d81c17d..f2329769 100644 --- a/ge/graph/build/label_allocator.cc +++ b/ge/graph/build/label_allocator.cc @@ -80,8 +80,7 @@ bool LabelAllocator::CollectFunctionalNode(ComputeGraphPtr &graph, std::setGetParentNode(); if (func_node == nullptr) { - REPORT_INNER_ERROR("E19999", "Parent node not set in node:%s(%s), graph:%s", - func_node->GetName().c_str(), func_node->GetType().c_str(), graph->GetName().c_str()); + REPORT_INNER_ERROR("E19999", "Parent node not set, graph:%s", graph->GetName().c_str()); GELOGE(INTERNAL_ERROR, "[Get][Node] Parent functional node not set: %s.", graph->GetName().c_str()); return false; } diff --git a/inc/framework/common/debug/ge_log.h b/inc/framework/common/debug/ge_log.h index 754712f3..3e646440 100644 --- a/inc/framework/common/debug/ge_log.h +++ b/inc/framework/common/debug/ge_log.h @@ -84,9 +84,10 @@ inline bool IsLogEnable(int module_name, int log_level) { ##__VA_ARGS__); \ } while (0) -#define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \ - dlog_error(MOD_NAME, "%lu %s: ErrorNo: %d(%s) " fmt, GeLog::GetTid(), __FUNCTION__, ERROR_CODE, \ - ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ##__VA_ARGS__) +#define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \ + dlog_error(MOD_NAME, "%lu %s: ErrorNo: %d(%s) %s" fmt, GeLog::GetTid(), __FUNCTION__, ERROR_CODE, \ + ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ErrorManager::GetInstance().GetLogHeader().c_str(), \ + ##__VA_ARGS__) // print memory when it is greater than 1KB. #define GE_PRINT_DYNAMIC_MEMORY(FUNC, PURPOSE, SIZE) \ From 3af68a42300f54e50f079ebf8ea41b01a02eeb59 Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Fri, 25 Jun 2021 20:53:08 +0800 Subject: [PATCH 07/50] Fix Set Control flow group for -1 --- .../mark_force_unknown_for_cond_pass.cc | 97 +++++++++++-------- .../passes/mark_force_unknown_for_cond_pass.h | 11 +++ .../passes/switch_to_stream_switch_pass.cc | 5 +- ge/hybrid/executor/node_state.cc | 35 ++++--- ge/hybrid/executor/node_state.h | 1 + ge/hybrid/model/node_item.cc | 6 +- ge/hybrid/model/node_item.h | 4 +- ge/hybrid/node_executor/node_executor.cc | 1 + ge/hybrid/node_executor/task_context.cc | 6 ++ ge/hybrid/node_executor/task_context.h | 1 + 10 files changed, 108 insertions(+), 59 deletions(-) diff --git a/ge/graph/passes/mark_force_unknown_for_cond_pass.cc b/ge/graph/passes/mark_force_unknown_for_cond_pass.cc index fbf69c04..233a1ff0 100644 --- a/ge/graph/passes/mark_force_unknown_for_cond_pass.cc +++ b/ge/graph/passes/mark_force_unknown_for_cond_pass.cc @@ -16,8 +16,6 @@ #include "graph/passes/mark_force_unknown_for_cond_pass.h" -#include - #include "graph/utils/node_utils.h" #include "graph/common/omg_util.h" @@ -26,17 +24,7 @@ namespace { inline bool IsMergeInLoop(const NodePtr &node) { const static std::set kLoopMergeInputs{ ENTER, REFENTER, NEXTITERATION, REFNEXTITERATION }; - std::string node_type; - (void)GetOriginalType(node, node_type); - return kLoopMergeInputs.count(node_type) > 0; -} - -inline bool IsSwitchInLoop(const NodePtr &node) { - const static std::set kLoopSwitchInputs{ MERGE, REFMERGE, LOOPCOND }; - - std::string node_type; - (void)GetOriginalType(node, node_type); - return kLoopSwitchInputs.count(node_type) > 0; + return kLoopMergeInputs.count(NodeUtils::GetNodeType(node)) > 0; } } @@ -44,10 +32,7 @@ Status MarkForceUnknownForCondPass::Run(ComputeGraphPtr graph) { GELOGD("MarkForceUnknownForCondPass Enter"); std::map> switch_groups; for (const auto &node : graph->GetDirectNode()) { - std::string node_type; - GE_CHK_STATUS_RET(GetOriginalType(node, node_type), - "[Get][OriginalType] of node in graph:%s failed.", graph->GetName().c_str()); - if (kMergeOpTypes.count(node_type) == 0) { + if (kMergeOpTypes.count(NodeUtils::GetNodeType(node)) == 0) { continue; } @@ -64,6 +49,51 @@ Status MarkForceUnknownForCondPass::Run(ComputeGraphPtr graph) { return SUCCESS; } +/// +/// @brief Deal with Switch node for LoopCond +/// @param [in] Switch node +/// @param [in] dest span +/// @param [out] Search queue +/// @return true: Switch In while loop / false: Not in while Loop. +/// +bool MarkForceUnknownForCondPass::DealWithLoopSwitch(const NodePtr &node, uint32_t dst_span, + std::queue> search_queue) { + /// LoopCond --->\. + /// \. + /// Enter-----------+ \. + /// +--> Merge --> Switch --> Exit + /// NextIteration---+ + const auto is_loop_op = [](const NodePtr &n) { + return NodeUtils::GetNodeType(n) == LOOPCOND; + }; + const auto is_exit_op = [](const NodePtr &n) { + return kExitOpTypes.count(NodeUtils::GetNodeType(n)) > 0; + }; + + const auto src_nodes = node->GetInAllNodes(); + const auto dst_nodes = node->GetOutAllNodes(); + if (std::none_of(src_nodes.begin(), src_nodes.end(), is_loop_op) && + std::none_of(dst_nodes.begin(), dst_nodes.end(), is_exit_op)) { + return false; + } + + for (const auto &m : src_nodes) { + if (kMergeOpTypes.count(NodeUtils::GetNodeType(m)) > 0) { + for (const auto &n : m->GetInAllNodes()) { + if (kNextIterationOpTypes.count(NodeUtils::GetNodeType(n)) > 0) { + continue; + } + + search_queue.push({n, dst_span}); + GELOGD("Travel in Loop: %s <-- %s <-- %s, span is: %u", node->GetName().c_str(), m->GetName().c_str(), + n->GetName().c_str(), dst_span); + } + } + } + + return true; +} + /// /// @brief Mark force unknown shape for Switch node /// @param [in] merge node @@ -72,6 +102,7 @@ Status MarkForceUnknownForCondPass::Run(ComputeGraphPtr graph) { /// void MarkForceUnknownForCondPass::MarkUnknownForSwitch(const NodePtr &node, std::vector &switch_group) { // Switch --> {Switch --> Merge} --> Merge + GELOGD("Search Switch node for Merge: %s", node->GetName().c_str()); std::unordered_set nodes_seen; std::queue> search_queue({{node, 0}}); while (!search_queue.empty()) { @@ -79,43 +110,25 @@ void MarkForceUnknownForCondPass::MarkUnknownForSwitch(const NodePtr &node, std: const auto dst_span = search_queue.front().second; search_queue.pop(); - // Switch --> Identity --> Constant - for (const auto &in_node : dst_node->GetInControlNodes()) { - if (nodes_seen.count(in_node) > 0) { - GELOGD("Travel node: %s, Skip already seen node: %s", dst_node->GetName().c_str(), in_node->GetName().c_str()); - continue; - } - nodes_seen.insert(in_node); - - if (in_node->GetType() == IDENTITY) { - GELOGD("Travel node: %s, In control: %s, span is: %u", dst_node->GetName().c_str(), - in_node->GetName().c_str(), dst_span); - search_queue.push({in_node, dst_span}); - } - } - - for (const auto &in_node : dst_node->GetInDataNodes()) { + for (const auto &in_node : dst_node->GetInAllNodes()) { if (nodes_seen.count(in_node) > 0) { GELOGD("Travel node: %s, Skip already seen node: %s", dst_node->GetName().c_str(), in_node->GetName().c_str()); continue; } nodes_seen.insert(in_node); - std::string node_type; - (void)GetOriginalType(in_node, node_type); + const std::string node_type = NodeUtils::GetNodeType(in_node); GELOGD("Travel node: %s, %s node: %s, span is: %u", dst_node->GetName().c_str(), node_type.c_str(), in_node->GetName().c_str(), dst_span); if (kSwitchOpTypes.count(node_type) > 0) { // Switch input node. + if (DealWithLoopSwitch(in_node, dst_span, search_queue)) { + continue; + } + if (dst_span > 0) { search_queue.push({in_node, dst_span - 1}); } else { - const auto &all_in_nodes = in_node->GetInDataNodes(); - if (std::any_of(all_in_nodes.begin(), all_in_nodes.end(), IsSwitchInLoop)) { - GELOGW("Travel node: %s, %s node: %s, Skip LoopCond switch", dst_node->GetName().c_str(), node_type.c_str(), - in_node->GetName().c_str()); - } else { - switch_group.emplace_back(in_node); - } + switch_group.emplace_back(in_node); } } else if (kMergeOpTypes.count(node_type) > 0) { // Merge input node. search_queue.push({in_node, dst_span + 1}); diff --git a/ge/graph/passes/mark_force_unknown_for_cond_pass.h b/ge/graph/passes/mark_force_unknown_for_cond_pass.h index 528a8fdc..d2be9a9e 100644 --- a/ge/graph/passes/mark_force_unknown_for_cond_pass.h +++ b/ge/graph/passes/mark_force_unknown_for_cond_pass.h @@ -19,12 +19,23 @@ #include "inc/graph_pass.h" +#include + namespace ge { class MarkForceUnknownForCondPass : public GraphPass { public: Status Run(ComputeGraphPtr graph); private: + /// + /// @brief Deal with Switch node for LoopCond + /// @param [in] Switch node + /// @param [in] dest span + /// @param [out] Search queue + /// @return true: Switch In while loop / false: Not in while Loop. + /// + bool DealWithLoopSwitch(const NodePtr &node, uint32_t dst_span, std::queue> search_queue); + /// /// @brief Mark force unknown shape for Switch node /// @param [in] merge node diff --git a/ge/graph/passes/switch_to_stream_switch_pass.cc b/ge/graph/passes/switch_to_stream_switch_pass.cc index 77a7c9db..7fecae31 100644 --- a/ge/graph/passes/switch_to_stream_switch_pass.cc +++ b/ge/graph/passes/switch_to_stream_switch_pass.cc @@ -395,8 +395,9 @@ NodePtr SwitchToStreamSwitchPass::CreateStreamSwitchNode(const ComputeGraphPtr & peer_cond_anchor->GetOwnerNode()->GetName().c_str(), stream_switch->GetName().c_str()); int64_t group_index = -1; - (void)AttrUtils::GetInt(switch_node->GetOpDesc(), ATTR_NAME_CONTROL_FLOW_GROUP, group_index); - SetControlFlowGroup(stream_switch, group_index); + if (AttrUtils::GetInt(switch_node->GetOpDesc(), ATTR_NAME_CONTROL_FLOW_GROUP, group_index)) { + SetControlFlowGroup(stream_switch, group_index); + } return stream_switch; } diff --git a/ge/hybrid/executor/node_state.cc b/ge/hybrid/executor/node_state.cc index 468c84e6..4b0d0c44 100644 --- a/ge/hybrid/executor/node_state.cc +++ b/ge/hybrid/executor/node_state.cc @@ -326,17 +326,37 @@ std::shared_ptr NodeState::GetTaskContext() { } void NodeState::SavePersistTensor(int input_idx, const TensorValue &tensor) { - if (node_item_->root_data_.count(input_idx) > 0) { + const auto is_persist_tensor = [](const std::map> &items, int idx) { + const auto is_exist = [&idx](const std::pair> &items) { + return items.second.count(idx) > 0; + }; + return std::any_of(items.begin(), items.end(), is_exist); + }; + + if (is_persist_tensor(node_item_->root_data_, input_idx)) { GELOGD("[%s] Save Root input tensor: %d", GetName().c_str(), input_idx); root_tensor_values_[input_idx] = tensor; - } - - if (node_item_->enter_data_.count(input_idx) > 0) { + } else if (is_persist_tensor(node_item_->enter_data_, input_idx)) { GELOGD("[%s] Save Enter input tensor: %d", GetName().c_str(), input_idx); root_tensor_values_[input_idx] = tensor; } } +void NodeState::UpdatePersistTensor() { + const auto update_tensor = [&](const std::map> &items) { + for (const auto &item : items) { + for (const auto idx : item.second) { + UpdatePersistTensor(idx); + } + } + }; + + update_tensor(node_item_->root_data_); + if (iteration_count_ > 0) { + update_tensor(node_item_->enter_data_); + } +} + void NodeState::UpdatePersistTensor(int input_idx) { const auto it = root_tensor_values_.find(input_idx); if (it == root_tensor_values_.end()) { @@ -363,16 +383,9 @@ void NodeState::ResetContext(uint64_t iteration) { data_scheduled_ = static_cast(node_item_->root_data_.size()); ctrl_scheduled_ = static_cast(node_item_->root_ctrl_.size()); - for (auto item : node_item_->root_data_) { - UpdatePersistTensor(item.first); - } - if (iteration > 0) { data_scheduled_ += static_cast(node_item_->enter_data_.size()); ctrl_scheduled_ += static_cast(node_item_->enter_ctrl_.size()); - for (auto item : node_item_->enter_data_) { - UpdatePersistTensor(item.first); - } } iteration_count_ = iteration; diff --git a/ge/hybrid/executor/node_state.h b/ge/hybrid/executor/node_state.h index 727402f1..f1cec215 100644 --- a/ge/hybrid/executor/node_state.h +++ b/ge/hybrid/executor/node_state.h @@ -132,6 +132,7 @@ struct NodeState { void RunNextIteration(); void SavePersistTensor(int input_idx, const TensorValue &tensor); + void UpdatePersistTensor(); Status NodeScheduled(const std::function &ready) const; diff --git a/ge/hybrid/model/node_item.cc b/ge/hybrid/model/node_item.cc index 250562ce..8e87c6e2 100644 --- a/ge/hybrid/model/node_item.cc +++ b/ge/hybrid/model/node_item.cc @@ -395,11 +395,13 @@ void NodeItem::SetDataSend(NodeItem *node_item, int anchor_index) { data_send_.emplace(node_item); node_item->data_recv_[this] = anchor_index; if (is_root_node_) { - node_item->root_data_[anchor_index] = this; + auto &data_anchors = node_item->root_data_[this]; + data_anchors.emplace(anchor_index); } // If Enter feed Not Merge, take as root Node. if (IsEnterOp() && (node_item->node_type != STREAMMERGE)) { - node_item->enter_data_[anchor_index] = this; + auto &data_anchors = node_item->enter_data_[this]; + data_anchors.emplace(anchor_index); } GELOGI("Node[%s] will control node[%s]", NodeName().c_str(), node_item->NodeName().c_str()); } diff --git a/ge/hybrid/model/node_item.h b/ge/hybrid/model/node_item.h index 12775b00..f6dcdcf6 100644 --- a/ge/hybrid/model/node_item.h +++ b/ge/hybrid/model/node_item.h @@ -148,9 +148,9 @@ struct NodeItem { int64_t frame_index_ = -1; int64_t parent_frame_ = -1; std::set root_ctrl_; // Recv ctrl from root node - std::map root_data_; // Recv data from root node + std::map> root_data_; // Recv data from root node std::set enter_ctrl_; // Recv ctrl from Enter node - std::map enter_data_; // Recv data from Enter node + std::map> enter_data_; // Recv data from Enter node std::set data_send_; // Send data notify to std::map data_recv_; // Recv data notify from std::set ctrl_send_; // Send ctrl notify to diff --git a/ge/hybrid/node_executor/node_executor.cc b/ge/hybrid/node_executor/node_executor.cc index 9e9354d9..eeb5ba20 100755 --- a/ge/hybrid/node_executor/node_executor.cc +++ b/ge/hybrid/node_executor/node_executor.cc @@ -39,6 +39,7 @@ const char *const kEngineNameHostCpu = "DNN_VM_HOST_CPU_OP_STORE"; Status NodeExecutor::PrepareTask(NodeTask &task, TaskContext &context) const { GE_CHK_STATUS_RET_NOLOG(context.AllocateOutputs()); GE_CHK_STATUS_RET_NOLOG(context.AllocateWorkspaces()); + GE_CHK_STATUS_RET_NOLOG(context.UpdatePersistTensor()); GE_CHK_STATUS_RET_NOLOG(task.UpdateArgs(context)); return SUCCESS; } diff --git a/ge/hybrid/node_executor/task_context.cc b/ge/hybrid/node_executor/task_context.cc index c0464c87..3c288981 100644 --- a/ge/hybrid/node_executor/task_context.cc +++ b/ge/hybrid/node_executor/task_context.cc @@ -470,6 +470,12 @@ Status TaskContext::PropagateOutputs() { return SUCCESS; } +Status TaskContext::UpdatePersistTensor() { + GE_CHECK_NOTNULL(node_state_); + node_state_->UpdatePersistTensor(); + return SUCCESS; +} + const void *TaskContext::GetVarBaseAddr() { return execution_context_->model->GetVarMemBase(); } diff --git a/ge/hybrid/node_executor/task_context.h b/ge/hybrid/node_executor/task_context.h index c96e194e..cff5d680 100644 --- a/ge/hybrid/node_executor/task_context.h +++ b/ge/hybrid/node_executor/task_context.h @@ -78,6 +78,7 @@ class TaskContext { Status AllocateOutputs(AllocationAttr *attr = nullptr); Status AllocateWorkspaces(); Status AllocateWorkspace(size_t size, void **buffer, void *ori_addr = nullptr); + Status UpdatePersistTensor(); bool IsTraceEnabled() const; From d4828ea130d310773161d5f1b8ccc313f283cd1a Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Sat, 26 Jun 2021 15:00:53 +0800 Subject: [PATCH 08/50] UpdatePersistTensor from ExecutionEngine --- ge/hybrid/executor/node_state.cc | 4 ++++ ge/hybrid/executor/worker/execution_engine.cc | 1 + ge/hybrid/node_executor/node_executor.cc | 1 - ge/hybrid/node_executor/task_context.cc | 11 +---------- ge/hybrid/node_executor/task_context.h | 1 - 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/ge/hybrid/executor/node_state.cc b/ge/hybrid/executor/node_state.cc index 4b0d0c44..7ab7b536 100644 --- a/ge/hybrid/executor/node_state.cc +++ b/ge/hybrid/executor/node_state.cc @@ -333,6 +333,10 @@ void NodeState::SavePersistTensor(int input_idx, const TensorValue &tensor) { return std::any_of(items.begin(), items.end(), is_exist); }; + if (root_tensor_values_.count(input_idx) > 0) { + return; + } + if (is_persist_tensor(node_item_->root_data_, input_idx)) { GELOGD("[%s] Save Root input tensor: %d", GetName().c_str(), input_idx); root_tensor_values_[input_idx] = tensor; diff --git a/ge/hybrid/executor/worker/execution_engine.cc b/ge/hybrid/executor/worker/execution_engine.cc index 8eecbc80..d4c73f58 100755 --- a/ge/hybrid/executor/worker/execution_engine.cc +++ b/ge/hybrid/executor/worker/execution_engine.cc @@ -375,6 +375,7 @@ Status ExecutionEngine::DoExecuteAsync(NodeState &node_state, RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[PrepareTask] Start"); GE_CHK_STATUS_RET(executor->PrepareTask(*task, task_context), "[Prepare][Task] for [%s] failed.", node_state.GetName().c_str()); + node_state.UpdatePersistTensor(); RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[PrepareTask] End"); GELOGD("[%s] Done task preparation successfully.", node_state.GetName().c_str()); diff --git a/ge/hybrid/node_executor/node_executor.cc b/ge/hybrid/node_executor/node_executor.cc index eeb5ba20..9e9354d9 100755 --- a/ge/hybrid/node_executor/node_executor.cc +++ b/ge/hybrid/node_executor/node_executor.cc @@ -39,7 +39,6 @@ const char *const kEngineNameHostCpu = "DNN_VM_HOST_CPU_OP_STORE"; Status NodeExecutor::PrepareTask(NodeTask &task, TaskContext &context) const { GE_CHK_STATUS_RET_NOLOG(context.AllocateOutputs()); GE_CHK_STATUS_RET_NOLOG(context.AllocateWorkspaces()); - GE_CHK_STATUS_RET_NOLOG(context.UpdatePersistTensor()); GE_CHK_STATUS_RET_NOLOG(task.UpdateArgs(context)); return SUCCESS; } diff --git a/ge/hybrid/node_executor/task_context.cc b/ge/hybrid/node_executor/task_context.cc index 3c288981..4ecc1558 100644 --- a/ge/hybrid/node_executor/task_context.cc +++ b/ge/hybrid/node_executor/task_context.cc @@ -460,22 +460,12 @@ Status TaskContext::PropagateOutputs() { subgraph_context_->all_inputs_[input_offset].SetName( node_item_->NodeName() + "_in_" + std::to_string(dst_input_idx)); } - - auto dst_node_state = subgraph_context_->GetOrCreateNodeState(dst_node_item); - GE_CHECK_NOTNULL(dst_node_state); - dst_node_state->SavePersistTensor(dst_input_idx, *tensor); } } (void)guard; return SUCCESS; } -Status TaskContext::UpdatePersistTensor() { - GE_CHECK_NOTNULL(node_state_); - node_state_->UpdatePersistTensor(); - return SUCCESS; -} - const void *TaskContext::GetVarBaseAddr() { return execution_context_->model->GetVarMemBase(); } @@ -501,6 +491,7 @@ void TaskContext::ReleaseInputsAndOutputs() { void TaskContext::ReleaseInput(int index) { auto input_tensor = MutableInput(index); if (input_tensor != nullptr) { + node_state_->SavePersistTensor(index, *input_tensor); input_tensor->Destroy(); GELOGD("[%s] Tensor of input[%d] released", GetNodeName(), index); } diff --git a/ge/hybrid/node_executor/task_context.h b/ge/hybrid/node_executor/task_context.h index cff5d680..c96e194e 100644 --- a/ge/hybrid/node_executor/task_context.h +++ b/ge/hybrid/node_executor/task_context.h @@ -78,7 +78,6 @@ class TaskContext { Status AllocateOutputs(AllocationAttr *attr = nullptr); Status AllocateWorkspaces(); Status AllocateWorkspace(size_t size, void **buffer, void *ori_addr = nullptr); - Status UpdatePersistTensor(); bool IsTraceEnabled() const; From e2cb3778f0e4724cec833363a878e6b28093ec04 Mon Sep 17 00:00:00 2001 From: wq160 Date: Thu, 24 Jun 2021 11:42:57 +0800 Subject: [PATCH 09/50] add infer_base and infer value range --- ge/CMakeLists.txt | 4 + .../formats/utils/formats_trans_utils.cc | 19 + ge/common/formats/utils/formats_trans_utils.h | 2 + ge/graph/passes/constant_folding_pass.cc | 26 +- ge/graph/passes/constant_folding_pass.h | 5 + ge/graph/passes/folding_pass.cc | 8 - ge/graph/passes/folding_pass.h | 2 - ge/graph/passes/infer_base_pass.cc | 386 ++++++++++++ ge/graph/passes/infer_base_pass.h | 65 ++ ge/graph/passes/infer_value_range_pass.cc | 500 +++++++++++++++ ge/graph/passes/infer_value_range_pass.h | 49 ++ ge/graph/preprocess/graph_preprocess.cc | 3 + metadef | 2 +- tests/ut/ge/CMakeLists.txt | 7 +- .../graph/passes/infer_base_pass_unittest.cc | 359 +++++++++++ .../passes/infer_value_range_pass_unittest.cc | 583 ++++++++++++++++++ 16 files changed, 1997 insertions(+), 23 deletions(-) create mode 100644 ge/graph/passes/infer_base_pass.cc create mode 100644 ge/graph/passes/infer_base_pass.h create mode 100644 ge/graph/passes/infer_value_range_pass.cc create mode 100644 ge/graph/passes/infer_value_range_pass.h create mode 100644 tests/ut/ge/graph/passes/infer_base_pass_unittest.cc create mode 100644 tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc diff --git a/ge/CMakeLists.txt b/ge/CMakeLists.txt index 2b9122da..dc80597c 100755 --- a/ge/CMakeLists.txt +++ b/ge/CMakeLists.txt @@ -298,7 +298,9 @@ set(TRAIN_SRC_LIST "graph/passes/hccl_continuous_memcpy_pass.cc" "graph/passes/identity_pass.cc" "graph/passes/ref_identity_delete_op_pass.cc" + "graph/passes/infer_base_pass.cc" "graph/passes/infershape_pass.cc" + "graph/passes/infer_value_range_pass.cc" "graph/passes/iterator_op_pass.cc" "graph/passes/link_gen_mask_nodes_pass.cc" "graph/passes/merge_pass.cc" @@ -547,7 +549,9 @@ set(INFER_SRC_LIST "graph/passes/shape_operate_op_remove_pass.cc" "graph/passes/assert_pass.cc" "graph/passes/dropout_pass.cc" + "graph/passes/infer_base_pass.cc" "graph/passes/infershape_pass.cc" + "graph/passes/infer_value_range_pass.cc" "graph/passes/unused_const_pass.cc" "graph/passes/permute_pass.cc" "graph/passes/ctrl_edge_transfer_pass.cc" diff --git a/ge/common/formats/utils/formats_trans_utils.cc b/ge/common/formats/utils/formats_trans_utils.cc index 052951ce..db1812d0 100755 --- a/ge/common/formats/utils/formats_trans_utils.cc +++ b/ge/common/formats/utils/formats_trans_utils.cc @@ -49,6 +49,25 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY std::string ShapeToString(const s return JoinToString(shape); } +GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY +std::string RangeToString(const std::vector> &ranges) { + bool first = true; + std::stringstream ss; + ss << "["; + for (const auto &range : ranges) { + if (first) { + first = false; + } else { + ss << ","; + } + ss << "{"; + ss << range.first << "," << range.second; + ss << "}"; + } + ss << "]"; + return ss.str(); +} + int64_t GetItemNumByShape(const std::vector &shape) { int64_t num = 1; for (auto dim : shape) { diff --git a/ge/common/formats/utils/formats_trans_utils.h b/ge/common/formats/utils/formats_trans_utils.h index 848e8b3a..64f9f820 100755 --- a/ge/common/formats/utils/formats_trans_utils.h +++ b/ge/common/formats/utils/formats_trans_utils.h @@ -54,6 +54,8 @@ std::string ShapeToString(const GeShape &shape); std::string ShapeToString(const std::vector &shape); +std::string RangeToString(const std::vector> &ranges); + int64_t GetItemNumByShape(const std::vector &shape); bool CheckShapeValid(const std::vector &shape, const int64_t expect_dims); diff --git a/ge/graph/passes/constant_folding_pass.cc b/ge/graph/passes/constant_folding_pass.cc index 6607388f..53b14fd5 100644 --- a/ge/graph/passes/constant_folding_pass.cc +++ b/ge/graph/passes/constant_folding_pass.cc @@ -20,17 +20,23 @@ #include "external/graph/operator_factory.h" #include "graph/utils/node_utils.h" #include "graph/utils/type_utils.h" +#include "ge_local_engine/engine/host_cpu_engine.h" #include "init/gelib.h" namespace ge { const int64_t kStartCallNum = 1; const std::string kKernelLibName = "aicpu_tf_kernel"; -// tf_kernel.json opsFlag config const std::string kOpsFlagClose = "0"; -Status RunOpKernelWithCheck(NodePtr &node, - const vector &inputs, - std::vector &outputs) { +const map> &ConstantFoldingPass::GetGeConstantFoldingPerfStatistic() const { + return statistic_of_ge_constant_folding_; +} +const map> &ConstantFoldingPass::GetOpConstantFoldingPerfStatistic() const { + return statistic_of_op_constant_folding_; +} + +Status ConstantFoldingPass::RunOpKernelWithCheck(NodePtr &node, const vector &inputs, + std::vector &outputs) { std::shared_ptr instance_ptr = ge::GELib::GetInstance(); if ((instance_ptr == nullptr) || (!instance_ptr->InitFlag())) { GELOGE(GE_CLI_GE_NOT_INITIALIZED, "[Check][Param] GE is not initialized or is finalized."); @@ -47,15 +53,13 @@ Status RunOpKernelWithCheck(NodePtr &node, if (ops_flag == kOpsFlagClose) { return UNSUPPORTED; } - return FoldingPass::RunOpKernel(node, inputs, outputs); + return RunOpKernel(node, inputs, outputs); } -const map> &ConstantFoldingPass::GetGeConstantFoldingPerfStatistic() const { - return statistic_of_ge_constant_folding_; -} - -const map> &ConstantFoldingPass::GetOpConstantFoldingPerfStatistic() const { - return statistic_of_op_constant_folding_; +Status ConstantFoldingPass::RunOpKernel(NodePtr &node, + const vector &inputs, + std::vector &outputs) { + return HostCpuEngine::GetInstance().Run(node, inputs, outputs); } Status ConstantFoldingPass::Run(ge::NodePtr &node) { diff --git a/ge/graph/passes/constant_folding_pass.h b/ge/graph/passes/constant_folding_pass.h index 703e6edd..7de48a17 100644 --- a/ge/graph/passes/constant_folding_pass.h +++ b/ge/graph/passes/constant_folding_pass.h @@ -28,6 +28,11 @@ class ConstantFoldingPass : public FoldingPass { Status Run(ge::NodePtr &node) override; const std::map> &GetGeConstantFoldingPerfStatistic() const; const std::map> &GetOpConstantFoldingPerfStatistic() const; + + static Status RunOpKernel(NodePtr &node, const vector &inputs, vector &outputs); + static Status RunOpKernelWithCheck(NodePtr &node, const vector &inputs, + std::vector &outputs); + private: std::map> statistic_of_op_constant_folding_; std::map> statistic_of_ge_constant_folding_; diff --git a/ge/graph/passes/folding_pass.cc b/ge/graph/passes/folding_pass.cc index c0a0f2a2..819c3b40 100755 --- a/ge/graph/passes/folding_pass.cc +++ b/ge/graph/passes/folding_pass.cc @@ -28,8 +28,6 @@ #include "inc/kernel.h" #include "inc/kernel_factory.h" #include "graph/debug/ge_attr_define.h" -#include "ge_local_engine/engine/host_cpu_engine.h" - namespace ge { namespace folding_pass { @@ -123,12 +121,6 @@ NodePtr AddIdentityNodeToGraph(const std::string &name, const GeTensorDesc &tens } } // namespace -Status FoldingPass::RunOpKernel(NodePtr &node, - const vector &inputs, - std::vector &outputs) { - return HostCpuEngine::GetInstance().Run(node, inputs, outputs); -} - Status FoldingPass::Folding(NodePtr &node, vector &outputs) { GE_CHECK_NOTNULL(node); GELOGD("begin folding node:%s", node->GetName().c_str()); diff --git a/ge/graph/passes/folding_pass.h b/ge/graph/passes/folding_pass.h index 745cffd7..c461ff5c 100755 --- a/ge/graph/passes/folding_pass.h +++ b/ge/graph/passes/folding_pass.h @@ -34,8 +34,6 @@ bool IsNoNeedConstantFolding(const NodePtr &node); using IndexsToAnchors = std::map>; class FoldingPass : public BaseNodePass { - public: - static Status RunOpKernel(NodePtr &node, const vector &inputs, vector &outputs); protected: Status Folding(NodePtr &node, vector &outputs); private: diff --git a/ge/graph/passes/infer_base_pass.cc b/ge/graph/passes/infer_base_pass.cc new file mode 100644 index 00000000..27eb0c54 --- /dev/null +++ b/ge/graph/passes/infer_base_pass.cc @@ -0,0 +1,386 @@ +/** + * Copyright 2021 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 "infer_base_pass.h" +#include "common/ge/ge_util.h" +#include "common/util/error_manager/error_manager.h" +#include "framework/common/debug/ge_log.h" +#include "framework/common/util.h" +#include "graph/debug/ge_attr_define.h" +#include "graph/utils/graph_utils.h" +#include "graph/utils/node_utils.h" +#include "graph/utils/tensor_utils.h" +#include "graph/utils/type_utils.h" + +namespace ge { +namespace { +graphStatus FindValidSubgraphNetoutput(const ConstNodePtr &node, const ComputeGraphPtr &sub_graph, NodePtr &netoutput) { + auto sub_nodes = sub_graph->GetDirectNode(); + for (size_t i = sub_nodes.size(); i > 0; --i) { + auto sub_node = sub_nodes.at(i - 1); + if (sub_node->GetType() == NETOUTPUT) { + if (sub_node == nullptr) { + REPORT_INNER_ERROR("E19999", "NetOutput node is null in subgraph %s, parent node %s.", + sub_graph->GetName().c_str(), node->GetName().c_str()); + GELOGE(GRAPH_FAILED, "[Check][Param] NetOutput node is null on sub graph %s, parent node %s", + sub_graph->GetName().c_str(), node->GetName().c_str()); + return GRAPH_FAILED; + } + auto sub_node_opdesc = sub_node->GetOpDesc(); + if (sub_node_opdesc == nullptr) { + REPORT_INNER_ERROR("E19999", "Invalid NetOutput node in subgraph %s, parent node %s, no OpDesc on it", + sub_graph->GetName().c_str(), node->GetName().c_str()); + GELOGE(GRAPH_FAILED, "[Check][Param] Invalid NetOutput node on sub graph %s, parent node %s, no OpDesc on it", + sub_graph->GetName().c_str(), node->GetName().c_str()); + return GRAPH_FAILED; + } + + netoutput = sub_node; + return GRAPH_SUCCESS; + } + } + + REPORT_INNER_ERROR("E19999", "Can not find the NetOutput node in subgraph %s, parent node %s", + sub_graph->GetName().c_str(), node->GetName().c_str()); + GELOGE(GRAPH_FAILED, "[Check][Param] Can not find the NetOutput node in subgraph %s, parent node %s", + sub_graph->GetName().c_str(), node->GetName().c_str()); + return GRAPH_FAILED; +} +} // namespace + +Status InferBasePass::Run(NodePtr &node) { + GE_CHECK_NOTNULL(node); + GE_CHECK_NOTNULL(node->GetOpDesc()); + + bool need_infer = NeedInfer(node); + if (!need_infer) { + GELOGD("Node %s does not need to infer.", node->GetName().c_str()); + return SUCCESS; + } + + std::set changed_nodes; + auto ret = InferAndUpdate(node, !OptionExists(kOptimizeAfterSubGraph), changed_nodes); + if (ret != GRAPH_SUCCESS) { + GELOGE(ret, "Infer and update for node %s failed! ret: %u", node->GetName().c_str(), ret); + return GRAPH_FAILED; + } + + AddChangedNodesImmediateRepass(changed_nodes); + return SUCCESS; +} + +bool InferBasePass::NeedInfer(const NodePtr &node) const { return true; } +void InferBasePass::AddChangedNodesImmediateRepass(const std::set &changed_nodes) { + for (const auto &node_ele : changed_nodes) { + AddImmediateRePassNode(node_ele); + } +} + +graphStatus InferBasePass::InferAndUpdate(NodePtr &node, bool before_subgraph, std::set &changed_nodes) { + graphStatus ret; + if (ContainsSubgraph(node)) { + if (before_subgraph) { + ret = UpdateTensorDescToSubgraphData(node); + } else { + ret = UpdateTensorDescToParentNodeOutput(node); + } + if (ret != GRAPH_SUCCESS) { + GELOGE(ret, "Update tensor desc failed between parent node %s and subgraphs. ret: %u", node->GetName().c_str(), + ret); + return ret; + } + } + + PrintInOutTensors(node, "before_infer"); + ret = Infer(node); + PrintInOutTensors(node, "after_infer"); + if (ret == GRAPH_NODE_NEED_REPASS) { + // if a node need re_pass, it is not necessary to update peer node input. + changed_nodes.insert(node); + return GRAPH_SUCCESS; + } else if (ret != GRAPH_SUCCESS && ret != GRAPH_NOT_CHANGED) { + GELOGE(ret, "Infer failed for node %s, ret: %u", node->GetName().c_str(), ret); + return ret; + } + + ret = UpdateTensorDescToPeerInputs(node, changed_nodes); + if (ret != GRAPH_SUCCESS) { + GELOGE(ret, "Node %s updates tensor desc to peer input nodes failed! ret: %u", node->GetName().c_str(), ret); + } + GELOGD("Node %s infer and update succeeded .", node->GetName().c_str()); + return ret; +} + +bool InferBasePass::ContainsSubgraph(const NodePtr &node) { + auto sub_graph_names = node->GetOpDesc()->GetSubgraphInstanceNames(); + return !sub_graph_names.empty(); +} + +graphStatus InferBasePass::UpdateTensorDescToPeerInputs(NodePtr &node, std::set &changed_nodes) { + auto op_desc = node->GetOpDesc(); + for (const auto &out_anchor : node->GetAllOutDataAnchors()) { + auto output_tensor = op_desc->MutableOutputDesc(out_anchor->GetIdx()); + for (const auto &peer_anchor : out_anchor->GetPeerInDataAnchors()) { + auto peer_anchor_opdesc = peer_anchor->GetOwnerNode()->GetOpDesc(); + if (peer_anchor_opdesc == nullptr) { + continue; + } + auto peer_input_desc = peer_anchor_opdesc->MutableInputDesc(peer_anchor->GetIdx()); + if (peer_input_desc == nullptr) { + continue; + } + + bool changed = false; + auto ret = UpdateTensorDesc(output_tensor, peer_input_desc, changed); + if (ret != GRAPH_SUCCESS) { + REPORT_CALL_ERROR("E19999", "Update peer input desc failed, node %s.", node->GetName().c_str()); + GELOGE(ret, "Update peer input desc failed, node %s.", node->GetName().c_str()); + return ret; + } + if (changed) { + changed_nodes.insert(peer_anchor->GetOwnerNode()); + GELOGD("Node %s update peer node succeeded, peer node %s is changed.", node->GetName().c_str(), + peer_anchor->GetOwnerNode()->GetName().c_str()); + } + } + } + return GRAPH_SUCCESS; +} + +std::vector InferBasePass::GetCurNodeSubgraphs(const NodePtr &node) { + std::vector cur_node_subgraph; + auto op_desc = node->GetOpDesc(); + auto sub_graph_names = op_desc->GetSubgraphInstanceNames(); + if (sub_graph_names.empty()) { + return cur_node_subgraph; + } + + auto root_graph = GraphUtils::FindRootGraph(node->GetOwnerComputeGraph()); + for (const auto &name : sub_graph_names) { + if (name.empty()) { + GELOGW("The node %s contains empty subgraph instance name", node->GetName().c_str()); + continue; + } + auto sub_graph = root_graph->GetSubgraph(name); + if (sub_graph == nullptr) { + GELOGW("The subgrpah %s for node %s is null.", name.c_str(), node->GetName().c_str()); + continue; + } + cur_node_subgraph.emplace_back(sub_graph); + } + return cur_node_subgraph; +} + +graphStatus InferBasePass::UpdateTensorDescToSubgraphData(NodePtr &node) { + auto op_desc = node->GetOpDesc(); + for (const auto &sub_graph : GetCurNodeSubgraphs(node)) { + for (const auto &node_sub : sub_graph->GetDirectNode()) { + if (node_sub->GetType() != DATA) { + continue; + } + + auto data_opdesc = node_sub->GetOpDesc(); + if (data_opdesc == nullptr) { + REPORT_INNER_ERROR("E19999", "Invalid data node on the sub graph %s parent node %s, no OpDesc", + sub_graph->GetName().c_str(), node->GetName().c_str()); + GELOGE(GRAPH_FAILED, "[Get][OpDesc] Invalid data node on the sub graph %s parent node %s, no OpDesc", + sub_graph->GetName().c_str(), node->GetName().c_str()); + return GRAPH_FAILED; + } + int ref_i; + if (!AttrUtils::GetInt(data_opdesc, ATTR_NAME_PARENT_NODE_INDEX, ref_i)) { + REPORT_INNER_ERROR("E19999", "Invalid data node on the sub graph %s parent node %s, no ref-index attribute", + sub_graph->GetName().c_str(), node->GetName().c_str()); + GELOGE(GRAPH_FAILED, "[Get][Int] Invalid data node on the sub graph %s parent node %s, no ref-index attribute", + sub_graph->GetName().c_str(), node->GetName().c_str()); + return GRAPH_FAILED; + } + GELOGD("Subgraph Data node ref_index is %d, parent node is %s.", ref_i, node->GetName().c_str()); + + // In multi-batch, data shape of subgraph is different, no need to refresh. + if (data_opdesc->HasAttr(ATTR_MBATCH_ORIGIN_INPUT_DIMS)) { + GELOGD("While updating subgraph data node, ignore node %s which is created by multi-dims", + data_opdesc->GetName().c_str()); + continue; + } + auto input_desc = op_desc->MutableInputDesc(ref_i); + if (input_desc == nullptr) { + REPORT_INNER_ERROR("E19999", + "The ref index(%d) on the data %s on the sub graph %s " + "parent node %s are incompatible, inputs num %u", + ref_i, node_sub->GetName().c_str(), sub_graph->GetName().c_str(), node->GetName().c_str(), + node->GetAllInDataAnchorsSize()); + GELOGE(GRAPH_FAILED, + "[Call][MutableInputDesc] The ref index(%d) on the data %s on the sub graph %s " + "parent node %s are incompatible, inputs num %u", + ref_i, node_sub->GetName().c_str(), sub_graph->GetName().c_str(), node->GetName().c_str(), + node->GetAllInDataAnchorsSize()); + return GRAPH_FAILED; + } + GELOGI("Ref index is %d, input_desc dtype is %d, node name is %s", ref_i, input_desc->GetDataType(), + node->GetName().c_str()); + + bool has_tensor_desc_changed = false; + auto data_input_td = data_opdesc->MutableInputDesc(0); + auto ret = UpdateTensorDesc(input_desc, data_input_td, has_tensor_desc_changed); + if (ret != GRAPH_SUCCESS) { + REPORT_CALL_ERROR("E19999", "Failed to update input desc of data %s on the sub graph %s parent node %s", + node_sub->GetName().c_str(), sub_graph->GetName().c_str(), node->GetName().c_str()); + GELOGE(GRAPH_FAILED, "[Update][InputDesc] of data %s on the sub graph %s parent node %s failed", + node_sub->GetName().c_str(), sub_graph->GetName().c_str(), node->GetName().c_str()); + return ret; + } + + auto data_output_td = data_opdesc->MutableOutputDesc(0); + ret = UpdateTensorDesc(input_desc, data_output_td, has_tensor_desc_changed); + if (ret != GRAPH_SUCCESS) { + REPORT_CALL_ERROR("E19999", "Failed to update output desc of data %s on the sub graph %s parent node %s", + node_sub->GetName().c_str(), sub_graph->GetName().c_str(), node->GetName().c_str()); + GELOGE(GRAPH_FAILED, "[Update][OutputDesc] of data %s on the sub graph %s parent node %s failed", + node_sub->GetName().c_str(), sub_graph->GetName().c_str(), node->GetName().c_str()); + return ret; + } + GELOGD("Parent node %s update subgraph data %s input and output succeed.", node->GetName().c_str(), + data_opdesc->GetName().c_str()); + } + } + return GRAPH_SUCCESS; +} + +graphStatus InferBasePass::UpdateTensorDescToParentNodeOutput(NodePtr &node) { + std::vector> ref_out_tensors(node->GetAllOutDataAnchorsSize()); + + for (const auto &sub_graph : GetCurNodeSubgraphs(node)) { + NodePtr netoutput; + auto ret = FindValidSubgraphNetoutput(node, sub_graph, netoutput); + if (ret != GRAPH_SUCCESS) { + return ret; + } + + auto netoutput_opdesc = netoutput->GetOpDesc(); + for (auto &netoutput_in_anchor : netoutput->GetAllInDataAnchors()) { + auto netoutput_in_desc = netoutput_opdesc->MutableInputDesc(netoutput_in_anchor->GetIdx()); + if (netoutput_in_desc == nullptr) { + REPORT_INNER_ERROR("E19999", + "Invalid NetOutput node on sub graph %s, parent node %s, can not find input tensor %d", + sub_graph->GetName().c_str(), node->GetName().c_str(), netoutput_in_anchor->GetIdx()); + GELOGE(GRAPH_FAILED, + "[Get][Tensor] Invalid NetOutput node on sub graph %s, parent node %s, can not find input tensor %d", + sub_graph->GetName().c_str(), node->GetName().c_str(), netoutput_in_anchor->GetIdx()); + return GRAPH_FAILED; + } + GELOGI("Netoutput in anchor index is %d, input tensor dim is %zu", netoutput_in_anchor->GetIdx(), + netoutput_in_desc->GetShape().GetDimNum()); + int ref_i; + if (!AttrUtils::GetInt(netoutput_in_desc, ATTR_NAME_PARENT_NODE_INDEX, ref_i)) { + // if there is no ref index on the TensorDesc, it means the output data will be ignored outer. + continue; + } + GELOGI("Parent node index of edge desc is %d", ref_i); + if (ref_i < 0 || static_cast(ref_i) >= node->GetAllOutDataAnchorsSize()) { + REPORT_INNER_ERROR("E19999", + "Invalid ref_index %d of parent node %s, ref_index should less than %u.", ref_i, + node->GetName().c_str(), node->GetAllOutDataAnchorsSize()); + GELOGE(GRAPH_FAILED, + "[Get][Ref_index] Invalid ref_index %d of parent node %s, ref_index should less than %u.", ref_i, + node->GetName().c_str(), node->GetAllOutDataAnchorsSize()); + return GRAPH_FAILED; + } + ref_out_tensors[ref_i].emplace_back(netoutput_in_desc); + } + } + + return UpdateParentNodeContainsSubgraphs(node, ref_out_tensors); +} + +graphStatus InferBasePass::UpdateParentNodeContainsSubgraphs( + NodePtr &node, const std::vector> &ref_out_tensors) { + for (size_t i = 0; i < ref_out_tensors.size(); i++) { + if (ref_out_tensors[i].empty()) { + REPORT_CALL_ERROR("E19999", "Parent node %s ref_index %zu subgraph output tensor list is empty.", + node->GetName().c_str(), i); + GELOGE(GRAPH_FAILED, "[Param][check] Parent node %s ref_index %zu subgraph output tensor list is empty.", + node->GetName().c_str(), i); + return GRAPH_FAILED; + } + auto node_op_desc = node->GetOpDesc(); + auto node_output_td = node_op_desc->MutableOutputDesc(i); + if (node_output_td == nullptr) { + REPORT_CALL_ERROR("E19999", "Node %s output %zu tensor desc is null.", node->GetName().c_str(), i); + GELOGE(GRAPH_FAILED, "[Param][check] Node %s output %zu tensor desc is null.", node->GetName().c_str(), i); + return GRAPH_FAILED; + } + + graphStatus ret; + if (node_op_desc->HasAttr(ATTR_NAME_BATCH_NUM)) { + ret = UpdateOutputFromSubgraphsForMultiDims(ref_out_tensors[i], node_output_td); + } else { + ret = UpdateOutputFromSubgraphs(ref_out_tensors[i], node_output_td); + } + if (ret != GRAPH_SUCCESS) { + REPORT_CALL_ERROR("E19999", "Node %s update output %zu tensor desc failed. ret: %u", node->GetName().c_str(), i, + ret); + GELOGE(GRAPH_FAILED, "[Param][check] Node %s update output %zu tensor desc failed. ret: %u", + node->GetName().c_str(), i, ret); + return ret; + } + GELOGD("Parent node %s successfully updated the output tensors from subgraphs.", node->GetName().c_str()); + } + return GRAPH_SUCCESS; +} + +void InferBasePass::PrintInOutTensors(const NodePtr &node, const std::string &phase) { + if (!IsLogEnable(GE, DLOG_DEBUG)) { + return; + } + if (node == nullptr) { + REPORT_INNER_ERROR("E19999", "Param node is nullptr, check invalid"); + GELOGE(GRAPH_FAILED, "[Check][Param] node is null"); + return; + } + ge::OpDescPtr op_desc = node->GetOpDesc(); + GE_IF_BOOL_EXEC(op_desc == nullptr, REPORT_INNER_ERROR("E19999", "Node has no opdesc, check invalid"); + GELOGE(GRAPH_FAILED, "[Get][OpDesc] op_desc is null."); return ); + std::stringstream ss; + ss << "{"; + int32_t in_idx = 0; + for (const auto &input_desc : op_desc->GetAllInputsDescPtr()) { + if (input_desc == nullptr) { + in_idx++; + continue; + } + if (in_idx > 0) { + ss << " "; + } + ss << "input_" << in_idx << " tensor: "; + ss << SerialTensorInfo(input_desc); + in_idx++; + } + int32_t out_idx = 0; + for (const auto &output_desc : op_desc->GetAllOutputsDescPtr()) { + if (output_desc == nullptr) { + out_idx++; + continue; + } + ss << " "; + ss << "output_" << out_idx << " tensor: "; + ss << SerialTensorInfo(output_desc); + out_idx++; + } + ss << "}"; + GELOGD("Infer tensor dump [%s], Node name: [%s]. %s", phase.c_str(), node->GetName().c_str(), ss.str().c_str()); +} +} // namespace ge diff --git a/ge/graph/passes/infer_base_pass.h b/ge/graph/passes/infer_base_pass.h new file mode 100644 index 00000000..3900b5db --- /dev/null +++ b/ge/graph/passes/infer_base_pass.h @@ -0,0 +1,65 @@ +/** + * Copyright 2021 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. + */ +#ifndef GE_GRAPH_PASSES_INFER_BASE_PASS_H_ +#define GE_GRAPH_PASSES_INFER_BASE_PASS_H_ + +#include "graph/passes/base_pass.h" + +namespace ge { +class InferBasePass : public BaseNodePass { + public: + Status Run(NodePtr &node) override; + graphStatus InferAndUpdate(NodePtr &node, bool before_subgraph, std::set &changed_nodes); + void PrintInOutTensors(const NodePtr &node, const std::string &phase); + + protected: + virtual std::string SerialTensorInfo(const GeTensorDescPtr &tensor_desc) const = 0; + virtual bool NeedInfer(const NodePtr &node) const; + virtual graphStatus Infer(NodePtr &node) = 0; + + /** + * Update the output TensorDesc by src TensorDesc. This will be called when updating peer node input desc. + * @param src, input TensorDesc + * @param dst, output TensorDesc to be updated + * @return + */ + virtual graphStatus UpdateTensorDesc(const GeTensorDescPtr &src, GeTensorDescPtr &dst, bool &changed) = 0; + + /** + * Update the output TensorDesc for nodes which contain subgraphs. + * In dynamic multi-dims/batch/images size scene, the update process maybe different, + * in which case, the `InferBasePass` will call method `UpdateOutputFromSubgraphsForMultiDims` instead. + * @param src, input TensorDesc from NetOutput nodes in all subgraphs + * @param dst, output TensorDesc to be updated + * @return + */ + virtual graphStatus UpdateOutputFromSubgraphs(const std::vector &src, + GeTensorDescPtr &dst) = 0; + virtual graphStatus UpdateOutputFromSubgraphsForMultiDims(const std::vector &src, + GeTensorDescPtr &dst) = 0; + + private: + void AddChangedNodesImmediateRepass(const std::set &changed_nodes); + bool ContainsSubgraph(const NodePtr &node); + std::vector GetCurNodeSubgraphs(const NodePtr &node); + graphStatus UpdateTensorDescToSubgraphData(NodePtr &node); + graphStatus UpdateTensorDescToParentNodeOutput(NodePtr &node); + graphStatus UpdateParentNodeContainsSubgraphs(NodePtr &node, + const std::vector> &ref_out_tensors); + graphStatus UpdateTensorDescToPeerInputs(NodePtr &node, std::set &changed_nodes); +}; +} // namespace ge +#endif // GE_GRAPH_PASSES_INFER_BASE_PASS_H_ diff --git a/ge/graph/passes/infer_value_range_pass.cc b/ge/graph/passes/infer_value_range_pass.cc new file mode 100644 index 00000000..b9cb88bc --- /dev/null +++ b/ge/graph/passes/infer_value_range_pass.cc @@ -0,0 +1,500 @@ +/** + * Copyright 2021 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 "graph/passes/infer_value_range_pass.h" +#include "common/formats/utils/formats_trans_utils.h" +#include "common/util/error_manager/error_manager.h" +#include "framework/common/debug/ge_log.h" +#include "graph/debug/ge_attr_define.h" +#include "graph/operator_factory_impl.h" +#include "graph/passes/constant_folding_pass.h" +#include "graph/utils/type_utils.h" +#include "common/ge/ge_util.h" + +using std::unique_ptr; +namespace ge { +namespace { +#define GET_DATA_BY_DTYPE(DTYPE, TYPE) \ + case (DTYPE): \ + ConstructValueRange(lower_boundary_tensor, upper_boundary_tensor, output_tensor_value_range); \ + break; + +void SerialShapeRange(const GeTensorDescPtr &desc, std::string &desc_str) { + std::vector> shape_range; + (void)desc->GetShapeRange(shape_range); + desc_str += formats::RangeToString(shape_range); + shape_range.clear(); + (void)desc->GetOriginShapeRange(shape_range); + desc_str += ","; + desc_str += formats::RangeToString(shape_range); + shape_range.clear(); +} + +Status RunCpuKernelForValueRange(NodePtr &node, const vector &inputs, + std::vector &outputs) { + // RunOpKernelWithCheck, RunOpKernel for test + auto ret = ConstantFoldingPass::RunOpKernel(node, inputs, outputs); + if (ret != SUCCESS) { + auto op_kernel = folding_pass::GetKernelByType(node); + if (op_kernel == nullptr) { + GELOGW("Calculate value range failed, no op kernel for node %s type %s", node->GetName().c_str(), + node->GetType().c_str()); + return NOT_CHANGED; + } + + ret = op_kernel->Compute(node->GetOpDesc(), inputs, outputs); + if (ret != SUCCESS) { + GELOGW("Calculate value range failed, node %s run cpu kernel failed.", node->GetName().c_str()); + return NOT_CHANGED; + } + } + GELOGI("Node %s type %s, run cpu kernel success.", node->GetName().c_str(), node->GetType().c_str()); + return SUCCESS; +} +} // namespace + +graphStatus InferValueRangePass::Infer(NodePtr &node) { + auto infer_value_range_param = OperatorFactoryImpl::GetInferValueRangePara(node->GetType()); + + // Use registered func to calculate value range + if (!infer_value_range_param.use_cpu_kernel) { + if (infer_value_range_param.infer_value_func == nullptr) { + GELOGW("The registered func of node %s to infer value range is nullptr.", node->GetName().c_str()); + return GRAPH_NOT_CHANGED; + } + Operator op = OpDescUtils::CreateOperatorFromNode(node); + auto ret = node->GetOpDesc()->CallInferValueRangeFunc(op); + if (ret != GRAPH_SUCCESS) { + GELOGW("Node %s call infer value range func failed, ret: %u.", node->GetName().c_str(), ret); + return GRAPH_NOT_CHANGED; + } + GELOGD("Node %s infer value range func succeed by registered func.", node->GetName().c_str()); + return GRAPH_SUCCESS; + } + + // if input value range has -1, cpu kernel cannot calculate correctly, so set {1:-1} + if (InputHasUnknownValueRange(node)) { + GELOGI("Node %s has unknown value range in input tensors, set value range {1:-1}, and skip cpu kernel.", + node->GetName().c_str()); + return GenerateWorstValueRange(node); + } + + // Use CPU kernel func to calculate value range + auto ret = ConstructInputAndInferValueRange(node); + if (ret != GRAPH_SUCCESS) { + GELOGW("Use CPU kernel to calculate value range failed. node: %s, ret: %u", node->GetName().c_str(), ret); + return GRAPH_NOT_CHANGED; + } + GELOGD("Node %s infer value range func succeed by running cpu kernel.", node->GetName().c_str()); + return GRAPH_SUCCESS; +} + +std::string InferValueRangePass::SerialTensorInfo(const GeTensorDescPtr &tensor_desc) const { + std::stringstream ss; + ss << "["; + ss << "(shape:[" << tensor_desc->MutableShape().ToString() << "]),"; + string range_str; + SerialShapeRange(tensor_desc, range_str); + ss << "(shape_range:" << range_str << "),"; + std::vector> value_range; + (void)tensor_desc->GetValueRange(value_range); + string value_range_str = formats::RangeToString(value_range); + ss << "(value_range:" << value_range_str << ")]"; + return ss.str(); +} + +bool InferValueRangePass::NeedInfer(const NodePtr &node) const { + auto infer_value_range_param = OperatorFactoryImpl::GetInferValueRangePara(node->GetType()); + if (!infer_value_range_param.is_initialized) { + GELOGD("Node %s does not register func to infer value range, skip infer_value_range_pass.", + node->GetName().c_str()); + return false; + } + + if (infer_value_range_param.when_call == INPUT_IS_DYNAMIC) { + // Only do infer for node that all inputs are dynamic, such as shape + if (InputIsDynamic(node)) { + return true; + } + GELOGD("Node %s register func to infer value range and when_call is INPUT_IS_DYNAMIC, but check input failed.", + node->GetName().c_str()); + } else if (infer_value_range_param.when_call == INPUT_HAS_VALUE_RANGE) { + // Only do infer for node that all inputs have value_range or node type of inputs is constant/const + if (InputIsConstOrHasValueRange(node)) { + return true; + } + GELOGD("Node %s register func to infer value range and when_call is INPUT_HAS_VALUE_RANGE, but check input failed.", + node->GetName().c_str()); + } + GELOGD("Node %s does not need to infer value range, skip infer_value_range_pass.", node->GetName().c_str()); + return false; +} + +bool InferValueRangePass::InputIsDynamic(const NodePtr &node) const{ + bool input_is_dynamic = false; + auto cur_op_desc = node->GetOpDesc(); + for (const auto &input_desc : cur_op_desc->GetAllInputsDescPtr()) { + auto dims = input_desc->GetShape().GetDims(); + for (auto dim : dims) { + if (dim == UNKNOWN_DIM || dim == UNKNOWN_DIM_NUM) { + input_is_dynamic = true; + break; + } + } + } + return input_is_dynamic; +} + +bool InferValueRangePass::InputIsConstOrHasValueRange(const NodePtr &node) const { + bool input_is_const_or_has_value_range = true; + auto cur_op_desc = node->GetOpDesc(); + auto in_data_anchors = node->GetAllInDataAnchors(); + for (size_t i = 0; i < in_data_anchors.size(); ++i) { + auto peer_out_anchor = in_data_anchors.at(i)->GetPeerOutAnchor(); + if (peer_out_anchor == nullptr) { + continue; + } + auto peer_node = peer_out_anchor->GetOwnerNode(); + if (peer_node == nullptr || peer_node->GetOpDesc() == nullptr) { + continue; + } + if ((peer_node->GetType() == CONSTANT) || (peer_node->GetType() == CONSTANTOP)) { + continue; + } + + const auto &input_desc = cur_op_desc->GetInputDesc(i); + std::vector> value_range; + (void)input_desc.GetValueRange(value_range); + if (value_range.empty()) { + GELOGD("Node %s input %zu does not have value range, skip infer_value_range_pass for current node.", + node->GetName().c_str(), i); + input_is_const_or_has_value_range = false; + break; + } + } + return input_is_const_or_has_value_range; +} + +bool InferValueRangePass::InputHasUnknownValueRange(const NodePtr &node) const { + bool has_unknown_value_range = false; + auto cur_op_desc = node->GetOpDesc(); + for (const auto &input_desc : cur_op_desc->GetAllInputsDescPtr()) { + std::vector> input_desc_value_range; + input_desc->GetValueRange(input_desc_value_range); + if (!input_desc_value_range.empty()) { + for (const auto &range : input_desc_value_range) { + if (range.first == -1 || range.second == -1) { + GELOGD("Node %s input tensors have unknown value range, value range is %s.", node->GetName().c_str(), + formats::RangeToString(input_desc_value_range).c_str()); + has_unknown_value_range = true; + } + } + } + } + return has_unknown_value_range; +} + +graphStatus InferValueRangePass::UpdateTensorDesc(const GeTensorDescPtr &src, GeTensorDescPtr &dst, bool &changed) { + if (src == nullptr || dst == nullptr) { + REPORT_CALL_ERROR("E19999", "While updating tensor desc, input desc is null."); + GELOGE(GRAPH_FAILED, "[Param][check] While updating tensor desc, input desc is null."); + return GRAPH_FAILED; + } + + changed = false; + std::vector> src_value_range; + std::vector> dst_value_range; + (void)src->GetValueRange(src_value_range); + (void)dst->GetValueRange(dst_value_range); + if (src_value_range != dst_value_range) { + GELOGD("While updating tensor desc, value range has been changed, src value range: %s, dst value range: %s.", + formats::RangeToString(src_value_range).c_str(), formats::RangeToString(dst_value_range).c_str()); + changed = true; + } + + dst->SetValueRange(src_value_range); + return GRAPH_SUCCESS; +} + +graphStatus InferValueRangePass::UpdateOutputFromSubgraphs(const std::vector &src, + GeTensorDescPtr &dst) { + std::vector> ref_out_tensor_value_range; + auto ref_out_tensor = src.at(0); + (void)ref_out_tensor->GetValueRange(ref_out_tensor_value_range); + for (auto &ref_tensor : src) { + std::vector> ref_tensor_value_range; + (void)ref_tensor->GetValueRange(ref_tensor_value_range); + + if (ref_tensor_value_range.size() != ref_out_tensor_value_range.size()) { + GELOGD("Update TensorDesc %s failed, rank of value ranges %s and %s are not the same, skip value range refresh.", + dst->GetName().c_str(), formats::RangeToString(ref_out_tensor_value_range).c_str(), + formats::RangeToString(ref_tensor_value_range).c_str()); + return GRAPH_SUCCESS; + } + + for (size_t j = 0; j < ref_out_tensor_value_range.size(); j++) { + if ((ref_out_tensor_value_range.at(j).first != ref_tensor_value_range.at(j).first) || + (ref_out_tensor_value_range.at(j).second != ref_tensor_value_range.at(j).second)) { + ref_out_tensor_value_range[j] = std::make_pair(1, -1); + } + } + } + GELOGD("While updating output desc from subgraphs, set parent node desc value range %s.", + formats::RangeToString(ref_out_tensor_value_range).c_str()); + dst->SetValueRange(ref_out_tensor_value_range); + return GRAPH_SUCCESS; +} + +graphStatus InferValueRangePass::UpdateOutputFromSubgraphsForMultiDims(const std::vector &src, + GeTensorDescPtr &dst) { + REPORT_INNER_ERROR("E19999", + "Update TensorDesc %s failed. In dynamic multi-dims size scene, there should be no value range.", + dst->GetName().c_str()); + GELOGE(GRAPH_FAILED, + "[Update][TensorDesc] %s failed. In dynamic multi-dims size scene, there should be no value range.", + dst->GetName().c_str()); + return GRAPH_FAILED; +} + +graphStatus InferValueRangePass::GenerateWorstValueRange(NodePtr &node) { + GELOGI("Node %s does not run cpu kernel, because input value range has -1.", node->GetName().c_str()); + OpDescPtr op_desc = node->GetOpDesc(); + for (size_t i = 0; i < op_desc->GetOutputsSize(); ++i) { + auto output_desc = op_desc->MutableOutputDesc(i); + if (output_desc == nullptr) { + continue; + } + auto output_i_shape = output_desc->GetShape(); + auto output_i_shape_size = output_i_shape.GetShapeSize(); + if (output_i_shape_size < 0) { + GELOGD("Node %s output shape is unknown, cannot infer value range, shape is %s.", node->GetName().c_str(), + formats::ShapeToString(output_i_shape).c_str()); + return GRAPH_NOT_CHANGED; + } + + std::vector> output_i_value_range(output_i_shape_size, {1, -1}); + output_desc->SetValueRange(output_i_value_range); + GELOGD("Node %s output %zu shape is %s, the generated worst value range is %s.", node->GetName().c_str(), i, + formats::ShapeToString(output_i_shape).c_str(), formats::RangeToString(output_i_value_range).c_str()); + } + return GRAPH_SUCCESS; +} + +template +graphStatus InferValueRangePass::ConstructData(const GeTensorDesc &tensor_desc, bool use_floor_value, + GeTensorPtr &output_ptr) { + std::vector> value_range; + (void)tensor_desc.GetValueRange(value_range); + if (static_cast(value_range.size()) != tensor_desc.GetShape().GetShapeSize()) { + GELOGW("Value range of input %s is invalid.", tensor_desc.GetName().c_str()); + return GRAPH_PARAM_INVALID; + } + + size_t value_range_data_num = value_range.size(); + unique_ptr buf(new (std::nothrow) T[value_range_data_num]()); + if (buf == nullptr) { + REPORT_INNER_ERROR("E19999", "New buf failed"); + GELOGE(MEMALLOC_FAILED, "New buf failed"); + return GRAPH_FAILED; + } + for (size_t j = 0; j < value_range_data_num; ++j) { + auto value_range_j = use_floor_value ? value_range[j].first : value_range[j].second; + buf[j] = static_cast(value_range_j); + } + + if (output_ptr->SetData(reinterpret_cast(buf.get()), value_range_data_num * sizeof(T)) != GRAPH_SUCCESS) { + GELOGW("Set data failed while constructing value range input tensor."); + return GRAPH_NOT_CHANGED; + } + return GRAPH_SUCCESS; +} + +graphStatus InferValueRangePass::ConstructDataByType(const GeTensorDesc &tensor_desc, bool use_floor_value, + GeTensorPtr &output_ptr) { + graphStatus ret = GRAPH_SUCCESS; + auto data_type = tensor_desc.GetDataType(); + output_ptr->MutableTensorDesc().SetDataType(data_type); + switch (data_type) { + case DT_FLOAT: + ret = ConstructData(tensor_desc, use_floor_value, output_ptr); + break; + case DT_DOUBLE: + ret = ConstructData(tensor_desc, use_floor_value, output_ptr); + break; + case DT_UINT8: + ret = ConstructData(tensor_desc, use_floor_value, output_ptr); + break; + case DT_INT8: + ret = ConstructData(tensor_desc, use_floor_value, output_ptr); + break; + case DT_UINT16: + ret = ConstructData(tensor_desc, use_floor_value, output_ptr); + break; + case DT_INT16: + ret = ConstructData(tensor_desc, use_floor_value, output_ptr); + break; + case DT_INT32: + ret = ConstructData(tensor_desc, use_floor_value, output_ptr); + break; + case DT_INT64: + ret = ConstructData(tensor_desc, use_floor_value, output_ptr); + break; + default: + GELOGW("Data type:%s is not supported.", TypeUtils::DataTypeToSerialString(data_type).c_str()); + ret = GRAPH_PARAM_INVALID; + } + return ret; +} + +vector InferValueRangePass::ConstructInputTensors(const NodePtr &node, bool use_floor_value) { + vector input_tensors; + auto cur_op_desc = node->GetOpDesc(); + auto in_data_anchors = node->GetAllInDataAnchors(); + for (size_t i = 0; i < in_data_anchors.size(); ++i) { + auto peer_out_anchor = in_data_anchors.at(i)->GetPeerOutAnchor(); + if (peer_out_anchor == nullptr) { + continue; + } + auto peer_node = peer_out_anchor->GetOwnerNode(); + if (peer_node == nullptr) { + continue; + } + + // construct input tensor by constant node + if ((peer_node->GetType() == CONSTANT) || (peer_node->GetType() == CONSTANTOP)) { + vector const_weight = OpDescUtils::MutableWeights(peer_node); + if (const_weight.empty()) { + GELOGW("MutableWeights failed, weight is empty, node: %s(%s)", peer_node->GetName().c_str(), + peer_node->GetType().c_str()); + return vector(); + } + // const/constant op has only one weight + if (const_weight.at(0) == nullptr) { + GELOGW("MutableWeights failed, weight of constant is null, node name: %s(%s)", + peer_node->GetName().c_str(), peer_node->GetType().c_str()); + return vector(); + } + input_tensors.push_back(const_weight.at(0)); + GELOGD("Node %s construct input tensor %zu by constant node.", node->GetName().c_str(), input_tensors.size()); + continue; + } + + // construct input tensor by boundary of value range + const auto &input_tensor_desc = cur_op_desc->GetInputDesc(i); + GeTensorPtr tmp_tensor_ptr = MakeShared(input_tensor_desc); + if (tmp_tensor_ptr == nullptr) { + REPORT_INNER_ERROR("E19999", "Make shared failed"); + GELOGE(MEMALLOC_FAILED, "Make shared failed"); + return vector(); + } + + auto ret = ConstructDataByType(input_tensor_desc, use_floor_value, tmp_tensor_ptr); + if (ret != GRAPH_SUCCESS) { + GELOGW("Construct input tensor by boundary of value range failed for input %s.", + input_tensor_desc.GetName().c_str()); + return vector(); + } + input_tensors.push_back(tmp_tensor_ptr); + GELOGD("Node %s construct input tensor %zu by input desc value range.", node->GetName().c_str(), + input_tensors.size()); + } + + return input_tensors; +} + +graphStatus InferValueRangePass::ConstructInputAndInferValueRange(NodePtr &node) { + auto inputs = ConstructInputTensors(node, true); + if (inputs.empty()) { + return GRAPH_PARAM_INVALID; + } + vector lower_boundary_outputs; + auto ret = RunCpuKernelForValueRange(node, inputs, lower_boundary_outputs); + if (ret != SUCCESS) { + GELOGW("Node %s run cpu kernel failed while calculating value range.", node->GetName().c_str()); + return GRAPH_PARAM_INVALID; + } + + inputs = ConstructInputTensors(node, false); + if (inputs.empty()) { + return GRAPH_PARAM_INVALID; + } + vector upper_boundary_outputs; + ret = RunCpuKernelForValueRange(node, inputs, upper_boundary_outputs); + if (ret != SUCCESS) { + GELOGW("Node %s run cpu kernel failed while calculating value range.", node->GetName().c_str()); + return GRAPH_PARAM_INVALID; + } + + // construct value range from output tensor + OpDescPtr node_desc = node->GetOpDesc(); + std::vector> output_tensor_value_range; + size_t node_output_desc_size = node_desc->GetOutputsSize(); + for (size_t i = 0; i < node_output_desc_size; ++i) { + output_tensor_value_range.clear(); + auto output_tensor_desc = node_desc->MutableOutputDesc(i); + auto output_shape_size = output_tensor_desc->GetShape().GetShapeSize(); + auto lower_boundary_tensor = lower_boundary_outputs[i]; + auto lower_boundary_shape = lower_boundary_tensor->GetTensorDesc().GetShape(); + auto upper_boundary_tensor = upper_boundary_outputs[i]; + auto upper_boundary_shape = upper_boundary_tensor->GetTensorDesc().GetShape(); + if (lower_boundary_shape.GetShapeSize() != output_shape_size || + upper_boundary_shape.GetShapeSize() != output_shape_size) { + GELOGD( + "Cpu kernel result shapes %s, %s and output shape %s do not match, can not infer value range for output %s.", + formats::ShapeToString(lower_boundary_shape).c_str(), formats::ShapeToString(upper_boundary_shape).c_str(), + formats::ShapeToString(output_tensor_desc->GetShape()).c_str(), output_tensor_desc->GetName().c_str()); + return GRAPH_PARAM_INVALID; + } + + auto data_type = output_tensor_desc->GetDataType(); + switch (data_type) { + GET_DATA_BY_DTYPE(DT_INT8, int8_t) + GET_DATA_BY_DTYPE(DT_INT16, int16_t) + GET_DATA_BY_DTYPE(DT_INT32, int32_t) + GET_DATA_BY_DTYPE(DT_INT64, int64_t) + GET_DATA_BY_DTYPE(DT_UINT8, uint8_t) + GET_DATA_BY_DTYPE(DT_UINT16, uint16_t) + GET_DATA_BY_DTYPE(DT_UINT32, uint32_t) + GET_DATA_BY_DTYPE(DT_UINT64, uint64_t) + GET_DATA_BY_DTYPE(DT_FLOAT, float) + GET_DATA_BY_DTYPE(DT_DOUBLE, double) + default: + GELOGW("Data type:%s is not supported.", TypeUtils::DataTypeToSerialString(data_type).c_str()); + return GRAPH_PARAM_INVALID; + } + output_tensor_desc->SetValueRange(output_tensor_value_range); + GELOGD("Node %s calculates output %zu value range %s by running cpu kernel.", node->GetName().c_str(), i, + formats::RangeToString(output_tensor_value_range).c_str()); + } + return GRAPH_SUCCESS; +} + +template +void InferValueRangePass::ConstructValueRange(const GeTensorPtr &left_tensor, const GeTensorPtr &right_tensor, + std::vector> &value_range) { + auto x = reinterpret_cast(left_tensor->GetData().GetData()); + auto y = reinterpret_cast(right_tensor->GetData().GetData()); + if (x == nullptr || y == nullptr) { + GELOGI("Output tensor of cpu kernel does not have data, no way to set value range."); + return; + } + for (auto j = 0; j < left_tensor->GetTensorDesc().GetShape().GetShapeSize(); ++j) { + auto left = static_cast(*(x + j)); + auto right = static_cast(*(y + j)); + value_range.emplace_back(std::make_pair(left, right)); + } +} +} // namespace ge diff --git a/ge/graph/passes/infer_value_range_pass.h b/ge/graph/passes/infer_value_range_pass.h new file mode 100644 index 00000000..eb485c87 --- /dev/null +++ b/ge/graph/passes/infer_value_range_pass.h @@ -0,0 +1,49 @@ +/** + * Copyright 2021 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. + */ + +#ifndef GE_GRAPH_PASSES_INFER_VALUE_RANGE_PASS_H_ +#define GE_GRAPH_PASSES_INFER_VALUE_RANGE_PASS_H_ + +#include "graph/passes/infer_base_pass.h" + +namespace ge { +class InferValueRangePass : public InferBasePass { + public: + graphStatus Infer(NodePtr &node) override; + + private: + std::string SerialTensorInfo(const GeTensorDescPtr &tensor_desc) const override; + graphStatus UpdateTensorDesc(const GeTensorDescPtr &src, GeTensorDescPtr &dst, bool &changed) override; + graphStatus UpdateOutputFromSubgraphs(const std::vector &src, GeTensorDescPtr &dst) override; + graphStatus UpdateOutputFromSubgraphsForMultiDims(const std::vector &src, + GeTensorDescPtr &dst) override; + bool NeedInfer(const NodePtr &node) const override; + + bool InputIsDynamic(const NodePtr &node) const; + bool InputIsConstOrHasValueRange(const NodePtr &node) const; + bool InputHasUnknownValueRange(const NodePtr &node) const; + graphStatus GenerateWorstValueRange(NodePtr &node); + template + graphStatus ConstructData(const GeTensorDesc &tensor_desc, bool use_floor_value, GeTensorPtr &output_ptr); + graphStatus ConstructDataByType(const GeTensorDesc &tensor_desc, bool use_floor_value, GeTensorPtr &output_ptr); + vector ConstructInputTensors(const NodePtr &node, bool use_floor_value); + template + void ConstructValueRange(const GeTensorPtr &left_tensor, const GeTensorPtr &right_tensor, + std::vector> &value_range); + graphStatus ConstructInputAndInferValueRange(NodePtr &node); +}; +} // namespace ge +#endif // GE_GRAPH_PASSES_INFER_VALUE_RANGE_PASS_H_ diff --git a/ge/graph/preprocess/graph_preprocess.cc b/ge/graph/preprocess/graph_preprocess.cc index 6fd83623..bc8646e7 100644 --- a/ge/graph/preprocess/graph_preprocess.cc +++ b/ge/graph/preprocess/graph_preprocess.cc @@ -54,6 +54,7 @@ #include "graph/passes/hccl_group_pass.h" #include "graph/passes/identity_pass.h" #include "graph/passes/infershape_pass.h" +#include "graph/passes/infer_value_range_pass.h" #include "graph/passes/merge_pass.h" #include "graph/passes/net_output_pass.h" #include "graph/passes/no_use_reshape_remove_pass.h" @@ -2016,6 +2017,8 @@ Status GraphPrepare::InferShapeForPreprocess() { names_to_passes.emplace_back("DimensionComputePass", &dimension_compute_pass); ConstantFoldingPass constant_folding_pass; names_to_passes.emplace_back("ConstantFoldingPass", &constant_folding_pass); + InferValueRangePass infer_value_pass; + names_to_passes.emplace_back("InferValuePass", &infer_value_pass); int32_t dev_count = 0; AicpuConstantFoldingPass aicpu_constant_folding_pass; diff --git a/metadef b/metadef index 2ad00e17..9e4a51a9 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit 2ad00e17886fd06c0d00f8a8cf370783a3d31818 +Subproject commit 9e4a51a9602195b82e326b853f5adbfefc3972b6 diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index b67dc23d..80b12e32 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -220,7 +220,9 @@ set(COMMON_SRC_FILES "${GE_CODE_DIR}/ge/graph/passes/shape_operate_op_remove_pass.cc" "${GE_CODE_DIR}/ge/graph/passes/assert_pass.cc" "${GE_CODE_DIR}/ge/graph/passes/dropout_pass.cc" + "${GE_CODE_DIR}/ge/graph/passes/infer_base_pass.cc" "${GE_CODE_DIR}/ge/graph/passes/infershape_pass.cc" + "${GE_CODE_DIR}/ge/graph/passes/infer_value_range_pass.cc" "${GE_CODE_DIR}/ge/graph/passes/unused_const_pass.cc" "${GE_CODE_DIR}/ge/graph/passes/permute_pass.cc" "${GE_CODE_DIR}/ge/graph/passes/ctrl_edge_transfer_pass.cc" @@ -534,7 +536,9 @@ set(GRAPH_PASS_COMMON_SRC_FILES "${GE_CODE_DIR}/ge/graph/passes/transpose_transdata_pass.cc" "${GE_CODE_DIR}/ge/graph/passes/hccl_memcpy_pass.cc" "${GE_CODE_DIR}/ge/graph/passes/no_use_reshape_remove_pass.cc" + "${GE_CODE_DIR}/ge/graph/passes/infer_base_pass.cc" "${GE_CODE_DIR}/ge/graph/passes/infershape_pass.cc" + "${GE_CODE_DIR}/ge/graph/passes/infer_value_range_pass.cc" "${GE_CODE_DIR}/ge/ge_local_engine/engine/host_cpu_engine.cc" "${GE_CODE_DIR}/ge/analyzer/analyzer.cc" "${GE_CODE_DIR}/ge/graph/passes/net_output_pass.cc" @@ -661,6 +665,8 @@ set(DISTINCT_GRAPH_LOAD_TEST_FILES ) set(PASS_TEST_FILES + "graph/passes/infer_value_range_pass_unittest.cc" + "graph/passes/infer_base_pass_unittest.cc" "graph/passes/prune_pass_unittest.cc" "graph/passes/enter_pass_unittest.cc" "graph/passes/switch_op_pass_unittest.cc" @@ -719,7 +725,6 @@ set(PASS_TEST_FILES "graph/passes/memcpy_addr_async_unittest.cc" "graph/passes/hccl_continuous_pass_unittest.cc" "graph/passes/hccl_memcpy_pass_unittest.cc" - ) set(KERNEL_TEST_FILES diff --git a/tests/ut/ge/graph/passes/infer_base_pass_unittest.cc b/tests/ut/ge/graph/passes/infer_base_pass_unittest.cc new file mode 100644 index 00000000..e9247f75 --- /dev/null +++ b/tests/ut/ge/graph/passes/infer_base_pass_unittest.cc @@ -0,0 +1,359 @@ +/** + * Copyright 2021 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 "graph/passes/infer_base_pass.h" +#include "graph/debug/ge_attr_define.h" +#include "graph/utils/tensor_utils.h" +#include "graph/utils/graph_utils.h" +#include "graph_builder_utils.h" + +using namespace std; +using namespace testing; +namespace ge { +class ChildPassBuilder; +static const char *kInferTimes = "infer_times"; +class InferBasePassStub : public InferBasePass { + public: + friend class ChildPassBuilder; + graphStatus Infer(NodePtr &node) override{ + call_infer_times++; + for (size_t i = 0; i < node->GetOutDataNodesSize(); ++i) { + auto output_td = node->GetOpDesc()->MutableOutputDesc(i); + int times = 0; + AttrUtils::GetInt(output_td, kInferTimes, times); + AttrUtils::SetInt(output_td, kInferTimes, times + 1); + } + return infer_result_; + }; + + int32_t call_infer_times = 0; + int32_t call_update_tensor_desc_times = 0; + int32_t call_update_from_subgraph_times = 0; + int32_t call_update_from_subgraph_multi_dims_times = 0; + std::vector> update_td_pairs; + + private: + bool NeedInfer(const NodePtr &node) const override { + return need_infer_; + }; + std::string SerialTensorInfo(const GeTensorDescPtr &tensor_desc) const override { return "test SerialTensorInfo"; }; + graphStatus UpdateTensorDesc(const GeTensorDescPtr &src, GeTensorDescPtr &dst, bool &changed) override { + call_update_tensor_desc_times++; + changed = td_changed_; + int times = 0; + if (AttrUtils::GetInt(src, kInferTimes, times)) { + AttrUtils::SetInt(dst, kInferTimes, times); + } + update_td_pairs.emplace_back(src, dst); + return GRAPH_SUCCESS; + }; + graphStatus UpdateOutputFromSubgraphs(const std::vector &src, GeTensorDescPtr &dst) override { + call_update_from_subgraph_times++; + return GRAPH_SUCCESS; + }; + graphStatus UpdateOutputFromSubgraphsForMultiDims(const std::vector &src, + GeTensorDescPtr &dst) override { + call_update_from_subgraph_multi_dims_times++; + return GRAPH_SUCCESS; + }; + bool td_changed_; + bool need_infer_; + graphStatus infer_result_; +}; + +class ChildPassBuilder { + public: + ChildPassBuilder &SetNeedInferFlag(bool flag) { + need_infer_ = flag; + return *this; + } + + ChildPassBuilder &SetInferResult(graphStatus ret) { + infer_result_ = ret; + return *this; + } + + ChildPassBuilder &SetTdChangedFlag(bool changed_flag) { + td_changed_ = changed_flag; + return *this; + } + + InferBasePassStub Build() { + InferBasePassStub ib; + ib.td_changed_ = td_changed_; + ib.need_infer_ = need_infer_; + ib.infer_result_ = infer_result_; + return ib; + } + + private: + bool td_changed_ = false; + bool need_infer_ = true; + graphStatus infer_result_ = GRAPH_SUCCESS; +}; + +class UtestGraphInferBasePassStub : public testing::Test { + protected: + void SetUp() {} + void TearDown() {} +}; + +/* + * data1 data2 + * \ / + * sub1 + * | + * netoutput + */ +ut::GraphBuilder TestSubgraphBuilder() { + ut::GraphBuilder builder = ut::GraphBuilder("branch_graph"); + std::vector shape1 = {1,1}; + auto data1 = builder.AddNode("data1_1", "Data", 1, 1, FORMAT_NCHW, DT_INT32, shape1); + auto data1_desc = data1->GetOpDesc(); + EXPECT_NE(data1_desc, nullptr); + AttrUtils::SetInt(data1_desc, "_parent_node_index", 0); + std::vector shape2 = {2,2}; + auto data2 = builder.AddNode("data2_1", "Data", 1, 1, FORMAT_NCHW, DT_INT32, shape2); + auto data2_desc = data2->GetOpDesc(); + EXPECT_NE(data2_desc, nullptr); + AttrUtils::SetInt(data2_desc, "_parent_node_index", 1); + + auto sub1 = builder.AddNode("Sub", "Sub", 2, 1); + std::vector shape7 = {8,8}; + auto netoutput = builder.AddNode("output", NETOUTPUT, 1, 0, FORMAT_NCHW, DT_INT32, shape7); + auto input0_desc = netoutput->GetOpDesc()->MutableInputDesc(0); + EXPECT_NE(input0_desc, nullptr); + AttrUtils::SetInt(input0_desc, "_parent_node_index", 0); + + builder.AddDataEdge(data1, 0, sub1, 0); + builder.AddDataEdge(data2, 0, sub1, 1); + builder.AddDataEdge(sub1, 0, netoutput, 0); + return builder; +} + +/* + * data1 data2 + * \ / + * case1 + * | + * netoutput + */ +ut::GraphBuilder RootGraphBuilder() { + ut::GraphBuilder builder = ut::GraphBuilder("root_graph"); + auto data1 = builder.AddNode("data1", "Data", 0, 1); + auto data2 = builder.AddNode("data2", "Data", 0, 1); + auto case1 = builder.AddNode("case1", CASE, 2, 1); + auto netoutput = builder.AddNode("netoutput", NETOUTPUT, 1, 0); + builder.AddDataEdge(data1, 0, case1, 0); + builder.AddDataEdge(data2, 0, case1, 1); + builder.AddDataEdge(case1, 0, netoutput, 0); + + auto parent_graph = builder.GetGraph(); + auto subgraph_builder = TestSubgraphBuilder(); + auto subgraph = subgraph_builder.GetGraph(); + case1->GetOpDesc()->AddSubgraphName(subgraph->GetName()); + case1->GetOpDesc()->SetSubgraphInstanceName(0, subgraph->GetName()); + subgraph->SetParentNode(case1); + subgraph->SetParentGraph(parent_graph); + EXPECT_EQ(parent_graph->AddSubgraph(subgraph->GetName(), subgraph), GRAPH_SUCCESS); + return builder; +} + +/* + * data1 data2 + * \ / + * add1 + * | + * netoutput + */ +ut::GraphBuilder NoSubgraphBuilder() { + ut::GraphBuilder builder = ut::GraphBuilder("no_subgraph"); + auto data1 = builder.AddNode("data1", "Data", 0, 1); + auto data2 = builder.AddNode("data2", "Data", 0, 1); + auto add1 = builder.AddNode("add1", ADD, 2, 1); + auto netoutput = builder.AddNode("netoutput", NETOUTPUT, 1, 0); + builder.AddDataEdge(data1, 0, add1, 0); + builder.AddDataEdge(data2, 0, add1, 1); + builder.AddDataEdge(add1, 0, netoutput, 0); + return builder; +} + +TEST_F(UtestGraphInferBasePassStub, CallInfer_WhenNeedInferReturnTrue) { + auto builder = NoSubgraphBuilder(); + auto test_graph = builder.GetGraph(); + auto add_node = test_graph->FindNode("add1"); + EXPECT_NE(add_node, nullptr); + ChildPassBuilder pass_builder; + auto stub_base_pass = pass_builder.Build(); + + // NeedInfer return true + EXPECT_EQ(stub_base_pass.Run(add_node), SUCCESS); + EXPECT_EQ(stub_base_pass.call_infer_times, 1); + int times = -1; + EXPECT_TRUE(AttrUtils::GetInt(add_node->GetOpDesc()->GetOutputDescPtr(0), kInferTimes, times)); + EXPECT_EQ(times, 1); +} + +TEST_F(UtestGraphInferBasePassStub, NotCallInfer_WhenNeedInferReturnFalse) { + auto builder = NoSubgraphBuilder(); + auto test_graph = builder.GetGraph(); + auto add_node = test_graph->FindNode("add1"); + EXPECT_NE(add_node, nullptr); + ChildPassBuilder pass_builder; + auto stub_base_pass = pass_builder.SetNeedInferFlag(false).Build(); + + // NeedInfer return false + EXPECT_EQ(stub_base_pass.Run(add_node), SUCCESS); + EXPECT_EQ(stub_base_pass.call_infer_times, 0); + int times = -1; + EXPECT_FALSE(AttrUtils::GetInt(add_node->GetOpDesc()->GetOutputDescPtr(0), kInferTimes, times)); +} + +TEST_F(UtestGraphInferBasePassStub, NotAddCurNodeRepass_CallUpdatePeerNode_WhenInferReturnSuccess) { + auto builder = NoSubgraphBuilder(); + auto test_graph = builder.GetGraph(); + auto add_node = test_graph->FindNode("add1"); + auto netoutput = test_graph->FindNode("netoutput"); + EXPECT_NE(add_node, nullptr); + EXPECT_NE(netoutput, nullptr); + ChildPassBuilder pass_builder; + auto stub_base_pass = pass_builder.Build(); + + EXPECT_EQ(stub_base_pass.Run(add_node), SUCCESS); + EXPECT_EQ(stub_base_pass.call_infer_times, 1); + EXPECT_EQ(stub_base_pass.call_update_tensor_desc_times, 1); + std::vector> expected_updated_tensor_desc_pairs = { + {add_node->GetOpDesc()->MutableOutputDesc(0), netoutput->GetOpDesc()->MutableInputDesc(0)}}; + EXPECT_EQ(stub_base_pass.update_td_pairs, expected_updated_tensor_desc_pairs); + EXPECT_EQ(stub_base_pass.GetNodesNeedRePassImmediately(), std::unordered_set({})); +} + +TEST_F(UtestGraphInferBasePassStub, AddCurNodeRepass_NotCallUpdatePeerNode_WhenInferReturnNeedRepass) { + auto builder = NoSubgraphBuilder(); + auto test_graph = builder.GetGraph(); + auto add_node = test_graph->FindNode("add1"); + EXPECT_NE(add_node, nullptr); + ChildPassBuilder pass_builder; + auto stub_base_pass = pass_builder.SetInferResult(GRAPH_NODE_NEED_REPASS).Build(); + + // do re_pass + EXPECT_EQ(stub_base_pass.Run(add_node), SUCCESS); + EXPECT_EQ(stub_base_pass.call_infer_times, 1); + EXPECT_EQ(stub_base_pass.call_update_tensor_desc_times, 0); + EXPECT_EQ(stub_base_pass.GetNodesNeedRePassImmediately(), std::unordered_set({add_node})); +} + +TEST_F(UtestGraphInferBasePassStub, NotAddPeerNodeRepass_AfterUpdatePeerNode_WhenUnchanged) { + auto builder = NoSubgraphBuilder(); + auto test_graph = builder.GetGraph(); + auto add_node = test_graph->FindNode("add1"); + auto netoutput = test_graph->FindNode("netoutput"); + EXPECT_NE(add_node, nullptr); + EXPECT_NE(netoutput, nullptr); + ChildPassBuilder pass_builder; + auto stub_base_pass = pass_builder.Build(); + + EXPECT_EQ(stub_base_pass.Run(add_node), SUCCESS); + EXPECT_EQ(stub_base_pass.call_update_tensor_desc_times, 1); + EXPECT_EQ(stub_base_pass.GetNodesNeedRePassImmediately(), std::unordered_set({})); + int times = -1; + EXPECT_TRUE(AttrUtils::GetInt(add_node->GetOpDesc()->GetOutputDescPtr(0), kInferTimes, times)); + EXPECT_EQ(times, 1); + times = -1; + EXPECT_TRUE(AttrUtils::GetInt(netoutput->GetOpDesc()->GetInputDescPtr(0), kInferTimes, times)); + EXPECT_EQ(times, 1); +} + +TEST_F(UtestGraphInferBasePassStub, AddPeerNodeRepass_AfterUpdatePeerNode_WhenChanged) { + auto builder = NoSubgraphBuilder(); + auto test_graph = builder.GetGraph(); + auto add_node = test_graph->FindNode("add1"); + auto netoutput = test_graph->FindNode("netoutput"); + EXPECT_NE(add_node, nullptr); + EXPECT_NE(netoutput, nullptr); + ChildPassBuilder pass_builder; + auto stub_base_pass = pass_builder.SetTdChangedFlag(true).Build(); + + EXPECT_EQ(stub_base_pass.Run(add_node), SUCCESS); + EXPECT_EQ(stub_base_pass.call_update_tensor_desc_times, 1); + EXPECT_EQ(stub_base_pass.GetNodesNeedRePassImmediately(), std::unordered_set({netoutput})); +} + +TEST_F(UtestGraphInferBasePassStub, TestUpdateSubgraphData_WhenBeforeSubgraph) { + auto builder = RootGraphBuilder(); + auto parent_graph = builder.GetGraph(); + auto subgraphs = parent_graph->GetAllSubgraphs(); + EXPECT_EQ(subgraphs.size(), 1); + + auto case_node = parent_graph->FindNode("case1"); + auto data1 = subgraphs[0]->FindNode("data1_1"); + auto data2 = subgraphs[0]->FindNode("data2_1"); + EXPECT_NE(case_node, nullptr); + EXPECT_NE(data1, nullptr); + EXPECT_NE(data2, nullptr); + ChildPassBuilder pass_builder; + auto stub_base_pass = pass_builder.SetInferResult(GRAPH_NODE_NEED_REPASS).Build(); + + EXPECT_EQ(stub_base_pass.Run(case_node), SUCCESS); + // when GRAPH_NODE_NEED_REPASS, not update peer node, only update two data, update input and output, 2*2 + EXPECT_EQ(stub_base_pass.call_update_tensor_desc_times, 4); + std::vector> expected_updated_tensor_desc_pairs = { + {case_node->GetOpDesc()->MutableInputDesc(0), data1->GetOpDesc()->MutableInputDesc(0)}, + {case_node->GetOpDesc()->MutableInputDesc(0), data1->GetOpDesc()->MutableOutputDesc(0)}, + {case_node->GetOpDesc()->MutableInputDesc(1), data2->GetOpDesc()->MutableInputDesc(0)}, + {case_node->GetOpDesc()->MutableInputDesc(1), data2->GetOpDesc()->MutableOutputDesc(0)}, + }; + EXPECT_EQ(stub_base_pass.update_td_pairs, expected_updated_tensor_desc_pairs); +} + +TEST_F(UtestGraphInferBasePassStub, TestUpdateParentNodeOutput_WhenAfterSubgraph) { + auto builder = RootGraphBuilder(); + auto parent_graph = builder.GetGraph(); + auto subgraphs = parent_graph->GetAllSubgraphs(); + EXPECT_EQ(subgraphs.size(), 1); + + auto case_node = parent_graph->FindNode("case1"); + EXPECT_NE(case_node, nullptr); + ChildPassBuilder pass_builder; + auto stub_base_pass = pass_builder.Build(); + stub_base_pass.SetOption(kOptimizeAfterSubGraph, ""); + + EXPECT_EQ(stub_base_pass.Run(case_node), SUCCESS); + EXPECT_EQ(stub_base_pass.call_update_from_subgraph_times, 1); + EXPECT_EQ(stub_base_pass.call_update_from_subgraph_multi_dims_times, 0); +} + +TEST_F(UtestGraphInferBasePassStub, TestUpdateParentNodeOutputForMultiDims_WhenAfterSubgraph) { + auto builder = RootGraphBuilder(); + auto parent_graph = builder.GetGraph(); + auto subgraphs = parent_graph->GetAllSubgraphs(); + EXPECT_EQ(subgraphs.size(), 1); + + auto case_node = parent_graph->FindNode("case1"); + auto set_ret = AttrUtils::SetInt(case_node->GetOpDesc(), ATTR_NAME_BATCH_NUM, 2); + EXPECT_EQ(set_ret, true); + EXPECT_NE(case_node, nullptr); + ChildPassBuilder pass_builder; + auto stub_base_pass = pass_builder.Build(); + stub_base_pass.SetOption(kOptimizeAfterSubGraph, ""); + + EXPECT_EQ(stub_base_pass.Run(case_node), SUCCESS); + EXPECT_EQ(stub_base_pass.call_update_from_subgraph_times, 0); + EXPECT_EQ(stub_base_pass.call_update_from_subgraph_multi_dims_times, 1); +} +} // namespace ge \ No newline at end of file diff --git a/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc b/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc new file mode 100644 index 00000000..fea1b27d --- /dev/null +++ b/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc @@ -0,0 +1,583 @@ +/** + * Copyright 2021 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 + +#define protected public +#define private public +#include "graph/passes/infer_value_range_pass.h" +#include "graph/utils/tensor_utils.h" +#include "graph/utils/graph_utils.h" +#include "graph_builder_utils.h" + +#include "inc/external/graph/operator_reg.h" +#include "inc/external/graph/operator.h" +#include "inc/external/graph/operator_factory.h" +#include "inc/graph/operator_factory_impl.h" +#include "inc/kernel.h" +#include "inc/kernel_factory.h" + +using namespace std; +using namespace testing; +namespace ge { +class UtestGraphInferValueRangePass : public testing::Test { + protected: + void SetUp() {} + void TearDown() {} +}; + +/* + * data1 const1 + * \ / + * case1 + * | + * relu10 + * | + * netoutput + */ +ut::GraphBuilder ParentGraphBuilder() { + ut::GraphBuilder builder = ut::GraphBuilder("g1"); + auto data1 = builder.AddNode("data1", "Data", 0, 1); + std::vector const_shape = {1}; + auto const1 = builder.AddNode("const1", "Const", 0, 1, FORMAT_NCHW, DT_INT32, const_shape); + auto case1 = builder.AddNode("case1", CASE, 2, 1); + auto relu1 = builder.AddNode("relu10", "Relu", 1, 1); + auto netoutput = builder.AddNode("netoutput", NETOUTPUT, 1, 0); + + int32_t weight[1] = {1}; + GeTensorDesc weight_desc(GeShape({1}), FORMAT_NHWC, DT_INT32); + GeTensorPtr tensor = std::make_shared(weight_desc, (uint8_t *)weight, sizeof(weight)); + OpDescUtils::SetWeights(const1, {tensor}); + auto case_in0_shape = GeShape({1, 1,-1, 224}); + auto case_in1_shape = GeShape({1,1}); + std::vector> in0_range = {make_pair(1, 1), make_pair(1, 1), + make_pair(1, -1), make_pair(1, 224)}; + std::vector> in1_range = {make_pair(1, 100), make_pair(1, 10)}; + case1->GetOpDesc()->MutableInputDesc(0)->SetShape(case_in0_shape); + case1->GetOpDesc()->MutableInputDesc(0)->SetValueRange(in0_range); + case1->GetOpDesc()->MutableInputDesc(1)->SetShape(case_in1_shape); + case1->GetOpDesc()->MutableInputDesc(1)->SetValueRange(in1_range); + + builder.AddDataEdge(data1, 0, case1, 0); + builder.AddDataEdge(const1, 0, case1, 1); + builder.AddDataEdge(case1, 0, relu1, 0); + builder.AddDataEdge(relu1, 0, netoutput, 0); + return builder; +} + +/* + * data1 data2 + * \ / + * switch + * / \ + * relu1 relu2 + * \ / + * merge + * | + * netoutput + */ +ut::GraphBuilder SwitchSubgraphBuilder(string graph_name, uint32_t num) { + ut::GraphBuilder builder = ut::GraphBuilder(graph_name); + + std::vector shape1 = {2,2}; + string data1_name = "data1_" + std::to_string(num); + auto data1 = builder.AddNode(data1_name, "Data", 1, 1, FORMAT_NCHW, DT_INT32, shape1); + auto data1_desc = data1->GetOpDesc(); + EXPECT_NE(data1_desc, nullptr); + AttrUtils::SetInt(data1_desc, "_parent_node_index", 0); + + std::vector shape2 = {3,3}; + string data2_name = "data2_" + std::to_string(num); + auto data2 = builder.AddNode(data2_name, "Data", 1, 1, FORMAT_NCHW, DT_INT32, shape2); + auto data2_desc = data2->GetOpDesc(); + EXPECT_NE(data2_desc, nullptr); + AttrUtils::SetInt(data2_desc, "_parent_node_index", 1); + + string switch_name = "switch_" + std::to_string(num); + auto switch1 = builder.AddNode(switch_name, "Switch", 2, 2); + + string relu1_name = "relu1_" + std::to_string(num); + auto relu1 = builder.AddNode(relu1_name, "Relu", 1, 1); + + string relu2_name = "relu2_" + std::to_string(num); + auto relu2 = builder.AddNode(relu2_name, "Relu", 1, 1); + + string merge_name = "merge_" + std::to_string(num); + auto merge = builder.AddNode(merge_name, "Merge", 2, 1); + + std::vector shape7 = {8,8}; + string output_name = "output_" + std::to_string(num); + auto netoutput = builder.AddNode(output_name, NETOUTPUT, 1, 0, FORMAT_NCHW, DT_INT32, shape7); + auto input0_desc = netoutput->GetOpDesc()->MutableInputDesc(0); + EXPECT_NE(input0_desc, nullptr); + AttrUtils::SetInt(input0_desc, "_parent_node_index", 0); + std::vector> range = {make_pair(1, -1), make_pair(1, -1)}; + input0_desc->SetValueRange(range); + + builder.AddDataEdge(data1, 0, switch1, 0); + builder.AddDataEdge(data2, 0, switch1, 1); + builder.AddDataEdge(switch1, 0, relu1, 0); + builder.AddDataEdge(switch1, 1, relu2, 0); + builder.AddDataEdge(relu1, 0, merge, 0); + builder.AddDataEdge(relu2, 0, merge, 1); + builder.AddDataEdge(merge, 0, netoutput, 0); + + return builder; +} + +void AddCaseSubgraph(ComputeGraphPtr &parent_graph, uint32_t branch_num) { + auto case_node = parent_graph->FindNode("case1"); + EXPECT_NE(case_node, nullptr); + + for (uint32_t i = 0; i < branch_num; ++i) { + string name = "Branch_Graph_" + std::to_string(i); + + auto builder_subgraph = SwitchSubgraphBuilder(name, i); + auto switch_subgraph = builder_subgraph.GetGraph(); + + case_node->GetOpDesc()->AddSubgraphName(switch_subgraph->GetName()); + case_node->GetOpDesc()->SetSubgraphInstanceName(i, switch_subgraph->GetName()); + + switch_subgraph->SetParentNode(case_node); + switch_subgraph->SetParentGraph(parent_graph); + EXPECT_EQ(parent_graph->AddSubgraph(switch_subgraph->GetName(), switch_subgraph), GRAPH_SUCCESS); + } +} + +TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UnregisteredNodeType) { + auto graph = std::make_shared("test_graph"); + GeTensorDesc ge_tensor_desc(GeShape({1, 1, 4, 192}), ge::FORMAT_NCHW, DT_FLOAT16); + auto addn_op_desc = std::make_shared("AddN", "AddN"); + addn_op_desc->AddInputDesc(ge_tensor_desc); + addn_op_desc->AddOutputDesc(ge_tensor_desc); + auto addn_op_node = graph->AddNode(addn_op_desc); + + InferValueRangePass infer_pass; + EXPECT_EQ(infer_pass.Run(addn_op_node), SUCCESS); +} + +auto ShapeValueInfer = [&](Operator &op) { + auto op_desc = OpDescUtils::GetOpDescFromOperator(op); + auto output_tensor_desc = op_desc->MutableOutputDesc(0); + std::vector> in_shape_range; + op_desc->MutableInputDesc(0)->GetShapeRange(in_shape_range); + if (!in_shape_range.empty()) { + output_tensor_desc->SetValueRange(in_shape_range); + } + return SUCCESS; +}; +REG_OP(Shape) + .OP_END_FACTORY_REG(Shape) +IMPL_INFER_VALUE_RANGE_FUNC(Shape, ShapeValueRangeFunc){ + auto op_desc = OpDescUtils::GetOpDescFromOperator(op); + auto output_tensor_desc = op_desc->MutableOutputDesc(0); + std::vector> in_shape_range; + op_desc->MutableInputDesc(0)->GetShapeRange(in_shape_range); + if (!in_shape_range.empty()) { + output_tensor_desc->SetValueRange(in_shape_range); + } + return GRAPH_SUCCESS; +} + +TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseRegistedFunc_NotInfer) { + INFER_VALUE_RANGE_CUSTOM_FUNC_REG(Shape, INPUT_IS_DYNAMIC, ShapeValueRangeFunc); + auto graph = std::make_shared("test_graph"); + GeTensorDesc ge_tensor_desc(GeShape({1, 1, 4, 192}), ge::FORMAT_NCHW, DT_INT32); + std::vector> shape_range = {make_pair(1, 1), make_pair(1, 1), + make_pair(4, 4), make_pair(192, 192)}; + ge_tensor_desc.SetShapeRange(shape_range); + GeTensorDesc output_tensor_desc(GeShape({4}), ge::FORMAT_NCHW, DT_INT32); + auto op_desc = std::make_shared("Shape", "Shape"); + op_desc->AddInputDesc(ge_tensor_desc); + op_desc->AddOutputDesc(output_tensor_desc); + auto op_node = graph->AddNode(op_desc); + + InferValueRangePass infer_pass; + EXPECT_EQ(infer_pass.Run(op_node), SUCCESS); + + auto output_0_desc = op_node->GetOpDesc()->GetOutputDesc(0); + std::vector> value_range; + output_0_desc.GetValueRange(value_range); + EXPECT_EQ(value_range.empty(), true); +} + +TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseRegistedFunc_DoInfer) { + // sqrt -> shape -> Output + INFER_VALUE_RANGE_CUSTOM_FUNC_REG(Shape, INPUT_IS_DYNAMIC, ShapeValueRangeFunc); + auto graph = std::make_shared("test_graph"); + GeTensorDesc sqrt_tensor_desc(GeShape({-1, -1, 4, 192}), ge::FORMAT_NCHW, DT_INT32); + std::vector> shape_range = {make_pair(1, 100), make_pair(1, 240), + make_pair(4, 4), make_pair(192, 192)}; + sqrt_tensor_desc.SetShapeRange(shape_range); + auto sqrt_op_desc = std::make_shared("Sqrt", "Sqrt"); + sqrt_op_desc->AddInputDesc(sqrt_tensor_desc); + sqrt_op_desc->AddOutputDesc(sqrt_tensor_desc); + auto sqrt_node = graph->AddNode(sqrt_op_desc); + + GeTensorDesc shape_output_desc(GeShape({4}), ge::FORMAT_NCHW, DT_INT32); + auto shape_op_desc = std::make_shared("Shape", "Shape"); + shape_op_desc->AddInputDesc(sqrt_tensor_desc); + shape_op_desc->AddOutputDesc(shape_output_desc); + auto shape_node = graph->AddNode(shape_op_desc); + + GeTensorDesc Output_in_tensor_desc(GeShape({4}), ge::FORMAT_NCHW, ge::DT_INT32); + auto Output_op_desc = std::make_shared("Output", "Output"); + Output_op_desc->AddInputDesc(Output_in_tensor_desc); + auto Output_node = graph->AddNode(Output_op_desc); + + ge::GraphUtils::AddEdge(sqrt_node->GetOutDataAnchor(0), shape_node->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), Output_node->GetInDataAnchor(0)); + EXPECT_EQ(graph->TopologicalSorting(), GRAPH_SUCCESS); + + + InferValueRangePass infer_pass; + auto ret = infer_pass.Run(shape_node); + EXPECT_EQ(ret, SUCCESS); + + auto output_0_desc = shape_node->GetOpDesc()->GetOutputDesc(0); + std::vector> value_range; + output_0_desc.GetValueRange(value_range); + EXPECT_EQ(value_range.size(), 4); + std::vector target_value_range = {1, 100, 1, 240, 4, 4, 192, 192}; + std::vector output_value_range; + for (auto pair : value_range) { + output_value_range.push_back(pair.first); + output_value_range.push_back(pair.second); + } + EXPECT_EQ(target_value_range, output_value_range); + + auto in_0_desc = Output_node->GetOpDesc()->GetInputDesc(0); + value_range.clear(); + in_0_desc.GetValueRange(value_range); + EXPECT_EQ(value_range.size(), 4); + output_value_range.clear(); + for (auto pair : value_range) { + output_value_range.push_back(pair.first); + output_value_range.push_back(pair.second); + } + EXPECT_EQ(target_value_range, output_value_range); + +} + +class AddKernel : public Kernel { + public: + Status Compute(const ge::OpDescPtr op_desc_ptr, const std::vector &input, + std::vector &v_output) override { + if (input[0]->GetTensorDesc().GetDataType() == DT_INT64 || input[0]->GetTensorDesc().GetDataType() == DT_UINT64) { + vector data_vec; + auto data_num = input[0]->GetTensorDesc().GetShape().GetShapeSize(); + auto x1_data = reinterpret_cast(input[0]->GetData().data()); + auto x2_data = reinterpret_cast(input[1]->GetData().data()); + for (size_t i = 0; i < data_num; i++) { + auto x_index = *(x1_data + i); + auto y_index = *(x2_data + i); + data_vec.push_back(x_index + y_index); + } + GeTensorPtr const_tensor = std::make_shared(input[0]->GetTensorDesc(), (uint8_t *)data_vec.data(), + data_num * sizeof(int64_t)); + v_output.emplace_back(const_tensor); + return SUCCESS; + } else if (input[0]->GetTensorDesc().GetDataType() == DT_INT32 || input[0]->GetTensorDesc().GetDataType() == DT_UINT32) { + vector data_vec; + auto data_num = input[0]->GetTensorDesc().GetShape().GetShapeSize(); + auto x1_data = reinterpret_cast(input[0]->GetData().data()); + auto x2_data = reinterpret_cast(input[1]->GetData().data()); + for (size_t i = 0; i < data_num; i++) { + auto x_index = *(x1_data + i); + auto y_index = *(x2_data + i); + data_vec.push_back(x_index + y_index); + } + GeTensorPtr const_tensor = std::make_shared(input[0]->GetTensorDesc(), (uint8_t *)data_vec.data(), + data_num * sizeof(int32_t)); + v_output.emplace_back(const_tensor); + return SUCCESS; + } + } +}; +REGISTER_KERNEL(ADD, AddKernel); +INFER_VALUE_RANGE_DEFAULT_REG(Add); +INFER_VALUE_RANGE_DEFAULT_REG(Sqrt); + +TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseCpuKernel_InputsHaveUnKnownValueRange) { + // shape --- add --- sqrt + // constant / + auto graph = std::make_shared("test_graph"); + + vector dims_vec = {4}; + vector data_vec = {1, 1, 1, 1}; + GeTensorDesc const_tensor_desc(ge::GeShape(dims_vec), ge::FORMAT_NCHW, ge::DT_INT64); + GeTensorPtr const_tensor = + std::make_shared(const_tensor_desc, (uint8_t *)data_vec.data(), data_vec.size() * sizeof(int64_t)); + + auto const_op_desc = std::make_shared("Constant", "Constant"); + const_op_desc->AddOutputDesc(const_tensor_desc); + EXPECT_EQ(OpDescUtils::SetWeights(const_op_desc, const_tensor), GRAPH_SUCCESS); + auto const_node = graph->AddNode(const_op_desc); + + GeTensorDesc shape_tensor_desc(GeShape({4}), ge::FORMAT_NCHW, ge::DT_INT64); + std::vector> unknown_value_range = {make_pair(1, -1), make_pair(1, 240), + make_pair(4, 4), make_pair(192, 192)}; + shape_tensor_desc.SetValueRange(unknown_value_range); + auto shape_op_desc = std::make_shared("Shape", "Shape"); + shape_op_desc->AddOutputDesc(shape_tensor_desc); + auto shape_node = graph->AddNode(shape_op_desc); + + GeTensorDesc add_tensor_desc(GeShape({4}), ge::FORMAT_NCHW, ge::DT_INT64); + auto add_op_desc = std::make_shared("Add", "Add"); + add_op_desc->AddInputDesc(shape_tensor_desc); + add_op_desc->AddInputDesc(const_tensor_desc); + add_op_desc->AddOutputDesc(add_tensor_desc); + auto add_node = graph->AddNode(add_op_desc); + + ge::GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), add_node->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(const_node->GetOutDataAnchor(0), add_node->GetInDataAnchor(1)); + + // test unknown value range + InferValueRangePass infer_pass; + EXPECT_EQ(infer_pass.Run(add_node), SUCCESS); + auto output_0_desc = add_node->GetOpDesc()->GetOutputDesc(0); + std::vector> out_value_range; + output_0_desc.GetValueRange(out_value_range); + EXPECT_EQ(out_value_range.size(), 4); + + std::vector unknown_target_value_range = {1, -1, 1, -1, 1, -1, 1, -1}; + std::vector output_value_range; + for (auto pair : out_value_range) { + output_value_range.push_back(pair.first); + output_value_range.push_back(pair.second); + } + EXPECT_EQ(unknown_target_value_range, output_value_range); +} + +TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseCpuKernel_InputsAreKnownValueRange_Int64) { + // shape --- add --- sqrt + // constant / + auto graph = std::make_shared("test_graph"); + + vector dims_vec = {4}; + vector data_vec = {1, 1, 1, 1}; + GeTensorDesc const_tensor_desc(ge::GeShape(dims_vec), ge::FORMAT_NCHW, ge::DT_INT64); + GeTensorPtr const_tensor = + std::make_shared(const_tensor_desc, (uint8_t *)data_vec.data(), data_vec.size() * sizeof(int64_t)); + + auto const_op_desc = std::make_shared("Constant", "Constant"); + const_op_desc->AddOutputDesc(const_tensor_desc); + EXPECT_EQ(OpDescUtils::SetWeights(const_op_desc, const_tensor), GRAPH_SUCCESS); + auto const_node = graph->AddNode(const_op_desc); + + GeTensorDesc shape_tensor_desc(GeShape({4}), ge::FORMAT_NCHW, ge::DT_INT64); + std::vector> unknown_value_range = {make_pair(1, 100), make_pair(1, 240), + make_pair(4, 4), make_pair(192, 192)}; + shape_tensor_desc.SetValueRange(unknown_value_range); + auto shape_op_desc = std::make_shared("Shape", "Shape"); + shape_op_desc->AddOutputDesc(shape_tensor_desc); + auto shape_node = graph->AddNode(shape_op_desc); + + GeTensorDesc add_tensor_desc(GeShape({4}), ge::FORMAT_NCHW, ge::DT_INT64); + auto add_op_desc = std::make_shared("Add", "Add"); + add_op_desc->AddInputDesc(shape_tensor_desc); + add_op_desc->AddInputDesc(const_tensor_desc); + add_op_desc->AddOutputDesc(add_tensor_desc); + auto add_node = graph->AddNode(add_op_desc); + + auto sqrt_op_desc = std::make_shared("Sqrt", "Sqrt"); + sqrt_op_desc->AddInputDesc(GeTensorDesc()); + auto sqrt_node = graph->AddNode(sqrt_op_desc); + + ge::GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), add_node->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(const_node->GetOutDataAnchor(0), add_node->GetInDataAnchor(1)); + ge::GraphUtils::AddEdge(add_node->GetOutDataAnchor(0), sqrt_node->GetInDataAnchor(1)); + + InferValueRangePass infer_pass; + EXPECT_EQ(infer_pass.Run(sqrt_node), SUCCESS); + + // test known value range + EXPECT_EQ(infer_pass.Run(add_node), SUCCESS); + auto output_0_desc = add_node->GetOpDesc()->GetOutputDesc(0); + std::vector> out_value_range; + output_0_desc.GetValueRange(out_value_range); + EXPECT_EQ(out_value_range.size(), 4); + + std::vector target_value_range = {2, 101, 2, 241, 5, 5, 193, 193}; + std::vector output_value_range; + for (auto pair : out_value_range) { + output_value_range.push_back(pair.first); + output_value_range.push_back(pair.second); + } + EXPECT_EQ(target_value_range, output_value_range); +} + +TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseCpuKernel_InputsAreKnownValueRange_Int32) { + // shape --- add --- sqrt + // constant / + auto graph = std::make_shared("test_graph"); + vector data_vec = {1, 100, 2, 200}; + GeTensorDesc const_tensor_desc(ge::GeShape({4}), ge::FORMAT_NCHW, ge::DT_INT32); + GeTensorPtr const_tensor = + std::make_shared(const_tensor_desc, (uint8_t *)data_vec.data(), data_vec.size() * sizeof(int32_t)); + auto const_op_desc = std::make_shared("Constant", "Constant"); + const_op_desc->AddOutputDesc(const_tensor_desc); + EXPECT_EQ(OpDescUtils::SetWeights(const_op_desc, const_tensor), GRAPH_SUCCESS); + auto const_node = graph->AddNode(const_op_desc); + + GeTensorDesc shape_tensor_desc(GeShape({4}), ge::FORMAT_NCHW, ge::DT_INT32); + std::vector> known_value_range = {make_pair(1, 100), make_pair(1, 240), + make_pair(4, 4), make_pair(192, 192)}; + shape_tensor_desc.SetValueRange(known_value_range); + auto shape_op_desc = std::make_shared("Shape", "Shape"); + shape_op_desc->AddOutputDesc(shape_tensor_desc); + auto shape_node = graph->AddNode(shape_op_desc); + + GeTensorDesc add_tensor_desc(GeShape({4}), ge::FORMAT_NCHW, ge::DT_INT32); + auto add_op_desc = std::make_shared("Add", "Add"); + add_op_desc->AddInputDesc(shape_tensor_desc); + add_op_desc->AddInputDesc(const_tensor_desc); + add_op_desc->AddOutputDesc(add_tensor_desc); + auto add_node = graph->AddNode(add_op_desc); + + ge::GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), add_node->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(const_node->GetOutDataAnchor(0), add_node->GetInDataAnchor(1)); + + InferValueRangePass infer_pass; + EXPECT_EQ(infer_pass.Run(add_node), SUCCESS); + auto output_0_desc = add_node->GetOpDesc()->GetOutputDesc(0); + std::vector> out_value_range; + output_0_desc.GetValueRange(out_value_range); + EXPECT_EQ(out_value_range.size(), 4); + + std::vector target_value_range = {2, 101, 101, 340, 6, 6, 392, 392}; + std::vector output_value_range; + for (auto pair : out_value_range) { + output_value_range.push_back(pair.first); + output_value_range.push_back(pair.second); + } + EXPECT_EQ(target_value_range, output_value_range); +} + +REG_OP(Case) + .OP_END_FACTORY_REG(Case) +IMPL_INFER_VALUE_RANGE_FUNC(Case, ValueRangeFunc){ + auto op_desc = OpDescUtils::GetOpDescFromOperator(op); + auto output_tensor_desc = op_desc->MutableOutputDesc(0); + std::vector> in_value_range; + output_tensor_desc->GetValueRange(in_value_range); + if (in_value_range.empty()) { + std::vector> out_value_range = {make_pair(1, 2), make_pair(1, 3), + make_pair(1, 4), make_pair(1, 5)};; + output_tensor_desc->SetValueRange(out_value_range); + } + return GRAPH_SUCCESS; +} +INFER_VALUE_RANGE_CUSTOM_FUNC_REG(Case, INPUT_HAS_VALUE_RANGE, ValueRangeFunc); + +TEST_F(UtestGraphInferValueRangePass, CallRun_HasCaeSubgraph_WhenBeforeSubgraph) { + auto builder = ParentGraphBuilder(); + auto parent_graph = builder.GetGraph(); + AddCaseSubgraph(parent_graph, 2); + auto subgraphs = parent_graph->GetAllSubgraphs(); + EXPECT_EQ(subgraphs.size(), 2); + + // check before subgraph + auto case_node = parent_graph->FindNode("case1"); + EXPECT_NE(case_node, nullptr); + InferValueRangePass infer_pass; + EXPECT_EQ(infer_pass.Run(case_node), SUCCESS); + + auto case_out_0_desc = case_node->GetOpDesc()->MutableOutputDesc(0); + std::vector> out_value_range; + case_out_0_desc->GetValueRange(out_value_range); + EXPECT_EQ(out_value_range.size(), 4); + std::vector target_value_range = {1,2,1,3,1,4,1,5}; + std::vector output_value_range_list; + for (auto pair : out_value_range) { + output_value_range_list.push_back(pair.first); + output_value_range_list.push_back(pair.second); + } + EXPECT_EQ(target_value_range, output_value_range_list); + + auto data_node = subgraphs[0]->FindNode("data1_0"); + auto data_output_0_desc = data_node->GetOpDesc()->GetOutputDesc(0); + std::vector target_value_range_list = {1, 1, 1, 1, 1, -1, 1, 224}; + std::vector> output_value_range; + data_output_0_desc.GetValueRange(output_value_range); + EXPECT_EQ(output_value_range.size(), 4); + std::vector data_value_range_list; + for (auto pair : output_value_range) { + data_value_range_list.push_back(pair.first); + data_value_range_list.push_back(pair.second); + } + EXPECT_EQ(data_value_range_list, target_value_range_list); + + data_node = subgraphs[0]->FindNode("data2_0"); + auto data2_input_0_desc = data_node->GetOpDesc()->GetInputDesc(0); + std::vector target_value_range_list2 = {1, 100, 1, 10}; + out_value_range.clear(); + data2_input_0_desc.GetValueRange(out_value_range); + EXPECT_EQ(out_value_range.size(), 2); + data_value_range_list.clear(); + for (auto pair : out_value_range) { + data_value_range_list.push_back(pair.first); + data_value_range_list.push_back(pair.second); + } + EXPECT_EQ(data_value_range_list, target_value_range_list2); +} + +TEST_F(UtestGraphInferValueRangePass, CallRun_HasCaeSubgraph_WhenAfterSubgraph) { + auto builder = ParentGraphBuilder(); + auto parent_graph = builder.GetGraph(); + AddCaseSubgraph(parent_graph, 2); + auto subgraphs = parent_graph->GetAllSubgraphs(); + EXPECT_EQ(subgraphs.size(), 2); + + auto case_node = parent_graph->FindNode("case1"); + EXPECT_NE(case_node, nullptr); + InferValueRangePass infer_pass; + // check after subgraph + infer_pass.options_[kOptimizeAfterSubGraph] = "yes"; + EXPECT_EQ(infer_pass.Run(case_node), SUCCESS); + + std::vector out_target_dims = {1, -1, 1, -1}; + auto case_out = case_node->GetOpDesc()->GetOutputDescPtr(0); + std::vector> out_value_range; + case_out->GetValueRange(out_value_range); + EXPECT_EQ(out_value_range.size(), 2); + + std::vector output_value_range_list; + for (auto pair : out_value_range) { + output_value_range_list.push_back(pair.first); + output_value_range_list.push_back(pair.second); + } + EXPECT_EQ(out_target_dims, output_value_range_list); +} + +TEST_F(UtestGraphInferValueRangePass, CallRun_HasSubgraph_WhenAfterSubgraph_ForMultiDims) { + auto builder = ParentGraphBuilder(); + auto parent_graph = builder.GetGraph(); + AddCaseSubgraph(parent_graph, 2); + auto subgraphs = parent_graph->GetAllSubgraphs(); + EXPECT_EQ(subgraphs.size(), 2); + + auto case_node = parent_graph->FindNode("case1"); + EXPECT_NE(case_node, nullptr); + InferValueRangePass infer_pass; + infer_pass.options_[kOptimizeAfterSubGraph] = "yes"; + + // check after subgraph for multi-batch + auto set_ret = AttrUtils::SetInt(case_node->GetOpDesc(), ATTR_NAME_BATCH_NUM, 2); + EXPECT_EQ(set_ret, true); + EXPECT_EQ(infer_pass.Run(case_node), GRAPH_FAILED); +} +} // namespace ge From eccff67f421da4ae147c629f61821676acf550d2 Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Sat, 26 Jun 2021 15:42:55 +0800 Subject: [PATCH 10/50] Clear UpdatePersistTensor Warning for first run --- ge/graph/passes/mark_force_unknown_for_cond_pass.cc | 6 +++--- ge/graph/passes/mark_force_unknown_for_cond_pass.h | 2 +- ge/hybrid/executor/node_state.cc | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ge/graph/passes/mark_force_unknown_for_cond_pass.cc b/ge/graph/passes/mark_force_unknown_for_cond_pass.cc index 233a1ff0..aa36a43b 100644 --- a/ge/graph/passes/mark_force_unknown_for_cond_pass.cc +++ b/ge/graph/passes/mark_force_unknown_for_cond_pass.cc @@ -56,8 +56,8 @@ Status MarkForceUnknownForCondPass::Run(ComputeGraphPtr graph) { /// @param [out] Search queue /// @return true: Switch In while loop / false: Not in while Loop. /// -bool MarkForceUnknownForCondPass::DealWithLoopSwitch(const NodePtr &node, uint32_t dst_span, - std::queue> search_queue) { +bool MarkForceUnknownForCondPass::DealAsLoopSwitch(const NodePtr &node, uint32_t dst_span, + std::queue> &search_queue) { /// LoopCond --->\. /// \. /// Enter-----------+ \. @@ -121,7 +121,7 @@ void MarkForceUnknownForCondPass::MarkUnknownForSwitch(const NodePtr &node, std: GELOGD("Travel node: %s, %s node: %s, span is: %u", dst_node->GetName().c_str(), node_type.c_str(), in_node->GetName().c_str(), dst_span); if (kSwitchOpTypes.count(node_type) > 0) { // Switch input node. - if (DealWithLoopSwitch(in_node, dst_span, search_queue)) { + if (DealAsLoopSwitch(in_node, dst_span, search_queue)) { continue; } diff --git a/ge/graph/passes/mark_force_unknown_for_cond_pass.h b/ge/graph/passes/mark_force_unknown_for_cond_pass.h index d2be9a9e..030b55ee 100644 --- a/ge/graph/passes/mark_force_unknown_for_cond_pass.h +++ b/ge/graph/passes/mark_force_unknown_for_cond_pass.h @@ -34,7 +34,7 @@ class MarkForceUnknownForCondPass : public GraphPass { /// @param [out] Search queue /// @return true: Switch In while loop / false: Not in while Loop. /// - bool DealWithLoopSwitch(const NodePtr &node, uint32_t dst_span, std::queue> search_queue); + bool DealAsLoopSwitch(const NodePtr &node, uint32_t dst_span, std::queue> &search_queue); /// /// @brief Mark force unknown shape for Switch node diff --git a/ge/hybrid/executor/node_state.cc b/ge/hybrid/executor/node_state.cc index 7ab7b536..ad38c792 100644 --- a/ge/hybrid/executor/node_state.cc +++ b/ge/hybrid/executor/node_state.cc @@ -355,6 +355,10 @@ void NodeState::UpdatePersistTensor() { } }; + if (root_tensor_values_.empty()) { + return; + } + update_tensor(node_item_->root_data_); if (iteration_count_ > 0) { update_tensor(node_item_->enter_data_); From 01dfd8974956525c7977f926a94aee25335c7b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=B6=9B?= Date: Sat, 26 Jun 2021 16:16:34 +0800 Subject: [PATCH 11/50] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!1?= =?UTF-8?q?849=20:=20add=20copy=20graph'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ge/graph/manager/graph_manager.cc | 2 +- ge/hybrid/model/hybrid_model.h | 1 - ge/hybrid/model/hybrid_model_builder.cc | 47 ++++--------------- ge/hybrid/model/hybrid_model_builder.h | 1 - ge/model/ge_root_model.h | 5 -- .../executor/subgraph_executor_unittest.cc | 3 -- .../model/hybrid_model_builder_unittest.cc | 26 ++-------- 7 files changed, 15 insertions(+), 70 deletions(-) diff --git a/ge/graph/manager/graph_manager.cc b/ge/graph/manager/graph_manager.cc index 01a2e502..66026f8d 100755 --- a/ge/graph/manager/graph_manager.cc +++ b/ge/graph/manager/graph_manager.cc @@ -3131,10 +3131,10 @@ void GraphManager::PreRunThread(GraphManager *graph_manager) { } // Avoid repeatively prerun for graphs owns same graph_id in online inference concurrency if (count > 1 && graph_node->GetBuildFlag()) { + graph_node->Lock(); GELOGD("Avoid repeatively prerun, graph_id:%u.", args.graph_id); // In online inference concurrency senario, graph_node is allowed to be locked for 'count' times graph_node->SetSemSize(count); - graph_node->Lock(); graph_manager->run_args_q_.Push(RunArgs( { graph_node, args.graph_id, args.session_id, args.error_context, args.input_tensor, graph_node->GetGeRootModel(), GetThreadLocalContext(), args.callback })); GELOGI("[PreRunThread] Loop end. Start to run with cached build model."); diff --git a/ge/hybrid/model/hybrid_model.h b/ge/hybrid/model/hybrid_model.h index 77246e20..9821242a 100644 --- a/ge/hybrid/model/hybrid_model.h +++ b/ge/hybrid/model/hybrid_model.h @@ -147,7 +147,6 @@ class HybridModel { GeRootModelPtr ge_root_model_; std::map input_nodes_; ComputeGraphPtr root_graph_; - ComputeGraphPtr orig_root_graph_; std::map device_variable_nodes_; //lint !e148 std::map host_variable_nodes_; //lint !e148 std::map> variable_tensors_; diff --git a/ge/hybrid/model/hybrid_model_builder.cc b/ge/hybrid/model/hybrid_model_builder.cc index 8f96ea9d..1f68f374 100755 --- a/ge/hybrid/model/hybrid_model_builder.cc +++ b/ge/hybrid/model/hybrid_model_builder.cc @@ -147,7 +147,6 @@ Status HybridModelBuilder::Build() { GE_CHK_STATUS_RET(ValidateParams(), "[Invoke][ValidateParams] failed, model_name_:[%s]", GetGraphName()); hybrid_model_.model_name_ = ge_root_model_->GetModelName(); GELOGI("[%s] Start to build hybrid model.", GetGraphName()); - GE_CHK_STATUS_RET(CopyGraph(), "[Invoke][CopyGraph] failed, model_name_:[%s]", GetGraphName()); GE_CHK_STATUS_RET(InitRuntimeParams(), "[Invoke][InitRuntimeParams] failed, model_name_:[%s]", GetGraphName()); GE_CHK_STATUS_RET(RecoverGraphUnknownFlag(), "[Invoke][RecoverGraphUnknownFlag] failed, model_name_:[%s]", GetGraphName()); @@ -172,12 +171,11 @@ Status HybridModelBuilder::Build() { Status HybridModelBuilder::BuildForSingleOp() { GE_CHK_STATUS_RET(ValidateParams(), "[Invoke][ValidateParams] failed, model_name_:[%s]", GetGraphName()); - hybrid_model_.root_graph_ = ge_root_model_->GetRootGraph(); hybrid_model_.model_name_ = ge_root_model_->GetRootGraph()->GetName(); GELOGI("[%s] Start to build hybrid model.", GetGraphName()); auto ret = ge_root_model_->GetSubgraphInstanceNameToModel(); - const GeModelPtr ge_model = ret[hybrid_model_.root_graph_->GetName()]; - GE_CHK_STATUS_RET(IndexTaskDefs(hybrid_model_.root_graph_, ge_model), + const GeModelPtr ge_model = ret[ge_root_model_->GetRootGraph()->GetName()]; + GE_CHK_STATUS_RET(IndexTaskDefs(ge_root_model_->GetRootGraph(), ge_model), "[Invoke][IndexTaskDefs] failed, model_name_:[%s]", GetGraphName()); GE_CHK_STATUS_RET(LoadGraph(), "[Invoke][LoadGraph] failed, model_name_:[%s]", GetGraphName()); GE_CHK_STATUS_RET(InitWeights(), "[Invoke][InitWeights] failed, model_name_:[%s]", GetGraphName()); @@ -192,29 +190,6 @@ Status HybridModelBuilder::ValidateParams() { return SUCCESS; } -Status HybridModelBuilder::CopyGraph() { - GELOGD("Copy compute graph begin."); - auto root_graph = ge_root_model_->GetRootGraph(); - - ge_root_model_->IncreaseBuildTimes(); - std::string new_graph_name = ge_root_model_->GetRootGraph()->GetName() + "_" + - std::to_string(ge_root_model_->GetBuildTimes()); - ComputeGraphPtr new_root_graph = MakeShared(new_graph_name); - GE_CHECK_NOTNULL(new_root_graph); - int32_t depth = 0; - std::map node_old_2_new; - std::map op_desc_old_2_new; - graphStatus ret = GraphUtils::CopyComputeGraph(root_graph, new_root_graph, node_old_2_new, op_desc_old_2_new, depth); - if (ret != GRAPH_SUCCESS) { - GELOGE(GRAPH_FAILED, "Copy compute graph failed."); - return GRAPH_FAILED; - } - hybrid_model_.root_graph_ = new_root_graph; - - GELOGD("Copy compute graph[%s] success.", new_graph_name.c_str()); - return SUCCESS; -} - Status HybridModelBuilder::BuildNodeItem(const NodePtr &node, NodeItem &node_item) { auto op_desc = node->GetOpDesc(); GE_CHK_STATUS_RET(ParseForceInfershapeNodes(node, node_item), @@ -835,13 +810,12 @@ Status HybridModelBuilder::BuildOutputMapping(GraphItem &graph_item, } Status HybridModelBuilder::LoadGraph() { - auto root_graph = hybrid_model_.root_graph_; + auto root_graph = ge_root_model_->GetRootGraph(); if (!GetContext().GetHostExecFlag()) { std::shared_ptr merged_graph; GELOGI("Before merging subgraphs DirectNodesSize = %zu, GetAllNodesSize = %zu", root_graph->GetDirectNodesSize(), root_graph->GetAllNodesSize()); - hybrid_model_.orig_root_graph_ = root_graph; GE_CHK_GRAPH_STATUS_RET(UnfoldSubgraphs(root_graph, merged_graph), "[Invoke][UnfoldSubgraphs]Failed to unfold subgraphs, model_name_:%s.", GetGraphName()); root_graph = std::move(merged_graph); @@ -899,7 +873,6 @@ Status HybridModelBuilder::LoadGraph() { } for (auto &it : hybrid_model_.known_shape_sub_models_) { auto node_item = MutableNodeItem(it.first); - GE_CHECK_NOTNULL(node_item); AscendString graph_name; GE_CHK_GRAPH_STATUS_RET(it.second->GetGraph().GetName(graph_name), "Failed to get subgraph name"); auto subgraph = hybrid_model_.GetRootGraph()->GetSubgraph(graph_name.GetString()); @@ -1148,9 +1121,7 @@ Status HybridModelBuilder::InitWeights() { sub_weight_buffer->GetSize()); auto subgraph = GraphUtils::GetComputeGraph(subgraph_model.second->GetGraph()); if (subgraph != ge_root_model_->GetRootGraph()) { - subgraph = hybrid_model_.root_graph_->GetSubgraph(subgraph_model.first); - } else { - subgraph = hybrid_model_.root_graph_; + subgraph = ge_root_model_->GetRootGraph()->GetSubgraph(subgraph_model.first); } GE_CHECK_NOTNULL(subgraph); hybrid_model_.weight_buffer_map_.emplace(subgraph->GetName(), std::move(sub_weight_buffer)); @@ -1329,7 +1300,7 @@ Status HybridModelBuilder::IndexTaskDefs(const ComputeGraphPtr &sub_graph, const } Status HybridModelBuilder::IndexTaskDefs() { - const auto &root_graph = hybrid_model_.root_graph_; + const auto root_graph = ge_root_model_->GetRootGraph(); const auto &root_graph_name = root_graph->GetName(); if (SetOutputNameAttr(*root_graph) != SUCCESS) { GELOGW("Set output name attr failed."); @@ -1363,7 +1334,7 @@ Status HybridModelBuilder::IndexTaskDefs() { Status HybridModelBuilder::IndexSpecialNodes() { GELOGD("Start to index special nodes"); - const auto &root_graph = hybrid_model_.root_graph_; + const auto &root_graph = ge_root_model_->GetRootGraph(); for (auto &node : root_graph->GetAllNodes()) { GE_CHECK_NOTNULL(node); GE_CHECK_NOTNULL(node->GetOpDesc()); @@ -1518,7 +1489,7 @@ Status HybridModelBuilder::InitRuntimeParams() { runtime_param_.session_id = ret ? static_cast(value) : 0; ret = ge::AttrUtils::GetInt(first_model, ATTR_MODEL_TASK_GEN_VAR_ADDR, value); runtime_param_.logic_var_base = ret ? static_cast(value) : 0; - runtime_param_.graph_id = hybrid_model_.root_graph_->GetGraphID(); + runtime_param_.graph_id = ge_root_model_->GetRootGraph()->GetGraphID(); value = 0; for (auto &it : ge_root_model_->GetSubgraphInstanceNameToModel()) { (void) ge::AttrUtils::GetInt(it.second, ATTR_MODEL_VAR_SIZE, value); @@ -1655,7 +1626,7 @@ Status HybridModelBuilder::TransAllVarData() { } Status HybridModelBuilder::CopyVarData() { - GE_CHK_STATUS_RET(TransVarDataUtils::CopyVarData(hybrid_model_.root_graph_, + GE_CHK_STATUS_RET(TransVarDataUtils::CopyVarData(ge_root_model_->GetRootGraph(), runtime_param_.session_id, hybrid_model_.device_id_), "[Invoke][CopyVarData] failed."); @@ -1738,7 +1709,7 @@ Status HybridModelBuilder::LoadKnownShapedSubgraph(ComputeGraph &graph, NodeItem } Status HybridModelBuilder::RecoverGraphUnknownFlag() { - const auto &root_graph = hybrid_model_.root_graph_; + const auto &root_graph = ge_root_model_->GetRootGraph(); for (auto &sub_graph : root_graph->GetAllSubgraphs()) { GE_CHECK_NOTNULL(sub_graph); for (const auto &node : sub_graph->GetDirectNode()) { diff --git a/ge/hybrid/model/hybrid_model_builder.h b/ge/hybrid/model/hybrid_model_builder.h index 05830e82..9c1eb187 100644 --- a/ge/hybrid/model/hybrid_model_builder.h +++ b/ge/hybrid/model/hybrid_model_builder.h @@ -56,7 +56,6 @@ class HybridModelBuilder { Status BuildOutputMapping(GraphItem &partitioned_call, const NodeItem &node_item, bool is_root_graph); Status ValidateParams(); Status LoadGraph(); - Status CopyGraph(); Status LoadGeModel(ComputeGraph &graph, const GeModelPtr &ge_model); static Status InitHcclExecutorOnDemand(const GeModelPtr &ge_model); Status LoadTask(NodeItem &node_item); diff --git a/ge/model/ge_root_model.h b/ge/model/ge_root_model.h index b6e3d081..9e8e116e 100755 --- a/ge/model/ge_root_model.h +++ b/ge/model/ge_root_model.h @@ -60,10 +60,6 @@ class GeRootModel { bool GetTrainFlag() const { return train_flag_; } - int32_t GetBuildTimes() const { return hybrid_build_times_; } - - void IncreaseBuildTimes() { hybrid_build_times_++; } - private: ComputeGraphPtr root_graph_ = nullptr; std::map subgraph_instance_name_to_model_; @@ -73,7 +69,6 @@ class GeRootModel { bool train_flag_ = false; std::string model_name_; bool is_specific_stream_ = false; - int32_t hybrid_build_times_ = 0; }; } // namespace ge using GeRootModelPtr = std::shared_ptr; diff --git a/tests/ut/ge/hybrid/executor/subgraph_executor_unittest.cc b/tests/ut/ge/hybrid/executor/subgraph_executor_unittest.cc index 827705ae..2dc3b639 100644 --- a/tests/ut/ge/hybrid/executor/subgraph_executor_unittest.cc +++ b/tests/ut/ge/hybrid/executor/subgraph_executor_unittest.cc @@ -249,9 +249,6 @@ TEST_F(UtestSubgraphExecutor, cond_graph_schedule_tasks) { graph_context.callback_manager = std::unique_ptr(new CallbackManager()); ASSERT_EQ(graph_context.callback_manager->Init(), SUCCESS); - auto root_graph = hybrid_model.root_graph_; - switch_t = root_graph->FindNode("switch_t"); - switch_f = root_graph->FindNode("switch_f"); const auto node_it_t = hybrid_model.node_items_.find(switch_t); const auto node_it_f = hybrid_model.node_items_.find(switch_f); ASSERT_NE(hybrid_model.node_items_.end(), node_it_t); diff --git a/tests/ut/ge/hybrid/model/hybrid_model_builder_unittest.cc b/tests/ut/ge/hybrid/model/hybrid_model_builder_unittest.cc index 10f7c0fe..5567aca2 100644 --- a/tests/ut/ge/hybrid/model/hybrid_model_builder_unittest.cc +++ b/tests/ut/ge/hybrid/model/hybrid_model_builder_unittest.cc @@ -214,17 +214,11 @@ TEST_F(UtestHybridModelBuilder, normal_hybrid_model_build) { ASSERT_EQ(it->second->frame_index_, index); ASSERT_EQ(it->second->parent_frame_, -1); }; - auto root_graph = hybrid_model.root_graph_; - auto enter1_node = root_graph->FindNode("enter"); - auto active1_node = root_graph->FindNode("active1"); - auto active2_node = root_graph->FindNode("active2"); - auto active3_node = root_graph->FindNode("active3"); - auto output1_node = root_graph->FindNode("net_output"); - TestFrameGroup(enter1_node, control_group_index); - TestFrameGroup(active1_node, control_group_index); - TestFrameGroup(active2_node, control_group_index); - TestFrameGroup(active3_node, control_group_index); - TestFrameGroup(output1_node, -1); + TestFrameGroup(enter1, control_group_index); + TestFrameGroup(active1, control_group_index); + TestFrameGroup(active2, control_group_index); + TestFrameGroup(active3, control_group_index); + TestFrameGroup(output1, -1); engine_mapping.clear(); task_executor.clear(); @@ -379,14 +373,4 @@ TEST_F(UtestHybridModelBuilder, TestInitHcclExecutorOnDemand) { NodeExecutorManager::GetInstance().builders_.erase(NodeExecutorManager::ExecutorType::HCCL); ASSERT_EQ(HybridModelBuilder::InitHcclExecutorOnDemand(ge_model), SUCCESS); } - -TEST_F(UtestHybridModelBuilder, copy_graph_success) { -ComputeGraphPtr graph = std::make_shared("test"); -GeRootModelPtr ge_root_model = make_shared(graph); -HybridModel hybrid_model(ge_root_model); -HybridModelBuilder hybrid_model_builder(hybrid_model); - -Status st = hybrid_model_builder.CopyGraph(); -EXPECT_EQ(st, SUCCESS); -} } // namespace ge From 572990a616dc60da23bcb70fbd436e7f2948cc88 Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Sat, 26 Jun 2021 23:20:31 +0800 Subject: [PATCH 12/50] UT for control flow group --- tests/depends/mmpa/src/mmpa_stub.cc | 4 + tests/ut/ge/CMakeLists.txt | 3 +- .../logical_stream_allocator_unittest.cc | 10 +- .../graph/build/stream_allocator_unittest.cc | 2 +- .../ge/graph/passes/assert_pass_unittest.cc | 6 +- .../ut/ge/graph/passes/base_pass_unittest.cc | 14 +- .../graph/passes/cond_branch_v1_unittest.cc | 6 +- .../passes/constant_folding_pass_unittest.cc | 38 +++--- .../passes/dimension_compute_pass_unittest.cc | 8 +- .../ssd_prior_box_kernel_unittest.cc | 2 +- ...a_nodes_with_common_input_pass_unittest.cc | 2 +- ...rk_force_unknown_for_cond_pass_unittest.cc | 129 ++++++++++++------ .../ut/ge/graph/passes/merge_pass_unittest.cc | 28 ++-- .../passes/parallel_group_pass_unittest.cc | 12 +- .../passes/reshape_recovery_pass_unittest.cc | 6 +- .../passes/reshape_remove_pass_unittest.cc | 16 +-- .../resource_pair_control_pass_unittest.cc | 2 +- .../switch_logic_remove_pass_unittest.cc | 12 +- .../trans_op_breadth_fusion_pass_unittest.cc | 4 +- .../trans_op_depth_fusion_pass_unittest.cc | 14 +- ...p_nearby_allreduce_fusion_pass_unittest.cc | 4 +- .../graph/passes/variable_op_pass_unittest.cc | 2 +- .../variable_accelerate_ctrl_unittest.cc | 10 +- 23 files changed, 195 insertions(+), 139 deletions(-) diff --git a/tests/depends/mmpa/src/mmpa_stub.cc b/tests/depends/mmpa/src/mmpa_stub.cc index aae8de9f..b0f1fb87 100644 --- a/tests/depends/mmpa/src/mmpa_stub.cc +++ b/tests/depends/mmpa/src/mmpa_stub.cc @@ -345,6 +345,10 @@ INT32 mmIsDir(const CHAR *fileName) INT32 mmGetEnv(const CHAR *name, CHAR *value, UINT32 len) { + const char *env = getenv(name); + if (env != nullptr) { + strcpy(value, env); + } return 0; } diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 95b9e388..57677cf0 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -720,7 +720,6 @@ set(PASS_TEST_FILES "graph/passes/memcpy_addr_async_unittest.cc" "graph/passes/hccl_continuous_pass_unittest.cc" "graph/passes/hccl_memcpy_pass_unittest.cc" - ) set(KERNEL_TEST_FILES @@ -850,7 +849,6 @@ set(HYBRID_TEST_FILES "hybrid/executor/hybrid_model_async_executor_unittest.cc" "hybrid/executor/hybrid_model_pipeline_executor_unittest.cc" "hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc" - ) set(OTHERS_TEST_FILES @@ -877,6 +875,7 @@ add_library(ge_ut_graph STATIC target_compile_definitions(ge_ut_graph PRIVATE google=ascend_private + FMK_SUPPORT_DUMP ) target_compile_options(ge_ut_graph PRIVATE diff --git a/tests/ut/ge/graph/build/logical_stream_allocator_unittest.cc b/tests/ut/ge/graph/build/logical_stream_allocator_unittest.cc index 218bfd0d..352984fa 100644 --- a/tests/ut/ge/graph/build/logical_stream_allocator_unittest.cc +++ b/tests/ut/ge/graph/build/logical_stream_allocator_unittest.cc @@ -349,7 +349,7 @@ class UtestLogicalStreamAllocator : public testing::Test { /// B --> C(AllReduce) --- D /// / /// stream id: 0 A - /// \ + /// \. /// E --> F(AllReduce) --- G /// stream id: 2 2 2 /// @@ -599,7 +599,7 @@ TEST_F(UtestLogicalStreamAllocator, test_label_not_reusable2) { /// case of multi-output, then unuse stream /// sub1 -/// / | \ +/// / | \. /// sub2 sub3 sub4 TEST_F(UtestLogicalStreamAllocator, test_multiOut_new_stream) { SubGraphInfoPtr data = CreateDataSubgraph(); @@ -624,7 +624,7 @@ TEST_F(UtestLogicalStreamAllocator, test_multiOut_new_stream) { /// if paralle id 1, then use stream /// sub1 -/// / | | \ +/// / | | \. /// sub2 sub3 sub4 sub5 TEST_F(UtestLogicalStreamAllocator, test_parallel_one) { SubGraphInfoPtr data = CreateDataSubgraph(); @@ -653,7 +653,7 @@ TEST_F(UtestLogicalStreamAllocator, test_parallel_one) { /// if the param of engine independent is true, then set independent stream /// sub1 -/// / | | \ +/// / | | \. /// sub2 sub3 sub4 sub5 TEST_F(UtestLogicalStreamAllocator, test_independent) { SubGraphInfoPtr data = CreateDataSubgraph(); @@ -692,7 +692,7 @@ TEST_F(UtestLogicalStreamAllocator, test_independent) { /// set stream based on stream label, and then based on independent /// sub1 -/// / | | \ +/// / | | \. /// sub2 sub3 sub4 sub5 TEST_F(UtestLogicalStreamAllocator, test_independent_switch_label) { SubGraphInfoPtr data = CreateDataSubgraph(); diff --git a/tests/ut/ge/graph/build/stream_allocator_unittest.cc b/tests/ut/ge/graph/build/stream_allocator_unittest.cc index 019e75d1..4ae871af 100644 --- a/tests/ut/ge/graph/build/stream_allocator_unittest.cc +++ b/tests/ut/ge/graph/build/stream_allocator_unittest.cc @@ -36,7 +36,7 @@ class UtestStreamAllocator : public testing::Test { /// /// A - /// / \ + /// / \. /// B C /// | | /// D 400 diff --git a/tests/ut/ge/graph/passes/assert_pass_unittest.cc b/tests/ut/ge/graph/passes/assert_pass_unittest.cc index 4aa133d3..9247681c 100644 --- a/tests/ut/ge/graph/passes/assert_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/assert_pass_unittest.cc @@ -55,7 +55,7 @@ class UtestGraphPassesAssertPass : public Test { }; /// D E -/// | \ | \ +/// | \ | \. /// F C G /// : | : /// H A I @@ -134,8 +134,8 @@ TEST_F(UtestGraphPassesAssertPass, assert_pass_test2) { EXPECT_EQ(graph->FindNode("D"), nullptr); } -/// E F -/// | \ | \ +/// E F +/// | \ | \. /// H C -> D G /// \ | : /// A I diff --git a/tests/ut/ge/graph/passes/base_pass_unittest.cc b/tests/ut/ge/graph/passes/base_pass_unittest.cc index 9bba5d77..c687e07f 100644 --- a/tests/ut/ge/graph/passes/base_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/base_pass_unittest.cc @@ -130,7 +130,7 @@ class UTESTGraphPassesBasePass : public testing::Test { /// reshape1 /// | /// add1 -/// / \ +/// / \. /// | | /// data1 const1 ComputeGraphPtr BuildGraph1() { @@ -148,9 +148,9 @@ ComputeGraphPtr BuildGraph1() { } /// sum1 -/// / \ -/// / \ -/// / \ +/// / \. +/// / \. +/// / \. /// reshape1 addn1 /// | c | /// add1 <--- shape1 @@ -217,7 +217,7 @@ void CheckIterOrder(UtestTestPass *pass, std::vector &loop, vector &cond) { /******************************************************************************* - * Exit Identify - * \ / \. - * \ / \. - * Switch Add - * / | | - * / | | - * / | | - * LoopCond | | - * \ | | - * \ | | - * \ | | - * Less | | - * \ | NextIteration - * \ | | - * \ | | - * Merge <---------| - * | - * | - * Enter + * | + * +--------------------- Merge ----------------------+ + * / | + * / | + * / | + * / | + * Exit Identify | + * \ / \. | + * \ / \. | + * Switch Add Add + * / | | | + * / | | | + * / | | | + * LoopCond | | | + * \ | | | + * \ | | | + * \ | | | + * Less | | | + * \ | NextIteration | + * \ | | | + * \ | | | + * Merge <---------| | + * | | + * | | + * Enter | + * \ | + * \ | + * Switch Switch + * | | + * +-----------------Equal----------------------+ + * | ******************************************************************************/ - auto data1 = CreateNode(*graph, "data", DATA, 1, 1); + auto data1 = CreateNode(*graph, "data1", DATA, 1, 1); + auto data2 = CreateNode(*graph, "data2", DATA, 1, 1); + + auto equal1 = CreateNode(*graph, "equal1", EQUAL, 2, 1); + auto switch1 = CreateNode(*graph, "switch1", SWITCH, 2, 2); + auto switch2 = CreateNode(*graph, "switch2", SWITCH, 2, 2); + auto enter1 = CreateNode(*graph, "enter", ENTER, 1, 1); - auto merge1 = CreateNode(*graph, "merge", MERGE, 2, 2); - auto less1 = CreateNode(*graph, "less", LESS, 2, 1); + auto merge1 = CreateNode(*graph, "merge1", MERGE, 2, 2); + auto less1 = CreateNode(*graph, "less1", LESS, 2, 1); auto loop1 = CreateNode(*graph, "loopcond", LOOPCOND, 1, 1); - auto switch1 = CreateNode(*graph, "switch", SWITCH, 2, 2); + auto switch3 = CreateNode(*graph, "switch3", SWITCH, 2, 2); auto ident1 = CreateNode(*graph, "identity", IDENTITY, 1, 1); - auto add1 = CreateNode(*graph, "add", ADD, 2, 1); + auto add1 = CreateNode(*graph, "add1", ADD, 2, 1); auto next1 = CreateNode(*graph, "next", NEXTITERATION, 1, 1); auto exit1 = CreateNode(*graph, "exit", EXIT, 1, 1); - auto value0 = CreateNode(*graph, "const", CONSTANT, 0, 1); - auto value1 = CreateNode(*graph, "const", CONSTANT, 0, 1); + auto value1 = CreateNode(*graph, "const1", CONSTANT, 0, 1); + + auto value2 = CreateNode(*graph, "const2", CONSTANT, 0, 1); + auto add2 = CreateNode(*graph, "add2", ADD, 2, 1); + auto merge2 = CreateNode(*graph, "merge2", MERGE, 2, 2); auto output1 = CreateNode(*graph, "net_output", NETOUTPUT, 1, 1); - GraphUtils::AddEdge(data1->GetOutDataAnchor(0), enter1->GetInDataAnchor(0)); + GraphUtils::AddEdge(data1->GetOutDataAnchor(0), equal1->GetInDataAnchor(0)); + GraphUtils::AddEdge(data2->GetOutDataAnchor(0), equal1->GetInDataAnchor(1)); + GraphUtils::AddEdge(data1->GetOutDataAnchor(0), switch1->GetInDataAnchor(0)); + GraphUtils::AddEdge(data2->GetOutDataAnchor(0), switch2->GetInDataAnchor(0)); + GraphUtils::AddEdge(equal1->GetOutDataAnchor(0), switch1->GetInDataAnchor(1)); + GraphUtils::AddEdge(equal1->GetOutDataAnchor(0), switch2->GetInDataAnchor(1)); + cond.emplace_back(switch1); + cond.emplace_back(switch2); + + GraphUtils::AddEdge(switch1->GetOutDataAnchor(0), enter1->GetInDataAnchor(0)); // false GraphUtils::AddEdge(enter1->GetOutDataAnchor(0), merge1->GetInDataAnchor(0)); GraphUtils::AddEdge(merge1->GetOutDataAnchor(0), less1->GetInDataAnchor(0)); GraphUtils::AddEdge(value1->GetOutDataAnchor(0), less1->GetInDataAnchor(1)); GraphUtils::AddEdge(less1->GetOutDataAnchor(0), loop1->GetInDataAnchor(0)); - GraphUtils::AddEdge(loop1->GetOutDataAnchor(0), switch1->GetInDataAnchor(0)); - GraphUtils::AddEdge(merge1->GetOutDataAnchor(0), switch1->GetInDataAnchor(1)); + GraphUtils::AddEdge(loop1->GetOutDataAnchor(0), switch3->GetInDataAnchor(0)); + GraphUtils::AddEdge(merge1->GetOutDataAnchor(0), switch3->GetInDataAnchor(1)); + loop.emplace_back(merge1); - GraphUtils::AddEdge(switch1->GetOutDataAnchor(0), exit1->GetInDataAnchor(0)); - GraphUtils::AddEdge(switch1->GetOutDataAnchor(1), ident1->GetInDataAnchor(0)); + GraphUtils::AddEdge(switch3->GetOutDataAnchor(0), exit1->GetInDataAnchor(0)); // false + GraphUtils::AddEdge(switch3->GetOutDataAnchor(1), ident1->GetInDataAnchor(0)); // true + loop.emplace_back(switch3); GraphUtils::AddEdge(ident1->GetOutDataAnchor(0), add1->GetInDataAnchor(0)); GraphUtils::AddEdge(value1->GetOutDataAnchor(0), add1->GetInDataAnchor(1)); GraphUtils::AddEdge(add1->GetOutDataAnchor(0), next1->GetInDataAnchor(0)); - GraphUtils::AddEdge(next1->GetOutDataAnchor(0), merge1->GetInDataAnchor(1)); - GraphUtils::AddEdge(exit1->GetOutDataAnchor(0), output1->GetInDataAnchor(0)); - merge = merge1; + GraphUtils::AddEdge(switch2->GetOutDataAnchor(1), add2->GetInDataAnchor(1)); // true + GraphUtils::AddEdge(value2->GetOutDataAnchor(0), add2->GetInDataAnchor(0)); + + GraphUtils::AddEdge(exit1->GetOutDataAnchor(0), merge2->GetInDataAnchor(0)); + GraphUtils::AddEdge(add2->GetOutDataAnchor(0), merge2->GetInDataAnchor(1)); + GraphUtils::AddEdge(merge2->GetOutDataAnchor(0), output1->GetInDataAnchor(0)); + + cond.emplace_back(merge2); + merge = merge2; } static void CreateCondGraph(ComputeGraphPtr &graph, NodePtr &merge) { @@ -197,12 +235,27 @@ static void CreateCondGraph(ComputeGraphPtr &graph, NodePtr &merge) { TEST_F(UtestMarkForceUnknownForCondPass, skip_while_loop_merge) { auto graph = std::make_shared("test_graph"); NodePtr merge; - CreateLoopGraph(graph, merge); - - AttrUtils::SetBool(merge->GetOpDesc(), ATTR_NAME_FORCE_UNKNOWN_SHAPE, true); + vector loop; + vector cond; + CreateLoopGraph(graph, merge, loop, cond); MarkForceUnknownForCondPass mark_force_unknown_pass; EXPECT_EQ(mark_force_unknown_pass.Run(graph), SUCCESS); // skip LoopCond + setenv("DUMP_GE_GRAPH", "1", true); + GE_DUMP(graph, "control_group"); + unsetenv("DUMP_GE_GRAPH"); + + EXPECT_EQ(loop.size(), 2); + for (const auto &node : loop) { + EXPECT_FALSE(node->GetOpDesc()->HasAttr(ATTR_NAME_CONTROL_FLOW_GROUP)); + } + + EXPECT_EQ(cond.size(), 3); + for (const auto &node : cond) { + int64_t group_index = -1; + EXPECT_TRUE(AttrUtils::GetInt(node->GetOpDesc(), ATTR_NAME_CONTROL_FLOW_GROUP, group_index)); + EXPECT_EQ(group_index, merge->GetOpDesc()->GetId()); + } } TEST_F(UtestMarkForceUnknownForCondPass, skip_known_shape_merge) { diff --git a/tests/ut/ge/graph/passes/merge_pass_unittest.cc b/tests/ut/ge/graph/passes/merge_pass_unittest.cc index 75fdb21b..f8f0afea 100644 --- a/tests/ut/ge/graph/passes/merge_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/merge_pass_unittest.cc @@ -110,8 +110,8 @@ TEST_F(UtestGraphPassesMergePass, multiple_inputs) { } /// Merge -/// | \ -/// | \ +/// | \. +/// | \. /// Op1 Op2 Merge2 /// \ | | /// \ | Op3 @@ -137,10 +137,10 @@ TEST_F(UtestGraphPassesMergePass, empty_input_cut_branch_meet_net_output_with_da } /// Merge -/// | \ -/// | \ +/// | \. +/// | \. /// Op1 Op2 Merge2 -/// \ | | \ +/// \ | | \. /// \ | Op3 /// \ | : /// NetOutput @@ -165,8 +165,8 @@ TEST_F(UtestGraphPassesMergePass, empty_input_cut_branch_meet_net_output_with_co TEST_F(UtestGraphPassesMergePass, empty_input_cut_branch) { /// Merge - /// | \ - /// | \ + /// | \. + /// | \. /// Op1 Op2 Merge2 /// \ | | /// \ | Op3 @@ -210,7 +210,7 @@ TEST_F(UtestGraphPassesMergePass, empty_input_cut_branch) { /// Op1 Op2 Merge2 /// \ | /// \ Op3 - /// \ + /// \. /// Merge3 ret = pass_.Run(merge_node2); @@ -224,7 +224,7 @@ TEST_F(UtestGraphPassesMergePass, single_non_const_input) { /// Op1 /// | /// Merge - /// / \ + /// / \. /// Op2 Op3 auto merge_node = NewNode("Merge", MERGE, 1, 2); auto node1 = NewNode("Op1", RELU, 1, 1); @@ -253,7 +253,7 @@ TEST_F(UtestGraphPassesMergePass, single_const_input) { /// Const /// | /// Merge Pass Const - /// / \ ===> / \ + /// / \ ===> / \. /// Op1 Op2 Op1 Op2 auto merge_node = NewNode("Merge", MERGE, 1, 2); auto const_node = NewNode("Const", CONSTANT, 1, 1); @@ -284,7 +284,7 @@ TEST_F(UtestGraphPassesMergePass, single_const_input_value_index_two_out_nodes) /// / | ===> / \(control anchor) /// Op1 | \ Op1 Constant /// Op2 Op3 | - /// / \ + /// / \. /// Op2 Op3 auto merge_node = NewNode("Merge", MERGE, 1, 2); auto const_node = NewNode("Const", CONSTANT, 1, 1); @@ -329,7 +329,7 @@ TEST_F(UtestGraphPassesMergePass, single_const_input_value_index_two_out_nodes1) /// / | ===> / \(control anchor) /// Op1 | \ Op1 Constant /// Op2 Op3 | - /// / \ + /// / \. /// Op2 Op3 auto merge_node = NewNode("Merge", MERGE, 1, 2); auto const_node = NewNode("Const", CONSTANT, 1, 1); @@ -357,7 +357,7 @@ TEST_F(UtestGraphPassesMergePass, const_with_control_input) { /// C /// | /// Merge - /// / \ + /// / \. /// Op1 Op2 auto switch_node = NewNode("Switch", SWITCH, 1, 2); auto identity_node = NewNode("Identity", SWITCH, 1, 1); @@ -381,7 +381,7 @@ TEST_F(UtestGraphPassesMergePass, const_with_control_input) { /// . /// . /// C - /// / \ + /// / \. /// Op1 Op2 auto ret = pass_.Run(merge_node); EXPECT_EQ(ret, SUCCESS); diff --git a/tests/ut/ge/graph/passes/parallel_group_pass_unittest.cc b/tests/ut/ge/graph/passes/parallel_group_pass_unittest.cc index d5b1db41..374fe837 100644 --- a/tests/ut/ge/graph/passes/parallel_group_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/parallel_group_pass_unittest.cc @@ -66,11 +66,11 @@ class UtestGraphPassesParallelGgroupPass : public testing::Test { void BuildDefaultGraph() { /// input - /// \ + /// \. /// sqrt pred /// \ / /// cast - /// / \ + /// / \. /// switch_t switch_f /// | | /// F T @@ -118,13 +118,13 @@ class UtestGraphPassesParallelGgroupPass : public testing::Test { void BuildDefaultGraph1() { /// input - /// \ + /// \. /// sqrt pred /// \ / /// Switch /// | | /// ----F T---- - /// \ | / \ + /// \ | / \. /// \ Merge1 Merge2 /// \_________| input_node_ = NewNode("input", RELU, 0, 1); @@ -164,14 +164,14 @@ class UtestGraphPassesParallelGgroupPass : public testing::Test { void BuildDefaultGraph2() { /// input input1 - /// \ \ + /// \ \. /// sqrt pred sqrt1 pred1 /// \ / \ / /// Switch Switch1 /// | | _______| /// | | / /// ____F T____ - /// \ | / \ + /// \ | / \. /// \ Merge1 Merge2 /// \__________| input_node_ = NewNode("input", RELU, 0, 2); diff --git a/tests/ut/ge/graph/passes/reshape_recovery_pass_unittest.cc b/tests/ut/ge/graph/passes/reshape_recovery_pass_unittest.cc index 3be11452..f941645e 100644 --- a/tests/ut/ge/graph/passes/reshape_recovery_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/reshape_recovery_pass_unittest.cc @@ -31,9 +31,9 @@ class UtestReshapeRecoveryPass : public testing::Test { namespace { /// netoutput1 -/// | \ -///transdata1 \ -/// | \ +/// | \. +///transdata1 \. +/// | \. /// | transdata2 /// | / /// var1 const1 diff --git a/tests/ut/ge/graph/passes/reshape_remove_pass_unittest.cc b/tests/ut/ge/graph/passes/reshape_remove_pass_unittest.cc index 351e96d7..ca0cac86 100644 --- a/tests/ut/ge/graph/passes/reshape_remove_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/reshape_remove_pass_unittest.cc @@ -35,7 +35,7 @@ namespace { /// transdata1 /// | /// reshape1 -/// | \ +/// | \. /// var1 const1 ut::GraphBuilder Graph1Builder() { ut::GraphBuilder builder = ut::GraphBuilder("g1"); @@ -55,11 +55,11 @@ ut::GraphBuilder Graph1Builder() { } /// netoutput1 -/// | \ -///transdata1 \ -/// | \ +/// | \. +///transdata1 \. +/// | \. /// reshape1 reshape2 -/// | \ / \ +/// | \ / \. /// var1 const1 var2 ut::GraphBuilder Graph2Builder() { ut::GraphBuilder builder = ut::GraphBuilder("g2"); @@ -83,9 +83,9 @@ ut::GraphBuilder Graph2Builder() { } /// netoutput1 -/// | \ -///transdata1 \ -/// | \ +/// | \. +///transdata1 \. +/// | \. /// reshape1 transdata2 /// | \ / /// var1 const1 diff --git a/tests/ut/ge/graph/passes/resource_pair_control_pass_unittest.cc b/tests/ut/ge/graph/passes/resource_pair_control_pass_unittest.cc index 6d12a49d..8cdfd0c7 100644 --- a/tests/ut/ge/graph/passes/resource_pair_control_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/resource_pair_control_pass_unittest.cc @@ -34,7 +34,7 @@ class UtestResourcePairControlPass : public testing::Test { namespace { /// netoutput1 -/// | \ +/// | \. /// StackPush StackPop /// | | /// var1 const1 diff --git a/tests/ut/ge/graph/passes/switch_logic_remove_pass_unittest.cc b/tests/ut/ge/graph/passes/switch_logic_remove_pass_unittest.cc index dcad318c..22734047 100644 --- a/tests/ut/ge/graph/passes/switch_logic_remove_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/switch_logic_remove_pass_unittest.cc @@ -63,9 +63,9 @@ ComputeGraphPtr BuildGraph1() { /// netoutput1 /// | /// merge1 -/// / \ +/// / \. /// / add1 -/// / F| \ +/// / F| \. /// addn1 swtich2 var3 /// \F T/ | /// switch1 | @@ -101,9 +101,9 @@ ComputeGraphPtr BuildGraph2() { /// add1 /// / \T /// var3 swtich2 -/// T/ \ -/// switch1 \ -/// / \ \ +/// T/ \. +/// switch1 \. +/// / \ \. /// var1 var2 var4 ComputeGraphPtr BuildGraph3() { auto builder = ut::GraphBuilder("g3"); @@ -129,7 +129,7 @@ ComputeGraphPtr BuildGraph3() { /// netoutput1 /// | /// merge1 -/// / \ +/// / \. /// add1 addn1 /// / \T F/ /// var3 swtich2 diff --git a/tests/ut/ge/graph/passes/trans_op_breadth_fusion_pass_unittest.cc b/tests/ut/ge/graph/passes/trans_op_breadth_fusion_pass_unittest.cc index dbb163e1..d05bd695 100644 --- a/tests/ut/ge/graph/passes/trans_op_breadth_fusion_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/trans_op_breadth_fusion_pass_unittest.cc @@ -402,7 +402,7 @@ TEST_F(UtestGraphPassesTransOpBreadthFusionPass, test_multi_anchor_case) { } /// ----> netoutput1 -/// / | \ +/// / | \. /// transdata1 transdata2 transdata3 /// \ / | /// var1-------------- @@ -432,7 +432,7 @@ static ComputeGraphPtr BuildGraph1() { } /// ---------> netoutput1 -/// / | \ +/// / | \. /// transdata1 transdata2(l1) transdata3(l1) /// \ / | /// var1------------------ diff --git a/tests/ut/ge/graph/passes/trans_op_depth_fusion_pass_unittest.cc b/tests/ut/ge/graph/passes/trans_op_depth_fusion_pass_unittest.cc index a9ea41ea..dbac3246 100644 --- a/tests/ut/ge/graph/passes/trans_op_depth_fusion_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/trans_op_depth_fusion_pass_unittest.cc @@ -456,19 +456,19 @@ TEST_F(UtestGraphPassesTransOpDepthFusionPass, test_transop_with_multi_out_edge) /// -->transpose1 -->transpose3-->sinh2 /// | \ / /// | -->transpose2 - /// | \ + /// | \. /// / -->cast3-->cast4-->sinh3 /// / /// / -->transpose4-->transpose5-->sinh4 /// / / /// Node4D-->Cast1-->Cast2-->Cast5 -->reshape2-->sinh5 - /// \ \ + /// \ \. /// \ -->sinh6 - /// \ + /// \. /// \ -->transpose6-->transpose7-->sinh9 /// \ / /// -->reshape-->cast6-->cast7-->sinh8 - /// \ + /// \. /// -->sinh7 /// after optimized graph @@ -479,15 +479,15 @@ TEST_F(UtestGraphPassesTransOpDepthFusionPass, test_transop_with_multi_out_edge) /// / /-->transpose3-->sinh2 /// -->Cast1 /// / \-->sinh7 - /// / \ + /// / \. /// / -->sinh9 /// Node4D /// \ -->sinh4 /// \ / /// -->Cast5-->sinh5 - /// \ \ + /// \ \. /// \ -->sinh6 - /// \ + /// \. /// -->Cast7-->sinh8 ge::ComputeGraphPtr graph = std::make_shared("test"); diff --git a/tests/ut/ge/graph/passes/transop_nearby_allreduce_fusion_pass_unittest.cc b/tests/ut/ge/graph/passes/transop_nearby_allreduce_fusion_pass_unittest.cc index 1220b35e..9c6d8276 100644 --- a/tests/ut/ge/graph/passes/transop_nearby_allreduce_fusion_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/transop_nearby_allreduce_fusion_pass_unittest.cc @@ -180,7 +180,7 @@ ComputeGraphPtr GetGraph7(size_t symmetric_transdata_num, size_t asymmetric_tran /// TransData TransData ... MatMul ... /// \ | / / / /// HcomAllReduce - /// / | \ \ \ + /// / | \ \ \. /// TransData TransData ... RealDiv ... ComputeGraphPtr graph = std::make_shared("test"); NodePtr allreduce = @@ -340,7 +340,7 @@ TEST(UtestTransopNearbyAllreduceFusionPass, test7_all_reduce_with_multiple_trans /// TransData TransData ... MatMul ... /// \ | / / / /// HcomAllReduce - /// / | \ \ \ + /// / | \ \ \. /// TransData TransData ... RealDiv ... size_t symmetric_transdata_num = 20; size_t asymmetric_transdata_num = 20; diff --git a/tests/ut/ge/graph/passes/variable_op_pass_unittest.cc b/tests/ut/ge/graph/passes/variable_op_pass_unittest.cc index f1ea7a27..655867a7 100644 --- a/tests/ut/ge/graph/passes/variable_op_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/variable_op_pass_unittest.cc @@ -66,7 +66,7 @@ namespace { /// transdata2 /// | /// assign1 -/// / \ +/// / \. /// transdata1 | /// | | /// var1 const1 diff --git a/tests/ut/ge/graph/variable_accelerate_ctrl_unittest.cc b/tests/ut/ge/graph/variable_accelerate_ctrl_unittest.cc index 37b4bda7..bf350b6c 100644 --- a/tests/ut/ge/graph/variable_accelerate_ctrl_unittest.cc +++ b/tests/ut/ge/graph/variable_accelerate_ctrl_unittest.cc @@ -35,8 +35,8 @@ namespace { /// shapeNo1 /// | /// addnYes1 -/// / \ -/// / \ +/// / \. +/// / \. /// const1 const2 ComputeGraphPtr BuildGraph1() { @@ -57,9 +57,9 @@ ComputeGraphPtr BuildGraph1() { /// /// netoutput1 -/// / \ \ -/// add1 assign1 \ -/// / \ / \ \ +/// / \ \. +/// add1 assign1 \. +/// / \ / \ \. /// var1 var2 const1 var3 ComputeGraphPtr BuildGraph2() { From a4aae38d72c9bc0e564ecce4d6da4ad02d46a0fd Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Sat, 26 Jun 2021 23:25:58 +0800 Subject: [PATCH 13/50] Remove UT dump env --- .../graph/passes/mark_force_unknown_for_cond_pass_unittest.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/ut/ge/graph/passes/mark_force_unknown_for_cond_pass_unittest.cc b/tests/ut/ge/graph/passes/mark_force_unknown_for_cond_pass_unittest.cc index 50991822..557359b7 100644 --- a/tests/ut/ge/graph/passes/mark_force_unknown_for_cond_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/mark_force_unknown_for_cond_pass_unittest.cc @@ -241,9 +241,6 @@ TEST_F(UtestMarkForceUnknownForCondPass, skip_while_loop_merge) { MarkForceUnknownForCondPass mark_force_unknown_pass; EXPECT_EQ(mark_force_unknown_pass.Run(graph), SUCCESS); // skip LoopCond - setenv("DUMP_GE_GRAPH", "1", true); - GE_DUMP(graph, "control_group"); - unsetenv("DUMP_GE_GRAPH"); EXPECT_EQ(loop.size(), 2); for (const auto &node : loop) { From 020d7cb8a04780fb7cf99ddd8a578281a26128ce Mon Sep 17 00:00:00 2001 From: lichun Date: Mon, 28 Jun 2021 10:34:54 +0800 Subject: [PATCH 14/50] remove SetDataType --- ge/hybrid/executor/subgraph_executor.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/ge/hybrid/executor/subgraph_executor.cc b/ge/hybrid/executor/subgraph_executor.cc index 6979d05f..33a2846c 100644 --- a/ge/hybrid/executor/subgraph_executor.cc +++ b/ge/hybrid/executor/subgraph_executor.cc @@ -109,7 +109,6 @@ Status SubgraphExecutor::InitInputsForUnknownShape(const std::vectorSetShape(tensor_desc->GetShape()); output_desc->SetOriginShape(tensor_desc->GetOriginShape()); - output_desc->SetDataType(tensor_desc->GetDataType()); node_state->SetSkipInferShape(true); } } From 91fd6e45ddd8ccbc0d1289c59efffac3ebbd2d13 Mon Sep 17 00:00:00 2001 From: WeiGangqiang Date: Tue, 22 Jun 2021 14:53:24 +0800 Subject: [PATCH 15/50] add ge running env config and perfact graph dsl --- .clang-format | 2 +- build.sh | 7 +- ge/ge_runtime/task/hccl_task.cc | 1 + tests/depends/slog/src/slog_stub.cc | 62 ++++++-- tests/framework/CMakeLists.txt | 4 +- tests/framework/cmake/graphengine.cmake | 31 +--- .../ge_graph_dsl/op_desc/op_desc_cfg_box.h | 34 ++-- .../ge_graph_dsl/src/op_desc_cfg_box.cc | 29 +++- .../ge_graph_dsl/tests/op_desc_config_test.cc | 75 +++++++++ .../ge_graph_dsl/tests/stub/optype_stub.cc | 1 + tests/framework/ge_running_env/CMakeLists.txt | 18 +++ .../ge_running_env/include/CMakeLists.txt | 17 ++ .../include/ge_running_env/env_installer.h} | 29 ++-- .../include/ge_running_env/fake_engine.h | 56 +++++++ .../include/ge_running_env/fake_ns.h | 28 ++++ .../include/ge_running_env/fake_op.h | 49 ++++++ .../ge_running_env/fake_ops_kernel_builder.h} | 39 ++--- .../fake_ops_kernel_info_store.h | 39 +++++ .../ge_running_env/ge_running_env_faker.h | 45 ++++++ .../ge_running_env/info_store_holder.h} | 40 ++--- .../ge_running_env/src/CMakeLists.txt | 45 ++++++ .../ge_running_env/src/engine/fake_engine.cc | 81 ++++++++++ .../src/engine/fake_ops_kernel_builder.cc} | 43 ++--- .../src/engine/fake_ops_kernel_info_store.cc | 42 +++++ .../src/engine/info_store_holder.cc | 49 ++++++ .../src/env/ge_default_running_env.cc | 56 +++++++ .../src/env/ge_default_running_env.h | 32 ++++ .../src/env/ge_running_env_faker.cc | 109 +++++++++++++ .../ge_running_env/src/op/fake_op.cc | 95 +++++++++++ .../ge_running_env/src/op/fake_op_repo.cc | 39 +++++ .../ge_running_env/src/op/fake_op_repo.h | 31 ++++ .../ge_running_env/tests/CMakeLists.txt | 33 ++++ .../tests/test_ge_running_env_faker.cc | 148 ++++++++++++++++++ .../ge_running_env/tests/test_main.cc | 34 ++++ tests/framework/stub_engine/CMakeLists.txt | 58 ------- .../stub_engine/engine/stub_engine.cc | 74 --------- .../stub_engine/engine/stub_engine.h | 127 --------------- tests/framework/stub_engine/inc/st_types.h | 33 ---- .../ops_kernel_store/op/host_op.cc | 41 ----- .../ops_kernel_store/op/stub_op_factory.cc | 51 ------ .../ops_kernel_store/op/stub_op_factory.h | 109 ------------- .../ops_kernel_store/stub_ops_kernel_store.cc | 77 --------- .../ops_kernel_store/stub_ops_kernel_store.h | 73 --------- tests/st/testcase/CMakeLists.txt | 2 +- tests/st/testcase/test_framework_dummy.cc | 16 +- tests/st/testcase/test_main.cc | 37 +++++ 46 files changed, 1328 insertions(+), 813 deletions(-) create mode 100644 tests/framework/ge_graph_dsl/tests/op_desc_config_test.cc create mode 100644 tests/framework/ge_running_env/CMakeLists.txt create mode 100644 tests/framework/ge_running_env/include/CMakeLists.txt rename tests/framework/{stub_engine/ops_kernel_store/op/host_op.h => ge_running_env/include/ge_running_env/env_installer.h} (52%) create mode 100644 tests/framework/ge_running_env/include/ge_running_env/fake_engine.h create mode 100644 tests/framework/ge_running_env/include/ge_running_env/fake_ns.h create mode 100644 tests/framework/ge_running_env/include/ge_running_env/fake_op.h rename tests/framework/{stub_engine/ops_kernel_store/stub_ops_kernel_builder.h => ge_running_env/include/ge_running_env/fake_ops_kernel_builder.h} (59%) create mode 100644 tests/framework/ge_running_env/include/ge_running_env/fake_ops_kernel_info_store.h create mode 100644 tests/framework/ge_running_env/include/ge_running_env/ge_running_env_faker.h rename tests/framework/{stub_engine/ops_kernel_store/op/op.h => ge_running_env/include/ge_running_env/info_store_holder.h} (51%) create mode 100644 tests/framework/ge_running_env/src/CMakeLists.txt create mode 100644 tests/framework/ge_running_env/src/engine/fake_engine.cc rename tests/framework/{stub_engine/ops_kernel_store/stub_ops_kernel_builder.cc => ge_running_env/src/engine/fake_ops_kernel_builder.cc} (73%) create mode 100644 tests/framework/ge_running_env/src/engine/fake_ops_kernel_info_store.cc create mode 100644 tests/framework/ge_running_env/src/engine/info_store_holder.cc create mode 100644 tests/framework/ge_running_env/src/env/ge_default_running_env.cc create mode 100644 tests/framework/ge_running_env/src/env/ge_default_running_env.h create mode 100644 tests/framework/ge_running_env/src/env/ge_running_env_faker.cc create mode 100644 tests/framework/ge_running_env/src/op/fake_op.cc create mode 100644 tests/framework/ge_running_env/src/op/fake_op_repo.cc create mode 100644 tests/framework/ge_running_env/src/op/fake_op_repo.h create mode 100644 tests/framework/ge_running_env/tests/CMakeLists.txt create mode 100644 tests/framework/ge_running_env/tests/test_ge_running_env_faker.cc create mode 100644 tests/framework/ge_running_env/tests/test_main.cc delete mode 100644 tests/framework/stub_engine/CMakeLists.txt delete mode 100644 tests/framework/stub_engine/engine/stub_engine.cc delete mode 100644 tests/framework/stub_engine/engine/stub_engine.h delete mode 100644 tests/framework/stub_engine/inc/st_types.h delete mode 100644 tests/framework/stub_engine/ops_kernel_store/op/host_op.cc delete mode 100644 tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.cc delete mode 100644 tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.h delete mode 100644 tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.cc delete mode 100644 tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.h create mode 100644 tests/st/testcase/test_main.cc diff --git a/.clang-format b/.clang-format index c931e8f0..e7f9d935 100644 --- a/.clang-format +++ b/.clang-format @@ -50,7 +50,7 @@ CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 2 +ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DerivePointerAlignment: true DisableFormat: false diff --git a/build.sh b/build.sh index 61f86945..dbbf696b 100755 --- a/build.sh +++ b/build.sh @@ -144,7 +144,6 @@ build_graphengine() CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_UT=ON" fi - if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_ST=ON" fi @@ -176,7 +175,7 @@ build_graphengine() TARGET="ge_compiler atc_atc.bin ge_executor_shared ${TARGET}" elif [ "X$ENABLE_GE_ST" = "Xon" ] then - TARGET="ge_graph_dsl_test graph_engine_test" + TARGET="ge_graph_dsl_test ge_running_env_test graph_engine_test" elif [ "X$ENABLE_GE_UT" = "Xon" ] then TARGET="ut_libgraph ut_libge_multiparts_utest ut_libge_others_utest ut_libge_kernel_utest ut_libge_distinct_load_utest" @@ -244,13 +243,13 @@ if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then mkdir -p ${OUTPUT_PATH}/plugin/opskernel cp ${BUILD_PATH}/tests/framework/libnnengine.so ${OUTPUT_PATH}/plugin/nnengine cp ${BUILD_PATH}/engine_conf.json ${OUTPUT_PATH}/plugin/nnengine/ge_config - cp ${BUILD_PATH}/tests/framework/libhost_cpu_engine.so ${OUTPUT_PATH}/plugin/opskernel cp ${BUILD_PATH}/tests/framework/libge_local_engine.so ${OUTPUT_PATH}/plugin/opskernel - cp ${BUILD_PATH}/tests/framework/stub_engine/libfe.so ${OUTPUT_PATH}/plugin/opskernel #prepare st execution bin cp ${BUILD_PATH}/tests/st/testcase/graph_engine_test ${OUTPUT_PATH} + cp ${BUILD_PATH}/tests/framework/ge_running_env/tests/ge_running_env_test ${OUTPUT_PATH} cp ${BUILD_PATH}/tests/framework/ge_graph_dsl/tests/ge_graph_dsl_test ${OUTPUT_PATH} #execute st testcase + RUN_TEST_CASE=${OUTPUT_PATH}/ge_running_env_test && ${RUN_TEST_CASE} RUN_TEST_CASE=${OUTPUT_PATH}/graph_engine_test && ${RUN_TEST_CASE} RUN_TEST_CASE=${OUTPUT_PATH}/ge_graph_dsl_test && ${RUN_TEST_CASE} if [[ "$?" -ne 0 ]]; then diff --git a/ge/ge_runtime/task/hccl_task.cc b/ge/ge_runtime/task/hccl_task.cc index 2ffe5185..b1c7158c 100644 --- a/ge/ge_runtime/task/hccl_task.cc +++ b/ge/ge_runtime/task/hccl_task.cc @@ -16,6 +16,7 @@ #include "ge_runtime/task/hccl_task.h" #include +#include "framework/common/util.h" #include "ge_runtime/task/task_factory.h" #include "common/opskernel/ops_kernel_info_store.h" #include "common/opskernel/ge_task_info.h" diff --git a/tests/depends/slog/src/slog_stub.cc b/tests/depends/slog/src/slog_stub.cc index d0eb49c5..238a6b37 100644 --- a/tests/depends/slog/src/slog_stub.cc +++ b/tests/depends/slog/src/slog_stub.cc @@ -23,13 +23,46 @@ void dav_log(int module_id, const char *fmt, ...) {} -void DlogErrorInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } +static int log_level = DLOG_ERROR; + +#define __DO_PRINT() \ + do { \ + const int FMT_BUFF_SIZE = 1024; \ + char fmt_buff[FMT_BUFF_SIZE] = {0}; \ + va_list valist; \ + va_start(valist, fmt); \ + vsnprintf(fmt_buff, FMT_BUFF_SIZE, fmt, valist); \ + va_end(valist); \ + printf("%s \n", fmt_buff); \ + } while (0) + +void DlogErrorInner(int module_id, const char *fmt, ...) { + if (log_level > DLOG_ERROR) { + return; + } + __DO_PRINT(); +} -void DlogWarnInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } +void DlogWarnInner(int module_id, const char *fmt, ...) { + if (log_level > DLOG_WARN) { + return; + } + __DO_PRINT(); +} -void DlogInfoInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } +void DlogInfoInner(int module_id, const char *fmt, ...) { + if (log_level > DLOG_INFO) { + return; + } + __DO_PRINT(); +} -void DlogDebugInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } +void DlogDebugInner(int module_id, const char *fmt, ...) { + if (log_level > DLOG_DEBUG) { + return; + } + __DO_PRINT(); +} void DlogEventInner(int module_id, const char *fmt, ...) { dav_log(module_id, fmt); } @@ -39,30 +72,25 @@ void DlogWithKVInner(int module_id, int level, KeyValue *pst_kv_array, int kv_nu dav_log(module_id, fmt); } -int dlog_setlevel(int module_id, int level, int enable_event) { return DLOG_DEBUG; } +int dlog_setlevel(int module_id, int level, int enable_event) { + log_level = level; + return log_level; +} -int dlog_getlevel(int module_id, int *enable_event) { return DLOG_DEBUG; } +int dlog_getlevel(int module_id, int *enable_event) { return log_level; } -int CheckLogLevel(int moduleId, int logLevel) -{ - return 1; -} +int CheckLogLevel(int moduleId, int log_level_check) { return log_level >= log_level_check; } /** * @ingroup plog * @brief DlogReportInitialize: init log in service process before all device setting. * @return: 0: SUCCEED, others: FAILED */ -int DlogReportInitialize() { - return 0; -} +int DlogReportInitialize() { return 0; } /** * @ingroup plog * @brief DlogReportFinalize: release log resource in service process after all device reset. * @return: 0: SUCCEED, others: FAILED */ -int DlogReportFinalize() { - return 0; -} - +int DlogReportFinalize() { return 0; } diff --git a/tests/framework/CMakeLists.txt b/tests/framework/CMakeLists.txt index d7c806a6..8a2218b4 100644 --- a/tests/framework/CMakeLists.txt +++ b/tests/framework/CMakeLists.txt @@ -15,8 +15,8 @@ include(cmake/graphengine.cmake) add_subdirectory(easy_graph) -add_subdirectory(stub_engine) add_subdirectory(ge_graph_dsl) +add_subdirectory(ge_running_env) file(GLOB_RECURSE UTILS_SRC CONFIGURE_DEPENDS "utils/*.cc" @@ -29,4 +29,4 @@ target_include_directories(framework ) set_target_properties(framework PROPERTIES CXX_STANDARD 11) -target_link_libraries(framework PUBLIC ge_graph_dsl graphengine fe) +target_link_libraries(framework PUBLIC ge_graph_dsl ge_with_env) diff --git a/tests/framework/cmake/graphengine.cmake b/tests/framework/cmake/graphengine.cmake index 81aa00cc..3c18b560 100644 --- a/tests/framework/cmake/graphengine.cmake +++ b/tests/framework/cmake/graphengine.cmake @@ -150,7 +150,7 @@ set_target_properties(metadef_graph PROPERTIES CXX_STANDARD 11) # ---- Target : Local engine ---- -add_library(ge_local_engine SHARED ${LOCAL_ENGINE_SRC} ${METADEF_REGISTER_SRCS}) +add_library(ge_local_engine SHARED ${LOCAL_ENGINE_SRC}) target_include_directories(ge_local_engine PUBLIC @@ -169,38 +169,11 @@ target_compile_options(ge_local_engine PRIVATE target_link_libraries(ge_local_engine PUBLIC $ ${STUB_LIBS} - metadef_graph -lrt -ldl -lpthread -lgcov ) set_target_properties(ge_local_engine PROPERTIES CXX_STANDARD 11) -# ---- Target : Host engine ---- - -add_library(host_cpu_engine SHARED ${HOST_ENGINE_SRC}) - -target_include_directories(host_cpu_engine - PUBLIC - "${INCLUDE_DIRECTORIES}" - "${GE_CODE_DIR}/ge/host_cpu_engine" -) - -target_compile_definitions(host_cpu_engine PRIVATE - google=ascend_private - FMK_SUPPORT_DUMP -) - -target_compile_options(host_cpu_engine PRIVATE - -g --coverage -fprofile-arcs -ftest-coverage - -Werror=format -) - -target_link_libraries(host_cpu_engine PUBLIC - $ ${STUB_LIBS} metadef_graph -lrt -ldl -lpthread -lgcov -) - -set_target_properties(host_cpu_engine PROPERTIES CXX_STANDARD 11) - # ---- Target : engine plugin---- # @@ -273,4 +246,4 @@ target_link_libraries(graphengine PUBLIC ) set_target_properties(graphengine PROPERTIES CXX_STANDARD 11) -add_dependencies(graphengine host_cpu_engine ge_local_engine nnengine engine_conf.json optimizer_priority.pbtxt) +add_dependencies(graphengine ge_local_engine nnengine engine_conf.json optimizer_priority.pbtxt) diff --git a/tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg_box.h b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg_box.h index af3a1971..2be05972 100644 --- a/tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg_box.h +++ b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg_box.h @@ -21,6 +21,7 @@ #include "ge_graph_dsl/ge.h" #include "ge_graph_dsl/op_desc/op_box.h" #include "ge_graph_dsl/op_desc/op_desc_cfg.h" +#include "graph/ge_attr_value.h" #include "graph/op_desc.h" GE_NS_BEGIN @@ -29,19 +30,32 @@ struct OpDescCfgBox : OpBox, private OpDescCfg { OpDescCfgBox(const OpType &opType); OpDescCfgBox &InCnt(int in_cnt); OpDescCfgBox &OutCnt(int out_cnt); + OpDescCfgBox &ParentNodeIndex(int node_index); OpDescCfgBox &TensorDesc(Format format = FORMAT_NCHW, DataType data_type = DT_FLOAT, - std::vector shape = {1, 1, 224, 224}); - template - OpDescCfgBox& Attr(const std::string &name, Type value) { - auto attrvalue = ge::GeAttrValue::CreateFrom(value); - attrs_.emplace(std::make_pair(name, attrvalue)); - return *this; - } + std::vector shape = {1, 1, 224, 224}); + OpDescCfgBox &Weight(GeTensorPtr &); - private: + template + OpDescCfgBox &Attr(const std::string &name, Type &&value) { + auto attrvalue = ge::GeAttrValue::CreateFrom(std::forward(value)); + attrs_.emplace(std::make_pair(name, attrvalue)); + return *this; + } + + template + OpDescCfgBox &Attr(const std::string &name, Type &value) { + auto attrvalue = ge::GeAttrValue::CreateFrom(value); + attrs_.emplace(std::make_pair(name, attrvalue)); + return *this; + } + + OpDescCfgBox &Attr(const std::string &name, int value); + OpDescCfgBox &Attr(const std::string &name, const char *value); OpDescPtr Build(const ::EG_NS::NodeId &id) const override; - void UpdateAttrs(OpDescPtr&) const; - std::map attrs_; + + private: + void UpdateAttrs(OpDescPtr &) const; + std::map attrs_; }; #define OP_CFG(optype) ::GE_NS::OpDescCfgBox(optype) diff --git a/tests/framework/ge_graph_dsl/src/op_desc_cfg_box.cc b/tests/framework/ge_graph_dsl/src/op_desc_cfg_box.cc index fc2a6c1c..be7cd831 100644 --- a/tests/framework/ge_graph_dsl/src/op_desc_cfg_box.cc +++ b/tests/framework/ge_graph_dsl/src/op_desc_cfg_box.cc @@ -17,8 +17,8 @@ #include "ge_graph_dsl/op_desc/op_desc_cfg_box.h" #include "easy_graph/infra/status.h" #include "ge_graph_dsl/op_desc/op_desc_cfg_repo.h" -#include "ge_graph_dsl/op_desc/op_desc_cfg.h" #include "external/graph/gnode.h" +#include "graph/debug/ge_attr_define.h" #include "graph/ge_tensor.h" using ::EG_NS::Status; @@ -44,6 +44,26 @@ OpDescCfgBox &OpDescCfgBox::OutCnt(int out_cnt) { return *this; } +OpDescCfgBox &OpDescCfgBox::ParentNodeIndex(int node_index) { + this->Attr(ATTR_NAME_PARENT_NODE_INDEX, node_index); + return *this; +} + +OpDescCfgBox &OpDescCfgBox::Attr(const std::string &name, int value) { + this->Attr(name, (int64_t)value); + return *this; +} + +OpDescCfgBox &OpDescCfgBox::Attr(const std::string &name, const char *value) { + this->Attr(name, std::string(value)); + return *this; +} + +OpDescCfgBox &OpDescCfgBox::Weight(GeTensorPtr &tensor_ptr) { + this->Attr(ATTR_NAME_WEIGHTS, tensor_ptr); + return *this; +} + OpDescCfgBox &OpDescCfgBox::TensorDesc(Format format, DataType data_type, std::vector shape) { default_tensor_.format_ = format; default_tensor_.data_type_ = data_type; @@ -51,10 +71,9 @@ OpDescCfgBox &OpDescCfgBox::TensorDesc(Format format, DataType data_type, std::v return *this; } -void OpDescCfgBox::UpdateAttrs(OpDescPtr& op_desc) const { - std::for_each(attrs_.begin(), attrs_.end(), [&op_desc](const auto &attr){ - op_desc->SetAttr(attr.first, attr.second); - }); +void OpDescCfgBox::UpdateAttrs(OpDescPtr &op_desc) const { + std::for_each(attrs_.begin(), attrs_.end(), + [&op_desc](const auto &attr) { op_desc->SetAttr(attr.first, attr.second); }); } OpDescPtr OpDescCfgBox::Build(const ::EG_NS::NodeId &id) const { diff --git a/tests/framework/ge_graph_dsl/tests/op_desc_config_test.cc b/tests/framework/ge_graph_dsl/tests/op_desc_config_test.cc new file mode 100644 index 00000000..eee5d7c2 --- /dev/null +++ b/tests/framework/ge_graph_dsl/tests/op_desc_config_test.cc @@ -0,0 +1,75 @@ +/** + * Copyright 2021 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 "gtest/gtest.h" +#include "framework/common/types.h" +#include "graph/debug/ge_attr_define.h" +#include "ge_graph_dsl/op_desc/op_desc_cfg_box.h" +#include "graph/ge_tensor.h" +#include "graph/utils/attr_utils.h" +GE_NS_BEGIN + +class OpDescCfgTest : public testing::Test {}; + +TEST_F(OpDescCfgTest, test_attr_set_string_success) { + auto op_ptr = OP_CFG(DATA).Attr(ENTER_ATTR_FRAME_NAME, "1").Build("data1"); + + ge::GeAttrValue ret; + op_ptr->GetAttr(ENTER_ATTR_FRAME_NAME, ret); + std::string value; + ret.GetValue(value); + + ASSERT_EQ(value, "1"); +} + +TEST_F(OpDescCfgTest, test_attr_set_int_success) { + auto op_ptr = OP_CFG(DATA).Attr(ENTER_ATTR_FRAME_NAME, 2).Build("data1"); + + ge::GeAttrValue ret; + op_ptr->GetAttr(ENTER_ATTR_FRAME_NAME, ret); + int64_t value; + ret.GetValue(value); + + ASSERT_EQ(value, 2); +} + +TEST_F(OpDescCfgTest, test_attr_set_perent_node_index_success) { + auto op_ptr = OP_CFG(DATA).ParentNodeIndex(2).Build("data1"); + + ge::GeAttrValue ret; + op_ptr->GetAttr(ATTR_NAME_PARENT_NODE_INDEX, ret); + int64_t value; + ret.GetValue(value); + + ASSERT_EQ(value, 2); +} + +TEST_F(OpDescCfgTest, test_attr_set_weight_success) { + int64_t dims_size = 1; + vector data_vec = {5}; + for_each(data_vec.begin(), data_vec.end(), [&](int64_t &data) { dims_size *= data; }); + vector data_value_vec(dims_size, 1); + GeTensorDesc data_tensor_desc(GeShape(data_vec), FORMAT_NCHW, DT_INT32); + GeTensorPtr data_tensor = std::make_shared(data_tensor_desc, (uint8_t *)data_value_vec.data(), + data_value_vec.size() * sizeof(int32_t)); + + auto op_ptr = OP_CFG(CONSTANT).Weight(data_tensor).Build("const1"); + + ConstGeTensorPtr tensor_value; + ASSERT_TRUE(AttrUtils::GetTensor(op_ptr, ge::ATTR_NAME_WEIGHTS, tensor_value)); + ASSERT_EQ(tensor_value->GetTensorDesc().GetDataType(), DT_INT32); +} + +GE_NS_END diff --git a/tests/framework/ge_graph_dsl/tests/stub/optype_stub.cc b/tests/framework/ge_graph_dsl/tests/stub/optype_stub.cc index b83d68fc..071f8c36 100644 --- a/tests/framework/ge_graph_dsl/tests/stub/optype_stub.cc +++ b/tests/framework/ge_graph_dsl/tests/stub/optype_stub.cc @@ -23,6 +23,7 @@ GE_NS_BEGIN REGISTER_OPTYPE_DEFINE(DATA, "Data"); REGISTER_OPTYPE_DEFINE(HCOMALLGATHER, "HcomAllGather"); REGISTER_OPTYPE_DEFINE(VARIABLE, "Variable"); +REGISTER_OPTYPE_DEFINE(CONSTANT, "Const"); REGISTER_OPTYPE_DEFINE(CONSTANTOP, "Constant"); REGISTER_OPTYPE_DEFINE(LESS, "Less"); REGISTER_OPTYPE_DEFINE(MUL, "Mul"); diff --git a/tests/framework/ge_running_env/CMakeLists.txt b/tests/framework/ge_running_env/CMakeLists.txt new file mode 100644 index 00000000..deac4e03 --- /dev/null +++ b/tests/framework/ge_running_env/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright 2021 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. +# ============================================================================ + +add_subdirectory(include) +add_subdirectory(src) +add_subdirectory(tests) \ No newline at end of file diff --git a/tests/framework/ge_running_env/include/CMakeLists.txt b/tests/framework/ge_running_env/include/CMakeLists.txt new file mode 100644 index 00000000..b71b0578 --- /dev/null +++ b/tests/framework/ge_running_env/include/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright 2021 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. +# ============================================================================ + +add_library(ge_running_env_inc INTERFACE) +target_include_directories(ge_running_env_inc INTERFACE ./) diff --git a/tests/framework/stub_engine/ops_kernel_store/op/host_op.h b/tests/framework/ge_running_env/include/ge_running_env/env_installer.h similarity index 52% rename from tests/framework/stub_engine/ops_kernel_store/op/host_op.h rename to tests/framework/ge_running_env/include/ge_running_env/env_installer.h index 464df47a..79b65137 100644 --- a/tests/framework/stub_engine/ops_kernel_store/op/host_op.h +++ b/tests/framework/ge_running_env/include/ge_running_env/env_installer.h @@ -14,23 +14,22 @@ * limitations under the License. */ -#ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_HOST_OP_H_ -#define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_HOST_OP_H_ +#ifndef H1D9F4FDE_BB21_4DE4_AC7E_751920B45039 +#define H1D9F4FDE_BB21_4DE4_AC7E_751920B45039 -#include "stub_engine/ops_kernel_store/op/op.h" +#include "fake_ns.h" +#include "opskernel_manager/ops_kernel_manager.h" +#include "register/ops_kernel_builder_registry.h" -namespace ge { -namespace st { -class GE_FUNC_VISIBILITY HostOp : public Op { - public: - HostOp(const Node &node, RunContext &run_context) : Op(node, run_context) {} - ~HostOp() override = default; - HostOp &operator=(const HostOp &op) = delete; - HostOp(const HostOp &op) = delete; +FAKE_NS_BEGIN - Status Run() override; +struct EnvInstaller { + virtual void InstallTo(std::map&) const {} + virtual void InstallTo(std::map&) const {} + virtual void InstallTo(std::map&) const {} + virtual void Install() const {} }; -} // namespace st -} // namespace ge -#endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_HOST_OP_H_ +FAKE_NS_END + +#endif diff --git a/tests/framework/ge_running_env/include/ge_running_env/fake_engine.h b/tests/framework/ge_running_env/include/ge_running_env/fake_engine.h new file mode 100644 index 00000000..c4207223 --- /dev/null +++ b/tests/framework/ge_running_env/include/ge_running_env/fake_engine.h @@ -0,0 +1,56 @@ +/** + * Copyright 2021 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. + */ +#ifndef HAF5E9BF2_752F_4E03_B0A5_E1B912A5FA24 +#define HAF5E9BF2_752F_4E03_B0A5_E1B912A5FA24 + +#include +#include "fake_ns.h" +#include "ge_running_env/env_installer.h" +#include "common/opskernel/ops_kernel_info_types.h" +#include "opskernel_manager/ops_kernel_manager.h" +#include "register/ops_kernel_builder_registry.h" +#include "fake_ops_kernel_builder.h" +#include "fake_ops_kernel_info_store.h" + +FAKE_NS_BEGIN + +using FakeOpsKernelBuilderPtr = std::shared_ptr; +using FakeOpsKernelInfoStorePtr = std::shared_ptr; + +struct FakeEngine : EnvInstaller { + FakeEngine(const std::string& engine_name); + FakeEngine& KernelBuilder(FakeOpsKernelBuilderPtr); + FakeEngine& KernelInfoStore(FakeOpsKernelInfoStorePtr); + FakeEngine& KernelInfoStore(const std::string&); + + private: + void InstallTo(std::map&) const override; + void InstallTo(std::map&) const override; + + private: + template + void InstallFor(std::map& maps, const std::map>&) const; + + private: + std::string engine_name_; + std::set info_store_names_; + std::map custom_builders_; + std::map custom_info_stores_; +}; + +FAKE_NS_END + +#endif diff --git a/tests/framework/ge_running_env/include/ge_running_env/fake_ns.h b/tests/framework/ge_running_env/include/ge_running_env/fake_ns.h new file mode 100644 index 00000000..c802e109 --- /dev/null +++ b/tests/framework/ge_running_env/include/ge_running_env/fake_ns.h @@ -0,0 +1,28 @@ +/** + * Copyright 2021 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. + */ +#ifndef H7AEFF0EA_9FDE_487F_8562_2917A2D48EA2 +#define H7AEFF0EA_9FDE_487F_8562_2917A2D48EA2 + +#define FAKE_NS ge +#define FAKE_NS_BEGIN namespace FAKE_NS { +#define FAKE_NS_END } +#define USING_STUB_NS using namespace FAKE_NS; +#define FWD_DECL_STUB(type) \ + namespace FAKE_NS { \ + struct type; \ + } + +#endif diff --git a/tests/framework/ge_running_env/include/ge_running_env/fake_op.h b/tests/framework/ge_running_env/include/ge_running_env/fake_op.h new file mode 100644 index 00000000..cc442cdb --- /dev/null +++ b/tests/framework/ge_running_env/include/ge_running_env/fake_op.h @@ -0,0 +1,49 @@ +/** + * Copyright 2021 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. + */ +#ifndef H737AD661_27C0_400F_8B08_29701308C5D0 +#define H737AD661_27C0_400F_8B08_29701308C5D0 + +#include +#include +#include "fake_ns.h" +#include "ge_running_env/env_installer.h" +#include "graph/operator_factory.h" + +FAKE_NS_BEGIN + +struct FakeOp : EnvInstaller { + FakeOp(const std::string& op_type); + + FakeOp& Inputs(const std::vector&); + FakeOp& Outputs(const std::vector&); + FakeOp& InferShape(InferShapeFunc); + FakeOp& InfoStoreAndBuilder(const std::string&); + + private: + void Install() const override; + void InstallTo(std::map&) const override; + + private: + const std::string op_type_; + std::vector inputs_; + std::vector outputs_; + InferShapeFunc info_fun_; + std::set info_store_names_; +}; + +FAKE_NS_END + +#endif /* H737AD661_27C0_400F_8B08_29701308C5D0 */ diff --git a/tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.h b/tests/framework/ge_running_env/include/ge_running_env/fake_ops_kernel_builder.h similarity index 59% rename from tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.h rename to tests/framework/ge_running_env/include/ge_running_env/fake_ops_kernel_builder.h index 62dab542..acfe5e41 100644 --- a/tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.h +++ b/tests/framework/ge_running_env/include/ge_running_env/fake_ops_kernel_builder.h @@ -13,39 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef H39E4E719_91F4_4D0F_BA4F_6BA56CB1E20D +#define H39E4E719_91F4_4D0F_BA4F_6BA56CB1E20D -#ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_BUILDER_H_ -#define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_BUILDER_H_ +#include "fake_ns.h" +#include "common/opskernel/ops_kernel_builder.h" +#include "info_store_holder.h" -#if defined(_MSC_VER) -#ifdef FUNC_VISIBILITY -#define GE_FUNC_VISIBILITY _declspec(dllexport) -#else -#define GE_FUNC_VISIBILITY -#endif -#else -#ifdef FUNC_VISIBILITY -#define GE_FUNC_VISIBILITY __attribute__((visibility("default"))) -#else -#define GE_FUNC_VISIBILITY -#endif -#endif +FAKE_NS_BEGIN -#include "common/opskernel/ops_kernel_builder.h" +struct FakeOpsKernelBuilder : OpsKernelBuilder, InfoStoreHolder { + FakeOpsKernelBuilder(const std::string &kernel_lib_name); + FakeOpsKernelBuilder(); -namespace ge { -namespace st { -class GE_FUNC_VISIBILITY StubOpsKernelBuilder : public OpsKernelBuilder { - public: + private: Status Initialize(const map &options) override; - Status Finalize() override; - Status CalcOpRunningParam(Node &node) override; - Status GenerateTask(const Node &node, RunContext &context, std::vector &tasks) override; }; -} // namespace st -} // namespace ge -#endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_BUILDER_H_ +FAKE_NS_END + +#endif diff --git a/tests/framework/ge_running_env/include/ge_running_env/fake_ops_kernel_info_store.h b/tests/framework/ge_running_env/include/ge_running_env/fake_ops_kernel_info_store.h new file mode 100644 index 00000000..4a8ab9dc --- /dev/null +++ b/tests/framework/ge_running_env/include/ge_running_env/fake_ops_kernel_info_store.h @@ -0,0 +1,39 @@ +/** + * Copyright 2021 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. + */ +#ifndef H1EBABA85_7056_48F0_B496_E4DB68E5FED3 +#define H1EBABA85_7056_48F0_B496_E4DB68E5FED3 + +#include "fake_ns.h" +#include "common/opskernel/ops_kernel_info_store.h" +#include "ge/ge_api_types.h" +#include "info_store_holder.h" + +FAKE_NS_BEGIN + +struct FakeOpsKernelInfoStore : OpsKernelInfoStore, InfoStoreHolder { + FakeOpsKernelInfoStore(const std::string &kernel_lib_name); + FakeOpsKernelInfoStore(); + + private: + Status Initialize(const std::map &options) override; + Status Finalize() override; + bool CheckSupported(const OpDescPtr &op_desc, std::string &reason) const override; + void GetAllOpsKernelInfo(std::map &infos) const override; +}; + +FAKE_NS_END + +#endif diff --git a/tests/framework/ge_running_env/include/ge_running_env/ge_running_env_faker.h b/tests/framework/ge_running_env/include/ge_running_env/ge_running_env_faker.h new file mode 100644 index 00000000..6d325c6a --- /dev/null +++ b/tests/framework/ge_running_env/include/ge_running_env/ge_running_env_faker.h @@ -0,0 +1,45 @@ +/** + * Copyright 2021 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. + */ +#ifndef H99C11FC4_700E_4D4D_B073_7808FA88BEBC +#define H99C11FC4_700E_4D4D_B073_7808FA88BEBC + +#include "ge_running_env/fake_engine.h" +#include "fake_ns.h" +#include "opskernel_manager/ops_kernel_manager.h" +#include "register/ops_kernel_builder_registry.h" + +FAKE_NS_BEGIN + +struct GeRunningEnvFaker { + GeRunningEnvFaker(); + GeRunningEnvFaker &Reset(); + GeRunningEnvFaker &Install(const EnvInstaller &); + GeRunningEnvFaker &InstallDefault(); + static void BackupEnv(); + + private: + void flush(); + + private: + std::map> &op_kernel_info_; + std::map &ops_kernel_info_stores_; + std::map &ops_kernel_optimizers_; + std::map &ops_kernel_builders_; +}; + +FAKE_NS_END + +#endif /* H99C11FC4_700E_4D4D_B073_7808FA88BEBC */ diff --git a/tests/framework/stub_engine/ops_kernel_store/op/op.h b/tests/framework/ge_running_env/include/ge_running_env/info_store_holder.h similarity index 51% rename from tests/framework/stub_engine/ops_kernel_store/op/op.h rename to tests/framework/ge_running_env/include/ge_running_env/info_store_holder.h index 3741567a..85b6c75f 100644 --- a/tests/framework/stub_engine/ops_kernel_store/op/op.h +++ b/tests/framework/ge_running_env/include/ge_running_env/info_store_holder.h @@ -13,33 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef H7992249B_058D_40A1_94EA_52BBCB76434E +#define H7992249B_058D_40A1_94EA_52BBCB76434E -#ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_H_ -#define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_H_ - -#include -#include -#include -#include "common/ge_inner_error_codes.h" +#include "fake_ns.h" #include "common/opskernel/ops_kernel_info_types.h" -#include "graph/node.h" -namespace ge { -namespace st { -/** - * The base class for all op. - */ -class GE_FUNC_VISIBILITY Op { - public: - Op(const Node &node, RunContext &run_context) : run_context_(run_context), node_(node) {} - virtual ~Op() = default; - virtual Status Run() = 0; +FAKE_NS_BEGIN + +struct InfoStoreHolder { + InfoStoreHolder(); + InfoStoreHolder(const std::string&); + void EngineName(std::string engine_name); + void RegistOp(std::string op_type); + std::string GetLibName(); protected: - const RunContext &run_context_; - const Node &node_; + std::map op_info_map_; + std::string kernel_lib_name_; + std::string engine_name_; }; -} // namespace st -} // namespace ge -#endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_H_ +FAKE_NS_END + +#endif diff --git a/tests/framework/ge_running_env/src/CMakeLists.txt b/tests/framework/ge_running_env/src/CMakeLists.txt new file mode 100644 index 00000000..ae068bd3 --- /dev/null +++ b/tests/framework/ge_running_env/src/CMakeLists.txt @@ -0,0 +1,45 @@ +# Copyright 2021 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. +# ============================================================================ + +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cc" "*.CC" "*.cpp" "*.CPP" "*.c++") + +# ---- Target : stub Host engine ---- +add_library(ge_with_env STATIC ${SOURCES}) + +target_include_directories(ge_with_env + PUBLIC + include + ) + +target_include_directories(ge_with_env + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ) + +target_compile_definitions(ge_with_env PRIVATE + google=ascend_private + FMK_SUPPORT_DUMP + ) + +target_compile_options(ge_with_env PRIVATE + -g --coverage -fprofile-arcs -ftest-coverage + -Werror=format + ) + +target_link_libraries(ge_with_env PUBLIC + $ ge_running_env_inc graphengine -lrt -ldl -lpthread -lgcov + ) + +set_target_properties(ge_with_env PROPERTIES CXX_STANDARD 17) diff --git a/tests/framework/ge_running_env/src/engine/fake_engine.cc b/tests/framework/ge_running_env/src/engine/fake_engine.cc new file mode 100644 index 00000000..4b8fedbc --- /dev/null +++ b/tests/framework/ge_running_env/src/engine/fake_engine.cc @@ -0,0 +1,81 @@ +/** + * Copyright 2021 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 "ge_running_env/fake_engine.h" +#include "ge_running_env/fake_ops_kernel_builder.h" +#include "ge_running_env/fake_ops_kernel_info_store.h" +#include "opskernel_manager/ops_kernel_manager.h" + +FAKE_NS_BEGIN + +FakeEngine::FakeEngine(const std::string &engine_name) : engine_name_(engine_name) {} + +FakeEngine &FakeEngine::KernelInfoStore(const std::string &info_store) { + info_store_names_.insert(info_store); + return *this; +} + +FakeEngine &FakeEngine::KernelInfoStore(FakeOpsKernelInfoStorePtr ptr) { + info_store_names_.insert(ptr->GetLibName()); + custom_info_stores_.insert(std::make_pair(ptr->GetLibName(), ptr)); + return *this; +} + +FakeEngine &FakeEngine::KernelBuilder(FakeOpsKernelBuilderPtr builder) { + info_store_names_.insert(builder->GetLibName()); + custom_builders_.insert(std::make_pair(builder->GetLibName(), builder)); + return *this; +} + +namespace { +template +void InstallDefault(std::map &maps, const std::string &info_store_name, + const std::string &engine_name) { + auto parent_obj = std::make_shared(info_store_name); + if (parent_obj == nullptr) { + return; + } + parent_obj->EngineName(engine_name); + maps.insert(std::make_pair(parent_obj->GetLibName(), parent_obj)); +} +} // namespace + +template +void FakeEngine::InstallFor(std::map &maps, + const std::map> &child_maps) const { + if (info_store_names_.empty()) { + InstallDefault(maps, engine_name_, engine_name_); + } else { + for (auto &info_store_name : info_store_names_) { + auto iter = child_maps.find(info_store_name); + if (iter == child_maps.end()) { + InstallDefault(maps, info_store_name, engine_name_); + } else { + maps.insert(std::make_pair(iter->second->GetLibName(), iter->second)); + } + } + } +} + +void FakeEngine::InstallTo(std::map &ops_kernel_info_stores) const { + InstallFor(ops_kernel_info_stores, custom_info_stores_); +} + +void FakeEngine::InstallTo(std::map &ops_kernel_builders) const { + InstallFor(ops_kernel_builders, custom_builders_); +} + +FAKE_NS_END diff --git a/tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.cc b/tests/framework/ge_running_env/src/engine/fake_ops_kernel_builder.cc similarity index 73% rename from tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.cc rename to tests/framework/ge_running_env/src/engine/fake_ops_kernel_builder.cc index 2de8691f..77472249 100644 --- a/tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_builder.cc +++ b/tests/framework/ge_running_env/src/engine/fake_ops_kernel_builder.cc @@ -14,40 +14,25 @@ * limitations under the License. */ -#include "stub_ops_kernel_builder.h" -#include +#include "ge_running_env/fake_ops_kernel_builder.h" +#include "graph/utils/node_utils.h" #include "common/ge_inner_error_codes.h" #include "ge/ge_api_types.h" #include "graph/utils/node_utils.h" #include "graph/utils/tensor_utils.h" #include "graph/utils/type_utils.h" -#include #include "framework/common/debug/ge_log.h" -#include "host_cpu_engine/common/constant/constant.h" -#include "register/ops_kernel_builder_registry.h" -#include "inc/st_types.h" +FAKE_NS_BEGIN -namespace ge { -namespace st { -REGISTER_OPS_KERNEL_BUILDER(kAicoreLibName, StubOpsKernelBuilder); -REGISTER_OPS_KERNEL_BUILDER(kVectorLibName, StubOpsKernelBuilder); -REGISTER_OPS_KERNEL_BUILDER(kAicpuLibName, StubOpsKernelBuilder); -REGISTER_OPS_KERNEL_BUILDER(kAicpuAscendLibName, StubOpsKernelBuilder); -REGISTER_OPS_KERNEL_BUILDER(kHcclLibName, StubOpsKernelBuilder); -REGISTER_OPS_KERNEL_BUILDER(kRTSLibName, StubOpsKernelBuilder); +FakeOpsKernelBuilder::FakeOpsKernelBuilder(const std::string &info_store_name) : InfoStoreHolder(info_store_name) {} +FakeOpsKernelBuilder::FakeOpsKernelBuilder() : InfoStoreHolder() {} -Status StubOpsKernelBuilder::Finalize() { - return SUCCESS; -} -Status StubOpsKernelBuilder::Initialize(const map &options) { - return SUCCESS; -} +Status FakeOpsKernelBuilder::Finalize() { return SUCCESS; } +Status FakeOpsKernelBuilder::Initialize(const map &options) { return SUCCESS; } -Status StubOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) { +Status FakeOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) { OpDescPtr op_desc = ge_node.GetOpDesc(); if (op_desc == nullptr) { - GELOGE(FAILED, "[Get][OpDesc]CalcOpRunningParam failed, as op desc is null"); - REPORT_INNER_ERROR("E19999", "GetOpDesc failed."); return FAILED; } @@ -86,9 +71,9 @@ Status StubOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) { name.c_str(), type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(), TypeUtils::DataTypeToSerialString(data_type).c_str()); REPORT_CALL_ERROR( - "E19999", "CalcTensorMemSize failed for op[%s:%s] out[%zu] mem size, mem_size=%ld, format=%s, data_type=%s.", - name.c_str(), type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(), - TypeUtils::DataTypeToSerialString(data_type).c_str()); + "E19999", "CalcTensorMemSize failed for op[%s:%s] out[%zu] mem size, mem_size=%ld, format=%s, data_type=%s.", + name.c_str(), type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(), + TypeUtils::DataTypeToSerialString(data_type).c_str()); return FAILED; } GELOGI("Calc op[%s:%s] out[%zu] mem size is %ld, format=%s, data_type=%s.", name.c_str(), type.c_str(), i, @@ -111,9 +96,9 @@ Status StubOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) { return SUCCESS; } -Status StubOpsKernelBuilder::GenerateTask(const Node &node, RunContext &context, vector &tasks) { +Status FakeOpsKernelBuilder::GenerateTask(const Node &node, RunContext &context, vector &tasks) { // no need to generate device task return SUCCESS; } -} // namespace st -} // namespace ge \ No newline at end of file + +FAKE_NS_END diff --git a/tests/framework/ge_running_env/src/engine/fake_ops_kernel_info_store.cc b/tests/framework/ge_running_env/src/engine/fake_ops_kernel_info_store.cc new file mode 100644 index 00000000..348e1334 --- /dev/null +++ b/tests/framework/ge_running_env/src/engine/fake_ops_kernel_info_store.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2021 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 "external/ge/ge_api_error_codes.h" +#include "ge_running_env/fake_ops_kernel_info_store.h" + +FAKE_NS_BEGIN + +FakeOpsKernelInfoStore::FakeOpsKernelInfoStore(const std::string &info_store_name) : InfoStoreHolder(info_store_name) {} + +FakeOpsKernelInfoStore::FakeOpsKernelInfoStore() : InfoStoreHolder() {} + +Status FakeOpsKernelInfoStore::Finalize() { + op_info_map_.clear(); + return SUCCESS; +} + +Status FakeOpsKernelInfoStore::Initialize(const std::map &options) { return SUCCESS; } + +void FakeOpsKernelInfoStore::GetAllOpsKernelInfo(map &infos) const { infos = op_info_map_; } + +bool FakeOpsKernelInfoStore::CheckSupported(const OpDescPtr &op_desc, std::string &) const { + if (op_desc == nullptr) { + return false; + } + return op_info_map_.count(op_desc->GetType()) > 0; +} + +FAKE_NS_END diff --git a/tests/framework/ge_running_env/src/engine/info_store_holder.cc b/tests/framework/ge_running_env/src/engine/info_store_holder.cc new file mode 100644 index 00000000..231af93a --- /dev/null +++ b/tests/framework/ge_running_env/src/engine/info_store_holder.cc @@ -0,0 +1,49 @@ +/** + * Copyright 2021 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 "ge_running_env/info_store_holder.h" +FAKE_NS_BEGIN + +namespace { +std::string GenStoreName() { + static int store_id = 0; + return "store_" + std::to_string(store_id++); +} +} // namespace + +InfoStoreHolder::InfoStoreHolder(const std::string& kernel_lib_name) : kernel_lib_name_(kernel_lib_name) {} + +InfoStoreHolder::InfoStoreHolder() : kernel_lib_name_(GenStoreName()) {} + +void InfoStoreHolder::RegistOp(std::string op_type) { + OpInfo default_op_info = {.engine = engine_name_, + .opKernelLib = kernel_lib_name_, + .computeCost = 0, + .flagPartial = false, + .flagAsync = false, + .isAtomic = false}; + + auto iter = op_info_map_.find(op_type); + if (iter == op_info_map_.end()) { + op_info_map_.emplace(op_type, default_op_info); + } +} + +void InfoStoreHolder::EngineName(std::string engine_name) { engine_name_ = engine_name; } + +std::string InfoStoreHolder::GetLibName() { return kernel_lib_name_; } + +FAKE_NS_END diff --git a/tests/framework/ge_running_env/src/env/ge_default_running_env.cc b/tests/framework/ge_running_env/src/env/ge_default_running_env.cc new file mode 100644 index 00000000..ab705f55 --- /dev/null +++ b/tests/framework/ge_running_env/src/env/ge_default_running_env.cc @@ -0,0 +1,56 @@ +/** + * Copyright 2021 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 "ge_default_running_env.h" +#include "ge_running_env/ge_running_env_faker.h" +#include "ge_running_env/fake_op.h" + +FAKE_NS_BEGIN +namespace { +std::vector default_engines = {FakeEngine("AIcoreEngine").KernelInfoStore("AiCoreLib"), + FakeEngine("VectorEngine").KernelInfoStore("VectorLib"), + FakeEngine("DNN_VM_AICPU").KernelInfoStore("AicpuLib"), + FakeEngine("DNN_VM_AICPU_ASCEND").KernelInfoStore("AicpuAscendLib"), + FakeEngine("DNN_HCCL").KernelInfoStore("HcclLib"), + FakeEngine("DNN_VM_RTS").KernelInfoStore("RTSLib")}; + +std::vector fake_ops = { + FakeOp(ENTER).InfoStoreAndBuilder("RTSLib"), FakeOp(MERGE).InfoStoreAndBuilder("RTSLib"), + FakeOp(SWITCH).InfoStoreAndBuilder("RTSLib"), FakeOp(LOOPCOND).InfoStoreAndBuilder("RTSLib"), + FakeOp(STREAMMERGE).InfoStoreAndBuilder("RTSLib"), FakeOp(STREAMSWITCH).InfoStoreAndBuilder("RTSLib"), + FakeOp(STREAMACTIVE).InfoStoreAndBuilder("RTSLib"), FakeOp(EXIT).InfoStoreAndBuilder("RTSLib"), + + FakeOp(LESS).InfoStoreAndBuilder("AiCoreLib"), FakeOp(NEXTITERATION).InfoStoreAndBuilder("AiCoreLib"), + FakeOp(CAST).InfoStoreAndBuilder("AiCoreLib"), FakeOp(TRANSDATA).InfoStoreAndBuilder("AiCoreLib"), + FakeOp(NOOP).InfoStoreAndBuilder("AiCoreLib"), FakeOp(VARIABLE).InfoStoreAndBuilder("AiCoreLib"), + FakeOp(CONSTANT).InfoStoreAndBuilder("AiCoreLib"), FakeOp(ASSIGN).InfoStoreAndBuilder("AiCoreLib"), + FakeOp(ADD).InfoStoreAndBuilder("AiCoreLib"), FakeOp(MUL).InfoStoreAndBuilder("AiCoreLib"), + FakeOp(DATA).InfoStoreAndBuilder("AiCoreLib"), FakeOp(NETOUTPUT).InfoStoreAndBuilder("AiCoreLib"), + +}; +} // namespace + +void GeDefaultRunningEnv::InstallTo(GeRunningEnvFaker& ge_env) { + for (auto& fake_engine : default_engines) { + ge_env.Install(fake_engine); + } + + for (auto& fake_op : fake_ops) { + ge_env.Install(fake_op); + } +} + +FAKE_NS_END \ No newline at end of file diff --git a/tests/framework/ge_running_env/src/env/ge_default_running_env.h b/tests/framework/ge_running_env/src/env/ge_default_running_env.h new file mode 100644 index 00000000..b93c528a --- /dev/null +++ b/tests/framework/ge_running_env/src/env/ge_default_running_env.h @@ -0,0 +1,32 @@ +/** + * Copyright 2021 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. + */ + +#ifndef INC_5D044B8760CB41ABA108AE2E37E8EBDE +#define INC_5D044B8760CB41ABA108AE2E37E8EBDE + +#include "ge_running_env/fake_ns.h" + +FAKE_NS_BEGIN + +struct GeRunningEnvFaker; + +struct GeDefaultRunningEnv { + static void InstallTo(GeRunningEnvFaker&); +}; + +FAKE_NS_END + +#endif \ No newline at end of file diff --git a/tests/framework/ge_running_env/src/env/ge_running_env_faker.cc b/tests/framework/ge_running_env/src/env/ge_running_env_faker.cc new file mode 100644 index 00000000..2977f6b2 --- /dev/null +++ b/tests/framework/ge_running_env/src/env/ge_running_env_faker.cc @@ -0,0 +1,109 @@ +/** + * Copyright 2021 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 "external/ge/ge_api.h" +#include "opskernel_manager/ops_kernel_builder_manager.h" +#include "init/gelib.h" +#include "utility" +#include "ge_running_env/ge_running_env_faker.h" +#include "ge_default_running_env.h" +#include "ge_running_env/env_installer.h" +#include "op/fake_op_repo.h" + +FAKE_NS_BEGIN + +namespace { +OpsKernelManager& getKernelManger() { + std::shared_ptr instancePtr = ge::GELib::GetInstance(); + return instancePtr->OpsKernelManagerObj(); +} + +struct InitEnv { + static InitEnv& GetInstance() { + static InitEnv instance; + return instance; + } + + void reset(std::map& ops_kernel_info_stores, + std::map& builders) { + std::set remove_info_names; + for (auto iter : ops_kernel_info_stores) { + if (kernel_info_names.find(iter.first) == kernel_info_names.end()) { + remove_info_names.insert(iter.first); + } + } + for (auto info_name : remove_info_names) { + ops_kernel_info_stores.erase(info_name); + builders.erase(info_name); + } + } + + private: + InitEnv() { + for (auto iter : getKernelManger().GetAllOpsKernelInfoStores()) { + kernel_info_names.insert(iter.first); + } + } + + private: + std::set kernel_info_names; +}; +} // namespace + +GeRunningEnvFaker::GeRunningEnvFaker() + : op_kernel_info_(const_cast>&>(getKernelManger().GetAllOpsKernelInfo())), + ops_kernel_info_stores_( + const_cast&>(getKernelManger().GetAllOpsKernelInfoStores())), + ops_kernel_optimizers_( + const_cast&>(getKernelManger().GetAllGraphOptimizerObjs())), + ops_kernel_builders_(const_cast&>( + OpsKernelBuilderManager::Instance().GetAllOpsKernelBuilders())) { + Reset(); +} + +GeRunningEnvFaker& GeRunningEnvFaker::Reset() { + InitEnv& init_env = InitEnv::GetInstance(); + FakeOpRepo::Reset(); + init_env.reset(ops_kernel_info_stores_, ops_kernel_builders_); + flush(); + return *this; +} + +void GeRunningEnvFaker::BackupEnv() { InitEnv::GetInstance(); } + +GeRunningEnvFaker& GeRunningEnvFaker::Install(const EnvInstaller& installer) { + installer.Install(); + installer.InstallTo(ops_kernel_info_stores_); + installer.InstallTo(ops_kernel_optimizers_); + installer.InstallTo(ops_kernel_builders_); + flush(); + return *this; +} + +void GeRunningEnvFaker::flush() { + op_kernel_info_.clear(); + getKernelManger().GetOpsKernelInfo(""); +} + +GeRunningEnvFaker& GeRunningEnvFaker::InstallDefault() { + Reset(); + GeDefaultRunningEnv::InstallTo(*this); + return *this; +} + +FAKE_NS_END diff --git a/tests/framework/ge_running_env/src/op/fake_op.cc b/tests/framework/ge_running_env/src/op/fake_op.cc new file mode 100644 index 00000000..52bbee8d --- /dev/null +++ b/tests/framework/ge_running_env/src/op/fake_op.cc @@ -0,0 +1,95 @@ +/** + * Copyright 2021 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 "ge_running_env/fake_op.h" +#include "fake_op_repo.h" +#include "ge_running_env/info_store_holder.h" +#include "graph/operator_factory.h" + +FAKE_NS_BEGIN + +FakeOp::FakeOp(const std::string& op_type) : op_type_(op_type) {} + +FakeOp& FakeOp::Inputs(const std::vector& inputs) { + inputs_ = inputs; + return *this; +} + +FakeOp& FakeOp::Outputs(const std::vector& outputs) { + outputs_ = outputs; + return *this; +} + +FakeOp& FakeOp::InferShape(InferShapeFunc infer_fun) { + info_fun_ = infer_fun; + return *this; +} + +FakeOp& FakeOp::InfoStoreAndBuilder(const std::string& name) { + info_store_names_.insert(name); + return *this; +} + +namespace { + +void RegistOpToInfoStore(OpsKernelInfoStorePtr& info_store, const std::string& op_type) { + if (info_store == nullptr) { + return; + } + auto holder = dynamic_cast(info_store.get()); + holder->RegistOp(op_type); +} + +struct FakeOperator : Operator { + FakeOperator(const std::string& op_type) : Operator(op_type) {} + + FakeOperator& RegistInputs(const std::vector& inputs) { + for (auto& input : inputs) { + Operator::InputRegister(input); + } + return *this; + } + + FakeOperator& RegistOutputs(const std::vector& outputs) { + for (auto& output : outputs) { + Operator::OutputRegister(output); + } + return *this; + } +}; +} // namespace + +void FakeOp::InstallTo(std::map& info_stores) const { + std::for_each(info_store_names_.begin(), info_store_names_.end(), [=, &info_stores](auto& info_store_name) { + auto iter = info_stores.find(info_store_name); + if (iter != info_stores.end()) { + RegistOpToInfoStore(iter->second, op_type_); + } + }); +} + +void FakeOp::Install() const { + FakeOpRepo::Regist( + op_type_, + [op_type = this->op_type_, inputs = this->inputs_, outputs = this->outputs_](const std::string&) -> Operator { + return FakeOperator(op_type).RegistInputs(inputs).RegistOutputs(outputs); + }); + if (info_fun_) { + FakeOpRepo::Regist(op_type_, info_fun_); + } +} + +FAKE_NS_END diff --git a/tests/framework/ge_running_env/src/op/fake_op_repo.cc b/tests/framework/ge_running_env/src/op/fake_op_repo.cc new file mode 100644 index 00000000..7d571b8b --- /dev/null +++ b/tests/framework/ge_running_env/src/op/fake_op_repo.cc @@ -0,0 +1,39 @@ +/** + * Copyright 2021 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 "graph/operator_factory_impl.h" +#include "ge_running_env/fake_op.h" +#include "fake_op_repo.h" + +FAKE_NS_BEGIN + +void FakeOpRepo::Reset() { + if (OperatorFactoryImpl::operator_creators_) { + OperatorFactoryImpl::operator_creators_->clear(); + } + if (OperatorFactoryImpl::operator_infershape_funcs_) { + OperatorFactoryImpl::operator_infershape_funcs_->clear(); + } +} + +void FakeOpRepo::Regist(const std::string &operator_type, const OpCreator creator) { + OperatorFactoryImpl::RegisterOperatorCreator(operator_type, creator); +} +void FakeOpRepo::Regist(const std::string &operator_type, const InferShapeFunc infer_fun) { + OperatorFactoryImpl::RegisterInferShapeFunc(operator_type, infer_fun); +} + +FAKE_NS_END \ No newline at end of file diff --git a/tests/framework/ge_running_env/src/op/fake_op_repo.h b/tests/framework/ge_running_env/src/op/fake_op_repo.h new file mode 100644 index 00000000..345515e4 --- /dev/null +++ b/tests/framework/ge_running_env/src/op/fake_op_repo.h @@ -0,0 +1,31 @@ +/** + * Copyright 2021 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. + */ +#ifndef DBF6CE7CD4AC4A83BA4ED4B372FC66E4 +#define DBF6CE7CD4AC4A83BA4ED4B372FC66E4 + +#include "ge_running_env/fake_ns.h" +#include "graph/operator_factory.h" + +FAKE_NS_BEGIN + +struct FakeOpRepo { + static void Reset(); + static void Regist(const std::string &operator_type, const OpCreator); + static void Regist(const std::string &operator_type, const InferShapeFunc); +}; + +FAKE_NS_END +#endif \ No newline at end of file diff --git a/tests/framework/ge_running_env/tests/CMakeLists.txt b/tests/framework/ge_running_env/tests/CMakeLists.txt new file mode 100644 index 00000000..67a9bd70 --- /dev/null +++ b/tests/framework/ge_running_env/tests/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright 2021 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. +# ============================================================================ + +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cc" "*.CC" "*.cpp" "*.CPP") + +add_executable(ge_running_env_test ${SOURCES}) + +target_include_directories(ge_running_env_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_compile_options(ge_running_env_test PRIVATE + -g +) +set_target_properties(ge_running_env_test PROPERTIES CXX_STANDARD 17) + +target_link_libraries(ge_running_env_test PUBLIC gtest ge_with_env) + +include(CTest) +enable_testing() +add_test(NAME test COMMAND ge_running_env_test) \ No newline at end of file diff --git a/tests/framework/ge_running_env/tests/test_ge_running_env_faker.cc b/tests/framework/ge_running_env/tests/test_ge_running_env_faker.cc new file mode 100644 index 00000000..4429f4a7 --- /dev/null +++ b/tests/framework/ge_running_env/tests/test_ge_running_env_faker.cc @@ -0,0 +1,148 @@ +/** + * Copyright 2021 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 "graph/operator_factory_impl.h" +#include "init/gelib.h" +#include "external/ge/ge_api.h" +#include "opskernel_manager/ops_kernel_builder_manager.h" +#include "ge_running_env/fake_ops_kernel_builder.h" +#include "ge_running_env/fake_ns.h" +#include "ge_running_env/ge_running_env_faker.h" +#include "ge_running_env/fake_op.h" +FAKE_NS_BEGIN + +#define ASSERT_OPS_LIST_SIZE(list_size) \ + std::vector ops_list; \ + OperatorFactory::GetOpsTypeList(ops_list);\ + ASSERT_EQ(ops_list.size(), list_size); + +class GeRunningEvnFakerTest : public testing::Test { + protected: + void SetUp() {} + OpsKernelManager &kernel_manager = ge::GELib::GetInstance()->OpsKernelManagerObj(); + OpsKernelBuilderManager &builder_manager = OpsKernelBuilderManager::Instance(); +}; + +TEST_F(GeRunningEvnFakerTest, test_reset_running_env_is_success) { + GeRunningEnvFaker ge_env; + ge_env.Reset(); + ASSERT_OPS_LIST_SIZE(0); + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 1); + ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 1); + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 52); + ASSERT_EQ(kernel_manager.GetOpsKernelInfo(SWITCH).size(), 1); +} + +TEST_F(GeRunningEvnFakerTest, test_install_fake_op_success) { + GeRunningEnvFaker ge_env; + ge_env.Install(FakeOp(DATA)).Install(FakeOp(SWITCH)); + ASSERT_OPS_LIST_SIZE(2); + ASSERT_TRUE(OperatorFactory::IsExistOp(DATA)); + ASSERT_TRUE(OperatorFactory::IsExistOp(SWITCH)); +} + +TEST_F(GeRunningEvnFakerTest, test_install_fake_op_with_inputs_and_outputs_success) { + GeRunningEnvFaker ge_env; + ge_env.Install(FakeOp(ADD).Inputs({"x1", "x2"}).Outputs({"y"})); + + auto add1 = OperatorFactory::CreateOperator("add1", ADD); + + ASSERT_EQ(add1.GetInputsSize(), 2); + ASSERT_EQ(add1.GetOutputsSize(), 1); + ASSERT_OPS_LIST_SIZE(1); +} + +TEST_F(GeRunningEvnFakerTest, test_install_fake_op_with_infer_shape_success) { + GeRunningEnvFaker ge_env; + auto infer_fun = [](Operator &op) -> graphStatus { + TensorDesc input_desc = op.GetInputDescByName("data"); + return GRAPH_SUCCESS; + }; + ASSERT_TRUE(OperatorFactoryImpl::GetInferShapeFunc(DATA) == nullptr); + + ge_env.Install(FakeOp(DATA).Inputs({"data"}).InferShape(infer_fun)); + + ASSERT_TRUE(OperatorFactoryImpl::GetInferShapeFunc(DATA) != nullptr); +} + +TEST_F(GeRunningEvnFakerTest, test_install_engine_with_default_info_store) { + GeRunningEnvFaker ge_env; + ge_env.Install(FakeEngine("DNN_HCCL")); + + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 2); + ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 2); + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 52); + ASSERT_EQ(kernel_manager.GetOpsKernelInfo(SWITCH).size(), 1); +} + +TEST_F(GeRunningEvnFakerTest, test_install_engine_with_info_store_name) { + GeRunningEnvFaker ge_env; + ge_env.Install(FakeEngine("DNN_HCCL").KernelInfoStore("AiCoreLib2")) + .Install(FakeOp(SWITCH).InfoStoreAndBuilder("AiCoreLib2")); + + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 2); + ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 2); + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 52); + ASSERT_EQ(kernel_manager.GetOpsKernelInfo(SWITCH).size(), 2); +} + +TEST_F(GeRunningEvnFakerTest, test_install_custom_kernel_builder_success) { + struct FakeKernelBuilder : FakeOpsKernelBuilder { + Status CalcOpRunningParam(Node &node) override { + OpDescPtr op_desc = node.GetOpDesc(); + if (op_desc == nullptr) { + return FAILED; + } + return SUCCESS; + } + }; + + GeRunningEnvFaker ge_env; + auto ai_core_kernel = FakeEngine("DNN_HCCL").KernelBuilder(std::make_shared()); + ge_env.Reset().Install(ai_core_kernel); + + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 2); + ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 2); + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 52); +} + +TEST_F(GeRunningEvnFakerTest, test_install_custom_kernel_info_store_success) { + struct FakeKernelBuilder : FakeOpsKernelInfoStore { + FakeKernelBuilder(const std::string &kernel_lib_name) : FakeOpsKernelInfoStore(kernel_lib_name) {} + + bool CheckSupported(const OpDescPtr &op_desc, std::string &reason) const override { return FAILED; } + }; + + GeRunningEnvFaker ge_env; + auto ai_core_kernel = FakeEngine("DNN_HCCL").KernelInfoStore(std::make_shared("AiCoreLib2")); + ge_env.Reset().Install(ai_core_kernel); + + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 2); + ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 2); + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 52); +} + +TEST_F(GeRunningEvnFakerTest, test_install_default_fake_engine_success) { + GeRunningEnvFaker ge_env; + ge_env.InstallDefault(); + + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfoStores().size(), 7); + ASSERT_EQ(builder_manager.GetAllOpsKernelBuilders().size(), 7); + ASSERT_EQ(kernel_manager.GetAllOpsKernelInfo().size(), 66); +} + +FAKE_NS_END diff --git a/tests/framework/ge_running_env/tests/test_main.cc b/tests/framework/ge_running_env/tests/test_main.cc new file mode 100644 index 00000000..ede79c75 --- /dev/null +++ b/tests/framework/ge_running_env/tests/test_main.cc @@ -0,0 +1,34 @@ +/** + * Copyright 2021 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 "common/debug/log.h" +#include "external/ge/ge_api.h" +#include "ge_running_env/ge_running_env_faker.h" + +using namespace std; +using namespace ge; + +int main(int argc, char **argv) { + map options; + ge::GEInitialize(options); + GeRunningEnvFaker::BackupEnv(); + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + + return ret; +} diff --git a/tests/framework/stub_engine/CMakeLists.txt b/tests/framework/stub_engine/CMakeLists.txt deleted file mode 100644 index c86313c7..00000000 --- a/tests/framework/stub_engine/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -list(APPEND INCLUDE_DIRECTORIES - "${CMAKE_CURRENT_SOURCE_DIR}" - "${GE_CODE_DIR}" - "${GE_CODE_DIR}/inc" - "${GE_CODE_DIR}/metadef/inc" - "${GE_CODE_DIR}/ge" - "${GE_CODE_DIR}/ge/inc" - "${GE_CODE_DIR}/ge/ir_build" - "${GE_CODE_DIR}/metadef" - "${GE_CODE_DIR}/metadef/graph" - "${GE_CODE_DIR}/inc/external" - "${GE_CODE_DIR}/inc/framework/common" - "${GE_CODE_DIR}/metadef/inc/external" - "${GE_CODE_DIR}/metadef/inc/external/graph" - "${GE_CODE_DIR}/metadef/inc/graph" - "${GE_CODE_DIR}/inc/framework" - "${GE_CODE_DIR}/metadef/inc/common" - "${GE_CODE_DIR}/metadef/third_party" - "${GE_CODE_DIR}/metadef/third_party/transformer/inc" - "${GE_CODE_DIR}/parser" - "${GE_CODE_DIR}/parser/parser" - "${GE_CODE_DIR}/third_party/fwkacllib/inc" - "${GE_CODE_DIR}/third_party/fwkacllib/inc/cce" - "${GE_CODE_DIR}/third_party/fwkacllib/inc/ops" - "${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain" - "${GE_CODE_DIR}/tests/ut/ge" - "${GE_CODE_DIR}/tests/ut/common" - "${CMAKE_BINARY_DIR}" - "${CMAKE_BINARY_DIR}/proto/ge" - "${CMAKE_BINARY_DIR}/proto/ge/proto" - ) - -file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cc" "*.CC" "*.cpp" "*.CPP" "*.c++") - -# ---- Target : stub Host engine ---- -add_library(fe SHARED ${SOURCES}) - -target_include_directories(fe - PUBLIC - ${INCLUDE_DIRECTORIES} - ${CMAKE_CURRENT_SOURCE_DIR} - ) - -target_compile_definitions(fe PRIVATE - google=ascend_private - FMK_SUPPORT_DUMP - ) - -target_compile_options(fe PRIVATE - -g --coverage -fprofile-arcs -ftest-coverage - -Werror=format - ) - -target_link_libraries(fe PUBLIC - $ ${STUB_LIBS} metadef_graph -lmmpa -L${GE_CODE_DIR}/third_party/prebuild/x86_64 -lrt -ldl -lpthread -lgcov - ) - -set_target_properties(fe PROPERTIES CXX_STANDARD 11) diff --git a/tests/framework/stub_engine/engine/stub_engine.cc b/tests/framework/stub_engine/engine/stub_engine.cc deleted file mode 100644 index 622e8c4e..00000000 --- a/tests/framework/stub_engine/engine/stub_engine.cc +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 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 "stub_engine.h" -#include -#include -#include -#include -#include "framework/common/debug/ge_log.h" -#include "common/ge/ge_util.h" -#include "inc/st_types.h" - -namespace ge { -namespace st { -StubEngine &StubEngine::Instance() { - static StubEngine instance; - return instance; -} - -Status StubEngine::Initialize(const std::map &options) { - for (const auto engine_2_lib : kStubEngine2KernelLib) { - auto ops_kernel_store = MakeShared(engine_2_lib.second); - if (ops_kernel_store == nullptr) { - return FAILED; - } - ops_kernel_store_map_.insert(make_pair(engine_2_lib.second, ops_kernel_store)); - } - return SUCCESS; -} - -void StubEngine::GetOpsKernelInfoStores(std::map &ops_kernel_map) { - for (const auto name_2_ops_kernel_store : ops_kernel_store_map_) { - ops_kernel_map[name_2_ops_kernel_store.first] = name_2_ops_kernel_store.second; - } -} - -void StubEngine::GetGraphOptimizerObjs(std::map &) { - // no optimizer for host cpu engine -} - -Status StubEngine::Finalize() { - return SUCCESS; -} -} // namespace st -} // namespace ge - -ge::Status Initialize(const std::map &options) { - return ge::st::StubEngine::Instance().Initialize(options); -} - -void GetOpsKernelInfoStores(std::map &ops_kernel_map) { - ge::st::StubEngine::Instance().GetOpsKernelInfoStores(ops_kernel_map); -} - -void GetGraphOptimizerObjs(std::map &graph_optimizers) { - ge::st::StubEngine::Instance().GetGraphOptimizerObjs(graph_optimizers); -} - -ge::Status Finalize() { - return ge::st::StubEngine::Instance().Finalize(); -} diff --git a/tests/framework/stub_engine/engine/stub_engine.h b/tests/framework/stub_engine/engine/stub_engine.h deleted file mode 100644 index d3909115..00000000 --- a/tests/framework/stub_engine/engine/stub_engine.h +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Copyright 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. - */ - -#ifndef GRAPH_ENGINE_LLT_STUB_ENGINE_H_ -#define GRAPH_ENGINE_LLT_STUB_ENGINE_H_ - -#if defined(_MSC_VER) -#ifdef FUNC_VISIBILITY -#define GE_FUNC_VISIBILITY _declspec(dllexport) -#else -#define GE_FUNC_VISIBILITY -#endif -#else -#ifdef FUNC_VISIBILITY -#define GE_FUNC_VISIBILITY __attribute__((visibility("default"))) -#else -#define GE_FUNC_VISIBILITY -#endif -#endif - -#include -#include -#include -#include "inc/st_types.h" -#include "common/opskernel/ops_kernel_info_store.h" -#include "common/optimizer/graph_optimizer.h" -#include "stub_engine/ops_kernel_store/stub_ops_kernel_store.h" - -using OpsKernelInfoStorePtr = std::shared_ptr; -using StubOpsKernelInfoStorePtr = std::shared_ptr; -using GraphOptimizerPtr = std::shared_ptr; - -namespace ge { -namespace st { -/** - * host cpu engine. - * Used for the ops which executes on host. - */ -class GE_FUNC_VISIBILITY StubEngine { - public: - /** - * get StubEngine instance. - * @return StubEngine instance. - */ - static StubEngine &Instance(); - - virtual ~StubEngine() = default; - - /** - * When Ge start, GE will invoke this interface - * @return The status whether initialize successfully - */ - Status Initialize(const std::map &options); - - /** - * After the initialize, GE will invoke this interface - * to get the Ops kernel Store. - * @param ops_kernel_map The host cpu's ops kernel info - */ - void GetOpsKernelInfoStores(std::map &ops_kernel_map); - - /** - * After the initialize, GE will invoke this interface - * to get the Graph Optimizer. - * @param graph_optimizers The host cpu's Graph Optimizer objs - */ - void GetGraphOptimizerObjs(std::map &graph_optimizers); - - /** - * When the graph finished, GE will invoke this interface - * @return The status whether initialize successfully - */ - Status Finalize(); - - StubEngine(const StubEngine &StubEngine) = delete; - StubEngine(const StubEngine &&StubEngine) = delete; - StubEngine &operator=(const StubEngine &StubEngine) = delete; - StubEngine &operator=(StubEngine &&StubEngine) = delete; - - private: - StubEngine() = default; - map ops_kernel_store_map_; -}; -} // namespace st -} // namespace ge - -extern "C" { - -/** - * When Ge start, GE will invoke this interface - * @return The status whether initialize successfully - */ -GE_FUNC_VISIBILITY ge::Status Initialize(const map &options); - -/** - * After the initialize, GE will invoke this interface to get the Ops kernel Store - * @param ops_kernel_map The host cpu's ops kernel info - */ -GE_FUNC_VISIBILITY void GetOpsKernelInfoStores(std::map &ops_kernel_map); - -/** - * After the initialize, GE will invoke this interface to get the Graph Optimizer - * @param graph_optimizers The host cpu's Graph Optimizer objs - */ -GE_FUNC_VISIBILITY void GetGraphOptimizerObjs(std::map &graph_optimizers); - -/** - * When the graph finished, GE will invoke this interface - * @return The status whether initialize successfully - */ -GE_FUNC_VISIBILITY ge::Status Finalize(); -} - -#endif // GRAPH_ENGINE_LLT_STUB_ENGINE_H_ diff --git a/tests/framework/stub_engine/inc/st_types.h b/tests/framework/stub_engine/inc/st_types.h deleted file mode 100644 index 92aa00d9..00000000 --- a/tests/framework/stub_engine/inc/st_types.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2021 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. - */ -#ifndef GRAPHENGINE_ST_TYPES_H -#define GRAPHENGINE_ST_TYPES_H -#include -namespace ge { -namespace st { -const std::string kAicoreLibName = "AiCoreLib"; -const std::string kVectorLibName = "VectorLib"; -const std::string kAicpuLibName = "AicpuLib"; -const std::string kAicpuAscendLibName = "AicpuAscendLib"; -const std::string kHcclLibName = "HcclLib"; -const std::string kRTSLibName = "RTSLib"; -const std::map kStubEngine2KernelLib = { - {"AIcoreEngine", "AiCoreLib"}, {"VectorEngine", "VectorLib"}, - {"DNN_VM_AICPU", "AicpuLib"}, {"DNN_VM_AICPU_ASCEND", "AicpuAscendLib"}, - {"DNN_HCCL", "HcclLib"}, {"DNN_VM_RTS", "RTSLib"}}; -} // namespace st -} // namespace ge -#endif // GRAPHENGINE_ST_TYPES_H diff --git a/tests/framework/stub_engine/ops_kernel_store/op/host_op.cc b/tests/framework/stub_engine/ops_kernel_store/op/host_op.cc deleted file mode 100644 index 42678148..00000000 --- a/tests/framework/stub_engine/ops_kernel_store/op/host_op.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2021 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 "inc/st_types.h" -#include "stub_engine/ops_kernel_store/op/host_op.h" -#include "framework/common/util.h" -#include "stub_engine/ops_kernel_store/op/stub_op_factory.h" - -namespace ge { -namespace st { -Status HostOp::Run() { - // no need to generate device task - return SUCCESS; -} -REGISTER_OP_CREATOR(Enter, RTSLib, HostOp); -REGISTER_OP_CREATOR(Merge, RTSLib, HostOp); -REGISTER_OP_CREATOR(Switch, RTSLib, HostOp); -REGISTER_OP_CREATOR(Less, AiCoreLib, HostOp); -REGISTER_OP_CREATOR(NextIteration, AiCoreLib, HostOp); -REGISTER_OP_CREATOR(LoopCond, RTSLib, HostOp); -REGISTER_OP_CREATOR(Exit, RTSLib, HostOp); -REGISTER_OP_CREATOR(StreamMerge, RTSLib, HostOp); -REGISTER_OP_CREATOR(StreamSwitch, RTSLib, HostOp); -REGISTER_OP_CREATOR(StreamActive, RTSLib, HostOp); -REGISTER_OP_CREATOR(Cast, AiCoreLib, HostOp); -REGISTER_OP_CREATOR(Transdata, AiCoreLib, HostOp); -} // namespace st -} // namespace ge diff --git a/tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.cc b/tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.cc deleted file mode 100644 index 601bca4d..00000000 --- a/tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.cc +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2021 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 "stub_op_factory.h" -#include "framework/common/debug/ge_log.h" -#include "common/ge_inner_error_codes.h" -#include "graph/op_desc.h" - -namespace ge { -namespace st { -OpFactory &OpFactory::Instance() { - static OpFactory instance; - return instance; -} - -std::shared_ptr OpFactory::CreateOp(const Node &node, RunContext &run_context) { - auto iter = op_creator_map_.find(node.GetType()); - if (iter != op_creator_map_.end()) { - return iter->second(node, run_context); - } - GELOGE(FAILED, "Not supported OP, type = %s, name = %s", node.GetType().c_str(), node.GetName().c_str()); - return nullptr; -} - -void OpFactory::RegisterCreator(const std::string &type, const std::string &kernel_lib, const OP_CREATOR_FUNC &func) { - if (func == nullptr) { - GELOGW("Func is NULL."); - return; - } - - if (all_store_ops_.find(kernel_lib) != all_store_ops_.end()) { - all_store_ops_[kernel_lib].emplace_back(type); - } else { - all_store_ops_[kernel_lib] = {type}; - } -} -} // namespace st -} // namespace ge diff --git a/tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.h b/tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.h deleted file mode 100644 index f41fd07e..00000000 --- a/tests/framework/stub_engine/ops_kernel_store/op/stub_op_factory.h +++ /dev/null @@ -1,109 +0,0 @@ -/** - * Copyright 2021 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. - */ - -#ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_FACTORY_H_ -#define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_FACTORY_H_ - -#include -#include -#include -#include -#include -#include "common/ge/ge_util.h" -#include "stub_engine/ops_kernel_store/op/op.h" -#include "inc/st_types.h" - -namespace ge { -namespace st { -using OP_CREATOR_FUNC = std::function(const Node &, RunContext &)>; - -/** - * manage all the op, support create op. - */ -class GE_FUNC_VISIBILITY OpFactory { - public: - static OpFactory &Instance(); - - /** - * @brief create Op. - * @param [in] node share ptr of node - * @param [in] run_context run context - * @return not nullptr success - * @return nullptr fail - */ - std::shared_ptr CreateOp(const Node &node, RunContext &run_context); - - /** - * @brief Register Op create function. - * @param [in] type Op type - * @param [in] func Op create func - */ - void RegisterCreator(const std::string &type, const std::string &lib_name, const OP_CREATOR_FUNC &func); - - const std::vector &GetAllOps() const { - return all_ops_; - } - - const std::vector &GetAllOps(std::string lib_name) const { - auto iter = all_store_ops_.find(lib_name); - if (iter == all_store_ops_.end()) { - return all_ops_; - } - return iter->second; - } - - bool CheckSupported(const std::string &type) { - return op_creator_map_.find(type) != op_creator_map_.end(); - } - - OpFactory(const OpFactory &) = delete; - OpFactory &operator=(const OpFactory &) = delete; - OpFactory(OpFactory &&) = delete; - OpFactory &operator=(OpFactory &&) = delete; - - private: - OpFactory() = default; - ~OpFactory() = default; - - // the op creator function map - std::map op_creator_map_; - std::map> lib_op_creator_map_; - std::vector all_ops_; - std::map> all_store_ops_; -}; - -class GE_FUNC_VISIBILITY OpRegistrar { - public: - OpRegistrar(const std::string &type, const std::string &kernel_lib, const OP_CREATOR_FUNC &func) { - OpFactory::Instance().RegisterCreator(type, kernel_lib, func); - } - ~OpRegistrar() = default; - - OpRegistrar(const OpRegistrar &) = delete; - OpRegistrar &operator=(const OpRegistrar &) = delete; - OpRegistrar(OpRegistrar &&) = delete; - OpRegistrar &operator=(OpRegistrar &&) = delete; -}; - -#define REGISTER_OP_CREATOR(type, lib_name, clazz) \ - std::shared_ptr Creator_##type##Op(const Node &node, RunContext &run_context) { \ - return MakeShared(node, run_context); \ - } \ - OpRegistrar g_##type##Op_creator(#type, #lib_name, Creator_##type##Op) -} // namespace st -} // namespace ge - -#endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_FACTORY_H_ diff --git a/tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.cc b/tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.cc deleted file mode 100644 index d43fee88..00000000 --- a/tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.cc +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright 2021 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 "stub_ops_kernel_store.h" -#include -#include "ge/ge_api_types.h" -#include "framework/common/debug/ge_log.h" -#include "graph/utils/node_utils.h" -#include "graph/utils/tensor_utils.h" -#include "graph/utils/type_utils.h" -#include "op/stub_op_factory.h" - -namespace ge { -namespace st { -using domi::TaskDef; -using std::map; -using std::string; -using std::vector; - -Status StubOpsKernelInfoStore::Initialize(const map &options) { - GELOGI("StubOpsKernelInfoStore init start."); - string engine_name; - for (const auto &engine_2_lib : kStubEngine2KernelLib) { - if (engine_2_lib.second == store_name_) { - engine_name = engine_2_lib.first; - } - } - if (engine_name.empty()) { - return FAILED; - } - - OpInfo default_op_info = {.engine = engine_name, - .opKernelLib = store_name_, - .computeCost = 0, - .flagPartial = false, - .flagAsync = false, - .isAtomic = false}; - // Init op_info_map_ - auto all_ops_in_store = OpFactory::Instance().GetAllOps(store_name_); - for (auto &op : all_ops_in_store) { - op_info_map_[op] = default_op_info; - } - - GELOGI("StubOpsKernelInfoStore inited success. op num=%zu", op_info_map_.size()); - return SUCCESS; -} - -Status StubOpsKernelInfoStore::Finalize() { - op_info_map_.clear(); - return SUCCESS; -} - -void StubOpsKernelInfoStore::GetAllOpsKernelInfo(map &infos) const { - infos = op_info_map_; -} - -bool StubOpsKernelInfoStore::CheckSupported(const OpDescPtr &op_desc, std::string &) const { - if (op_desc == nullptr) { - return false; - } - return op_info_map_.count(op_desc->GetType()) > 0; -} -} // namespace st -} // namespace ge diff --git a/tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.h b/tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.h deleted file mode 100644 index ea7f712b..00000000 --- a/tests/framework/stub_engine/ops_kernel_store/stub_ops_kernel_store.h +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright 2021 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. - */ - -#ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_INFO_H_ -#define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_INFO_H_ - -#if defined(_MSC_VER) -#ifdef FUNC_VISIBILITY -#define GE_FUNC_VISIBILITY _declspec(dllexport) -#else -#define GE_FUNC_VISIBILITY -#endif -#else -#ifdef FUNC_VISIBILITY -#define GE_FUNC_VISIBILITY __attribute__((visibility("default"))) -#else -#define GE_FUNC_VISIBILITY -#endif -#endif - -#include -#include -#include - -#include "common/opskernel/ops_kernel_info_store.h" - -namespace ge { -namespace st { -/*const vector kStubOpKernelLibNameVec = { - "AiCoreLib", - "AicpuLib", - "HcclLib", - "RTSLib" -};*/ -class GE_FUNC_VISIBILITY StubOpsKernelInfoStore : public OpsKernelInfoStore { - public: - StubOpsKernelInfoStore(std::string store_name) : store_name_(store_name) {} - ~StubOpsKernelInfoStore() override = default; - Status Initialize(const std::map &options) override; - Status Finalize() override; - bool CheckSupported(const OpDescPtr &op_desc, std::string &reason) const override; - void GetAllOpsKernelInfo(std::map &infos) const override; - std::string GetOpsKernelStoreName() const { - return store_name_; - } - - StubOpsKernelInfoStore(const StubOpsKernelInfoStore &ops_kernel_store) = delete; - StubOpsKernelInfoStore(const StubOpsKernelInfoStore &&ops_kernel_store) = delete; - StubOpsKernelInfoStore &operator=(const StubOpsKernelInfoStore &ops_kernel_store) = delete; - StubOpsKernelInfoStore &operator=(StubOpsKernelInfoStore &&ops_kernel_store) = delete; - - private: - // store op name and OpInfo key-value pair - std::map op_info_map_; - std::string store_name_; -}; -} // namespace st -} // namespace ge - -#endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_INFO_H_ diff --git a/tests/st/testcase/CMakeLists.txt b/tests/st/testcase/CMakeLists.txt index 9d1d5a0e..b3663708 100644 --- a/tests/st/testcase/CMakeLists.txt +++ b/tests/st/testcase/CMakeLists.txt @@ -8,7 +8,7 @@ target_include_directories(graph_engine_test set_target_properties(graph_engine_test PROPERTIES CXX_STANDARD 17) -target_link_libraries(graph_engine_test PRIVATE gtest gtest_main framework) +target_link_libraries(graph_engine_test PRIVATE gtest framework) include(CTest) enable_testing() diff --git a/tests/st/testcase/test_framework_dummy.cc b/tests/st/testcase/test_framework_dummy.cc index 951e6b2b..0abdd18b 100644 --- a/tests/st/testcase/test_framework_dummy.cc +++ b/tests/st/testcase/test_framework_dummy.cc @@ -17,9 +17,13 @@ #include #include #include "external/ge/ge_api.h" +#include "ge_running_env/fake_engine.h" #include "graph/debug/ge_attr_define.h" #include "framework/common/types.h" + #include "builder/graph_builder_utils.h" +#include "ge_running_env/ge_running_env_faker.h" + #include "graph/operator_reg.h" #include "graph/operator.h" #define protected public @@ -109,8 +113,8 @@ Graph BuildV1ControlFlowGraph() { for_each(data_vec.begin(), data_vec.end(), [&](int64_t &data) { dims_size *= data; }); vector data_value_vec(dims_size, 1); GeTensorDesc data_tensor_desc(GeShape(data_vec), FORMAT_NCHW, DT_INT32); - GeTensorPtr data_tensor = make_shared(data_tensor_desc, (uint8_t *) data_value_vec.data(), - data_value_vec.size() * sizeof(int32_t)); + GeTensorPtr data_tensor = + make_shared(data_tensor_desc, (uint8_t *)data_value_vec.data(), data_value_vec.size() * sizeof(int32_t)); OpDescUtils::SetWeights(const_5->GetOpDesc(), data_tensor); OpDescUtils::SetWeights(const_2->GetOpDesc(), data_tensor); OpDescUtils::SetWeights(const_1->GetOpDesc(), data_tensor); @@ -120,13 +124,9 @@ Graph BuildV1ControlFlowGraph() { } // namespace class FrameworkTest : public testing::Test { protected: - void SetUp() { - // ge initialize - map options; - auto ret = ge::GEInitialize(options); - EXPECT_EQ(ret, SUCCESS); - } + void SetUp() { ge_env.InstallDefault(); } void TearDown() {} + GeRunningEnvFaker ge_env; }; /// data data diff --git a/tests/st/testcase/test_main.cc b/tests/st/testcase/test_main.cc new file mode 100644 index 00000000..a39c68aa --- /dev/null +++ b/tests/st/testcase/test_main.cc @@ -0,0 +1,37 @@ +/** + * Copyright 2021 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 "common/debug/log.h" +#include "external/ge/ge_api.h" +#include "ge_running_env/include/ge_running_env/ge_running_env_faker.h" + +using namespace std; +using namespace ge; + +int main(int argc, char **argv) { + // init the logging + map options; + auto init_status = ge::GEInitialize(options); + if (init_status != SUCCESS) { + std::cout << "ge init failed , ret code:" << init_status << endl; + } + GeRunningEnvFaker::BackupEnv(); + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} From 07a5635e8b5e08879c2013cffec6164e5697006d Mon Sep 17 00:00:00 2001 From: TangQunzhang Date: Mon, 28 Jun 2021 13:48:18 +0800 Subject: [PATCH 16/50] Print statics when malloc memory fail --- ge/graph/manager/graph_caching_allocator.cc | 18 ++++++++++++------ ge/graph/manager/graph_caching_allocator.h | 10 +++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ge/graph/manager/graph_caching_allocator.cc b/ge/graph/manager/graph_caching_allocator.cc index 82bfbda9..7b316fc3 100644 --- a/ge/graph/manager/graph_caching_allocator.cc +++ b/ge/graph/manager/graph_caching_allocator.cc @@ -20,7 +20,6 @@ #include #include -#include "framework/common/debug/ge_log.h" #include "graph/manager/graph_mem_manager.h" namespace ge { @@ -94,7 +93,8 @@ void IncreaseCount(std::map &count, size_t size) { } } -CachingAllocator::CachingAllocator(rtMemType_t memory_type) : memory_type_(memory_type), memory_allocator_(nullptr) { +CachingAllocator::CachingAllocator(rtMemType_t memory_type) + : memory_type_(memory_type), memory_allocator_(nullptr), called_malloc_counts_(0), called_free_counts_(0) { for (uint32_t i = 0; i < kNumBins; i++) { free_block_bins_[i] = nullptr; } @@ -121,6 +121,8 @@ Status CachingAllocator::Initialize(uint32_t device_id) { if (memory_allocator_ == nullptr) { return ACL_ERROR_GE_INTERNAL_ERROR; } + called_malloc_counts_ = 0; + called_free_counts_ = 0; return ge::SUCCESS; } @@ -133,6 +135,7 @@ void CachingAllocator::Finalize(uint32_t device_id) { uint8_t *CachingAllocator::Malloc(size_t size, uint8_t *org_ptr, uint32_t device_id) { GELOGI("Start malloc pool memory, size = %zu, device id = %u", size, device_id); + called_malloc_counts_++; size = GetBlockSize(size); uint8_t *ptr = nullptr; Block *block = FindFreeBlock(size, org_ptr, device_id); @@ -156,6 +159,7 @@ uint8_t *CachingAllocator::Malloc(size_t size, uint8_t *org_ptr, uint32_t device Status CachingAllocator::Free(uint8_t *ptr, uint32_t device_id) { GELOGI("Free device id = %u", device_id); + called_free_counts_++; if (ptr == nullptr) { REPORT_INNER_ERROR("E19999", "Param ptr is nullptr, device_id:%u, check invalid", device_id); GELOGE(PARAM_INVALID, "[Check][Param] Invalid memory pointer, device_id:%u", device_id); @@ -283,6 +287,7 @@ Status CachingAllocator::TryExtendCache(size_t size, uint32_t device_id) { if (memory_addr == nullptr) { GELOGE(ge::FAILED, "[Malloc][Memory] failed, no enough memory for size = %zu, device_id = %u", memory_size, device_id); + PrintStatics(DLOG_ERROR); return ge::FAILED; } GELOGT(TRACE_RUNNING, "Try to free cached memory size:%zu and malloc memory size:%zu success.", @@ -385,14 +390,14 @@ void CachingAllocator::FreeBlockBins() { } void PrintCount(std::map &count, const std::string &name, size_t total_size, size_t total_count) { - GELOGI("%6s total[size:%10zu count:%10zu].", name.c_str(), total_size, total_count); + GEEVENT("%6s total[size:%11zu count:%11zu].", name.c_str(), total_size, total_count); for (auto &it : count) { - GELOGI(" |- block[size:%10zu count:%10zu].", it.first, it.second); + GEEVENT(" |- block[size:%11zu count:%11zu].", it.first, it.second); } } -void CachingAllocator::PrintStatics() { - if (!IsLogEnable(GE_MODULE_NAME, DLOG_INFO)) { +void CachingAllocator::PrintStatics(int32_t level) { + if (!IsLogEnable(GE_MODULE_NAME, level)) { return; } size_t total_using_size = 0; @@ -435,6 +440,7 @@ void CachingAllocator::PrintStatics() { } } while (0); + GEEVENT("Called counts[malloc:%11zu free:%11zu].", called_malloc_counts_.load(), called_free_counts_.load()); PrintCount(malloc_block_stat, "Malloc", total_malloc_size, total_malloc_count); PrintCount(using_block_stat, "Using", total_using_size, total_using_count); PrintCount(free_block_stat, "Free", total_free_size, total_free_count); diff --git a/ge/graph/manager/graph_caching_allocator.h b/ge/graph/manager/graph_caching_allocator.h index 2db00ff2..d00858f3 100644 --- a/ge/graph/manager/graph_caching_allocator.h +++ b/ge/graph/manager/graph_caching_allocator.h @@ -27,6 +27,7 @@ #include #include +#include "framework/common/debug/ge_log.h" #include "framework/common/ge_inner_error_codes.h" #include "graph/node.h" #include "graph/manager/block_memory.h" @@ -192,9 +193,10 @@ class CachingAllocator { /// /// @ingroup ge_graph /// @brief print the memory info in pool + /// @param [in] log level /// @return void /// - void PrintStatics(); + void PrintStatics(int32_t level = DLOG_INFO); private: rtMemType_t memory_type_; @@ -213,6 +215,12 @@ class CachingAllocator { // malloced memorys from device std::map malloced_memory_; + + //user call Malloc total counts + std::atomic called_malloc_counts_; + + //user call Free total counts + std::atomic called_free_counts_; }; } // namespace ge #endif // GE_GRAPH_MANAGER_GRAPH_CACHING_ALLOCATOR_H_ From a6b6229967c1241494d86eb39200db8783e55a52 Mon Sep 17 00:00:00 2001 From: wuweikang Date: Thu, 13 May 2021 16:14:41 +0800 Subject: [PATCH 17/50] add copy graph --- ge/graph/manager/graph_manager.cc | 2 +- ge/hybrid/model/hybrid_model.h | 1 + ge/hybrid/model/hybrid_model_builder.cc | 45 +++++++++++++++---- ge/hybrid/model/hybrid_model_builder.h | 1 + .../executor/subgraph_executor_unittest.cc | 3 ++ .../model/hybrid_model_builder_unittest.cc | 26 ++++++++--- 6 files changed, 63 insertions(+), 15 deletions(-) diff --git a/ge/graph/manager/graph_manager.cc b/ge/graph/manager/graph_manager.cc index 66026f8d..01a2e502 100755 --- a/ge/graph/manager/graph_manager.cc +++ b/ge/graph/manager/graph_manager.cc @@ -3131,10 +3131,10 @@ void GraphManager::PreRunThread(GraphManager *graph_manager) { } // Avoid repeatively prerun for graphs owns same graph_id in online inference concurrency if (count > 1 && graph_node->GetBuildFlag()) { - graph_node->Lock(); GELOGD("Avoid repeatively prerun, graph_id:%u.", args.graph_id); // In online inference concurrency senario, graph_node is allowed to be locked for 'count' times graph_node->SetSemSize(count); + graph_node->Lock(); graph_manager->run_args_q_.Push(RunArgs( { graph_node, args.graph_id, args.session_id, args.error_context, args.input_tensor, graph_node->GetGeRootModel(), GetThreadLocalContext(), args.callback })); GELOGI("[PreRunThread] Loop end. Start to run with cached build model."); diff --git a/ge/hybrid/model/hybrid_model.h b/ge/hybrid/model/hybrid_model.h index 9821242a..77246e20 100644 --- a/ge/hybrid/model/hybrid_model.h +++ b/ge/hybrid/model/hybrid_model.h @@ -147,6 +147,7 @@ class HybridModel { GeRootModelPtr ge_root_model_; std::map input_nodes_; ComputeGraphPtr root_graph_; + ComputeGraphPtr orig_root_graph_; std::map device_variable_nodes_; //lint !e148 std::map host_variable_nodes_; //lint !e148 std::map> variable_tensors_; diff --git a/ge/hybrid/model/hybrid_model_builder.cc b/ge/hybrid/model/hybrid_model_builder.cc index 1f68f374..e80d9b90 100755 --- a/ge/hybrid/model/hybrid_model_builder.cc +++ b/ge/hybrid/model/hybrid_model_builder.cc @@ -147,6 +147,7 @@ Status HybridModelBuilder::Build() { GE_CHK_STATUS_RET(ValidateParams(), "[Invoke][ValidateParams] failed, model_name_:[%s]", GetGraphName()); hybrid_model_.model_name_ = ge_root_model_->GetModelName(); GELOGI("[%s] Start to build hybrid model.", GetGraphName()); + GE_CHK_STATUS_RET(CopyGraph(), "[Invoke][CopyGraph] failed, model_name_:[%s]", GetGraphName()); GE_CHK_STATUS_RET(InitRuntimeParams(), "[Invoke][InitRuntimeParams] failed, model_name_:[%s]", GetGraphName()); GE_CHK_STATUS_RET(RecoverGraphUnknownFlag(), "[Invoke][RecoverGraphUnknownFlag] failed, model_name_:[%s]", GetGraphName()); @@ -171,11 +172,12 @@ Status HybridModelBuilder::Build() { Status HybridModelBuilder::BuildForSingleOp() { GE_CHK_STATUS_RET(ValidateParams(), "[Invoke][ValidateParams] failed, model_name_:[%s]", GetGraphName()); + hybrid_model_.root_graph_ = ge_root_model_->GetRootGraph(); hybrid_model_.model_name_ = ge_root_model_->GetRootGraph()->GetName(); GELOGI("[%s] Start to build hybrid model.", GetGraphName()); auto ret = ge_root_model_->GetSubgraphInstanceNameToModel(); - const GeModelPtr ge_model = ret[ge_root_model_->GetRootGraph()->GetName()]; - GE_CHK_STATUS_RET(IndexTaskDefs(ge_root_model_->GetRootGraph(), ge_model), + const GeModelPtr ge_model = ret[hybrid_model_.root_graph_->GetName()]; + GE_CHK_STATUS_RET(IndexTaskDefs(hybrid_model_.root_graph_, ge_model), "[Invoke][IndexTaskDefs] failed, model_name_:[%s]", GetGraphName()); GE_CHK_STATUS_RET(LoadGraph(), "[Invoke][LoadGraph] failed, model_name_:[%s]", GetGraphName()); GE_CHK_STATUS_RET(InitWeights(), "[Invoke][InitWeights] failed, model_name_:[%s]", GetGraphName()); @@ -190,6 +192,27 @@ Status HybridModelBuilder::ValidateParams() { return SUCCESS; } +Status HybridModelBuilder::CopyGraph() { + GELOGD("Copy compute graph begin."); + auto root_graph = ge_root_model_->GetRootGraph(); + + std::string new_graph_name = ge_root_model_->GetRootGraph()->GetName(); + ComputeGraphPtr new_root_graph = MakeShared(new_graph_name); + GE_CHECK_NOTNULL(new_root_graph); + int32_t depth = 0; + std::map node_old_2_new; + std::map op_desc_old_2_new; + graphStatus ret = GraphUtils::CopyComputeGraph(root_graph, new_root_graph, node_old_2_new, op_desc_old_2_new, depth); + if (ret != GRAPH_SUCCESS) { + GELOGE(GRAPH_FAILED, "Copy compute graph failed."); + return GRAPH_FAILED; + } + hybrid_model_.root_graph_ = new_root_graph; + + GELOGD("Copy compute graph[%s] success.", new_graph_name.c_str()); + return SUCCESS; +} + Status HybridModelBuilder::BuildNodeItem(const NodePtr &node, NodeItem &node_item) { auto op_desc = node->GetOpDesc(); GE_CHK_STATUS_RET(ParseForceInfershapeNodes(node, node_item), @@ -810,12 +833,13 @@ Status HybridModelBuilder::BuildOutputMapping(GraphItem &graph_item, } Status HybridModelBuilder::LoadGraph() { - auto root_graph = ge_root_model_->GetRootGraph(); + auto root_graph = hybrid_model_.root_graph_; if (!GetContext().GetHostExecFlag()) { std::shared_ptr merged_graph; GELOGI("Before merging subgraphs DirectNodesSize = %zu, GetAllNodesSize = %zu", root_graph->GetDirectNodesSize(), root_graph->GetAllNodesSize()); + hybrid_model_.orig_root_graph_ = root_graph; GE_CHK_GRAPH_STATUS_RET(UnfoldSubgraphs(root_graph, merged_graph), "[Invoke][UnfoldSubgraphs]Failed to unfold subgraphs, model_name_:%s.", GetGraphName()); root_graph = std::move(merged_graph); @@ -873,6 +897,7 @@ Status HybridModelBuilder::LoadGraph() { } for (auto &it : hybrid_model_.known_shape_sub_models_) { auto node_item = MutableNodeItem(it.first); + GE_CHECK_NOTNULL(node_item); AscendString graph_name; GE_CHK_GRAPH_STATUS_RET(it.second->GetGraph().GetName(graph_name), "Failed to get subgraph name"); auto subgraph = hybrid_model_.GetRootGraph()->GetSubgraph(graph_name.GetString()); @@ -1121,7 +1146,9 @@ Status HybridModelBuilder::InitWeights() { sub_weight_buffer->GetSize()); auto subgraph = GraphUtils::GetComputeGraph(subgraph_model.second->GetGraph()); if (subgraph != ge_root_model_->GetRootGraph()) { - subgraph = ge_root_model_->GetRootGraph()->GetSubgraph(subgraph_model.first); + subgraph = hybrid_model_.root_graph_->GetSubgraph(subgraph_model.first); + } else { + subgraph = hybrid_model_.root_graph_; } GE_CHECK_NOTNULL(subgraph); hybrid_model_.weight_buffer_map_.emplace(subgraph->GetName(), std::move(sub_weight_buffer)); @@ -1300,7 +1327,7 @@ Status HybridModelBuilder::IndexTaskDefs(const ComputeGraphPtr &sub_graph, const } Status HybridModelBuilder::IndexTaskDefs() { - const auto root_graph = ge_root_model_->GetRootGraph(); + const auto &root_graph = hybrid_model_.root_graph_; const auto &root_graph_name = root_graph->GetName(); if (SetOutputNameAttr(*root_graph) != SUCCESS) { GELOGW("Set output name attr failed."); @@ -1334,7 +1361,7 @@ Status HybridModelBuilder::IndexTaskDefs() { Status HybridModelBuilder::IndexSpecialNodes() { GELOGD("Start to index special nodes"); - const auto &root_graph = ge_root_model_->GetRootGraph(); + const auto &root_graph = hybrid_model_.root_graph_; for (auto &node : root_graph->GetAllNodes()) { GE_CHECK_NOTNULL(node); GE_CHECK_NOTNULL(node->GetOpDesc()); @@ -1489,7 +1516,7 @@ Status HybridModelBuilder::InitRuntimeParams() { runtime_param_.session_id = ret ? static_cast(value) : 0; ret = ge::AttrUtils::GetInt(first_model, ATTR_MODEL_TASK_GEN_VAR_ADDR, value); runtime_param_.logic_var_base = ret ? static_cast(value) : 0; - runtime_param_.graph_id = ge_root_model_->GetRootGraph()->GetGraphID(); + runtime_param_.graph_id = hybrid_model_.root_graph_->GetGraphID(); value = 0; for (auto &it : ge_root_model_->GetSubgraphInstanceNameToModel()) { (void) ge::AttrUtils::GetInt(it.second, ATTR_MODEL_VAR_SIZE, value); @@ -1626,7 +1653,7 @@ Status HybridModelBuilder::TransAllVarData() { } Status HybridModelBuilder::CopyVarData() { - GE_CHK_STATUS_RET(TransVarDataUtils::CopyVarData(ge_root_model_->GetRootGraph(), + GE_CHK_STATUS_RET(TransVarDataUtils::CopyVarData(hybrid_model_.root_graph_, runtime_param_.session_id, hybrid_model_.device_id_), "[Invoke][CopyVarData] failed."); @@ -1709,7 +1736,7 @@ Status HybridModelBuilder::LoadKnownShapedSubgraph(ComputeGraph &graph, NodeItem } Status HybridModelBuilder::RecoverGraphUnknownFlag() { - const auto &root_graph = ge_root_model_->GetRootGraph(); + const auto &root_graph = hybrid_model_.root_graph_; for (auto &sub_graph : root_graph->GetAllSubgraphs()) { GE_CHECK_NOTNULL(sub_graph); for (const auto &node : sub_graph->GetDirectNode()) { diff --git a/ge/hybrid/model/hybrid_model_builder.h b/ge/hybrid/model/hybrid_model_builder.h index 9c1eb187..05830e82 100644 --- a/ge/hybrid/model/hybrid_model_builder.h +++ b/ge/hybrid/model/hybrid_model_builder.h @@ -56,6 +56,7 @@ class HybridModelBuilder { Status BuildOutputMapping(GraphItem &partitioned_call, const NodeItem &node_item, bool is_root_graph); Status ValidateParams(); Status LoadGraph(); + Status CopyGraph(); Status LoadGeModel(ComputeGraph &graph, const GeModelPtr &ge_model); static Status InitHcclExecutorOnDemand(const GeModelPtr &ge_model); Status LoadTask(NodeItem &node_item); diff --git a/tests/ut/ge/hybrid/executor/subgraph_executor_unittest.cc b/tests/ut/ge/hybrid/executor/subgraph_executor_unittest.cc index 2dc3b639..827705ae 100644 --- a/tests/ut/ge/hybrid/executor/subgraph_executor_unittest.cc +++ b/tests/ut/ge/hybrid/executor/subgraph_executor_unittest.cc @@ -249,6 +249,9 @@ TEST_F(UtestSubgraphExecutor, cond_graph_schedule_tasks) { graph_context.callback_manager = std::unique_ptr(new CallbackManager()); ASSERT_EQ(graph_context.callback_manager->Init(), SUCCESS); + auto root_graph = hybrid_model.root_graph_; + switch_t = root_graph->FindNode("switch_t"); + switch_f = root_graph->FindNode("switch_f"); const auto node_it_t = hybrid_model.node_items_.find(switch_t); const auto node_it_f = hybrid_model.node_items_.find(switch_f); ASSERT_NE(hybrid_model.node_items_.end(), node_it_t); diff --git a/tests/ut/ge/hybrid/model/hybrid_model_builder_unittest.cc b/tests/ut/ge/hybrid/model/hybrid_model_builder_unittest.cc index 5567aca2..10f7c0fe 100644 --- a/tests/ut/ge/hybrid/model/hybrid_model_builder_unittest.cc +++ b/tests/ut/ge/hybrid/model/hybrid_model_builder_unittest.cc @@ -214,11 +214,17 @@ TEST_F(UtestHybridModelBuilder, normal_hybrid_model_build) { ASSERT_EQ(it->second->frame_index_, index); ASSERT_EQ(it->second->parent_frame_, -1); }; - TestFrameGroup(enter1, control_group_index); - TestFrameGroup(active1, control_group_index); - TestFrameGroup(active2, control_group_index); - TestFrameGroup(active3, control_group_index); - TestFrameGroup(output1, -1); + auto root_graph = hybrid_model.root_graph_; + auto enter1_node = root_graph->FindNode("enter"); + auto active1_node = root_graph->FindNode("active1"); + auto active2_node = root_graph->FindNode("active2"); + auto active3_node = root_graph->FindNode("active3"); + auto output1_node = root_graph->FindNode("net_output"); + TestFrameGroup(enter1_node, control_group_index); + TestFrameGroup(active1_node, control_group_index); + TestFrameGroup(active2_node, control_group_index); + TestFrameGroup(active3_node, control_group_index); + TestFrameGroup(output1_node, -1); engine_mapping.clear(); task_executor.clear(); @@ -373,4 +379,14 @@ TEST_F(UtestHybridModelBuilder, TestInitHcclExecutorOnDemand) { NodeExecutorManager::GetInstance().builders_.erase(NodeExecutorManager::ExecutorType::HCCL); ASSERT_EQ(HybridModelBuilder::InitHcclExecutorOnDemand(ge_model), SUCCESS); } + +TEST_F(UtestHybridModelBuilder, copy_graph_success) { +ComputeGraphPtr graph = std::make_shared("test"); +GeRootModelPtr ge_root_model = make_shared(graph); +HybridModel hybrid_model(ge_root_model); +HybridModelBuilder hybrid_model_builder(hybrid_model); + +Status st = hybrid_model_builder.CopyGraph(); +EXPECT_EQ(st, SUCCESS); +} } // namespace ge From deecaf160a6a18ca9fa075606163fa16e53dba23 Mon Sep 17 00:00:00 2001 From: wq160 Date: Mon, 28 Jun 2021 10:37:15 +0800 Subject: [PATCH 18/50] Temporarily disable ImmediateRePass --- ge/graph/passes/infer_base_pass.cc | 5 ++--- tests/ut/ge/graph/passes/infer_base_pass_unittest.cc | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ge/graph/passes/infer_base_pass.cc b/ge/graph/passes/infer_base_pass.cc index 27eb0c54..25c45677 100644 --- a/ge/graph/passes/infer_base_pass.cc +++ b/ge/graph/passes/infer_base_pass.cc @@ -84,9 +84,8 @@ Status InferBasePass::Run(NodePtr &node) { bool InferBasePass::NeedInfer(const NodePtr &node) const { return true; } void InferBasePass::AddChangedNodesImmediateRepass(const std::set &changed_nodes) { - for (const auto &node_ele : changed_nodes) { - AddImmediateRePassNode(node_ele); - } +// need passed_nodes set to solve the problem that multi-input operators do repass in advance. +// when there is passed_nodes set, wo should call AddImmediateRePassNode for all nodes in changed_nodes. } graphStatus InferBasePass::InferAndUpdate(NodePtr &node, bool before_subgraph, std::set &changed_nodes) { diff --git a/tests/ut/ge/graph/passes/infer_base_pass_unittest.cc b/tests/ut/ge/graph/passes/infer_base_pass_unittest.cc index e9247f75..24cc5c1b 100644 --- a/tests/ut/ge/graph/passes/infer_base_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/infer_base_pass_unittest.cc @@ -255,7 +255,7 @@ TEST_F(UtestGraphInferBasePassStub, AddCurNodeRepass_NotCallUpdatePeerNode_WhenI EXPECT_EQ(stub_base_pass.Run(add_node), SUCCESS); EXPECT_EQ(stub_base_pass.call_infer_times, 1); EXPECT_EQ(stub_base_pass.call_update_tensor_desc_times, 0); - EXPECT_EQ(stub_base_pass.GetNodesNeedRePassImmediately(), std::unordered_set({add_node})); +// EXPECT_EQ(stub_base_pass.GetNodesNeedRePassImmediately(), std::unordered_set({add_node})); } TEST_F(UtestGraphInferBasePassStub, NotAddPeerNodeRepass_AfterUpdatePeerNode_WhenUnchanged) { @@ -291,7 +291,7 @@ TEST_F(UtestGraphInferBasePassStub, AddPeerNodeRepass_AfterUpdatePeerNode_WhenCh EXPECT_EQ(stub_base_pass.Run(add_node), SUCCESS); EXPECT_EQ(stub_base_pass.call_update_tensor_desc_times, 1); - EXPECT_EQ(stub_base_pass.GetNodesNeedRePassImmediately(), std::unordered_set({netoutput})); +// EXPECT_EQ(stub_base_pass.GetNodesNeedRePassImmediately(), std::unordered_set({netoutput})); } TEST_F(UtestGraphInferBasePassStub, TestUpdateSubgraphData_WhenBeforeSubgraph) { From e9bab262b736d4d56e3d78c8ed921fa811b752bd Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Mon, 28 Jun 2021 16:43:47 +0800 Subject: [PATCH 19/50] Fix bug of aicore input const. --- ge/single_op/task/op_task.cc | 54 ++++++++++++++++--- ge/single_op/task/op_task.h | 2 + .../ge/single_op/single_op_task_unittest.cc | 37 +++++++++++-- 3 files changed, 83 insertions(+), 10 deletions(-) diff --git a/ge/single_op/task/op_task.cc b/ge/single_op/task/op_task.cc index b6a78f9e..92d1e325 100755 --- a/ge/single_op/task/op_task.cc +++ b/ge/single_op/task/op_task.cc @@ -345,6 +345,53 @@ Status TbeOpTask::AllocateWorkspaces(const vector &workspace_sizes) { return SUCCESS; } +Status TbeOpTask::UpdateIoAddr(std::vector &args, const std::vector &inputs, + const std::vector &outputs) { + uintptr_t *arg_base = nullptr; + size_t arg_num = 0; + GetIoAddr(arg_base, arg_num); + + const vector v_is_input_const = op_desc_->GetIsInputConst(); + size_t non_const_index = 0; + for (size_t i = 0; i < op_desc_->GetAllInputsSize(); ++i) { + const GeTensorDescPtr tensor_desc = op_desc_->MutableInputDesc(static_cast(i)); + if (tensor_desc == nullptr) { + GELOGD("SingleOp: %s, Index: %zu, has no input", op_desc_->GetName().c_str(), i); + continue; + } + if (i < v_is_input_const.size() && v_is_input_const[i]) { + if (i >= arg_num) { + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Size] Args size is %zu, but get index is %zu.", arg_num, i); + REPORT_INNER_ERROR("E19999", "[Check][Size] Args size is %zu, but get index is %zu.", arg_num, i); + return ACL_ERROR_GE_PARAM_INVALID; + } + auto addr = reinterpret_cast(arg_base[i]); + GELOGD("SingleOp: %s, Index: %zu, input is const, addr = %p", op_desc_->GetName().c_str(), i, addr); + args.emplace_back(addr); + continue; + } + if (non_const_index >= inputs.size()) { + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Size] Input size is %zu, but get non_const_index is %zu", + inputs.size(), non_const_index); + REPORT_INNER_ERROR("E19999", "[Check][Size] Input size is %zu, but get non_const_index is %zu", + inputs.size(), non_const_index); + return ACL_ERROR_GE_PARAM_INVALID; + } + auto addr = inputs[non_const_index].data; + GELOGD("SingleOp: %s, input[%zu], addr = %p", op_desc_->GetName().c_str(), i, addr); + args.emplace_back(addr); + non_const_index++; + } + + for (size_t i = 0; i < outputs.size(); ++i) { + auto addr = outputs[i].data; + GELOGD("SingleOp: %s, output[%zu] addr = %p", op_desc_->GetName().c_str(), i, addr); + args.emplace_back(addr); + } + + return SUCCESS; +} + Status TbeOpTask::LaunchKernel(const vector &input_desc, const vector &input_buffers, vector &output_desc, @@ -355,12 +402,7 @@ Status TbeOpTask::LaunchKernel(const vector &input_desc, GE_CHK_STATUS_RET_NOLOG(UpdateRunInfo()); GE_CHK_STATUS_RET(AllocateWorkspaces(run_info_workspaces_), "[Allocate][Workspaces] failed."); std::vector args; - for (auto &buffer : input_buffers) { - args.emplace_back(buffer.data); - } - for (auto &buffer : output_buffers) { - args.emplace_back(buffer.data); - } + GE_CHK_STATUS_RET(UpdateIoAddr(args, input_buffers, output_buffers), "[Update][IoAddr] failed."); for (auto &buffer : workspaces_) { args.emplace_back(buffer); } diff --git a/ge/single_op/task/op_task.h b/ge/single_op/task/op_task.h index 19320bc0..0cbc1a29 100644 --- a/ge/single_op/task/op_task.h +++ b/ge/single_op/task/op_task.h @@ -101,6 +101,8 @@ class TbeOpTask : public OpTask { const vector &output_desc); Status AllocateWorkspaces(const std::vector &workspace_sizes); Status DoLaunchKernel(rtStream_t stream); + Status UpdateIoAddr(std::vector &args, const std::vector &inputs, + const std::vector &outputs); const void *stub_func_ = nullptr; std::unique_ptr args_; diff --git a/tests/ut/ge/single_op/single_op_task_unittest.cc b/tests/ut/ge/single_op/single_op_task_unittest.cc index a17c9012..472a88c3 100644 --- a/tests/ut/ge/single_op/single_op_task_unittest.cc +++ b/tests/ut/ge/single_op/single_op_task_unittest.cc @@ -91,8 +91,9 @@ TEST_F(UtestSingleOpTask, test_build_kernel_task) { TbeOpTask task_tmp; TbeOpTask *task = &task_tmp; ASSERT_EQ(model.BuildKernelTask(task_def, &task), SUCCESS); + ge::DataBuffer data_buffer; vector input_desc; - vector input_buffers; + vector input_buffers = { data_buffer }; vector output_desc; vector output_buffers; task->node_ = node; @@ -110,8 +111,36 @@ TEST_F(UtestSingleOpTask, test_build_kernel_task) { task->args_.reset(&task_args); ASSERT_EQ(task->LaunchKernel(input_desc, input_buffers, output_desc, output_buffers, stream_), SUCCESS); - char handle_tmp = '0'; - char *handle = &handle_tmp; + char *handle = "00"; task->SetHandle(handle); ASSERT_EQ(task->LaunchKernel(input_desc, input_buffers, output_desc, output_buffers, stream_), SUCCESS); -} \ No newline at end of file +} + +TEST_F(UtestSingleOpTask, test_update_ioaddr) { + auto graph = make_shared("graph"); + auto op_desc = make_shared("Add", "Add"); + + GeTensorDesc desc; + op_desc->AddInputDesc(desc); + op_desc->AddInputDesc(desc); + op_desc->AddOutputDesc(desc); + vector is_input_const = { true, false }; + op_desc->SetIsInputConst(is_input_const); + auto node = graph->AddNode(op_desc); + + TbeOpTask task; + task.op_desc_ = op_desc; + task.args_.reset(new (std::nothrow) uint8_t[sizeof(void *) * 3]); + + vector args; + vector inputs; + vector outputs; + ASSERT_EQ(task.UpdateIoAddr(args, inputs, outputs), ACL_ERROR_GE_PARAM_INVALID); + task.arg_size_ = sizeof(void *) * 3; + ASSERT_EQ(task.UpdateIoAddr(args, inputs, outputs), ACL_ERROR_GE_PARAM_INVALID); + + ge::DataBuffer data_buffer; + inputs = { data_buffer }; + ASSERT_EQ(task.UpdateIoAddr(args, inputs, outputs), SUCCESS); +} + From b9715a14584132d72ca9dd49811a943852730eca Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Mon, 28 Jun 2021 19:23:31 +0800 Subject: [PATCH 20/50] DSP: Switch -> TransData -> Cast -> Exit --- ge/graph/passes/next_iteration_pass.cc | 33 ++++++++++++------- ge/hybrid/executor/worker/execution_engine.cc | 2 +- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/ge/graph/passes/next_iteration_pass.cc b/ge/graph/passes/next_iteration_pass.cc index fb8f8627..1c2d7218 100644 --- a/ge/graph/passes/next_iteration_pass.cc +++ b/ge/graph/passes/next_iteration_pass.cc @@ -24,7 +24,9 @@ using std::string; namespace ge { namespace { -const int64_t kLoopType = 1; +constexpr int64_t kLoopType = 1; +constexpr uint8_t kMaxTransOp = 3; +constexpr uint8_t kTransOpIoSize = 1; } Status NextIterationPass::Run(ComputeGraphPtr graph) { @@ -287,18 +289,25 @@ void NextIterationPass::HandleSwitchExitNodes(const LoopCondGroup &loop_group, i std::string node_type; for (const auto &switch_node : loop_group.switch_nodes) { SetControlFlowGroup(switch_node, group_index); - for (const auto &node : switch_node->GetOutDataNodes()) { - (void)GetOriginalType(node, node_type); - if (kExitOpTypes.count(node_type) > 0) { - SetControlFlowGroup(node, group_index); - } else { - // For: Switch -> Cast -> Exit - for (const auto &n : node->GetOutDataNodes()) { - (void)GetOriginalType(n, node_type); - if (kExitOpTypes.count(node_type) > 0) { - SetControlFlowGroup(n, group_index); - } + for (auto node : switch_node->GetOutDataNodes()) { + // Switch --> Exit + // Switch --> Cast --> Exit + // Switch --> TransData --> Cast --> Exit + for (uint8_t i = 0; i < kMaxTransOp; ++i) { + if (node->GetInDataNodes().size() != kTransOpIoSize || node->GetAllOutDataAnchorsSize() != kTransOpIoSize) { + break; } + + if (kExitOpTypes.count(NodeUtils::GetNodeType(node)) > 0) { + SetControlFlowGroup(node, group_index); + break; + } + + const auto &all_nodes = node->GetOutAllNodes(); + if (all_nodes.size() != kTransOpIoSize) { + break; + } + node = all_nodes.at(0); } } } diff --git a/ge/hybrid/executor/worker/execution_engine.cc b/ge/hybrid/executor/worker/execution_engine.cc index d4c73f58..ca864244 100755 --- a/ge/hybrid/executor/worker/execution_engine.cc +++ b/ge/hybrid/executor/worker/execution_engine.cc @@ -373,9 +373,9 @@ Status ExecutionEngine::DoExecuteAsync(NodeState &node_state, auto executor = node_item.node_executor; GE_CHECK_NOTNULL(executor); RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[PrepareTask] Start"); + node_state.UpdatePersistTensor(); GE_CHK_STATUS_RET(executor->PrepareTask(*task, task_context), "[Prepare][Task] for [%s] failed.", node_state.GetName().c_str()); - node_state.UpdatePersistTensor(); RECORD_EXECUTION_EVENT(&context, task_context.GetNodeName(), "[PrepareTask] End"); GELOGD("[%s] Done task preparation successfully.", node_state.GetName().c_str()); From c7e8fc988d24c951dc1942847878e2b339e0e961 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Mon, 28 Jun 2021 19:26:20 +0800 Subject: [PATCH 21/50] Fix bug of multi_task. --- ge/single_op/single_op_model.cc | 128 ++++++++++++++++++-------------- ge/single_op/single_op_model.h | 6 ++ 2 files changed, 77 insertions(+), 57 deletions(-) diff --git a/ge/single_op/single_op_model.cc b/ge/single_op/single_op_model.cc index 08a0fcbc..e5d15beb 100755 --- a/ge/single_op/single_op_model.cc +++ b/ge/single_op/single_op_model.cc @@ -95,35 +95,6 @@ Status CheckInferDepend(GeModelPtr &ge_model, bool &is_infer_depend, bool &is_ho } return SUCCESS; } - -Status NeedHybridModel(GeModelPtr &ge_model, bool &flag) { - bool is_infer_depend = false; - bool is_host_mem = false; - GE_CHK_STATUS_RET(CheckInferDepend(ge_model, is_infer_depend, is_host_mem), "[Check][InferDepend] failed."); - bool need_d2h_cpy = is_infer_depend && !is_host_mem; - auto tasks = ge_model->GetModelTaskDefPtr()->task(); - int32_t kernel_task_num = 0; - for (int i = 0; i < tasks.size(); ++i) { - auto task_type = static_cast(tasks[i].type()); - if (task_type == RT_MODEL_TASK_KERNEL || task_type == RT_MODEL_TASK_ALL_KERNEL) { - const auto &context = task_type == RT_MODEL_TASK_KERNEL ? tasks[i].kernel().context() : - tasks[i].kernel_with_handle().context(); - auto kernel_type = static_cast(context.kernel_type()); - if (kernel_type == ccKernelType::TE) { - if (need_d2h_cpy) { - flag = true; - return SUCCESS; - } - kernel_task_num++; - if (kernel_task_num > 1) { - flag = true; - return SUCCESS; - } - } - } - } - return SUCCESS; -} } // namespace SingleOpModel::SingleOpModel(const std::string &model_name, const void *model_data, uint32_t model_size) @@ -596,50 +567,92 @@ Status SingleOpModel::BuildModelTaskKernel(StreamResource *stream_resource, cons } Status SingleOpModel::BuildTaskListForDynamicOp(StreamResource *stream_resource, DynamicSingleOp &single_op) { - auto ge_model = model_helper_.GetGeModel(); - GE_CHECK_NOTNULL(ge_model); - - auto compute_graph = GraphUtils::GetComputeGraph(ge_model->GetGraph()); - GE_CHECK_NOTNULL(compute_graph); - single_op.compute_graph_ = compute_graph; - auto tasks = ge_model->GetModelTaskDefPtr()->task(); - for (int i = 0; i < tasks.size(); ++i) { - const TaskDef &task_def = tasks[i]; - GELOGI("[%s] Task[%d], type = [%u], DebugString = [%s]", model_name_.c_str(), i, task_def.type(), - task_def.DebugString().c_str()); + if (tbe_tasks_.size() > 0) { + const auto &task_def = tbe_tasks_[0]; + GELOGD("Building TBE task."); + TbeOpTask *tbe_task = nullptr; + GE_CHK_STATUS_RET_NOLOG(BuildKernelTask(task_def, &tbe_task)); + tbe_task->SetModelArgs(model_name_, model_id_); + if (tbe_task->tiling_buffer_ != nullptr) { + GELOGD("tiling buffer is not nullptr."); + tbe_task->stream_resource_ = stream_resource; + } + single_op.op_task_.reset(tbe_task); + } else if (aicpu_tasks_.size() > 0) { + const auto &task_def = aicpu_tasks_[0]; auto task_type = static_cast(task_def.type()); - if (task_type == RT_MODEL_TASK_KERNEL || task_type == RT_MODEL_TASK_ALL_KERNEL) { - if (single_op.op_task_ != nullptr) { - GELOGE(ACL_ERROR_GE_OP_TASK_TYPE_INVALID, "[Check][TaskType]Do not support dynamic op with multiple tasks."); - REPORT_INNER_ERROR("E19999", - "BuildTaskListForDynamicOp fail for Do not support dynamic op with multiple tasks."); - return ACL_ERROR_GE_OP_TASK_TYPE_INVALID; - } - GE_CHK_STATUS_RET_NOLOG(BuildModelTaskKernel(stream_resource, task_def, single_op)); + if (task_type == RT_MODEL_TASK_KERNEL) { + GELOGD("Building AICPU_CC task"); + OpTask *task = nullptr; + uint64_t dynamic_singleop_kernel_id = aicpu_kernel_id++; + GELOGI("Build dynamic singleOp CCTask, kernel_id = %lu", dynamic_singleop_kernel_id); + GE_CHK_STATUS_RET_NOLOG(BuildCpuKernelTask(task_def.kernel(), &task, dynamic_singleop_kernel_id)); + task->SetModelArgs(model_name_, model_id_); + single_op.op_task_.reset(task); } else if (task_type == RT_MODEL_TASK_KERNEL_EX) { - if (single_op.op_task_ != nullptr) { - GELOGE(ACL_ERROR_GE_OP_TASK_TYPE_INVALID, "[Check][TaskType]Do not support dynamic op with multiple tasks."); - REPORT_INNER_ERROR("E19999", - "BuildTaskListForDynamicOp fail for Do not support dynamic op with multiple tasks."); - return ACL_ERROR_GE_OP_TASK_TYPE_INVALID; - } GELOGD("Building AICPU_TF task"); AiCpuTask *aicpu_task = nullptr; uint64_t dynamic_singleop_kernel_id = aicpu_kernel_id++; GELOGI("Build dynamic singleOp TfTask, kernel_id = %lu", dynamic_singleop_kernel_id); GE_CHK_STATUS_RET_NOLOG(BuildKernelExTask(task_def.kernel_ex(), &aicpu_task, dynamic_singleop_kernel_id)); if (aicpu_task->GetUnknownType() == DEPEND_COMPUTE) { - if (i >= tasks.size() - 1) { + if (aicpu_tasks_.size() < 2) { GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Task]The copy task of the fourth operator was not found."); REPORT_INNER_ERROR("E19999", "The copy task of the fourth operator was not found."); return ACL_ERROR_GE_PARAM_INVALID; } - ++i; - const TaskDef ©_task_def = tasks[i]; + const TaskDef ©_task_def = aicpu_tasks_[1]; GE_CHK_STATUS_RET_NOLOG(aicpu_task->SetMemCopyTask(copy_task_def.kernel_ex())); } aicpu_task->SetModelArgs(model_name_, model_id_); single_op.op_task_.reset(aicpu_task); + } + } + return SUCCESS; +} + +Status SingleOpModel::NeedHybridModel(GeModelPtr &ge_model, bool &need_hybrid_model) { + bool is_infer_depend = false; + bool is_host_mem = false; + GE_CHK_STATUS_RET(CheckInferDepend(ge_model, is_infer_depend, is_host_mem), "[Check][InferDepend] failed."); + bool need_d2h_cpy = is_infer_depend && !is_host_mem; + bool aicpu_multi_task = tbe_tasks_.size() >= 1 && aicpu_tasks_.size() >= 1; + bool aicore_multi_task = tbe_tasks_.size() > 1; + need_hybrid_model = need_d2h_cpy || aicore_multi_task || aicpu_multi_task; + return SUCCESS; +} + +Status SingleOpModel::ParseTasks() { + auto ge_model = model_helper_.GetGeModel(); + GE_CHECK_NOTNULL(ge_model); + + auto tasks = ge_model->GetModelTaskDefPtr()->task(); + for (int i = 0; i < tasks.size(); ++i) { + TaskDef &task_def = tasks[i]; + GELOGI("[%s] Task[%d], type = [%u], DebugString = [%s]", model_name_.c_str(), i, task_def.type(), + task_def.DebugString().c_str()); + auto task_type = static_cast(task_def.type()); + if (task_type == RT_MODEL_TASK_KERNEL) { + const auto &kernel_def = task_def.kernel(); + const auto &context = kernel_def.context(); + auto kernel_type = static_cast(context.kernel_type()); + if (kernel_type == ccKernelType::TE) { + tbe_tasks_.emplace_back(task_def); + } else if (kernel_type == ccKernelType::AI_CPU || kernel_type == ccKernelType::CUST_AI_CPU) { + aicpu_tasks_.emplace_back(task_def); + } else { + GELOGE(ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID, + "[Check][Param:TaskDef]Only TBE, AI_CPU, CUST_AI_CPU kernel are supported, but got %u", + context.kernel_type()); + REPORT_INNER_ERROR("E19999", + "BuildModelTaskKernel fail for got:%u not supported, Only TBE, AI_CPU, CUST_AI_CPU kernel are supported.", + context.kernel_type()); + return ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID; + } + } else if (task_type == RT_MODEL_TASK_ALL_KERNEL) { + tbe_tasks_.emplace_back(task_def); + } else if (task_type == RT_MODEL_TASK_KERNEL_EX) { + aicpu_tasks_.emplace_back(task_def); } else { // skip GELOGD("Skip task type: %d", static_cast(task_type)); @@ -654,6 +667,7 @@ Status SingleOpModel::BuildDynamicOp(StreamResource &resource, DynamicSingleOp & GE_CHK_STATUS_RET_NOLOG(InitModelMem(resource)); model_params_.memory_size = UINT64_MAX; model_params_.graph_is_dynamic = true; + GE_CHK_STATUS_RET(ParseTasks(), "[Parse][Tasks] failed."); auto ge_model = model_helper_.GetGeModel(); GE_CHECK_NOTNULL(ge_model); diff --git a/ge/single_op/single_op_model.h b/ge/single_op/single_op_model.h index b7f6b42a..98aed0f0 100755 --- a/ge/single_op/single_op_model.h +++ b/ge/single_op/single_op_model.h @@ -78,6 +78,12 @@ class SingleOpModel { void ParseArgTable(OpTask *task, SingleOp &op); Status InitHybridModelExecutor(const StreamResource &resource, const GeModelPtr &ge_model, SingleOp &single_op); Status SetHostMemTensor(DynamicSingleOp &single_op); + Status NeedHybridModel(GeModelPtr &ge_model, bool &flag); + Status ParseTasks(); + + std::vector tbe_tasks_; + std::vector atomic_tasks_; + std::vector aicpu_tasks_; std::string model_name_; uint32_t model_id_ = 0; From 98f34a58bbf8cad99b7e127942c83389a6305574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=8D=8E?= Date: Wed, 23 Jun 2021 19:36:26 +0800 Subject: [PATCH 22/50] opt info --- CMakeLists.txt | 1 + ge/CMakeLists.txt | 8 ++ ge/ge_opt_info/ge_opt_info.cc | 58 +++++++++ ge/ge_opt_info/ge_opt_info.h | 31 +++++ ge/graph/manager/graph_manager.cc | 7 + tests/CMakeLists.txt | 1 + tests/depends/opt_info/CMakeLists.txt | 37 ++++++ tests/depends/opt_info/src/opt_info_stub.cc | 46 +++++++ tests/framework/cmake/graphengine.cmake | 2 + tests/st/testcase/test_ge_opt_info.cc | 123 ++++++++++++++++++ tests/ut/ge/CMakeLists.txt | 14 ++ .../ut/ge/ge_opt_info/ge_opt_info_unittest.cc | 82 ++++++++++++ third_party/fwkacllib/inc/opt_info/opt_info.h | 32 +++++ 13 files changed, 442 insertions(+) create mode 100644 ge/ge_opt_info/ge_opt_info.cc create mode 100644 ge/ge_opt_info/ge_opt_info.h create mode 100644 tests/depends/opt_info/CMakeLists.txt create mode 100644 tests/depends/opt_info/src/opt_info_stub.cc create mode 100644 tests/st/testcase/test_ge_opt_info.cc create mode 100644 tests/ut/ge/ge_opt_info/ge_opt_info_unittest.cc create mode 100644 third_party/fwkacllib/inc/opt_info/opt_info.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e3cc1e32..41520b14 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,7 @@ else () #find_module(ascendcl_static libascendcl.a ${GE_LIB_PATH}) else() find_module(slog libalog.so ${ASCEND_ATC_DIR}) + find_module(opt_feature libopt_feature.so ${ASCEND_ATC_DIR}) find_module(static_mmpa libmmpa.a ${ASCEND_ATC_DIR}) if(PLATFORM STREQUAL "train") find_module(adump_server libadump_server.a ${ASCEND_RUNTIME_DIR}) diff --git a/ge/CMakeLists.txt b/ge/CMakeLists.txt index 2b9122da..5db2e7a9 100755 --- a/ge/CMakeLists.txt +++ b/ge/CMakeLists.txt @@ -434,6 +434,7 @@ set(TRAIN_SRC_LIST "graph/build/memory/max_block_mem_assigner.cc" "graph/build/memory/var_mem_assign_util.cc" "graph/build/memory/buffer_pool_mem_assigner.cc" + "ge_opt_info/ge_opt_info.cc" ) set(INFER_SRC_LIST @@ -711,6 +712,7 @@ set(INFER_SRC_LIST "graph/build/memory/max_block_mem_assigner.cc" "graph/build/memory/var_mem_assign_util.cc" "graph/build/memory/buffer_pool_mem_assigner.cc" + "ge_opt_info/ge_opt_info.cc" ) if (NOT ENABLE_D AND NOT ENABLE_ACL AND NOT ENABLE_MS_TESTCASES) @@ -765,11 +767,13 @@ target_include_directories(ge_runner SYSTEM PRIVATE ${GE_CODE_DIR}/../inc ${GE_CODE_DIR}/../toolchain/ide/ide-daemon/external ${GE_CODE_DIR}/../abl/adump/external + ${GE_CODE_DIR}/../abl/licctrl #### blue zone ${ASCEND_DIR}/driver/include ${ASCEND_DIR}/fwkacllib/include ${GE_CODE_DIR}/third_party/fwkacllib/inc ${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain + ${GE_CODE_DIR}/third_party/fwkacllib/inc/opt_info ) target_link_options(ge_runner PRIVATE @@ -792,6 +796,7 @@ target_link_libraries(ge_runner PRIVATE runtime error_manager ascend_hal_stub + opt_feature -Wl,--as-needed json -lrt @@ -839,11 +844,13 @@ target_include_directories(ge_compiler SYSTEM PRIVATE ${GE_CODE_DIR}/../inc ${GE_CODE_DIR}/../toolchain/ide/ide-daemon/external ${GE_CODE_DIR}/../abl/adump/external + ${GE_CODE_DIR}/../abl/licctrl #### blue zone #### ${ASCEND_DIR}/driver/include ${ASCEND_DIR}/fwkacllib/include ${GE_CODE_DIR}/third_party/fwkacllib/inc ${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain + ${GE_CODE_DIR}/third_party/fwkacllib/inc/opt_info ) target_link_options(ge_compiler PRIVATE @@ -863,6 +870,7 @@ target_link_libraries(ge_compiler PRIVATE error_manager slog runtime_compile + opt_feature -Wl,--as-needed json -lrt diff --git a/ge/ge_opt_info/ge_opt_info.cc b/ge/ge_opt_info/ge_opt_info.cc new file mode 100644 index 00000000..8c1b84ab --- /dev/null +++ b/ge/ge_opt_info/ge_opt_info.cc @@ -0,0 +1,58 @@ +/** + * Copyright 2021 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 "ge_opt_info/ge_opt_info.h" + +#include +#include +#include "graph/ge_local_context.h" +#include "ge/ge_api_types.h" +#include "common/debug/ge_log.h" +#include "opt_info.h" + +namespace ge { +Status GeOptInfo::SetOptInfo() { + std::string soc_ver; + graphStatus ret = GetThreadLocalContext().GetOption(SOC_VERSION, soc_ver); + if (ret != GRAPH_SUCCESS) { + REPORT_CALL_ERROR("E19999", "Get soc version failed."); + GELOGE(FAILED, "[Get][SocVersion]Get soc version failed."); + return FAILED; + } + GELOGD("Soc version:%s.", soc_ver.c_str()); + std::map opt_info; + // the first arg does not work at present. + if (gelc::GetOptInfo(gelc::kOffline, soc_ver, opt_info) != gelc::SUCCESS) { + REPORT_CALL_ERROR("E19999", "Get optional information failed, is_offline:%d, soc version:%s", + gelc::kOffline, soc_ver.c_str()); + GELOGE(FAILED, "[Get][OptInfo]Get optional information failed, is_offline:%d, soc version:%s", + gelc::kOffline, soc_ver.c_str()); + return FAILED; + } + // do nothing if get empty information + if (opt_info.empty()) { + GELOGI("Optional information is empty."); + return SUCCESS; + } + std::map graph_options = GetThreadLocalContext().GetAllGraphOptions(); + for (const auto &itr : opt_info) { + graph_options.emplace(itr.first, itr.second); + GELOGI("Get optional information success, key:%s, value:%s.", itr.first.c_str(), itr.second.c_str()); + } + GetThreadLocalContext().SetGraphOption(graph_options); + return SUCCESS; +} +} // namespace ge diff --git a/ge/ge_opt_info/ge_opt_info.h b/ge/ge_opt_info/ge_opt_info.h new file mode 100644 index 00000000..935dff25 --- /dev/null +++ b/ge/ge_opt_info/ge_opt_info.h @@ -0,0 +1,31 @@ +/** + * Copyright 2021 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. + */ + +#ifndef GE_OPT_INFO_GE_OPT_INFO_H_ +#define GE_OPT_INFO_GE_OPT_INFO_H_ + +#include "ge/ge_api_error_codes.h" +#include "register/register_types.h" + +namespace ge { +class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY GeOptInfo { + public: + GeOptInfo() = default; + static Status SetOptInfo(); +}; +} // namespace ge + +#endif // GE_OPT_INFO_GE_OPT_INFO_H_ diff --git a/ge/graph/manager/graph_manager.cc b/ge/graph/manager/graph_manager.cc index b862a7d6..0a4633ad 100755 --- a/ge/graph/manager/graph_manager.cc +++ b/ge/graph/manager/graph_manager.cc @@ -27,6 +27,7 @@ #include "common/math/math_util.h" #include "common/thread_pool.h" #include "common/dump/dump_manager.h" +#include "ge_opt_info/ge_opt_info.h" #include "analyzer/analyzer.h" #include "graph/common/ge_call_wrapper.h" #include "graph/common/local_context.h" @@ -1001,6 +1002,12 @@ Status GraphManager::PreRun(const GraphNodePtr &graph_node, const std::vector + c_sec +) + +target_include_directories(opt_feature_stub INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src) diff --git a/tests/depends/opt_info/src/opt_info_stub.cc b/tests/depends/opt_info/src/opt_info_stub.cc new file mode 100644 index 00000000..df518c4b --- /dev/null +++ b/tests/depends/opt_info/src/opt_info_stub.cc @@ -0,0 +1,46 @@ +/** + * Copyright 2021 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 "opt_info.h" +#include +#include +#include +#include + +namespace gelc { +namespace { +const std::vector kSocVersions = {"Ascend910"}; +} + +void SetAllOptInfo(std::map &opt_infos) { + opt_infos.emplace("opt_module.fe", "all"); + opt_infos.emplace("opt_module.pass", "all"); + opt_infos.emplace("opt_module.op_tune", "all"); + opt_infos.emplace("opt_module.rl_tune", "all"); + opt_infos.emplace("opt_module.aoe", "all"); +} + +Status GetOptInfo(WorkMode mode, const std::string &soc_ver, + std::map &opt_infos) { + if (std::find(kSocVersions.begin(), kSocVersions.end(), soc_ver)== kSocVersions.end()) { + SetAllOptInfo(opt_infos); + return SUCCESS; + } + opt_infos.emplace("opt_module.fe", "all"); + opt_infos.emplace("opt_module.pass", "all"); + opt_infos.emplace("opt_module.op_tune", "all"); + return SUCCESS; +} +} // namespace gelc diff --git a/tests/framework/cmake/graphengine.cmake b/tests/framework/cmake/graphengine.cmake index 81aa00cc..c4380016 100644 --- a/tests/framework/cmake/graphengine.cmake +++ b/tests/framework/cmake/graphengine.cmake @@ -103,6 +103,7 @@ list(APPEND INCLUDE_DIRECTORIES "${GE_CODE_DIR}/third_party/fwkacllib/inc/cce" "${GE_CODE_DIR}/third_party/fwkacllib/inc/ops" "${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain" + "${GE_CODE_DIR}/third_party/fwkacllib/inc/opt_info" "${GE_CODE_DIR}/tests/ut/ge" "${GE_CODE_DIR}/tests/ut/common" "${CMAKE_BINARY_DIR}" @@ -117,6 +118,7 @@ list(APPEND STUB_LIBS runtime_stub profiler_stub hccl_stub + opt_feature_stub error_manager_stub ascend_protobuf json diff --git a/tests/st/testcase/test_ge_opt_info.cc b/tests/st/testcase/test_ge_opt_info.cc new file mode 100644 index 00000000..457473b1 --- /dev/null +++ b/tests/st/testcase/test_ge_opt_info.cc @@ -0,0 +1,123 @@ +/** + * Copyright 2021 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 "easy_graph/graph/box.h" +#include "easy_graph/graph/node.h" +#include "easy_graph/builder/graph_dsl.h" +#include "easy_graph/builder/box_builder.h" +#include "easy_graph/layout/graph_layout.h" +#include "easy_graph/layout/engines/graph_easy/graph_easy_option.h" +#include "easy_graph/layout/engines/graph_easy/graph_easy_executor.h" +#include "graph/graph.h" +#include "graph/compute_graph.h" +#include "framework/common/types.h" +#include "graph/debug/ge_attr_define.h" +#include "ge_graph_dsl/graph_dsl.h" +#include "ge_graph_dsl/op_desc/op_desc_cfg_box.h" +#define protected public +#define private public +#include "ge_opt_info/ge_opt_info.h" +#undef private +#undef protected + +namespace ge { +class STEST_opt_info : public testing::Test { + protected: + void SetUp() {} + void TearDown() {} +}; + +TEST_F(STEST_opt_info, get_opt_info_all) { + std::map options = {{ge::SOC_VERSION, "Ascend310"}}; + GetThreadLocalContext().SetGlobalOption(options); + + /// data1 data2 + /// \ / + /// add + // build graph + DEF_GRAPH(g1) { + CHAIN(NODE("data1", DATA)->NODE("add", ADD)); + CHAIN(NODE("data2", DATA)->NODE("add")); + }); + + auto graph = ToGeGraph(g1); + + // new session & add graph + Session session(options); + auto ret = session.AddGraph(1, graph, options); + EXPECT_EQ(ret, SUCCESS); + // build input tensor + std::vector inputs; + // build_graph through session + ret = session.BuildGraph(1, inputs); + EXPECT_EQ(ret, SUCCESS); + + std::map graph_options = GetThreadLocalContext().GetAllGraphOptions(); + auto itr = graph_options.find("opt_module.fe"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.pass"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.op_tune"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.rl_tune"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.aoe"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); +} + +TEST_F(STEST_opt_info, get_opt_info_success) { + std::map options = {{ge::SOC_VERSION, "Ascend910"}}; + GetThreadLocalContext().SetGlobalOption(options); + + /// data1 data2 + /// \ / + /// add + // build graph + DEF_GRAPH(g1) { + CHAIN(NODE("data1", DATA)->NODE("add", ADD)); + CHAIN(NODE("data2", DATA)->NODE("add")); + }); + + auto graph = ToGeGraph(g1); + + // new session & add graph + Session session(options); + auto ret = session.AddGraph(1, graph, options); + EXPECT_EQ(ret, SUCCESS); + // build input tensor + std::vector inputs; + // build_graph through session + ret = session.BuildGraph(1, inputs); + EXPECT_EQ(ret, SUCCESS); + + std::map graph_options = GetThreadLocalContext().GetAllGraphOptions(); + auto itr = graph_options.find("opt_module.fe"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.pass"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.op_tune"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); +} +} // namespace ge diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 06b3e0f2..cf573343 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -62,6 +62,7 @@ include_directories(${GE_CODE_DIR}/third_party/fwkacllib/inc) include_directories(${GE_CODE_DIR}/third_party/fwkacllib/inc/cce) include_directories(${GE_CODE_DIR}/third_party/fwkacllib/inc/ops) include_directories(${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain) +include_directories(${GE_CODE_DIR}/third_party/fwkacllib/inc/opt_info) include_directories(${GE_CODE_DIR}/tests/ut/ge) include_directories(${GE_CODE_DIR}/tests/ut/common) include_directories(${CMAKE_BINARY_DIR}) @@ -346,6 +347,7 @@ set(COMMON_SRC_FILES "${GE_CODE_DIR}/ge/common/ge/datatype_util.cc" "${GE_CODE_DIR}/ge/ge_local_engine/engine/host_cpu_engine.cc" "${GE_CODE_DIR}/ge/session/omg.cc" + "${GE_CODE_DIR}/ge/ge_opt_info/ge_opt_info.cc" ) set(COMMON_FORMAT_SRC_FILES @@ -453,6 +455,7 @@ set(GRAPH_EXECUTE_COMMON_SRC_FILES "${GE_CODE_DIR}/ge/graph/manager/graph_manager.cc" "${GE_CODE_DIR}/ge/graph/manager/graph_context.cc" "${GE_CODE_DIR}/ge/graph/manager/util/rt_context_util.cc" + "${GE_CODE_DIR}/ge/ge_opt_info/ge_opt_info.cc" "${GE_CODE_DIR}/ge/graph/manager/graph_context.h" ) @@ -628,6 +631,10 @@ set(SINGLE_OP_SRC_FILES "${GE_CODE_DIR}/ge/hybrid/hybrid_davinci_model.cc" ) +set(GE_OPT_INFO_SRC_FILES + "${GE_CODE_DIR}/ge/ge_opt_info/ge_opt_info.cc" +) + # test files set(COMMON_TEST_FILES "graph/passes/graph_builder_utils.cc" @@ -813,6 +820,10 @@ set(MULTI_PARTS_TEST_FILES "common/host_cpu_engine_unittest.cc" ) +set(GE_OPT_INFO_TEST_FILES + "ge_opt_info/ge_opt_info_unittest.cc" +) + set(GENERATOR_TEST_FILES "generator/ge_generator_unittest.cc" ) @@ -864,6 +875,7 @@ list(APPEND COMMON_SHARED_LIBRARIES mmpa_stub hccl_stub error_manager_stub + opt_feature_stub ascend_protobuf json ) @@ -1109,10 +1121,12 @@ target_link_libraries(ut_libge_multiparts_utest # libge_others_utest add_executable(ut_libge_others_utest + ${GE_OPT_INFO_SRC_FILES} ${COMMON_TEST_FILES} ${PASS_TEST_FILES} ${EXECUTE_TEST_FILES} ${OTHERS_TEST_FILES} + ${GE_OPT_INFO_TEST_FILES} ) target_compile_options(ut_libge_others_utest PRIVATE diff --git a/tests/ut/ge/ge_opt_info/ge_opt_info_unittest.cc b/tests/ut/ge/ge_opt_info/ge_opt_info_unittest.cc new file mode 100644 index 00000000..20c123e9 --- /dev/null +++ b/tests/ut/ge/ge_opt_info/ge_opt_info_unittest.cc @@ -0,0 +1,82 @@ +/** + * Copyright 2021 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 + +#define protected public +#define private public +#include "ge_opt_info/ge_opt_info.h" +#include "graph/ge_local_context.h" +#include "external/ge/ge_api_types.h" +#undef private +#undef protected + +namespace ge { +class UTEST_opt_info : public testing::Test { + protected: + void SetUp() {} + void TearDown() {} +}; + +TEST_F(UTEST_opt_info, get_opt_info_success) { + std::map options = {{ge::SOC_VERSION, "Ascend910"}}; + GetThreadLocalContext().SetGlobalOption(options); + auto ret = GeOptInfo::SetOptInfo(); + EXPECT_EQ(ret, ge::SUCCESS); + std::map graph_options = GetThreadLocalContext().GetAllGraphOptions(); + auto itr = graph_options.find("opt_module.fe"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.pass"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.op_tune"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); +} + +TEST_F(UTEST_opt_info, get_opt_info_all) { + std::map global_options = {{ge::SOC_VERSION, "Ascend310"}}; + GetThreadLocalContext().SetGlobalOption(global_options); + auto ret = GeOptInfo::SetOptInfo(); + EXPECT_EQ(ret, ge::SUCCESS); + std::map graph_options = GetThreadLocalContext().GetAllGraphOptions(); + auto itr = graph_options.find("opt_module.fe"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.pass"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.op_tune"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.rl_tune"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); + itr = graph_options.find("opt_module.aoe"); + EXPECT_NE(itr, graph_options.end()); + EXPECT_EQ(itr->second, "all"); +} + +TEST_F(UTEST_opt_info, get_opt_info_failed) { + std::map options; + GetThreadLocalContext().SetGlobalOption(options); + auto ret = GeOptInfo::SetOptInfo(); + EXPECT_EQ(ret, ge::FAILED); +} + +} // namespace ge diff --git a/third_party/fwkacllib/inc/opt_info/opt_info.h b/third_party/fwkacllib/inc/opt_info/opt_info.h new file mode 100644 index 00000000..4dff695b --- /dev/null +++ b/third_party/fwkacllib/inc/opt_info/opt_info.h @@ -0,0 +1,32 @@ +/** + * Copyright 2021 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 + +namespace gelc { +using Status = uint32_t; +using WorkMode = uint32_t; +const Status SUCCESS = 0x0; +const Status FAILED = 0xFFFFFFFF; +const WorkMode kOffline = 0x0; +const WorkMode kInline = 0x01; + +__attribute__((visibility ("default"))) +Status GetOptInfo(WorkMode mode, const std::string &soc_ver, + std::map &opt_info_map); +} // namespace gelc + From ae348cf55a6cb7c5729dd6b4b5fb700723e8362b Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Tue, 29 Jun 2021 15:42:36 +0800 Subject: [PATCH 23/50] Fix ut. --- ge/single_op/task/op_task.cc | 120 +++++++++--------- ge/single_op/task/op_task.h | 6 +- ge/single_op/task/tbe_task_builder.cc | 1 + .../ge/single_op/single_op_task_unittest.cc | 23 ++-- tests/ut/ge/single_op/single_op_unittest.cc | 2 +- 5 files changed, 84 insertions(+), 68 deletions(-) diff --git a/ge/single_op/task/op_task.cc b/ge/single_op/task/op_task.cc index 92d1e325..632cd4d8 100755 --- a/ge/single_op/task/op_task.cc +++ b/ge/single_op/task/op_task.cc @@ -345,14 +345,46 @@ Status TbeOpTask::AllocateWorkspaces(const vector &workspace_sizes) { return SUCCESS; } -Status TbeOpTask::UpdateIoAddr(std::vector &args, const std::vector &inputs, - const std::vector &outputs) { - uintptr_t *arg_base = nullptr; - size_t arg_num = 0; - GetIoAddr(arg_base, arg_num); +Status TbeOpTask::UpdateTilingArgs(rtStream_t stream) { + size_t args_size = op_desc_->GetInputsSize() + op_desc_->GetOutputsSize() + workspaces_.size(); + if (tiling_buffer_ != nullptr) { + args_size++; + } + size_t temp_size = args_size * sizeof(void *); + if (arg_size_ < temp_size) { + GELOGD("Need to reset size of args_ from %zu to %zu.", arg_size_, temp_size); + std::unique_ptr args(new (std::nothrow) uint8_t[temp_size]()); + GE_CHECK_NOTNULL(args); + if (memcpy_s(args.get(), temp_size, args_.get(), arg_size_) != EOK) { + GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "[Update][KernelArgs] failed for [%s].", node_->GetName().c_str()); + REPORT_INNER_ERROR("E19999", "update kernel args failed for %s.", node_->GetName().c_str()); + return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; + } + args_.reset(args.release()); + arg_size_ = temp_size; + } + + uintptr_t *arg_base = reinterpret_cast(args_.get()); + size_t arg_index = op_desc_->GetInputsSize() + op_desc_->GetOutputsSize(); + for (size_t i = 0; i < workspaces_.size(); ++i) { + arg_base[arg_index++] = reinterpret_cast(workspaces_[i]); + } + + if (tiling_buffer_ != nullptr) { + GELOGD("[%s] Start to copy tiling info. size = %zu", node_->GetName().c_str(), tiling_data_.size()); + GE_CHK_RT_RET(rtMemcpyAsync(tiling_buffer_, max_tiling_size_, tiling_data_.data(), tiling_data_.size(), + RT_MEMCPY_HOST_TO_DEVICE_EX, stream)); + arg_base[arg_index] = reinterpret_cast(tiling_buffer_); + } + + return SUCCESS; +} + +Status TbeOpTask::SetArgIndex() { + arg_index_.clear(); const vector v_is_input_const = op_desc_->GetIsInputConst(); - size_t non_const_index = 0; + size_t input_index = 0; for (size_t i = 0; i < op_desc_->GetAllInputsSize(); ++i) { const GeTensorDescPtr tensor_desc = op_desc_->MutableInputDesc(static_cast(i)); if (tensor_desc == nullptr) { @@ -360,33 +392,33 @@ Status TbeOpTask::UpdateIoAddr(std::vector &args, const std::vector= arg_num) { - GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Size] Args size is %zu, but get index is %zu.", arg_num, i); - REPORT_INNER_ERROR("E19999", "[Check][Size] Args size is %zu, but get index is %zu.", arg_num, i); - return ACL_ERROR_GE_PARAM_INVALID; - } - auto addr = reinterpret_cast(arg_base[i]); - GELOGD("SingleOp: %s, Index: %zu, input is const, addr = %p", op_desc_->GetName().c_str(), i, addr); - args.emplace_back(addr); + GELOGD("SingleOp: %s, Index: %zu, input is const", op_desc_->GetName().c_str(), i); + input_index++; continue; } - if (non_const_index >= inputs.size()) { - GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Size] Input size is %zu, but get non_const_index is %zu", - inputs.size(), non_const_index); - REPORT_INNER_ERROR("E19999", "[Check][Size] Input size is %zu, but get non_const_index is %zu", - inputs.size(), non_const_index); - return ACL_ERROR_GE_PARAM_INVALID; - } - auto addr = inputs[non_const_index].data; - GELOGD("SingleOp: %s, input[%zu], addr = %p", op_desc_->GetName().c_str(), i, addr); - args.emplace_back(addr); - non_const_index++; + arg_index_.emplace_back(input_index); + input_index++; } + return SUCCESS; +} - for (size_t i = 0; i < outputs.size(); ++i) { - auto addr = outputs[i].data; - GELOGD("SingleOp: %s, output[%zu] addr = %p", op_desc_->GetName().c_str(), i, addr); - args.emplace_back(addr); +Status TbeOpTask::UpdateIoAddr(const vector &inputs, const vector &outputs) { + if (arg_index_.size() != inputs.size()) { + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Size] Args size is %zu, but get input size is %zu.", + arg_index_.size(), inputs.size()); + REPORT_INNER_ERROR("E19999", "[Check][Size] Args size is %zu, but get input size is %zu.", + arg_index_.size(), inputs.size()); + return ACL_ERROR_GE_PARAM_INVALID; + } + + uintptr_t *arg_base = reinterpret_cast(args_.get()); + for (size_t i = 0; i < arg_index_.size(); ++i) { + arg_base[arg_index_[i]] = reinterpret_cast(inputs[i].data); + } + + size_t input_size = op_desc_->GetInputsSize(); + for (size_t i = 0; i < op_desc_->GetOutputsSize(); ++i) { + arg_base[input_size + i] = reinterpret_cast(outputs[i].data); } return SUCCESS; @@ -398,37 +430,11 @@ Status TbeOpTask::LaunchKernel(const vector &input_desc, vector &output_buffers, rtStream_t stream) { GELOGD("[%s] Start to launch kernel", node_->GetName().c_str()); + GE_CHK_STATUS_RET(UpdateIoAddr(input_buffers, output_buffers), "[Update][IoAddr] failed."); GE_CHK_STATUS_RET_NOLOG(UpdateNodeByShape(input_desc, output_desc)); GE_CHK_STATUS_RET_NOLOG(UpdateRunInfo()); GE_CHK_STATUS_RET(AllocateWorkspaces(run_info_workspaces_), "[Allocate][Workspaces] failed."); - std::vector args; - GE_CHK_STATUS_RET(UpdateIoAddr(args, input_buffers, output_buffers), "[Update][IoAddr] failed."); - for (auto &buffer : workspaces_) { - args.emplace_back(buffer); - } - - if (tiling_buffer_ != nullptr) { - GELOGD("[%s] Start to copy tiling info. size = %zu", node_->GetName().c_str(), tiling_data_.size()); - GE_CHK_RT_RET(rtMemcpyAsync(tiling_buffer_, max_tiling_size_, tiling_data_.data(), tiling_data_.size(), - RT_MEMCPY_HOST_TO_DEVICE_EX, stream)); - - args.emplace_back(tiling_buffer_); - } - - GELOGD("Dst size is %zu, src size is %zu.", arg_size_, args.size() * sizeof(void *)); - // node with workspace: build can not get size of workspace, need to update arg_size_ when execute - if (arg_size_ < (args.size() * sizeof(void *))) { - size_t temp_size = args.size() * sizeof(void *); - GELOGD("Need to reset size of args_ from %zu to %zu.", arg_size_, temp_size); - args_.reset(new(std::nothrow) uint8_t[temp_size]()); - GE_CHECK_NOTNULL(args_); - arg_size_ = temp_size; - } - if (memcpy_s(args_.get(), arg_size_, args.data(), args.size() * sizeof(void *)) != EOK) { - GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "[Update][KernelArgs] failed for [%s].", node_->GetName().c_str()); - REPORT_INNER_ERROR("E19999", "update kernel args failed for %s.", node_->GetName().c_str()); - return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; - } + GE_CHK_STATUS_RET(UpdateTilingArgs(stream), "[Update][TilingArgs] failed."); GELOGD("[%s] Start to invoke rtKernelLaunch", node_->GetName().c_str()); GE_CHK_STATUS_RET(DoLaunchKernel(stream), "Failed to do launch kernel."); diff --git a/ge/single_op/task/op_task.h b/ge/single_op/task/op_task.h index 0cbc1a29..d3e8383d 100644 --- a/ge/single_op/task/op_task.h +++ b/ge/single_op/task/op_task.h @@ -85,6 +85,7 @@ class TbeOpTask : public OpTask { const OpDescPtr &op_desc, const domi::KernelDefWithHandle& kernel_def_with_handle); Status UpdateRunInfo() override; + Status SetArgIndex(); const void *GetArgs() const; size_t GetArgSize() const; @@ -100,9 +101,9 @@ class TbeOpTask : public OpTask { Status UpdateNodeByShape(const vector &input_desc, const vector &output_desc); Status AllocateWorkspaces(const std::vector &workspace_sizes); + Status UpdateTilingArgs(rtStream_t stream); Status DoLaunchKernel(rtStream_t stream); - Status UpdateIoAddr(std::vector &args, const std::vector &inputs, - const std::vector &outputs); + Status UpdateIoAddr(const vector &inputs, const vector &outputs); const void *stub_func_ = nullptr; std::unique_ptr args_; @@ -122,6 +123,7 @@ class TbeOpTask : public OpTask { void* handle_ = nullptr; std::string original_kernel_key_; std::string node_info_; + std::vector arg_index_; }; class AiCpuBaseTask : public OpTask { diff --git a/ge/single_op/task/tbe_task_builder.cc b/ge/single_op/task/tbe_task_builder.cc index c7ff13d1..e5206ea6 100644 --- a/ge/single_op/task/tbe_task_builder.cc +++ b/ge/single_op/task/tbe_task_builder.cc @@ -387,6 +387,7 @@ Status TbeTaskBuilder::BuildTask(TbeOpTask &task, const SingleOpModelParam ¶ } task.SetStubFunc(stub_name_, stub_func); } + GE_CHK_STATUS_RET(task.SetArgIndex(), "[Set][ArgTable] failed."); return SUCCESS; } diff --git a/tests/ut/ge/single_op/single_op_task_unittest.cc b/tests/ut/ge/single_op/single_op_task_unittest.cc index 472a88c3..020efc23 100644 --- a/tests/ut/ge/single_op/single_op_task_unittest.cc +++ b/tests/ut/ge/single_op/single_op_task_unittest.cc @@ -95,7 +95,7 @@ TEST_F(UtestSingleOpTask, test_build_kernel_task) { vector input_desc; vector input_buffers = { data_buffer }; vector output_desc; - vector output_buffers; + vector output_buffers = { data_buffer }; task->node_ = node; OpTilingFunc op_tiling_func = [](const TeOpParas &, const OpCompileInfo &, OpRunInfo &) -> bool {return true;}; OpTilingRegistryInterf("Add", op_tiling_func); @@ -107,8 +107,7 @@ TEST_F(UtestSingleOpTask, test_build_kernel_task) { task->max_tiling_size_ = 64; task->tiling_data_ = "tiling_data"; task->arg_size_ = 64; - uint8_t task_args{0}; - task->args_.reset(&task_args); + task->args_.reset(new (std::nothrow) uint8_t[sizeof(void *) * 3]); ASSERT_EQ(task->LaunchKernel(input_desc, input_buffers, output_desc, output_buffers, stream_), SUCCESS); char *handle = "00"; @@ -130,17 +129,25 @@ TEST_F(UtestSingleOpTask, test_update_ioaddr) { TbeOpTask task; task.op_desc_ = op_desc; - task.args_.reset(new (std::nothrow) uint8_t[sizeof(void *) * 3]); + task.node_ = node; + ASSERT_EQ(task.SetArgIndex(), SUCCESS); + task.arg_size_ = sizeof(void *) * 4; + task.args_.reset(new (std::nothrow) uint8_t[task.arg_size_]); + task.arg_index_ = {0}; vector args; vector inputs; vector outputs; - ASSERT_EQ(task.UpdateIoAddr(args, inputs, outputs), ACL_ERROR_GE_PARAM_INVALID); - task.arg_size_ = sizeof(void *) * 3; - ASSERT_EQ(task.UpdateIoAddr(args, inputs, outputs), ACL_ERROR_GE_PARAM_INVALID); + ASSERT_EQ(task.UpdateIoAddr(inputs, outputs), ACL_ERROR_GE_PARAM_INVALID); ge::DataBuffer data_buffer; inputs = { data_buffer }; - ASSERT_EQ(task.UpdateIoAddr(args, inputs, outputs), SUCCESS); + outputs = { data_buffer }; + ASSERT_EQ(task.UpdateIoAddr(inputs, outputs), SUCCESS); + + task.tiling_buffer_ = (void *)0x0001; + task.workspaces_ = { (void *)0x0002 }; + ASSERT_EQ(task.UpdateTilingArgs(nullptr), SUCCESS); + task.tiling_buffer_ = nullptr; } diff --git a/tests/ut/ge/single_op/single_op_unittest.cc b/tests/ut/ge/single_op/single_op_unittest.cc index db3de7ec..09aac153 100644 --- a/tests/ut/ge/single_op/single_op_unittest.cc +++ b/tests/ut/ge/single_op/single_op_unittest.cc @@ -103,7 +103,7 @@ TEST_F(UtestSingleOp, test_dynamic_singleop_execute_async1) { EXPECT_EQ(desc_ptr->AddInputDesc("x", GeTensorDesc(GeShape({2}), FORMAT_NCHW)), GRAPH_SUCCESS); dynamic_single_op.op_task_->op_desc_ = desc_ptr; // UpdateRunInfo failed - EXPECT_EQ(dynamic_single_op.ExecuteAsync(input_desc, input_buffers, output_desc, output_buffers), PARAM_INVALID); + EXPECT_EQ(dynamic_single_op.ExecuteAsync(input_desc, input_buffers, output_desc, output_buffers), ACL_ERROR_GE_PARAM_INVALID); } From a781b6c3548ec748d869cbb8d51e11d515c322a1 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Tue, 29 Jun 2021 16:56:06 +0800 Subject: [PATCH 24/50] Fix bug of atomic profiling. --- .../node_executor/aicore/aicore_node_executor.cc | 2 +- ge/hybrid/node_executor/aicore/aicore_op_task.cc | 10 ++++++++++ ge/hybrid/node_executor/aicore/aicore_op_task.h | 4 ++++ ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc | 2 +- ge/hybrid/node_executor/task_context.cc | 6 +++--- ge/hybrid/node_executor/task_context.h | 4 ++-- .../executor/worker/execution_engine_unittest.cc | 2 +- tests/ut/ge/hybrid/ge_hybrid_unittest.cc | 11 ++++++++++- 8 files changed, 32 insertions(+), 9 deletions(-) diff --git a/ge/hybrid/node_executor/aicore/aicore_node_executor.cc b/ge/hybrid/node_executor/aicore/aicore_node_executor.cc index c2ce24a4..7a22a062 100755 --- a/ge/hybrid/node_executor/aicore/aicore_node_executor.cc +++ b/ge/hybrid/node_executor/aicore/aicore_node_executor.cc @@ -208,7 +208,7 @@ Status AiCoreNodeTask::ExecuteAsync(TaskContext &context, std::function context.SetTaskId(task_id); context.SetStreamId(stream_id); GELOGD("Aicore node[%s] task_id: %u, stream_id: %u.", context.GetNodeName(), task_id, stream_id); - (void)context.SaveProfilingTaskDescInfo(task_id, stream_id, kTaskTypeAicore, (*it)->GetBlockDim()); + (void)context.SaveProfilingTaskDescInfo(task_id, stream_id, kTaskTypeAicore, (*it)->GetBlockDim(), (*it)->GetOpType()); RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[AiCoreNodeLaunchKernel] End"); RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[AiCoreNodeLaunchKernel] End"); } diff --git a/ge/hybrid/node_executor/aicore/aicore_op_task.cc b/ge/hybrid/node_executor/aicore/aicore_op_task.cc index a32f2999..b34cc0c6 100644 --- a/ge/hybrid/node_executor/aicore/aicore_op_task.cc +++ b/ge/hybrid/node_executor/aicore/aicore_op_task.cc @@ -33,6 +33,7 @@ namespace { constexpr char const *kAttrSupportDynamicShape = "support_dynamicshape"; constexpr char const *kAttrOpParamSize = "op_para_size"; constexpr char const *kAttrAtomicOpParamSize = "atomic_op_para_size"; +const string kAtomicOpType = "DynamicAtomicAddrClean"; std::atomic log_id(0); } // namespace @@ -51,6 +52,7 @@ bool TbeHandleRegistry::AddHandle(std::unique_ptr &&holder) { } Status AiCoreOpTask::Init(const OpDesc &op_desc, const domi::TaskDef &task_def) { + op_type_ = op_desc.GetType(); log_name_ = op_desc.GetName() + "_tvmbin"; log_id_ = log_id++; auto op_desc_ptr = MakeShared(op_desc); @@ -538,6 +540,10 @@ const std::string &AiCoreOpTask::GetName() const { return stub_name_; } +const std::string &AiCoreOpTask::GetOpType() const { + return op_type_; +} + std::string AiCoreOpTask::GetKeyForOpParamSize() const { return kAttrOpParamSize; } @@ -631,6 +637,10 @@ std::string AtomicAddrCleanOpTask::GetKeyForKernelName(const OpDesc &op_desc) co return op_desc.GetName() + "_atomic_kernelname"; } +const std::string &AtomicAddrCleanOpTask::GetOpType() const { + return kAtomicOpType; +} + Status AtomicAddrCleanOpTask::CalcTilingInfo(const NodePtr &node, OpRunInfo &tiling_info) { GELOGD("[%s] Start to invoke OpAtomicCalculate.", node->GetName().c_str()); GE_CHK_STATUS_RET(optiling::OpAtomicCalculateV2(*node, tiling_info), diff --git a/ge/hybrid/node_executor/aicore/aicore_op_task.h b/ge/hybrid/node_executor/aicore/aicore_op_task.h index b03bd9e4..8d7be0db 100755 --- a/ge/hybrid/node_executor/aicore/aicore_op_task.h +++ b/ge/hybrid/node_executor/aicore/aicore_op_task.h @@ -78,6 +78,8 @@ class AiCoreOpTask { void SetSingleOp(bool is_single_op) {is_single_op_ = is_single_op;}; + virtual const std::string& GetOpType() const; + protected: Status UpdateTilingInfo(TaskContext &context); virtual std::string GetKeyForOpParamSize() const; @@ -117,12 +119,14 @@ class AiCoreOpTask { uint64_t log_id_ = 0; std::string log_name_; uint32_t offset_ = 0; + std::string op_type_; }; class AtomicAddrCleanOpTask : public AiCoreOpTask { public: Status Init(const OpDesc &op_desc, const domi::TaskDef &task_def) override; Status UpdateArgs(TaskContext &task_context) override; + const std::string& GetOpType() const override; protected: std::string GetKeyForOpParamSize() const override; diff --git a/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc b/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc index c83a76d1..820c9b56 100755 --- a/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc +++ b/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc @@ -207,7 +207,7 @@ Status AicpuNodeTaskBase::ExecuteAsync(TaskContext &context, std::functionSynchronize(GetStream()); } -Status TaskContext::SaveProfilingTaskDescInfo(uint32_t task_id, uint32_t stream_id, - const std::string &task_type, uint32_t block_dim) { +Status TaskContext::SaveProfilingTaskDescInfo(uint32_t task_id, uint32_t stream_id, const std::string &task_type, + uint32_t block_dim, const std::string &op_type) { if (ProfilingManager::Instance().ProfilingModelLoadOn()) { const NodeItem &node_item = GetNodeItem(); auto op_desc = node_item.GetOpDesc(); @@ -589,7 +589,7 @@ Status TaskContext::SaveProfilingTaskDescInfo(uint32_t task_id, uint32_t stream TaskDescInfo tmp_task_desc_info; tmp_task_desc_info.model_name = dynamic_model_name; tmp_task_desc_info.op_name = op_desc->GetName(); - tmp_task_desc_info.op_type = op_desc->GetType(); + tmp_task_desc_info.op_type = op_type; tmp_task_desc_info.block_dim = block_dim; tmp_task_desc_info.task_type = task_type; tmp_task_desc_info.task_id = task_id; diff --git a/ge/hybrid/node_executor/task_context.h b/ge/hybrid/node_executor/task_context.h index c96e194e..5304606b 100644 --- a/ge/hybrid/node_executor/task_context.h +++ b/ge/hybrid/node_executor/task_context.h @@ -118,8 +118,8 @@ class TaskContext { void *handle_ = nullptr; const std::vector& GetProfilingTaskDescInfo() const { return task_desc_info; } - Status SaveProfilingTaskDescInfo(uint32_t task_id, uint32_t stream_id, - const std::string &task_type, uint32_t block_dim); + Status SaveProfilingTaskDescInfo(uint32_t task_id, uint32_t stream_id, const std::string &task_type, + uint32_t block_dim, const std::string &op_type); void ClearProfilingTaskDescInfo() { task_desc_info.clear(); } private: diff --git a/tests/ut/ge/hybrid/executor/worker/execution_engine_unittest.cc b/tests/ut/ge/hybrid/executor/worker/execution_engine_unittest.cc index cc20d614..07701f4d 100644 --- a/tests/ut/ge/hybrid/executor/worker/execution_engine_unittest.cc +++ b/tests/ut/ge/hybrid/executor/worker/execution_engine_unittest.cc @@ -119,7 +119,7 @@ TEST_F(UtestExecutionEngine, ExecuteAsync_without_callback_and_kernel_task) { uint32_t stream_id = 1; std::string task_type = "rts"; uint32_t block_dim = 0; - node_state->GetTaskContext()->SaveProfilingTaskDescInfo(task_id, stream_id, task_type, block_dim); + node_state->GetTaskContext()->SaveProfilingTaskDescInfo(task_id, stream_id, task_type, block_dim, op_desc->GetType()); ASSERT_TRUE(node_state->GetTaskContext() != nullptr); diff --git a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc index 4f14f628..688d3a34 100644 --- a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc +++ b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc @@ -100,7 +100,7 @@ TEST_F(UtestGeHybrid, aicore_op_task_init_success) { 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); - ASSERT_EQ(aicore_task->InitWithTaskDef(*op_desc.get(), task_def), SUCCESS); + ASSERT_EQ(aicore_task->Init(*op_desc.get(), task_def), SUCCESS); rtStream_t stream = nullptr; rtStreamCreate(&stream, 0); ASSERT_EQ(aicore_task->LaunchKernel(stream), SUCCESS); @@ -676,6 +676,15 @@ TEST_F(UtestGeHybrid, test_key_for_kernel_bin) { EXPECT_EQ(atomic_task->GetKeyForKernelName(op_desc), "Sum_atomic_kernelname"); } +TEST_F(UtestGeHybrid, test_op_type) { + auto aicore_task = std::unique_ptr(new(std::nothrow)hybrid::AiCoreOpTask()); + aicore_task->op_type_ = "Add"; + EXPECT_EQ(aicore_task->GetOpType(), "Add"); + + auto atomic_task = std::unique_ptr(new(std::nothrow)hybrid::AtomicAddrCleanOpTask()); + EXPECT_EQ(atomic_task->GetOpType(), "DynamicAtomicAddrClean"); +} + TEST_F(UtestGeHybrid, TestParseDependentInputNodesForHccl) { NodeExecutorManager::GetInstance().engine_mapping_.emplace("ops_kernel_info_hccl", NodeExecutorManager::ExecutorType::HCCL); From 813f2fe4a2eb234153ce0ad5a5801c98bdb9be4f Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Tue, 29 Jun 2021 19:11:56 +0800 Subject: [PATCH 25/50] Fix ut. --- ge/single_op/task/op_task.cc | 10 ++++------ ge/single_op/task/op_task.h | 4 +++- ge/single_op/task/tbe_task_builder.cc | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ge/single_op/task/op_task.cc b/ge/single_op/task/op_task.cc index 632cd4d8..28ec7f64 100755 --- a/ge/single_op/task/op_task.cc +++ b/ge/single_op/task/op_task.cc @@ -346,7 +346,7 @@ Status TbeOpTask::AllocateWorkspaces(const vector &workspace_sizes) { } Status TbeOpTask::UpdateTilingArgs(rtStream_t stream) { - size_t args_size = op_desc_->GetInputsSize() + op_desc_->GetOutputsSize() + workspaces_.size(); + size_t args_size = input_num_ + output_num_ + workspaces_.size(); if (tiling_buffer_ != nullptr) { args_size++; } @@ -361,12 +361,12 @@ Status TbeOpTask::UpdateTilingArgs(rtStream_t stream) { return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; } - args_.reset(args.release()); + args_ = std::move(args); arg_size_ = temp_size; } uintptr_t *arg_base = reinterpret_cast(args_.get()); - size_t arg_index = op_desc_->GetInputsSize() + op_desc_->GetOutputsSize(); + size_t arg_index = input_num_ + output_num_; for (size_t i = 0; i < workspaces_.size(); ++i) { arg_base[arg_index++] = reinterpret_cast(workspaces_[i]); } @@ -382,7 +382,6 @@ Status TbeOpTask::UpdateTilingArgs(rtStream_t stream) { } Status TbeOpTask::SetArgIndex() { - arg_index_.clear(); const vector v_is_input_const = op_desc_->GetIsInputConst(); size_t input_index = 0; for (size_t i = 0; i < op_desc_->GetAllInputsSize(); ++i) { @@ -416,9 +415,8 @@ Status TbeOpTask::UpdateIoAddr(const vector &inputs, const vector(inputs[i].data); } - size_t input_size = op_desc_->GetInputsSize(); for (size_t i = 0; i < op_desc_->GetOutputsSize(); ++i) { - arg_base[input_size + i] = reinterpret_cast(outputs[i].data); + arg_base[input_num_ + i] = reinterpret_cast(outputs[i].data); } return SUCCESS; diff --git a/ge/single_op/task/op_task.h b/ge/single_op/task/op_task.h index d3e8383d..f93e031a 100644 --- a/ge/single_op/task/op_task.h +++ b/ge/single_op/task/op_task.h @@ -123,7 +123,9 @@ class TbeOpTask : public OpTask { void* handle_ = nullptr; std::string original_kernel_key_; std::string node_info_; - std::vector arg_index_; + std::vector arg_index_; // data index in args + size_t input_num_; // Include const input + size_t output_num_; }; class AiCpuBaseTask : public OpTask { diff --git a/ge/single_op/task/tbe_task_builder.cc b/ge/single_op/task/tbe_task_builder.cc index e5206ea6..db8ecfe2 100644 --- a/ge/single_op/task/tbe_task_builder.cc +++ b/ge/single_op/task/tbe_task_builder.cc @@ -388,6 +388,8 @@ Status TbeTaskBuilder::BuildTask(TbeOpTask &task, const SingleOpModelParam ¶ task.SetStubFunc(stub_name_, stub_func); } GE_CHK_STATUS_RET(task.SetArgIndex(), "[Set][ArgTable] failed."); + task.input_num_ = op_desc_->GetInputsSize(); + task.output_num_ = op_desc_->GetOutputsSize(); return SUCCESS; } From 59c97eef3eef0903c54052fe4b6428e5597db58c Mon Sep 17 00:00:00 2001 From: wq160 Date: Tue, 29 Jun 2021 10:58:45 +0800 Subject: [PATCH 26/50] set scalar tensor value range --- ge/graph/passes/infer_value_range_pass.cc | 3 ++ .../passes/replace_with_empty_const_pass.cc | 14 ++++-- .../passes/replace_with_empty_const_pass.h | 2 +- .../passes/infer_value_range_pass_unittest.cc | 48 +++++++++++++++++++ 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/ge/graph/passes/infer_value_range_pass.cc b/ge/graph/passes/infer_value_range_pass.cc index b9cb88bc..e714e90a 100644 --- a/ge/graph/passes/infer_value_range_pass.cc +++ b/ge/graph/passes/infer_value_range_pass.cc @@ -286,6 +286,9 @@ graphStatus InferValueRangePass::GenerateWorstValueRange(NodePtr &node) { } std::vector> output_i_value_range(output_i_shape_size, {1, -1}); + if (output_i_shape.IsScalar()) { + output_i_value_range.emplace_back(1, -1); + } output_desc->SetValueRange(output_i_value_range); GELOGD("Node %s output %zu shape is %s, the generated worst value range is %s.", node->GetName().c_str(), i, formats::ShapeToString(output_i_shape).c_str(), formats::RangeToString(output_i_value_range).c_str()); diff --git a/ge/graph/passes/replace_with_empty_const_pass.cc b/ge/graph/passes/replace_with_empty_const_pass.cc index 3176d1ee..6cb31627 100644 --- a/ge/graph/passes/replace_with_empty_const_pass.cc +++ b/ge/graph/passes/replace_with_empty_const_pass.cc @@ -71,7 +71,7 @@ Status ReplaceWithEmptyConstPass::Run(NodePtr &node) { GELOGI("Node %s Got empty output_desc_ptr, ignore current pass.", node->GetName().c_str()); return SUCCESS; } - if (!IsEmptyTenor(output_desc_ptr->GetShape())) { + if (!IsKnownEmptyTenor(output_desc_ptr->GetShape())) { is_all_output_empty = false; break; } @@ -107,12 +107,16 @@ Status ReplaceWithEmptyConstPass::GetOutputsOfCurrNode(const NodePtr &node_to_re return SUCCESS; } -bool ReplaceWithEmptyConstPass::IsEmptyTenor(const GeShape &shape) const { +bool ReplaceWithEmptyConstPass::IsKnownEmptyTenor(const GeShape &shape) const { + bool is_known_empty_tensor = false; for (auto dim : shape.GetDims()) { - if (dim == 0) { - return true; + if (dim < 0) { + // current dim is unknown dim, skip replace + return false; + } else if (dim == 0) { + is_known_empty_tensor = true; } } - return false; + return is_known_empty_tensor; } } // namespace ge diff --git a/ge/graph/passes/replace_with_empty_const_pass.h b/ge/graph/passes/replace_with_empty_const_pass.h index fde75358..90103432 100644 --- a/ge/graph/passes/replace_with_empty_const_pass.h +++ b/ge/graph/passes/replace_with_empty_const_pass.h @@ -26,7 +26,7 @@ class ReplaceWithEmptyConstPass : public FoldingPass { private: Status GetOutputsOfCurrNode(const NodePtr &node_to_replace, vector &outputs); - bool IsEmptyTenor(const GeShape &shape) const; + bool IsKnownEmptyTenor(const GeShape &shape) const; }; } // namespace ge #endif // GE_GRAPH_PASSES_REPLACE_WITH_EMPTY_CONST_PASS_H_ diff --git a/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc b/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc index fea1b27d..576d679c 100644 --- a/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc @@ -362,6 +362,54 @@ TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseCpuKernel_InputsHave EXPECT_EQ(unknown_target_value_range, output_value_range); } +TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseCpuKernel_InputsHaveUnKnownValueRange_ScalarOutput) { + // shape --- add --- sqrt + // constant / + auto graph = std::make_shared("test_graph"); + vector data_vec = {1}; + GeTensorDesc const_tensor_desc(ge::GeShape(), ge::FORMAT_NCHW, ge::DT_INT64); + GeTensorPtr const_tensor = + std::make_shared(const_tensor_desc, (uint8_t *)data_vec.data(), data_vec.size() * sizeof(int64_t)); + + auto const_op_desc = std::make_shared("Constant", "Constant"); + const_op_desc->AddOutputDesc(const_tensor_desc); + EXPECT_EQ(OpDescUtils::SetWeights(const_op_desc, const_tensor), GRAPH_SUCCESS); + auto const_node = graph->AddNode(const_op_desc); + + GeTensorDesc shape_tensor_desc(GeShape(), ge::FORMAT_NCHW, ge::DT_INT64); + std::vector> unknown_value_range = {make_pair(1, -1)}; + shape_tensor_desc.SetValueRange(unknown_value_range); + auto shape_op_desc = std::make_shared("Shape", "Shape"); + shape_op_desc->AddOutputDesc(shape_tensor_desc); + auto shape_node = graph->AddNode(shape_op_desc); + + GeTensorDesc add_tensor_desc(GeShape(), ge::FORMAT_NCHW, ge::DT_INT64); + auto add_op_desc = std::make_shared("Add", "Add"); + add_op_desc->AddInputDesc(shape_tensor_desc); + add_op_desc->AddInputDesc(const_tensor_desc); + add_op_desc->AddOutputDesc(add_tensor_desc); + auto add_node = graph->AddNode(add_op_desc); + + ge::GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), add_node->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(const_node->GetOutDataAnchor(0), add_node->GetInDataAnchor(1)); + + // test unknown value range + InferValueRangePass infer_pass; + EXPECT_EQ(infer_pass.Run(add_node), SUCCESS); + auto output_0_desc = add_node->GetOpDesc()->GetOutputDesc(0); + std::vector> out_value_range; + output_0_desc.GetValueRange(out_value_range); + EXPECT_EQ(out_value_range.size(), 1); + + std::vector unknown_target_value_range = {1, -1}; + std::vector output_value_range; + for (auto pair : out_value_range) { + output_value_range.push_back(pair.first); + output_value_range.push_back(pair.second); + } + EXPECT_EQ(unknown_target_value_range, output_value_range); +} + TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseCpuKernel_InputsAreKnownValueRange_Int64) { // shape --- add --- sqrt // constant / From 4f3f54d56407d045fa37bf02508cc101a46e1bef Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Tue, 29 Jun 2021 19:19:08 +0800 Subject: [PATCH 27/50] Fix ut. --- ge/single_op/task/op_task.h | 2 +- tests/ut/ge/single_op/single_op_task_unittest.cc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ge/single_op/task/op_task.h b/ge/single_op/task/op_task.h index f93e031a..97d8a342 100644 --- a/ge/single_op/task/op_task.h +++ b/ge/single_op/task/op_task.h @@ -124,7 +124,7 @@ class TbeOpTask : public OpTask { std::string original_kernel_key_; std::string node_info_; std::vector arg_index_; // data index in args - size_t input_num_; // Include const input + size_t input_num_; // include const input size_t output_num_; }; diff --git a/tests/ut/ge/single_op/single_op_task_unittest.cc b/tests/ut/ge/single_op/single_op_task_unittest.cc index 020efc23..b0c98205 100644 --- a/tests/ut/ge/single_op/single_op_task_unittest.cc +++ b/tests/ut/ge/single_op/single_op_task_unittest.cc @@ -134,6 +134,8 @@ TEST_F(UtestSingleOpTask, test_update_ioaddr) { task.arg_size_ = sizeof(void *) * 4; task.args_.reset(new (std::nothrow) uint8_t[task.arg_size_]); task.arg_index_ = {0}; + task.input_num_ = 2; + task.output_num_ = 1; vector args; vector inputs; From 9f6aff6759714c0093045b563f9b6f5bba8d46a6 Mon Sep 17 00:00:00 2001 From: wuweikang Date: Fri, 18 Jun 2021 09:32:57 +0800 Subject: [PATCH 28/50] check dump option --- ge/common/dump/dump_properties.cc | 243 ++++++++++++++++-- ge/common/dump/dump_properties.h | 18 +- ge/session/inner_session.cc | 2 +- tests/ut/ge/CMakeLists.txt | 1 + .../ut/ge/common/dump_properties_unittest.cc | 126 +++++++++ 5 files changed, 364 insertions(+), 26 deletions(-) create mode 100644 tests/ut/ge/common/dump_properties_unittest.cc diff --git a/ge/common/dump/dump_properties.cc b/ge/common/dump/dump_properties.cc index ef755540..010347c0 100644 --- a/ge/common/dump/dump_properties.cc +++ b/ge/common/dump/dump_properties.cc @@ -18,6 +18,7 @@ #include #include +#include #include "common/ge/ge_util.h" #include "framework/common/util.h" @@ -37,6 +38,159 @@ const uint32_t kAtomicOverflow = (0x1 << 1); const uint32_t kAllOverflow = (kAicoreOverflow | kAtomicOverflow); } // namespace namespace ge { +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::Split(const std::string &s, + std::vector &result, + const char *delchar) { + if (s.empty()) { + return; + } + result.clear(); + + char *buffer = new (std::nothrow)char[s.size() + 1]; + if (buffer == nullptr) { + GELOGE(FAILED, "[Split][string] failed while malloc memory, string value is:%s", s.c_str()); + REPORT_CALL_ERROR("E19999", "Memory malloc may fail when split string, get fatal exception, " + "string value is:%s", s.c_str()); + return; + } + buffer[s.size()] = '\0'; + errno_t e = strcpy_s(buffer, s.size() + 1, s.c_str()); + if (e != EOK) { + delete[] buffer; + return; + } + char *context = nullptr; + char *p = strtok_s(buffer, delchar, &context); + while (p != nullptr) { + result.emplace_back(p); + p = strtok_s(nullptr, delchar, &context); + } + delete[] buffer; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckDumpStep(const std::string &dump_step) { + std::string modified_dum_step = dump_step + "|"; + std::smatch result; + std::vector match_vecs; + std::regex pattern(R"((\d{1,}-\d{1,}\||\d{1,}\|)+)"); + if (regex_match(modified_dum_step, result, pattern)) { + Split(result.str(), match_vecs, "|"); + if (match_vecs.empty()) { + REPORT_CALL_ERROR("E19999", "Split may get fatal exception, dump_step:%s.", dump_step.c_str()); + GELOGE(FAILED, "[Check][Param] failed. Split may get fatal exception, ge.exec.dumpStep:%s.", dump_step.c_str()); + return FAILED; + } + // 100 is the max sets of dump steps. + if (match_vecs.size() > 100) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpStep", + dump_step.c_str(), + " is not supported, only support dump <= 100 sets of data"})); + GELOGE(PARAM_INVALID, "[Check][Param] get dump_step value:%s, " + "dump_step only support dump <= 100 sets of data.", dump_step.c_str()); + return PARAM_INVALID; + } + for (const auto &match_vec : match_vecs) { + std::vector vec_after_split; + Split(match_vec, vec_after_split, "-"); + if (match_vecs.empty()) { + REPORT_CALL_ERROR("E19999", "Split may get fatal exception."); + GELOGE(FAILED, "[Check][Param] failed, split may get fatal exception."); + return FAILED; + } + if (vec_after_split.size() > 1) { + if (std::atoi(vec_after_split[0].c_str()) >= std::atoi(vec_after_split[1].c_str())) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpStep", + dump_step.c_str(), + " is not supported." + "in range steps, the first step is >= second step, correct example:'0|5|10-20"})); + GELOGE(PARAM_INVALID, "[Check][Param] get dump_step value:%s, " + "in range steps, the first step is >= second step, correct example:'0|5|10-20'", dump_step.c_str()); + return PARAM_INVALID; + } + } + } + } else { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpStep", + dump_step.c_str(), + " is not supported, correct example:'0|5|10|50-100."})); + GELOGE(PARAM_INVALID, "[Check][Param] get dump_step value:%s, " + "dump_step string style is error, correct example:'0|5|10|50-100.'", dump_step.c_str()); + return PARAM_INVALID; + } + return SUCCESS; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckDumpMode(const std::string &dump_mode) { + const std::set dump_mode_list = {"input", "output", "all"}; + std::set::iterator iter; + + if ((iter = dump_mode_list.find(dump_mode)) == dump_mode_list.end()) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpMode", + dump_mode.c_str(), + " is not supported, should be one of the following:[input, output, all]"})); + GELOGE(PARAM_INVALID, "[Check][Param] the dump_debug_mode:%s, is is not supported," + "should be one of the following:[input, output, all].", dump_mode.c_str()); + return PARAM_INVALID; + } + return SUCCESS; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckDumpPath(const std::string &input) { + if (mmIsDir(input.c_str()) != EN_OK) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpPath", + input.c_str(), + " is not a directory."})); + GELOGE(PARAM_INVALID, "[Check][Param] the path:%s, is not directory.", input.c_str()); + return PARAM_INVALID; + } + char trusted_path[MMPA_MAX_PATH] = { "\0" }; + if (mmRealPath(input.c_str(), trusted_path, MMPA_MAX_PATH) != EN_OK) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpPath", + input.c_str(), + " dumpPath invalid."})); + GELOGE(PARAM_INVALID, "[Check][Param] the dumpPath:%s, is invalid.", input.c_str()); + return PARAM_INVALID; + } + if (mmAccess2(trusted_path, R_OK | W_OK) != EN_OK) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpPath", + input.c_str(), + " does't have read, write permissions."})); + GELOGE(PARAM_INVALID, "[Check][Param] the path:%s, does't have read, write permissions.", input.c_str()); + return PARAM_INVALID; + } + return SUCCESS; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckEnableDump(const std::string &input) { + std::set enable_dump_option_list = {"1", "0"}; + auto it = enable_dump_option_list.find(input); + if (it == enable_dump_option_list.end()) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.enableDump", + input.c_str(), + " only support 1 or 0."})); + GELOGE(PARAM_INVALID, "[Check][Param] Not support ge.exec.enableDump or ge.exec.enableDumpDebug format:%s, " + "only support 1 or 0.", input.c_str()); + return PARAM_INVALID; + } + return SUCCESS; +} + FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties::DumpProperties(const DumpProperties &other) { CopyFrom(other); } @@ -47,7 +201,26 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties &DumpProperties: return *this; } -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::InitByOptions() { +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::SetDumpOptions() { + if (enable_dump_ == kEnableFlag) { + std::string dump_step; + if (GetContext().GetOption(OPTION_EXEC_DUMP_STEP, dump_step) == GRAPH_SUCCESS) { + GE_CHK_STATUS_RET(CheckDumpStep(dump_step), "[Check][dump_step] failed."); + GELOGI("Get dump step %s successfully", dump_step.c_str()); + SetDumpStep(dump_step); + } + string dump_mode = "output"; + if (GetContext().GetOption(OPTION_EXEC_DUMP_MODE, dump_mode) == GRAPH_SUCCESS) { + GELOGI("Get dump mode %s successfully", dump_mode.c_str()); + GE_CHK_STATUS_RET(CheckDumpMode(dump_mode), "[Check][dump_mode] failed."); + SetDumpMode(dump_mode); + } + AddPropertyValue(DUMP_ALL_MODEL, {}); + } + return SUCCESS; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::InitByOptions() { enable_dump_.clear(); enable_dump_debug_.clear(); dump_path_.clear(); @@ -57,17 +230,32 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::InitByOpti is_infer_op_debug_ = false; op_debug_mode_ = 0; - std::string enable_dump; + std::string enable_dump = std::to_string(false); (void)GetContext().GetOption(OPTION_EXEC_ENABLE_DUMP, enable_dump); enable_dump_ = enable_dump; + if (!enable_dump_.empty()) { + GE_CHK_STATUS_RET(CheckEnableDump(enable_dump_), "[Check][enable_dump] failed."); + } - std::string enable_dump_debug; + std::string enable_dump_debug = std::to_string(false); (void)GetContext().GetOption(OPTION_EXEC_ENABLE_DUMP_DEBUG, enable_dump_debug); enable_dump_debug_ = enable_dump_debug; - + if (!enable_dump_debug_.empty()) { + GE_CHK_STATUS_RET(CheckEnableDump(enable_dump_debug_), "[Check][enable_dump_debug] failed."); + } + if ((enable_dump_ == kEnableFlag) && (enable_dump_debug_ == kEnableFlag)) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.enableDump and ge.exec.enableDumpDebug", + enable_dump_ + ", " + enable_dump_debug, + "ge.exec.enableDump and ge.exec.enableDumpDebug cannot be set to 1 at the same time."})); + GELOGE(FAILED, "ge.exec.enableDump and ge.exec.enableDumpDebug cannot be both set to 1 at the same time."); + return FAILED; + } if ((enable_dump_ == kEnableFlag) || (enable_dump_debug_ == kEnableFlag)) { std::string dump_path; if (GetContext().GetOption(OPTION_EXEC_DUMP_PATH, dump_path) == GRAPH_SUCCESS) { + GE_CHK_STATUS_RET(CheckDumpPath(dump_path), "Check dump path failed."); if (!dump_path.empty() && dump_path[dump_path.size() - 1] != '/') { dump_path = dump_path + "/"; } @@ -75,25 +263,21 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::InitByOpti GELOGI("Get dump path %s successfully", dump_path.c_str()); SetDumpPath(dump_path); } else { - GELOGW("Dump path is not set"); + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpPath", + dump_path, + "ge.exec.dumpPath is not set."})); + GELOGE(FAILED, "[Check][dump_path] failed. Dump path is not set."); + return FAILED; } } - if (enable_dump_ == kEnableFlag) { - std::string dump_step; - if (GetContext().GetOption(OPTION_EXEC_DUMP_STEP, dump_step) == GRAPH_SUCCESS) { - GELOGI("Get dump step %s successfully", dump_step.c_str()); - SetDumpStep(dump_step); - } - string dump_mode; - if (GetContext().GetOption(OPTION_EXEC_DUMP_MODE, dump_mode) == GRAPH_SUCCESS) { - GELOGI("Get dump mode %s successfully", dump_mode.c_str()); - SetDumpMode(dump_mode); - } - AddPropertyValue(DUMP_ALL_MODEL, {}); - } + GE_CHK_STATUS_RET(SetDumpOptions(), "SetDumpOptions failed."); + + GE_CHK_STATUS_RET(SetDumpDebugOptions(), "SetDumpDebugOptions failed."); - SetDumpDebugOptions(); + return SUCCESS; } // The following is the new dump scenario of the fusion operator @@ -253,14 +437,20 @@ void DumpProperties::CopyFrom(const DumpProperties &other) { } } -void DumpProperties::SetDumpDebugOptions() { +Status DumpProperties::SetDumpDebugOptions() { if (enable_dump_debug_ == kEnableFlag) { std::string dump_debug_mode; if (GetContext().GetOption(OPTION_EXEC_DUMP_DEBUG_MODE, dump_debug_mode) == GRAPH_SUCCESS) { GELOGD("Get dump debug mode %s successfully", dump_debug_mode.c_str()); } else { - GELOGW("Dump debug mode is not set."); - return; + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpDebugMode", + dump_debug_mode, + "ge.exec.dumpDebugMode is not set."})); + GELOGE(PARAM_INVALID, "[Check][dump_debug_mode] failed. Dump debug mode is not set."); + + return PARAM_INVALID; } if (dump_debug_mode == OP_DEBUG_AICORE) { @@ -276,10 +466,17 @@ void DumpProperties::SetDumpDebugOptions() { is_train_op_debug_ = true; op_debug_mode_ = kAllOverflow; } else { - GELOGW("ge.exec.dumpDebugMode is invalid."); + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpDebugMode", + dump_debug_mode, + "ge.exec.dumpDebugMode is invalid."})); + GELOGE(PARAM_INVALID, "[Set][DumpDebugOptions] failed, ge.exec.dumpDebugMode is invalid."); + return PARAM_INVALID; } } else { GELOGI("ge.exec.enableDumpDebug is false or is not set."); } + return SUCCESS; } } // namespace ge diff --git a/ge/common/dump/dump_properties.h b/ge/common/dump/dump_properties.h index 98487491..cbfc362d 100644 --- a/ge/common/dump/dump_properties.h +++ b/ge/common/dump/dump_properties.h @@ -23,6 +23,7 @@ #include namespace ge { +using Status = uint32_t; class DumpProperties { public: DumpProperties() = default; @@ -33,7 +34,7 @@ class DumpProperties { DumpProperties &operator=(const DumpProperties &dump); - void InitByOptions(); + Status InitByOptions(); void AddPropertyValue(const std::string &model, const std::set &layers); @@ -95,7 +96,20 @@ class DumpProperties { private: void CopyFrom(const DumpProperties &other); - void SetDumpDebugOptions(); + Status SetDumpDebugOptions(); + + Status SetDumpOptions(); + + void Split(const std::string &s, std::vector &result, const char *delchar); + + Status CheckDumpStep(const std::string &dump_step); + + Status CheckDumpMode(const std::string &dump_mode); + + Status CheckDumpPath(const std::string &input); + + Status CheckEnableDump(const std::string &input); + std::string enable_dump_; std::string enable_dump_debug_; diff --git a/ge/session/inner_session.cc b/ge/session/inner_session.cc index aabbe19c..b3df08ce 100755 --- a/ge/session/inner_session.cc +++ b/ge/session/inner_session.cc @@ -109,7 +109,7 @@ Status InnerSession::Initialize() { GE_CHK_RT_RET(rtSetDevice(GetContext().DeviceId())); DumpProperties dump_properties; - dump_properties.InitByOptions(); + GE_CHK_STATUS_RET(dump_properties.InitByOptions(), "Init dump properties failed."); GE_CHK_STATUS_RET(AddDumpProperties(dump_properties), "[Add][DumpProperties] failed."); ret = graph_manager_.Initialize(options_); diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index cf573343..d7568ccc 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -774,6 +774,7 @@ set(MULTI_PARTS_TEST_FILES "common/util_unittest.cc" "common/dump_manager_unittest.cc" "common/dump_op_unittest.cc" + "common/dump_properties_unittest.cc" "common/dump_exception_unittest.cc" "common/opdebug_register_unittest.cc" "common/format_transfer_unittest.cc" diff --git a/tests/ut/ge/common/dump_properties_unittest.cc b/tests/ut/ge/common/dump_properties_unittest.cc new file mode 100644 index 00000000..57809013 --- /dev/null +++ b/tests/ut/ge/common/dump_properties_unittest.cc @@ -0,0 +1,126 @@ +/** + * 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 + +#define protected public +#define private public + +#include "common/dump/dump_properties.h" +#include "ge_local_context.h" +#include "ge/ge_api_types.h" +#include "common/debug/log.h" +#include "common/ge_inner_error_codes.h" + +namespace ge { +class UTEST_dump_properties : public testing::Test { + protected: + void SetUp() {} + void TearDown() {} +}; + +TEST_F(UTEST_dump_properties, check_dump_step) { + DumpProperties dp; + std::string dump_step{"0|3-5|10"}; + std::string unsupport_input1{"0|5-3|10"}; + std::string unsupport_input2{"one"}; + std::string unsupport_input3; + for (int i = 0; i < 200; ++i) { + unsupport_input3 += std::to_string(i) + "|"; + } + unsupport_input3.pop_back(); + Status st = dp.CheckDumpStep(dump_step); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckDumpStep(unsupport_input1); + EXPECT_NE(st, SUCCESS); + st = dp.CheckDumpStep(unsupport_input2); + EXPECT_NE(st, SUCCESS); + st = dp.CheckDumpStep(unsupport_input3); + EXPECT_NE(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, check_dump_mode) { + DumpProperties dp; + std::string dump_mode_1{"input"}; + std::string dump_mode_2{"output"}; + std::string dump_mode_3{"all"}; + std::string unsupport_input1{"mode1"}; + Status st = dp.CheckDumpMode(dump_mode_1); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckDumpMode(dump_mode_2); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckDumpMode(dump_mode_3); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckDumpMode(unsupport_input1); + EXPECT_NE(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, check_dump_path) { + DumpProperties dp; + std::string dump_path{"/tmp/"}; + std::string unsupport_input1{" \\unsupported"}; + Status st = dp.CheckDumpPath(dump_path); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckDumpPath(unsupport_input1); + EXPECT_NE(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, check_enable_dump) { + DumpProperties dp; + std::string enable_dump_t{"1"}; + std::string enable_dump_f{"0"}; + std::string unsupport_input1{"true"}; + std::string unsupport_input2{"false"}; + Status st = dp.CheckEnableDump(enable_dump_t); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckEnableDump(enable_dump_f); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckEnableDump(unsupport_input1); + EXPECT_NE(st, SUCCESS); + st = dp.CheckEnableDump(unsupport_input2); + EXPECT_NE(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, init_by_options_success_1) { + DumpProperties dp; + std::map options {{OPTION_EXEC_ENABLE_DUMP, "1"}, + {OPTION_EXEC_DUMP_PATH, "/tmp/"}, + {OPTION_EXEC_DUMP_STEP, "0|1-3|10"}, + {OPTION_EXEC_DUMP_MODE, "all"}}; + GetThreadLocalContext().SetGlobalOption(options); + Status st = dp.InitByOptions(); + EXPECT_EQ(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, init_by_options_success_2) { + DumpProperties dp; + std::map options {{OPTION_EXEC_ENABLE_DUMP_DEBUG, "1"}, + {OPTION_EXEC_DUMP_PATH, "/tmp/"}, + {OPTION_EXEC_DUMP_DEBUG_MODE, "aicore_overflow"}}; + GetThreadLocalContext().SetGlobalOption(options); + Status st = dp.InitByOptions(); + EXPECT_EQ(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, init_by_options_failed) { + DumpProperties dp; + std::map options {{OPTION_EXEC_ENABLE_DUMP_DEBUG, "1"}, + {OPTION_EXEC_DUMP_PATH, "/tmp/"}}; + GetThreadLocalContext().SetGlobalOption(options); + Status st = dp.InitByOptions(); + EXPECT_NE(st, SUCCESS); +} +} // namespace ge \ No newline at end of file From e1c506026cc082fed10f63630bfb3c2275ce245b Mon Sep 17 00:00:00 2001 From: wangxiaotian22 Date: Tue, 29 Jun 2021 21:08:22 +0800 Subject: [PATCH 29/50] fix sc --- ge/graph/preprocess/multi_batch_copy_graph.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ge/graph/preprocess/multi_batch_copy_graph.cc b/ge/graph/preprocess/multi_batch_copy_graph.cc index 1634c8ce..fd3a4e91 100644 --- a/ge/graph/preprocess/multi_batch_copy_graph.cc +++ b/ge/graph/preprocess/multi_batch_copy_graph.cc @@ -1206,7 +1206,7 @@ Status MultiBatchGraphCopyer::CheckCopyResult(const std::vector &start_ auto dims = NodeUtils::GetOutputDesc(*node, kDataOutIndex).GetShape().GetDims(); if (!IsAllDimsPositive(dims)) { REPORT_CALL_ERROR("E19999", "Failed to copy multi batch graph, the node %s still has unknown shape %s", - node->GetName().c_str(), formats::ShapeToString(dims).c_str()); + node->GetName().c_str(), formats::ShapeToString(dims).c_str()); GELOGE(INTERNAL_ERROR, "[Check][Param] Failed to copy multi batch graph, the node %s still has unknown shape %s", node->GetName().c_str(), formats::ShapeToString(dims).c_str()); return INTERNAL_ERROR; From faaef130b4192da826a7965006b8952969bf8218 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Wed, 30 Jun 2021 10:20:59 +0800 Subject: [PATCH 30/50] Add ut. --- ge/single_op/single_op.h | 1 - 1 file changed, 1 deletion(-) diff --git a/ge/single_op/single_op.h b/ge/single_op/single_op.h index 7e05dd5f..94d7227b 100755 --- a/ge/single_op/single_op.h +++ b/ge/single_op/single_op.h @@ -92,7 +92,6 @@ class DynamicSingleOp { rtStream_t stream_ = nullptr; size_t num_inputs_ = 0; size_t num_outputs_ = 0; - ComputeGraphPtr compute_graph_; }; } // namespace ge #endif // GE_SINGLE_OP_SINGLE_OP_H_ From e7296ed73c1b133df356245791dc533e2e4b8e6f Mon Sep 17 00:00:00 2001 From: wangxiaotian22 Date: Wed, 30 Jun 2021 15:19:38 +0800 Subject: [PATCH 31/50] fix sc + --- ge/ge_runtime/task/label_goto_task.cc | 2 +- ge/single_op/task/op_task.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ge/ge_runtime/task/label_goto_task.cc b/ge/ge_runtime/task/label_goto_task.cc index 4302bff3..7cb6d556 100644 --- a/ge/ge_runtime/task/label_goto_task.cc +++ b/ge/ge_runtime/task/label_goto_task.cc @@ -72,7 +72,7 @@ bool LabelGotoTask::Distribute() { return false; } - rt_ret = rtLabelListCpy((void**)label_list.data(), label_list.size(), label_info_, label_info_size); + rt_ret = rtLabelListCpy(reinterpret_cast(label_list.data()), label_list.size(), label_info_, label_info_size); if (rt_ret != RT_ERROR_NONE) { GELOGE(RT_FAILED, "Call rt api failed, ret: %#x", rt_ret); return false; diff --git a/ge/single_op/task/op_task.h b/ge/single_op/task/op_task.h index 19320bc0..75b0707b 100644 --- a/ge/single_op/task/op_task.h +++ b/ge/single_op/task/op_task.h @@ -33,6 +33,10 @@ #include "register/op_tiling.h" namespace ge { +namespace { +const int kAddressNum = 2; +} // namespace + class StreamResource; struct SingleOpModelParam; class OpTask { @@ -256,7 +260,7 @@ class MemcpyAsyncTask : public OpTask { friend class SingleOpModel; friend class RtsKernelTaskBuilder; - uintptr_t addresses_[2]; + uintptr_t addresses_[kAddressNum]; size_t dst_max_; size_t count_; rtMemcpyKind_t kind_; From 2c7342bb3ae956e6f4884cc0e99068d215c178b0 Mon Sep 17 00:00:00 2001 From: wq160 Date: Tue, 29 Jun 2021 21:10:52 +0800 Subject: [PATCH 32/50] add scalar tensor value range process --- ge/graph/passes/infer_value_range_pass.cc | 30 ++++++++++--- .../passes/infer_value_range_pass_unittest.cc | 45 +++++++++++++++++++ 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/ge/graph/passes/infer_value_range_pass.cc b/ge/graph/passes/infer_value_range_pass.cc index e714e90a..03a18fdb 100644 --- a/ge/graph/passes/infer_value_range_pass.cc +++ b/ge/graph/passes/infer_value_range_pass.cc @@ -301,12 +301,26 @@ graphStatus InferValueRangePass::ConstructData(const GeTensorDesc &tensor_desc, GeTensorPtr &output_ptr) { std::vector> value_range; (void)tensor_desc.GetValueRange(value_range); - if (static_cast(value_range.size()) != tensor_desc.GetShape().GetShapeSize()) { - GELOGW("Value range of input %s is invalid.", tensor_desc.GetName().c_str()); + size_t value_range_data_num = value_range.size(); + auto tensor_shape = tensor_desc.GetShape(); + bool value_range_and_tensor_shape_matched = true; + if (tensor_shape.IsScalar()){ + // scalar tensor has only one value_range pair + if (value_range_data_num != 1) { + value_range_and_tensor_shape_matched = false; + } + } else { + // normal tensor, value_range size is equal to tensor shape size. + if (static_cast(value_range_data_num) != tensor_shape.GetShapeSize()) { + value_range_and_tensor_shape_matched = false; + } + } + if (!value_range_and_tensor_shape_matched) { + GELOGW("Input %s value range and tensor shape do not match. Value range size is %zu, tensor shape is %s.", + tensor_desc.GetName().c_str(), value_range_data_num, formats::ShapeToString(tensor_shape).c_str()); return GRAPH_PARAM_INVALID; } - size_t value_range_data_num = value_range.size(); unique_ptr buf(new (std::nothrow) T[value_range_data_num]()); if (buf == nullptr) { REPORT_INNER_ERROR("E19999", "New buf failed"); @@ -494,10 +508,16 @@ void InferValueRangePass::ConstructValueRange(const GeTensorPtr &left_tensor, co GELOGI("Output tensor of cpu kernel does not have data, no way to set value range."); return; } - for (auto j = 0; j < left_tensor->GetTensorDesc().GetShape().GetShapeSize(); ++j) { + auto left_tensor_shape = left_tensor->GetTensorDesc().GetShape(); + for (auto j = 0; j < left_tensor_shape.GetShapeSize(); ++j) { auto left = static_cast(*(x + j)); auto right = static_cast(*(y + j)); - value_range.emplace_back(std::make_pair(left, right)); + value_range.emplace_back(left, right); + } + + if (left_tensor_shape.IsScalar()) { + GELOGD("When inferring value range, output tensors of cpu kernel are scalar tensors."); + value_range.emplace_back(static_cast(*x), static_cast(*y)); } } } // namespace ge diff --git a/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc b/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc index 576d679c..c39755b3 100644 --- a/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc +++ b/tests/ut/ge/graph/passes/infer_value_range_pass_unittest.cc @@ -293,6 +293,9 @@ class AddKernel : public Kernel { } else if (input[0]->GetTensorDesc().GetDataType() == DT_INT32 || input[0]->GetTensorDesc().GetDataType() == DT_UINT32) { vector data_vec; auto data_num = input[0]->GetTensorDesc().GetShape().GetShapeSize(); + if (input[0]->GetTensorDesc().GetShape().IsScalar()) { + data_num = 1; + } auto x1_data = reinterpret_cast(input[0]->GetData().data()); auto x2_data = reinterpret_cast(input[1]->GetData().data()); for (size_t i = 0; i < data_num; i++) { @@ -410,6 +413,48 @@ TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseCpuKernel_InputsHave EXPECT_EQ(unknown_target_value_range, output_value_range); } +TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseCpuKernel_InputsAreKnownValueRange_ScalarOutput) { + // shape --- add --- sqrt + // constant / + auto graph = std::make_shared("test_graph"); + vector data_vec = {2}; + GeTensorDesc const_td(ge::GeShape(), ge::FORMAT_NCHW, ge::DT_INT32); + GeTensorPtr const_tensor = std::make_shared(const_td, (uint8_t *)data_vec.data(), sizeof(int32_t)); + auto const_op_desc = std::make_shared("Constant", "Constant"); + const_op_desc->AddOutputDesc(const_td); + EXPECT_EQ(OpDescUtils::SetWeights(const_op_desc, const_tensor), GRAPH_SUCCESS); + auto const_node = graph->AddNode(const_op_desc); + + GeTensorDesc shape_td(GeShape(), ge::FORMAT_NCHW, ge::DT_INT32); + std::vector> known_value_range = {make_pair(1, 100)}; + shape_td.SetValueRange(known_value_range); + auto shape_op_desc = std::make_shared("Shape", "Shape"); + shape_op_desc->AddOutputDesc(shape_td); + auto shape_node = graph->AddNode(shape_op_desc); + + GeTensorDesc add_td(GeShape(), ge::FORMAT_NCHW, ge::DT_INT32); + auto add_op_desc = std::make_shared("Add", "Add"); + add_op_desc->AddInputDesc(shape_td); + add_op_desc->AddInputDesc(const_td); + add_op_desc->AddOutputDesc(add_td); + auto add_node = graph->AddNode(add_op_desc); + + ge::GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), add_node->GetInDataAnchor(0)); + ge::GraphUtils::AddEdge(const_node->GetOutDataAnchor(0), add_node->GetInDataAnchor(1)); + + InferValueRangePass infer_pass; + EXPECT_EQ(infer_pass.Run(add_node), SUCCESS); + + auto output_0_desc = add_node->GetOpDesc()->GetOutputDesc(0); + std::vector> out_value_range; + output_0_desc.GetValueRange(out_value_range); + EXPECT_EQ(out_value_range.size(), 1); + + std::vector target_value_range = {3, 102}; + std::vector output_value_range = {out_value_range[0].first, out_value_range[0].second}; + EXPECT_EQ(output_value_range, target_value_range); +} + TEST_F(UtestGraphInferValueRangePass, CallRun_NoSubgraph_UseCpuKernel_InputsAreKnownValueRange_Int64) { // shape --- add --- sqrt // constant / From f9e7359ad37746bacdb246e255cc32c7250d767a Mon Sep 17 00:00:00 2001 From: chenyemeng Date: Wed, 30 Jun 2021 16:10:57 +0800 Subject: [PATCH 33/50] header file update --- .../inc/external/runtime/rt_error_codes.h | 7 + third_party/fwkacllib/inc/runtime/base.h | 8 +- third_party/fwkacllib/inc/runtime/config.h | 43 +++++ third_party/fwkacllib/inc/runtime/dev.h | 5 + third_party/fwkacllib/inc/runtime/event.h | 37 +++- third_party/fwkacllib/inc/runtime/kernel.h | 83 +++++++-- third_party/fwkacllib/inc/runtime/mem.h | 11 ++ third_party/fwkacllib/inc/runtime/rt_model.h | 13 +- .../fwkacllib/inc/toolchain/prof_callback.h | 31 +++- third_party/fwkacllib/inc/toolchain/slog.h | 62 +++---- .../inc/toolchain/tuning_tool/tune_api.h | 160 ++++++++++-------- 11 files changed, 332 insertions(+), 128 deletions(-) diff --git a/third_party/fwkacllib/inc/external/runtime/rt_error_codes.h b/third_party/fwkacllib/inc/external/runtime/rt_error_codes.h index 67146dbe..9f216a56 100755 --- a/third_party/fwkacllib/inc/external/runtime/rt_error_codes.h +++ b/third_party/fwkacllib/inc/external/runtime/rt_error_codes.h @@ -38,6 +38,7 @@ static const int32_t ACL_ERROR_RT_STREAM_NO_CB_REG = 107015; // callba static const int32_t ACL_ERROR_RT_INVALID_MEMORY_TYPE = 107016; // invalid memory type static const int32_t ACL_ERROR_RT_INVALID_HANDLE = 107017; // invalid handle static const int32_t ACL_ERROR_RT_INVALID_MALLOC_TYPE = 107018; // invalid malloc type +static const int32_t ACL_ERROR_RT_WAIT_TIMEOUT = 107019; // wait timeout static const int32_t ACL_ERROR_RT_FEATURE_NOT_SUPPORT = 207000; // feature not support static const int32_t ACL_ERROR_RT_MEMORY_ALLOCATION = 207001; // memory allocation error @@ -50,6 +51,7 @@ static const int32_t ACL_ERROR_RT_NO_EVENT_RESOURCE = 207007; // no eve static const int32_t ACL_ERROR_RT_NO_STREAM_RESOURCE = 207008; // no stream resource static const int32_t ACL_ERROR_RT_NO_NOTIFY_RESOURCE = 207009; // no notify resource static const int32_t ACL_ERROR_RT_NO_MODEL_RESOURCE = 207010; // no model resource +static const int32_t ACL_ERROR_RT_NO_CDQ_RESOURCE = 207011; // no cdq resource static const int32_t ACL_ERROR_RT_INTERNAL_ERROR = 507000; // runtime internal error static const int32_t ACL_ERROR_RT_TS_ERROR = 507001; // ts internel error @@ -85,9 +87,14 @@ static const int32_t ACL_ERROR_RT_DEBUG_UNREGISTER_FAIL = 507030; // debug static const int32_t ACL_ERROR_RT_LABEL_CONTEXT = 507031; // label not in current context static const int32_t ACL_ERROR_RT_PROGRAM_USE_OUT = 507032; // program register num use out static const int32_t ACL_ERROR_RT_DEV_SETUP_ERROR = 507033; // device setup error +static const int32_t ACL_ERROR_RT_VECTOR_CORE_TIMEOUT = 507034; // vector core timeout +static const int32_t ACL_ERROR_RT_VECTOR_CORE_EXCEPTION = 507035; // vector core exception +static const int32_t ACL_ERROR_RT_VECTOR_CORE_TRAP_EXCEPTION = 507036; // vector core trap exception +static const int32_t ACL_ERROR_RT_CDQ_BATCH_ABNORMAL = 507037; // cdq alloc batch abnormal static const int32_t ACL_ERROR_RT_DRV_INTERNAL_ERROR = 507899; // drv internal error static const int32_t ACL_ERROR_RT_AICPU_INTERNAL_ERROR = 507900; // aicpu internal error +static const int32_t ACL_ERROR_RT_SOCKET_CLOSE = 507901; // hdc disconnect #ifdef __cplusplus } diff --git a/third_party/fwkacllib/inc/runtime/base.h b/third_party/fwkacllib/inc/runtime/base.h index 40bc91f7..7fc1cdea 100644 --- a/third_party/fwkacllib/inc/runtime/base.h +++ b/third_party/fwkacllib/inc/runtime/base.h @@ -156,7 +156,7 @@ RTS_API rtError_t rtProfilerTrace(uint64_t id, bool notify, uint32_t flags, rtSt /** * @ingroup profiling_base - * @brief ts send keypoint for step info. + * @brief ts send keypoint profiler log. */ RTS_API rtError_t rtProfilerTraceEx(uint64_t id, uint64_t modelId, uint16_t tagId, rtStream_t stream); @@ -206,7 +206,7 @@ RTS_API rtError_t rtRegDeviceStateCallback(const char *regName, rtDeviceStateCal /** * @ingroup dvrt_base - * @brief register callback for fail task + * @brief register callback for fail task * @param [in] uniName unique register name, can't be null * @param [in] callback fail task callback function * @param [out] NA @@ -345,11 +345,11 @@ RTS_API rtError_t rtLabelCreateEx(rtLabel_t *label, rtStream_t stream); * @return RT_ERROR_NONE for ok * @return RT_ERROR_INVALID_VALUE for error input */ -rtError_t rtLabelCreateExV2(rtLabel_t *label, rtModel_t model, rtStream_t stream); +RTS_API rtError_t rtLabelCreateExV2(rtLabel_t *label, rtModel_t model, rtStream_t stream); /** * @ingroup dvrt_base - * @brief get current thread last stream id and task id + * @brief get current thread last stream id and task id * @param [out] stream id and task id * @param [in] null * @return RT_ERROR_NONE for ok diff --git a/third_party/fwkacllib/inc/runtime/config.h b/third_party/fwkacllib/inc/runtime/config.h index ee104693..c1327c45 100644 --- a/third_party/fwkacllib/inc/runtime/config.h +++ b/third_party/fwkacllib/inc/runtime/config.h @@ -46,6 +46,12 @@ typedef enum tagRtChipType { CHIP_END, } rtChipType_t; +typedef enum tagRtAicpuScheType { + SCHEDULE_SOFTWARE = 0, /* Software Schedule */ + SCHEDULE_SOFTWARE_OPT, + SCHEDULE_HARDWARE, /* HWTS Schedule */ +} rtAicpuScheType; + typedef enum tagRtVersion { VER_BEGIN = 0, VER_NA = VER_BEGIN, @@ -65,6 +71,7 @@ typedef enum tagRtPlatformType { PLATFORM_LHISI_CS, PLATFORM_DC, PLATFORM_CLOUD_V2, + PLATFORM_LHISI_SD3403, PLATFORM_END, } rtPlatformType_t; @@ -126,6 +133,11 @@ typedef struct tagRtPlatformConfig { uint32_t platformConfig; } rtPlatformConfig_t; +typedef enum tagRTTaskTimeoutType { + RT_TIMEOUT_TYPE_OP_WAIT = 0, + RT_TIMEOUT_TYPE_OP_EXECUTE, +} rtTaskTimeoutType_t; + /** * @ingroup * @brief get AI core count @@ -184,6 +196,37 @@ RTS_API rtError_t rtMemGetL2Info(rtStream_t stream, void **ptr, uint32_t *size); */ RTS_API rtError_t rtGetRuntimeVersion(uint32_t *runtimeVersion); + +/** + * @ingroup + * @brief get device feature ability by device id, such as task schedule ability. + * @param [in] deviceId + * @param [in] moduleType + * @param [in] featureType + * @param [out] value + * @return RT_ERROR_NONE for ok + * @return RT_ERROR_INVALID_VALUE for error input + */ +RTS_API rtError_t rtGetDeviceCapability(int32_t deviceId, int32_t moduleType, int32_t featureType, int32_t *value); + +/** + * @ingroup + * @brief set event wait task timeout time. + * @param [in] timeout + * @return RT_ERROR_NONE for ok + * @return RT_ERROR_INVALID_VALUE for error input + */ +RTS_API rtError_t rtSetOpWaitTimeOut(uint32_t timeout); + +/** + * @ingroup + * @brief set op execute task timeout time. + * @param [in] timeout + * @return RT_ERROR_NONE for ok + * @return RT_ERROR_INVALID_VALUE for error input + */ +RTS_API rtError_t rtSetOpExecuteTimeOut(uint32_t timeout); + #if defined(__cplusplus) && !defined(COMPILE_OMG_PACKAGE) } #endif diff --git a/third_party/fwkacllib/inc/runtime/dev.h b/third_party/fwkacllib/inc/runtime/dev.h index e82ec5fa..2cf6712f 100644 --- a/third_party/fwkacllib/inc/runtime/dev.h +++ b/third_party/fwkacllib/inc/runtime/dev.h @@ -63,6 +63,11 @@ typedef enum tagRtFeatureType { FEATURE_TYPE_RSV } rtFeatureType_t; +typedef enum tagRtDeviceFeatureType { + FEATURE_TYPE_SCHE, + FEATURE_TYPE_END, +} rtDeviceFeatureType_t; + typedef enum tagMemcpyInfo { MEMCPY_INFO_SUPPORT_ZEROCOPY = 0, MEMCPY_INFO_RSV diff --git a/third_party/fwkacllib/inc/runtime/event.h b/third_party/fwkacllib/inc/runtime/event.h index 41e611ea..57948c47 100644 --- a/third_party/fwkacllib/inc/runtime/event.h +++ b/third_party/fwkacllib/inc/runtime/event.h @@ -23,12 +23,23 @@ extern "C" { #endif +typedef enum rtEventWaitStatus { + EVENT_STATUS_COMPLETE = 0, + EVENT_STATUS_NOT_READY = 1, + EVENT_STATUS_MAX = 2, +} rtEventWaitStatus_t; + /** * @ingroup event_flags * @brief event op bit flags */ -#define RT_EVENT_DEFAULT (0x00) -#define RT_EVENT_WITH_FLAG (0x01) +#define RT_EVENT_DEFAULT (0x0E) +#define RT_EVENT_WITH_FLAG (0x0B) + +#define RT_EVENT_DDSYNC_NS 0x01U +#define RT_EVENT_STREAM_MARK 0x02U +#define RT_EVENT_DDSYNC 0x04U +#define RT_EVENT_TIME_LINE 0x08U /** * @ingroup dvrt_event @@ -104,6 +115,16 @@ RTS_API rtError_t rtEventSynchronize(rtEvent_t event); */ RTS_API rtError_t rtEventQuery(rtEvent_t event); +/** + * @ingroup dvrt_event + * @brief Queries an event's wait status + * @param [in] event event to query + * @param [in out] EVENT_WAIT_STATUS status + * @return EVENT_STATUS_COMPLETE for complete + * @return EVENT_STATUS_NOT_READY for not complete + */ +RTS_API rtError_t rtEventQueryWaitStatus(rtEvent_t event, rtEventWaitStatus_t *status); + /** * @ingroup dvrt_event * @brief computes the elapsed time between events. @@ -176,6 +197,18 @@ RTS_API rtError_t rtNotifyRecord(rtNotify_t notify, rtStream_t stream); */ RTS_API rtError_t rtNotifyWait(rtNotify_t notify, rtStream_t stream); +/** + * @ingroup dvrt_event + * @brief Wait for a notify with time out + * @param [in] notify_ notify to be wait + * @param [in] stream_ input stream + * @param [in] timeOut input timeOut + * @return RT_ERROR_NONE for ok + * @return RT_ERROR_INVALID_VALUE for error input + * @return RT_ERROR_STREAM_CONTEXT for stream is not in current ctx + */ +RTS_API rtError_t rtNotifyWaitWithTimeOut(rtNotify_t notify_, rtStream_t stream_, uint32_t timeOut); + /** * @ingroup dvrt_event * @brief Name a notify diff --git a/third_party/fwkacllib/inc/runtime/kernel.h b/third_party/fwkacllib/inc/runtime/kernel.h index 402fadef..9b0221c7 100644 --- a/third_party/fwkacllib/inc/runtime/kernel.h +++ b/third_party/fwkacllib/inc/runtime/kernel.h @@ -111,6 +111,16 @@ typedef struct rtKernelInfo { uint32_t module_size; } *rtKernelInfo_t; +/** + * @ingroup rt_kernel + * @brief op name + */ +typedef struct rtKernelLaunchNames { + const char *soName; // defined for so name + const char *kernelName; // defined for kernel type name + const char *opName; // defined for operator name +} rtKernelLaunchNames_t; + /** * @ingroup rt_KernelConfigDump * @brief device dump type @@ -173,13 +183,7 @@ typedef void (*rtCallback_t)(void *fnData); * @ingroup rt_kernel * @brief magic number of elf binary for aicube */ -#define RT_DEV_BINARY_MAGIC_ELF_AICUBE 0x41415247 - -/** - * @ingroup rt_kernel - * @brief magic number of elf binary for aivector - */ -#define RT_DEV_BINARY_MAGIC_ELF_AIVECTOR 0x41415248 +#define RT_DEV_BINARY_MAGIC_ELF_AICUBE 0x41494343 /** * @ingroup rt_kernel_flags @@ -192,14 +196,14 @@ typedef void (*rtCallback_t)(void *fnData); #define RT_KERNEL_CUSTOM_AICPU (0x08) // STARS topic scheduler sqe : topic_type -#define RT_KERNEL_DEVICE_FIRST (0X10) -#define RT_KERNEL_HOST_ONLY (0X20) -#define RT_KERNEL_HOST_FIRST (0X30) +#define RT_KERNEL_DEVICE_FIRST (0x10) +#define RT_KERNEL_HOST_ONLY (0x20) +#define RT_KERNEL_HOST_FIRST (0x40) /** * @ingroup rt_kernel * @brief kernel mode - */ +**/ #define RT_DEFAULT_KERNEL_MODE (0x00) #define RT_NORMAL_KERNEL_MODE (0x01) #define RT_ALL_KERNEL_MODE (0x02) @@ -222,7 +226,7 @@ RTS_API rtError_t rtDevBinaryRegister(const rtDevBinary_t *bin, void **handle); /** * @ingroup rt_kernel - * @brief register device binary + * @brief register device binary with all kernel * @param [in] bin device binary description * @param [out] handle device binary handle * @return RT_ERROR_NONE for ok @@ -341,7 +345,7 @@ RTS_API rtError_t rtKernelLaunch(const void *stubFunc, uint32_t blockDim, void * * @ingroup rt_kernel * @brief launch kernel with handle to device * @param [in] handle program - * @param [in] devFunc device function description + * @param [in] devFunc device function description. * @param [in] blockDim block dimentions * @param [in] args argments address for kernel function * @param [in] argsSize argements size @@ -352,7 +356,7 @@ RTS_API rtError_t rtKernelLaunch(const void *stubFunc, uint32_t blockDim, void * * @return RT_ERROR_INVALID_VALUE for error input */ RTS_API rtError_t rtKernelLaunchWithHandle(void *handle, const void *devFunc, uint32_t blockDim, void *args, uint32_t argsSize, - rtSmDesc_t *smDesc, rtStream_t stream, const void *kernelInfo); + rtSmDesc_t *smDesc, rtStream_t stream_, const void *kernelInfo); /** * @ingroup rt_kernel @@ -371,7 +375,7 @@ RTS_API rtError_t rtKernelLaunchWithFlag(const void *stubFunc, uint32_t blockDim rtSmDesc_t *smDesc, rtStream_t stream, uint32_t flags); /** - * @ingroup rt_kernel + * @ingroup rt_kernel(abandoned) * @brief launch kernel to device * @param [in] args argments address for kernel function * @param [in] argsSize argements size @@ -383,7 +387,21 @@ RTS_API rtError_t rtKernelLaunchWithFlag(const void *stubFunc, uint32_t blockDim RTS_API rtError_t rtKernelLaunchEx(void *args, uint32_t argsSize, uint32_t flags, rtStream_t stream); /** - * @ingroup rt_kernel + * @ingroup rt_kernel(in use) + * @brief launch kernel to device + * @param [in] opName opkernel name + * @param [in] args argments address for kernel function + * @param [in] argsSize argements size + * @param [in] flags launch flags + * @param [in] stream associated stream + * @return RT_ERROR_NONE for ok + * @return RT_ERROR_INVALID_VALUE for error input + */ +RTS_API rtError_t rtKernelLaunchFwk(const char *opName, void *args, uint32_t argsSize, uint32_t flags, + rtStream_t rtStream); + +/** + * @ingroup rt_kernel(abandoned) * @brief launch cpu kernel to device * @param [in] soName so name * @param [in] kernelName kernel name @@ -399,7 +417,22 @@ RTS_API rtError_t rtCpuKernelLaunch(const void *soName, const void *kernelName, uint32_t argsSize, rtSmDesc_t *smDesc, rtStream_t stream); /** - * @ingroup rt_kernel + * @ingroup rt_kernel(in use) + * @brief launch cpu kernel to device + * @param [in] launchNames names for kernel launch + * @param [in] blockDim block dimentions + * @param [in] args argments address for kernel function + * @param [in] argsSize argments size + * @param [in] smDesc shared memory description + * @param [in] stream associated stream + * @return RT_ERROR_NONE for ok + * @return RT_ERROR_INVALID_VALUE for error input + */ +RTS_API rtError_t rtAicpuKernelLaunch(const rtKernelLaunchNames_t *launchNames, + uint32_t blockDim, const void *args, uint32_t argsSize, rtSmDesc_t *smDesc, rtStream_t stream); + +/** + * @ingroup rt_kernel(abandoned) * @brief launch cpu kernel to device with dump identifier * @param [in] soName so name * @param [in] kernelName kernel name @@ -416,6 +449,22 @@ RTS_API rtError_t rtCpuKernelLaunchWithFlag(const void *soName, const void *kern const void *args, uint32_t argsSize, rtSmDesc_t *smDesc, rtStream_t stream, uint32_t flags); +/** + * @ingroup rt_kernel(in use) + * @brief launch cpu kernel to device with dump identifier + * @param [in] launchNames names for kernel launch + * @param [in] blockDim block dimentions + * @param [in] args argments address for kernel function + * @param [in] argsSize argments size + * @param [in] smDesc shared memory description + * @param [in] stream associated stream + * @param [in] flag dump flag or others function flag + * @return RT_ERROR_NONE for ok + * @return RT_ERROR_INVALID_VALUE for error input + */ +RTS_API rtError_t rtAicpuKernelLaunchWithFlag(const rtKernelLaunchNames_t *launchNames, uint32_t blockDim, + const void *args, uint32_t argsSize, rtSmDesc_t *smDesc, rtStream_t stream, uint32_t flags); + /** * @ingroup rt_kernel * @brief L1 fusion dump addr transfered to device diff --git a/third_party/fwkacllib/inc/runtime/mem.h b/third_party/fwkacllib/inc/runtime/mem.h index 30af85d9..bace4bc6 100644 --- a/third_party/fwkacllib/inc/runtime/mem.h +++ b/third_party/fwkacllib/inc/runtime/mem.h @@ -116,6 +116,9 @@ typedef enum tagRtMemInfoType { typedef enum tagRtRecudeKind { RT_MEMCPY_SDMA_AUTOMATIC_ADD = 10, // D2D, SDMA inline reduce, include 1P, and P2P + RT_MEMCPY_SDMA_AUTOMATIC_MAX = 11, + RT_MEMCPY_SDMA_AUTOMATIC_MIN = 12, + RT_MEMCPY_SDMA_AUTOMATIC_EQUAL = 13, RT_RECUDE_KIND_END } rtRecudeKind_t; @@ -123,6 +126,14 @@ typedef enum tagRtDataType { RT_DATA_TYPE_FP32 = 0, // fp32 RT_DATA_TYPE_FP16 = 1, // fp16 RT_DATA_TYPE_INT16 = 2, // int16 + RT_DATA_TYPE_INT4 = 3, // int4 + RT_DATA_TYPE_INT8 = 4, // int8 + RT_DATA_TYPE_INT32 = 5, // int32 + RT_DATA_TYPE_BFP16 = 6, // bfp16 + RT_DATA_TYPE_BFP32 = 7, // bfp32 + RT_DATA_TYPE_UINT8 = 8, // uint8 + RT_DATA_TYPE_UINT16= 9, // uint16 + RT_DATA_TYPE_UINT32= 10,// uint32 RT_DATA_TYPE_END } rtDataType_t; diff --git a/third_party/fwkacllib/inc/runtime/rt_model.h b/third_party/fwkacllib/inc/runtime/rt_model.h index 30b8f053..a7618b45 100644 --- a/third_party/fwkacllib/inc/runtime/rt_model.h +++ b/third_party/fwkacllib/inc/runtime/rt_model.h @@ -135,12 +135,13 @@ typedef struct tagAllKernelTaskInfo { uint16_t argsCount; uint16_t argsSize; uint16_t reserved; - const void *dev_func; + void *devfunc; void *handle; uint8_t *smDesc; uint8_t *args; uint16_t *argsOffset; } rtAllKernelTaskInfo_t; + typedef struct tagKernelTaskInfoEx { uint32_t flags; uint32_t argsSize; @@ -198,6 +199,13 @@ typedef struct tagProfilerTraceTaskInfo { uint32_t reserved[6]; } rtProfilerTrace_t; +typedef struct tagProfilerTraceExTaskInfo { + uint64_t profilerTraceId; + uint64_t modelId; + uint16_t tagId; + uint8_t reserved[22]; +} rtProfilerTraceEx_t; + typedef struct tagrtMemcpyAsyncTaskInfo { void *dst; uint64_t destMax; @@ -265,7 +273,7 @@ typedef struct tagTaskInfo { union { rtKernelTaskInfoEx_t kernelTaskEx; rtKernelTaskInfo_t kernelTask; - rtAllKernelTaskInfo_t allkernelTask; + rtAllKernelTaskInfo_t allKernelTask; rtEventTaskInfo_t eventTask; rtStreamSwitchTaskInfo_t streamSwitchTask; rtStreamActiveTaskInfo_t streamActiveTask; @@ -273,6 +281,7 @@ typedef struct tagTaskInfo { rtLabelSwitchTaskInfo_t labelSwitchTask; rtLabelGotoTaskInfo_t labelGotoTask; rtProfilerTrace_t profilertraceTask; + rtProfilerTraceEx_t profilertraceExTask; rtMemcpyAsyncTaskInfo_t memcpyAsyncTask; rtNotifyTaskInfo_t notifyTask; rtReduceAsyncTaskInfo_t reduceAsyncTask; diff --git a/third_party/fwkacllib/inc/toolchain/prof_callback.h b/third_party/fwkacllib/inc/toolchain/prof_callback.h index 18550157..5073cfb1 100644 --- a/third_party/fwkacllib/inc/toolchain/prof_callback.h +++ b/third_party/fwkacllib/inc/toolchain/prof_callback.h @@ -108,7 +108,19 @@ enum MsprofCtrlCallbackType { MSPROF_CTRL_INIT_ACL_ENV = 0, // start profiling with acl env MSPROF_CTRL_INIT_ACL_JSON, // start profiling with acl.json MSPROF_CTRL_INIT_GE_OPTIONS, // start profiling with ge env and options - MSPROF_CTRL_FINALIZE // stop profiling + MSPROF_CTRL_FINALIZE, // stop profiling + MSPROF_CTRL_REPORT_FUN_P, // for report callback + MSPROF_CTRL_PROF_SWITCH_ON, // for prof switch on + MSPROF_CTRL_PROF_SWITCH_OFF // for prof switch off +}; + +#define MSPROF_MAX_DEV_NUM (64) + +struct MsprofCommandHandle { + uint64_t profSwitch; + uint32_t devNums; // length of device id list + uint32_t devIdList[MSPROF_MAX_DEV_NUM]; + uint32_t modelId; }; /** @@ -129,6 +141,23 @@ typedef int32_t (*MsprofCtrlCallback)(uint32_t type, void *data, uint32_t len); */ typedef void (*MsprofSetDeviceCallback)(uint32_t devId, bool isOpenDevice); +/* + * @name MsprofInit + * @brief Profiling module init + * @param [in] dataType: profiling type: ACL Env/ACL Json/GE Option + * @param [in] data: profiling switch data + * @param [in] dataLen: Length of data + * @return 0:SUCCESS, >0:FAILED + */ +int32_t MsprofInit(uint32_t dataType, void *data, uint32_t dataLen); + +/* + * @name AscendCL + * @brief Finishing Profiling + * @param NULL + * @return 0:SUCCESS, >0:FAILED + */ +int32_t MsprofFinalize(); #ifdef __cplusplus } #endif diff --git a/third_party/fwkacllib/inc/toolchain/slog.h b/third_party/fwkacllib/inc/toolchain/slog.h index ba286d02..cc7c83ca 100644 --- a/third_party/fwkacllib/inc/toolchain/slog.h +++ b/third_party/fwkacllib/inc/toolchain/slog.h @@ -17,6 +17,8 @@ #ifndef D_SYSLOG_H_ #define D_SYSLOG_H_ +static const int TMP_LOG = 0; + #ifdef __cplusplus #ifndef LOG_CPP extern "C" { @@ -120,15 +122,15 @@ typedef struct tagKV { } KeyValue; typedef enum { - APPLICATION = 0, - SYSTEM + APPLICATION = 0, + SYSTEM } ProcessType; typedef struct { - ProcessType type; - unsigned int pid; - unsigned int deviceId; - char reserved[RESERVERD_LENGTH]; + ProcessType type; + unsigned int pid; + unsigned int deviceId; + char reserved[RESERVERD_LENGTH]; } LogAttr; /** @@ -141,7 +143,7 @@ enum { IDEDD, /**< IDE daemon device */ IDEDH, /**< IDE daemon host */ HCCL, /**< HCCL */ - FMK, /**< Framework */ + FMK, /**< Adapter */ HIAIENGINE, /**< Matrix */ DVPP, /**< DVPP */ RUNTIME, /**< Runtime */ @@ -162,11 +164,11 @@ enum { MDCDEFAULT, /**< MDC undefine */ MDCSC, /**< MDC spatial cognition */ MDCPNC, - MLL, + MLL, /**< abandon */ DEVMM, /**< Dlog memory managent */ KERNEL, /**< Kernel */ LIBMEDIA, /**< Libmedia */ - CCECPU, /**< ai cpu */ + CCECPU, /**< aicpu shedule */ ASCENDDK, /**< AscendDK */ ROS, /**< ROS */ HCCP, @@ -179,7 +181,7 @@ enum { TSDUMP, /**< TSDUMP module */ AICPU, /**< AICPU module */ LP, /**< LP module */ - TDT, + TDT, /**< tsdaemon or aicpu shedule */ FE, MD, MB, @@ -261,7 +263,7 @@ DLL_EXPORT int DlogSetAttr(LogAttr logAttr); #define dlog_error(moduleId, fmt, ...) \ do { \ DlogErrorInner(moduleId, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -276,7 +278,7 @@ DLL_EXPORT int DlogSetAttr(LogAttr logAttr); if(CheckLogLevel(moduleId, DLOG_WARN) == 1) { \ DlogWarnInner(moduleId, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ } \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -291,7 +293,7 @@ DLL_EXPORT int DlogSetAttr(LogAttr logAttr); if(CheckLogLevel(moduleId, DLOG_INFO) == 1) { \ DlogInfoInner(moduleId, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ } \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -306,7 +308,7 @@ DLL_EXPORT int DlogSetAttr(LogAttr logAttr); if(CheckLogLevel(moduleId, DLOG_DEBUG) == 1) { \ DlogDebugInner(moduleId, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ } \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -318,7 +320,7 @@ DLL_EXPORT int DlogSetAttr(LogAttr logAttr); #define dlog_event(moduleId, fmt, ...) \ do { \ DlogEventInner(moduleId, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -334,7 +336,7 @@ DLL_EXPORT int DlogSetAttr(LogAttr logAttr); if(CheckLogLevel(moduleId, level) == 1) { \ DlogInner(moduleId, level, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ } \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -351,7 +353,7 @@ DLL_EXPORT int DlogSetAttr(LogAttr logAttr); if(CheckLogLevel(moduleId, level) == 1) { \ DlogInner(moduleId, level, "[%s:%d][%s]" fmt, __FILE__, __LINE__, submodule, ##__VA_ARGS__); \ } \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -369,7 +371,7 @@ DLL_EXPORT int DlogSetAttr(LogAttr logAttr); if(CheckLogLevel(moduleId, level) == 1) { \ DlogWithKVInner(moduleId, level, pstKVArray, kvNum, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ } \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -381,13 +383,13 @@ DLL_EXPORT void DlogFlush(void); * @ingroup slog * @brief Internal log interface, other modules are not allowed to call this interface */ -void DlogErrorInner(int moduleId, const char *fmt, ...) __attribute__((format(printf, 2, 3))); -void DlogWarnInner(int moduleId, const char *fmt, ...) __attribute__((format(printf, 2, 3))); -void DlogInfoInner(int moduleId, const char *fmt, ...) __attribute__((format(printf, 2, 3))); -void DlogDebugInner(int moduleId, const char *fmt, ...) __attribute__((format(printf, 2, 3))); -void DlogEventInner(int moduleId, const char *fmt, ...) __attribute__((format(printf, 2, 3))); -void DlogInner(int moduleId, int level, const char *fmt, ...) __attribute__((format(printf, 3, 4))); -void DlogWithKVInner(int moduleId, int level, KeyValue *pstKVArray, int kvNum, const char *fmt, ...) __attribute__((format(printf, 5, 6))); +void DlogErrorInner(int moduleId, const char *fmt, ...); +void DlogWarnInner(int moduleId, const char *fmt, ...); +void DlogInfoInner(int moduleId, const char *fmt, ...); +void DlogDebugInner(int moduleId, const char *fmt, ...); +void DlogEventInner(int moduleId, const char *fmt, ...); +void DlogInner(int moduleId, int level, const char *fmt, ...); +void DlogWithKVInner(int moduleId, int level, KeyValue *pstKVArray, int kvNum, const char *fmt, ...); #ifdef __cplusplus #ifndef LOG_CPP @@ -453,7 +455,7 @@ DLL_EXPORT int DlogSetAttrForC(LogAttr logAttr); if(CheckLogLevelForC(moduleId, level) == 1) { \ DlogInnerForC(moduleId, level, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ } \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -470,7 +472,7 @@ DLL_EXPORT int DlogSetAttrForC(LogAttr logAttr); if(CheckLogLevelForC(moduleId, level) == 1) { \ DlogInnerForC(moduleId, level, "[%s:%d][%s]" fmt, __FILE__, __LINE__, submodule, ##__VA_ARGS__); \ } \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -488,7 +490,7 @@ DLL_EXPORT int DlogSetAttrForC(LogAttr logAttr); if(CheckLogLevelForC(moduleId, level) == 1) { \ DlogWithKVInnerForC(moduleId, level, pstKVArray, kvNum, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ } \ - } while (0) + } while (TMP_LOG != 0) /** * @ingroup slog @@ -500,8 +502,8 @@ DLL_EXPORT void DlogFlushForC(void); * @ingroup slog * @brief Internal log interface, other modules are not allowed to call this interface */ -void DlogInnerForC(int moduleId, int level, const char *fmt, ...) __attribute__((format(printf, 3, 4))); -void DlogWithKVInnerForC(int moduleId, int level, KeyValue *pstKVArray, int kvNum, const char *fmt, ...) __attribute__((format(printf, 5, 6))); +void DlogInnerForC(int moduleId, int level, const char *fmt, ...); +void DlogWithKVInnerForC(int moduleId, int level, KeyValue *pstKVArray, int kvNum, const char *fmt, ...); #ifdef __cplusplus } diff --git a/third_party/fwkacllib/inc/toolchain/tuning_tool/tune_api.h b/third_party/fwkacllib/inc/toolchain/tuning_tool/tune_api.h index 6208f462..2cf6e0c4 100644 --- a/third_party/fwkacllib/inc/toolchain/tuning_tool/tune_api.h +++ b/third_party/fwkacllib/inc/toolchain/tuning_tool/tune_api.h @@ -1,72 +1,88 @@ -/** - * @file tune_api.h - * - * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.\n - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n - * 描述:mstune调优接口头文件 - */ -/** @defgroup mstune mstune调优接口 */ -#ifndef TUNE_API_H -#define TUNE_API_H -#include -#include -#include -#include "graph/graph.h" -#include "ge/ge_api.h" - -/** - * @ingroup mstune - * - * mstune status - */ -enum MsTuneStatus { - MSTUNE_SUCCESS, /** tune success */ - MSTUNE_FAILED, /** tune failed */ -}; - -// Option key: for train options sets -const std::string MSTUNE_SELF_KEY = "mstune"; -const std::string MSTUNE_GEINIT_KEY = "initialize"; -const std::string MSTUNE_GESESS_KEY = "session"; - -/** - * @ingroup mstune - * @par 描述: 命令行调优 - * - * @attention 无 - * @param option [IN] 调优参数 - * @param msg [OUT] 调优异常下返回信息 - * @retval #MSTUNE_SUCCESS 执行成功 - * @retval #MSTUNE_FAILED 执行失败 - * @par 依赖: - * @li tune_api.cpp:该接口所属的开发包。 - * @li tune_api.h:该接口声明所在的头文件。 - * @see 无 - * @since - */ -MsTuneStatus MsTuning(const std::map &option, std::string &msg); - -/** - * @ingroup mstune - * @par 描述: 梯度调优 - * - * @attention 无 - * @param tuningGraph [IN] 调优图 - * @param dependGraph [IN] 调优依赖图 - * @param session [IN] ge连接会话 - * @param option [IN] 参数集. 包含调优参数及ge参数 - * @retval #MSTUNE_SUCCESS 执行成功 - * @retval #MSTUNE_FAILED 执行失败 - * @par 依赖: - * @li tune_api.cpp:该接口所属的开发包。 - * @li tune_api.h:该接口声明所在的头文件。 - * @see 无 - * @since - */ -extern "C" MsTuneStatus MsTrainTuning(ge::Graph &tuningGraph, std::vector &dependGraph, - ge::Session *session, const std::map> &option); - -#endif +/** + * @file tune_api.h + * + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.\n + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n + * 描述:aoe调优接口头文件 + */ +/** @defgroup aoe aoe调优接口 */ +#ifndef TUNE_API_H +#define TUNE_API_H +#include +#include +#include "ge/ge_api.h" +#include "aoe_types.h" + +/** + * @ingroup aoe + * @par 描述: 命令行调优 + * + * @attention 无 + * @param option [IN] 调优参数 + * @param msg [OUT] 调优异常下返回信息 + * @retval #AOE_SUCCESS 执行成功 + * @retval #AOE_FAILURE 执行失败 + * @par 依赖: + * @li tune_api.cpp:该接口所属的开发包。 + * @li tune_api.h:该接口声明所在的头文件。 + * @see 无 + * @since + */ +AoeStatus AoeOfflineTuning(const std::map &option, std::string &msg); + +/** + * @ingroup aoe + * @par 描述: 调优初始化 + * + * @attention 无 + * @param session [IN] ge连接会话 + * @param option [IN] 参数集. 包含调优参数及ge参数 + * @retval #AOE_SUCCESS 执行成功 + * @retval #AOE_FAILURE 执行失败 + * @par 依赖: + * @li tune_api.cpp:该接口所属的开发包。 + * @li tune_api.h:该接口声明所在的头文件。 + * @see 无 + * @since + */ +extern "C" AoeStatus AoeOnlineInitialize(ge::Session *session, const std::map &option); + +/** + * @ingroup aoe + * @par 描述: 调优去初始化 + * + * @attention 无 + * @param 无 + * @retval #AOE_SUCCESS 执行成功 + * @retval #AOE_FAILURE 执行失败 + * @par 依赖: + * @li tune_api.cpp:该接口所属的开发包。 + * @li tune_api.h:该接口声明所在的头文件。 + * @see 无 + * @since + */ +extern "C" AoeStatus AoeOnlineFinalize(); + +/** + * @ingroup aoe + * @par 描述: 调优处理 + * + * @attention 无 + * @param tuningGraph [IN] 调优图 + * @param dependGraph [IN] 调优依赖图 + * @param session [IN] ge连接会话 + * @param option [IN] 参数集. 包含调优参数及ge参数 + * @retval #AOE_SUCCESS 执行成功 + * @retval #AOE_FAILURE 执行失败 + * @par 依赖: + * @li tune_api.cpp:该接口所属的开发包。 + * @li tune_api.h:该接口声明所在的头文件。 + * @see 无 + * @since + */ +extern "C" AoeStatus AoeOnlineTuning(ge::Graph &tuningGraph, std::vector &dependGraph, + ge::Session *session, const std::map &option); +#endif From d1bb84d4ea4ff58a4d08d2fce112b8f289175da0 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Wed, 30 Jun 2021 16:59:03 +0800 Subject: [PATCH 34/50] Fix ut. --- ge/single_op/single_op_model.h | 1 - .../node_executor/node_executor_unittest.cc | 4 ++-- .../ge/single_op/single_op_model_unittest.cc | 20 ++++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ge/single_op/single_op_model.h b/ge/single_op/single_op_model.h index 98aed0f0..b5198e3d 100755 --- a/ge/single_op/single_op_model.h +++ b/ge/single_op/single_op_model.h @@ -82,7 +82,6 @@ class SingleOpModel { Status ParseTasks(); std::vector tbe_tasks_; - std::vector atomic_tasks_; std::vector aicpu_tasks_; std::string model_name_; diff --git a/tests/ut/ge/hybrid/node_executor/node_executor_unittest.cc b/tests/ut/ge/hybrid/node_executor/node_executor_unittest.cc index 8a1240d3..a6f5c2de 100644 --- a/tests/ut/ge/hybrid/node_executor/node_executor_unittest.cc +++ b/tests/ut/ge/hybrid/node_executor/node_executor_unittest.cc @@ -97,7 +97,7 @@ TEST_F(NodeExecutorTest, TestInitAndFinalize) { manager.FinalizeExecutors(); ASSERT_FALSE(manager.executors_.empty()); manager.FinalizeExecutors(); - ASSERT_TRUE(manager.executors_.empty()); - ASSERT_TRUE(finalized); + // ASSERT_TRUE(manager.executors_.empty()); + // ASSERT_TRUE(finalized); } } // namespace ge diff --git a/tests/ut/ge/single_op/single_op_model_unittest.cc b/tests/ut/ge/single_op/single_op_model_unittest.cc index e4a53340..2c0073f5 100644 --- a/tests/ut/ge/single_op/single_op_model_unittest.cc +++ b/tests/ut/ge/single_op/single_op_model_unittest.cc @@ -311,7 +311,7 @@ TEST_F(UtestSingleOpModel, BuildTaskList) { ASSERT_EQ(mem_task.LaunchKernel(0), SUCCESS); } -TEST_F(UtestSingleOpModel, build_aicpu_task) { +TEST_F(UtestSingleOpModel, build_dynamic_task) { ComputeGraphPtr graph = make_shared("single_op"); GeModelPtr ge_model = make_shared(); ge_model->SetGraph(GraphUtils::CreateGraphFromComputeGraph(graph)); @@ -321,6 +321,15 @@ TEST_F(UtestSingleOpModel, build_aicpu_task) { domi::TaskDef *task_def = model_task_def->add_task(); task_def->set_type(RT_MODEL_TASK_KERNEL_EX); + domi::TaskDef *task_def2 = model_task_def->add_task(); + task_def2->set_type(RT_MODEL_TASK_KERNEL); + domi::KernelDef *kernel_def = task_def2->mutable_kernel(); + domi::KernelContext *context = kernel_def->mutable_context(); + context->set_kernel_type(6); // ccKernelType::AI_CPU + + domi::TaskDef *task_def3 = model_task_def->add_task(); + task_def3->set_type(RT_MODEL_TASK_ALL_KERNEL); + string model_data_str = "123456789"; SingleOpModel model("model", model_data_str.c_str(), model_data_str.size()); std::mutex stream_mu; @@ -329,8 +338,17 @@ TEST_F(UtestSingleOpModel, build_aicpu_task) { DynamicSingleOp single_op(0, &stream_mu, stream); model.model_helper_.model_ = ge_model; auto op_desc = std::make_shared("add", "Add"); + 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); NodePtr node = graph->AddNode(op_desc); model.op_list_[0] = node; StreamResource *res = new (std::nothrow) StreamResource(1); + + ASSERT_EQ(model.ParseTasks(), SUCCESS); + ASSERT_EQ(model.BuildTaskListForDynamicOp(res, single_op), SUCCESS); + model.tbe_tasks_.clear(); ASSERT_EQ(model.BuildTaskListForDynamicOp(res, single_op), SUCCESS); + model.aicpu_tasks_[0] = *task_def2; + model.BuildTaskListForDynamicOp(res, single_op); } From 25557f9bf05bf39cd2034ad5480956151555408e Mon Sep 17 00:00:00 2001 From: wangzhengjun Date: Wed, 30 Jun 2021 17:08:09 +0800 Subject: [PATCH 35/50] set size for dynamic input --- .../executor/hybrid_model_async_executor.cc | 8 ++++-- .../hybrid_model_async_executor_unittest.cc | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ge/hybrid/executor/hybrid_model_async_executor.cc b/ge/hybrid/executor/hybrid_model_async_executor.cc index e0dd768d..229cce84 100644 --- a/ge/hybrid/executor/hybrid_model_async_executor.cc +++ b/ge/hybrid/executor/hybrid_model_async_executor.cc @@ -295,13 +295,15 @@ Status HybridModelAsyncExecutor::PrepareInputs(const InputData ¤t_data, Hy } } tensor_desc->SetShape(shape); - args.input_desc[input_index] = tensor_desc; - GELOGD("Update shape of input[%zu] to [%s]", input_index, tensor_desc->MutableShape().ToString().c_str()); + GELOGD("Update shape[%s] of input[%zu] to [%s]", + shape.ToString().c_str(), input_index, tensor_desc->MutableShape().ToString().c_str()); GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetTensorMemorySizeInBytes(*tensor_desc, tensor_size), "[Invoke][GetTensorMemorySizeInBytes]Failed to calc tensor size," "index = %zu, shape = [%s], model_id = %u.", input_index, tensor_desc->GetShape().ToString().c_str(), model_id_); - GELOGD("Input tensor[%zu] size = %zu", input_index, tensor_size); + GELOGD("Input tensor[%zu] size = %ld", input_index, tensor_size); + TensorUtils::SetSize(*tensor_desc, tensor_size); + args.input_desc[input_index] = tensor_desc; } GE_CHECK_GE(tensor_size, 0); diff --git a/tests/ut/ge/hybrid/executor/hybrid_model_async_executor_unittest.cc b/tests/ut/ge/hybrid/executor/hybrid_model_async_executor_unittest.cc index f772af23..c053885f 100644 --- a/tests/ut/ge/hybrid/executor/hybrid_model_async_executor_unittest.cc +++ b/tests/ut/ge/hybrid/executor/hybrid_model_async_executor_unittest.cc @@ -103,4 +103,32 @@ TEST_F(UtestHybridModelAsyncExecutor, Test_execute) { context.callback_manager->callback_queue_.Push(eof_entry); ASSERT_EQ(executor.Execute(args), SUCCESS); } + +TEST_F(UtestHybridModelAsyncExecutor, test_PrepareInputs) { + ComputeGraphPtr graph = std::make_shared("test"); + GeRootModelPtr ge_root_model = make_shared(graph); + ge_root_model->SetModelName("test_name"); + GeModelPtr ge_sub_model = make_shared(); + HybridModel hybrid_model(ge_root_model); + HybridModelAsyncExecutor executor(&hybrid_model); + GeTensorDescPtr tensor_desc = make_shared(GeShape({-1, 16, 16, 3})); + tensor_desc->SetShapeRange({{1, 256}, {16, 16}, {16, 16}, {3, 3}}); + executor.input_tensor_desc_.insert({0, tensor_desc}); + executor.device_id_ = 0; + executor.input_sizes_.insert({0, -1}); + executor.is_input_dynamic_.push_back(true); + + unique_ptr data_buf(new (std::nothrow)uint8_t[3072]); + InputData input_data; + input_data.blobs.push_back(DataBuffer(data_buf.get(), 3072, false)); + input_data.shapes.push_back({1, 16, 16, 3}); + HybridModelExecutor::ExecuteArgs args; + + auto ret = executor.PrepareInputs(input_data, args); + ASSERT_EQ(ret, SUCCESS); + ASSERT_EQ(args.input_desc[0]->GetShape().ToString(), GeShape({1, 16, 16, 3}).ToString()); + int64_t tensor_size = 0; + TensorUtils::GetSize(*(args.input_desc[0]), tensor_size); + ASSERT_EQ(tensor_size, 3104); +} } // namespace ge \ No newline at end of file From 022ec1c8c050437906025bfac682efdbc5fada8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=B6=9B?= Date: Wed, 30 Jun 2021 19:20:09 +0800 Subject: [PATCH 36/50] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!1?= =?UTF-8?q?842=20:=20check=20dump=20option'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ge/common/dump/dump_properties.cc | 243 ++---------------- ge/common/dump/dump_properties.h | 18 +- ge/session/inner_session.cc | 2 +- tests/ut/ge/CMakeLists.txt | 1 - .../ut/ge/common/dump_properties_unittest.cc | 126 --------- 5 files changed, 26 insertions(+), 364 deletions(-) delete mode 100644 tests/ut/ge/common/dump_properties_unittest.cc diff --git a/ge/common/dump/dump_properties.cc b/ge/common/dump/dump_properties.cc index 010347c0..ef755540 100644 --- a/ge/common/dump/dump_properties.cc +++ b/ge/common/dump/dump_properties.cc @@ -18,7 +18,6 @@ #include #include -#include #include "common/ge/ge_util.h" #include "framework/common/util.h" @@ -38,159 +37,6 @@ const uint32_t kAtomicOverflow = (0x1 << 1); const uint32_t kAllOverflow = (kAicoreOverflow | kAtomicOverflow); } // namespace namespace ge { -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::Split(const std::string &s, - std::vector &result, - const char *delchar) { - if (s.empty()) { - return; - } - result.clear(); - - char *buffer = new (std::nothrow)char[s.size() + 1]; - if (buffer == nullptr) { - GELOGE(FAILED, "[Split][string] failed while malloc memory, string value is:%s", s.c_str()); - REPORT_CALL_ERROR("E19999", "Memory malloc may fail when split string, get fatal exception, " - "string value is:%s", s.c_str()); - return; - } - buffer[s.size()] = '\0'; - errno_t e = strcpy_s(buffer, s.size() + 1, s.c_str()); - if (e != EOK) { - delete[] buffer; - return; - } - char *context = nullptr; - char *p = strtok_s(buffer, delchar, &context); - while (p != nullptr) { - result.emplace_back(p); - p = strtok_s(nullptr, delchar, &context); - } - delete[] buffer; -} - -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckDumpStep(const std::string &dump_step) { - std::string modified_dum_step = dump_step + "|"; - std::smatch result; - std::vector match_vecs; - std::regex pattern(R"((\d{1,}-\d{1,}\||\d{1,}\|)+)"); - if (regex_match(modified_dum_step, result, pattern)) { - Split(result.str(), match_vecs, "|"); - if (match_vecs.empty()) { - REPORT_CALL_ERROR("E19999", "Split may get fatal exception, dump_step:%s.", dump_step.c_str()); - GELOGE(FAILED, "[Check][Param] failed. Split may get fatal exception, ge.exec.dumpStep:%s.", dump_step.c_str()); - return FAILED; - } - // 100 is the max sets of dump steps. - if (match_vecs.size() > 100) { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.dumpStep", - dump_step.c_str(), - " is not supported, only support dump <= 100 sets of data"})); - GELOGE(PARAM_INVALID, "[Check][Param] get dump_step value:%s, " - "dump_step only support dump <= 100 sets of data.", dump_step.c_str()); - return PARAM_INVALID; - } - for (const auto &match_vec : match_vecs) { - std::vector vec_after_split; - Split(match_vec, vec_after_split, "-"); - if (match_vecs.empty()) { - REPORT_CALL_ERROR("E19999", "Split may get fatal exception."); - GELOGE(FAILED, "[Check][Param] failed, split may get fatal exception."); - return FAILED; - } - if (vec_after_split.size() > 1) { - if (std::atoi(vec_after_split[0].c_str()) >= std::atoi(vec_after_split[1].c_str())) { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.dumpStep", - dump_step.c_str(), - " is not supported." - "in range steps, the first step is >= second step, correct example:'0|5|10-20"})); - GELOGE(PARAM_INVALID, "[Check][Param] get dump_step value:%s, " - "in range steps, the first step is >= second step, correct example:'0|5|10-20'", dump_step.c_str()); - return PARAM_INVALID; - } - } - } - } else { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.dumpStep", - dump_step.c_str(), - " is not supported, correct example:'0|5|10|50-100."})); - GELOGE(PARAM_INVALID, "[Check][Param] get dump_step value:%s, " - "dump_step string style is error, correct example:'0|5|10|50-100.'", dump_step.c_str()); - return PARAM_INVALID; - } - return SUCCESS; -} - -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckDumpMode(const std::string &dump_mode) { - const std::set dump_mode_list = {"input", "output", "all"}; - std::set::iterator iter; - - if ((iter = dump_mode_list.find(dump_mode)) == dump_mode_list.end()) { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.dumpMode", - dump_mode.c_str(), - " is not supported, should be one of the following:[input, output, all]"})); - GELOGE(PARAM_INVALID, "[Check][Param] the dump_debug_mode:%s, is is not supported," - "should be one of the following:[input, output, all].", dump_mode.c_str()); - return PARAM_INVALID; - } - return SUCCESS; -} - -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckDumpPath(const std::string &input) { - if (mmIsDir(input.c_str()) != EN_OK) { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.dumpPath", - input.c_str(), - " is not a directory."})); - GELOGE(PARAM_INVALID, "[Check][Param] the path:%s, is not directory.", input.c_str()); - return PARAM_INVALID; - } - char trusted_path[MMPA_MAX_PATH] = { "\0" }; - if (mmRealPath(input.c_str(), trusted_path, MMPA_MAX_PATH) != EN_OK) { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.dumpPath", - input.c_str(), - " dumpPath invalid."})); - GELOGE(PARAM_INVALID, "[Check][Param] the dumpPath:%s, is invalid.", input.c_str()); - return PARAM_INVALID; - } - if (mmAccess2(trusted_path, R_OK | W_OK) != EN_OK) { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.dumpPath", - input.c_str(), - " does't have read, write permissions."})); - GELOGE(PARAM_INVALID, "[Check][Param] the path:%s, does't have read, write permissions.", input.c_str()); - return PARAM_INVALID; - } - return SUCCESS; -} - -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckEnableDump(const std::string &input) { - std::set enable_dump_option_list = {"1", "0"}; - auto it = enable_dump_option_list.find(input); - if (it == enable_dump_option_list.end()) { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.enableDump", - input.c_str(), - " only support 1 or 0."})); - GELOGE(PARAM_INVALID, "[Check][Param] Not support ge.exec.enableDump or ge.exec.enableDumpDebug format:%s, " - "only support 1 or 0.", input.c_str()); - return PARAM_INVALID; - } - return SUCCESS; -} - FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties::DumpProperties(const DumpProperties &other) { CopyFrom(other); } @@ -201,26 +47,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties &DumpProperties: return *this; } -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::SetDumpOptions() { - if (enable_dump_ == kEnableFlag) { - std::string dump_step; - if (GetContext().GetOption(OPTION_EXEC_DUMP_STEP, dump_step) == GRAPH_SUCCESS) { - GE_CHK_STATUS_RET(CheckDumpStep(dump_step), "[Check][dump_step] failed."); - GELOGI("Get dump step %s successfully", dump_step.c_str()); - SetDumpStep(dump_step); - } - string dump_mode = "output"; - if (GetContext().GetOption(OPTION_EXEC_DUMP_MODE, dump_mode) == GRAPH_SUCCESS) { - GELOGI("Get dump mode %s successfully", dump_mode.c_str()); - GE_CHK_STATUS_RET(CheckDumpMode(dump_mode), "[Check][dump_mode] failed."); - SetDumpMode(dump_mode); - } - AddPropertyValue(DUMP_ALL_MODEL, {}); - } - return SUCCESS; -} - -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::InitByOptions() { +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::InitByOptions() { enable_dump_.clear(); enable_dump_debug_.clear(); dump_path_.clear(); @@ -230,32 +57,17 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::InitByOp is_infer_op_debug_ = false; op_debug_mode_ = 0; - std::string enable_dump = std::to_string(false); + std::string enable_dump; (void)GetContext().GetOption(OPTION_EXEC_ENABLE_DUMP, enable_dump); enable_dump_ = enable_dump; - if (!enable_dump_.empty()) { - GE_CHK_STATUS_RET(CheckEnableDump(enable_dump_), "[Check][enable_dump] failed."); - } - std::string enable_dump_debug = std::to_string(false); + std::string enable_dump_debug; (void)GetContext().GetOption(OPTION_EXEC_ENABLE_DUMP_DEBUG, enable_dump_debug); enable_dump_debug_ = enable_dump_debug; - if (!enable_dump_debug_.empty()) { - GE_CHK_STATUS_RET(CheckEnableDump(enable_dump_debug_), "[Check][enable_dump_debug] failed."); - } - if ((enable_dump_ == kEnableFlag) && (enable_dump_debug_ == kEnableFlag)) { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.enableDump and ge.exec.enableDumpDebug", - enable_dump_ + ", " + enable_dump_debug, - "ge.exec.enableDump and ge.exec.enableDumpDebug cannot be set to 1 at the same time."})); - GELOGE(FAILED, "ge.exec.enableDump and ge.exec.enableDumpDebug cannot be both set to 1 at the same time."); - return FAILED; - } + if ((enable_dump_ == kEnableFlag) || (enable_dump_debug_ == kEnableFlag)) { std::string dump_path; if (GetContext().GetOption(OPTION_EXEC_DUMP_PATH, dump_path) == GRAPH_SUCCESS) { - GE_CHK_STATUS_RET(CheckDumpPath(dump_path), "Check dump path failed."); if (!dump_path.empty() && dump_path[dump_path.size() - 1] != '/') { dump_path = dump_path + "/"; } @@ -263,21 +75,25 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::InitByOp GELOGI("Get dump path %s successfully", dump_path.c_str()); SetDumpPath(dump_path); } else { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.dumpPath", - dump_path, - "ge.exec.dumpPath is not set."})); - GELOGE(FAILED, "[Check][dump_path] failed. Dump path is not set."); - return FAILED; + GELOGW("Dump path is not set"); } } - GE_CHK_STATUS_RET(SetDumpOptions(), "SetDumpOptions failed."); - - GE_CHK_STATUS_RET(SetDumpDebugOptions(), "SetDumpDebugOptions failed."); + if (enable_dump_ == kEnableFlag) { + std::string dump_step; + if (GetContext().GetOption(OPTION_EXEC_DUMP_STEP, dump_step) == GRAPH_SUCCESS) { + GELOGI("Get dump step %s successfully", dump_step.c_str()); + SetDumpStep(dump_step); + } + string dump_mode; + if (GetContext().GetOption(OPTION_EXEC_DUMP_MODE, dump_mode) == GRAPH_SUCCESS) { + GELOGI("Get dump mode %s successfully", dump_mode.c_str()); + SetDumpMode(dump_mode); + } + AddPropertyValue(DUMP_ALL_MODEL, {}); + } - return SUCCESS; + SetDumpDebugOptions(); } // The following is the new dump scenario of the fusion operator @@ -437,20 +253,14 @@ void DumpProperties::CopyFrom(const DumpProperties &other) { } } -Status DumpProperties::SetDumpDebugOptions() { +void DumpProperties::SetDumpDebugOptions() { if (enable_dump_debug_ == kEnableFlag) { std::string dump_debug_mode; if (GetContext().GetOption(OPTION_EXEC_DUMP_DEBUG_MODE, dump_debug_mode) == GRAPH_SUCCESS) { GELOGD("Get dump debug mode %s successfully", dump_debug_mode.c_str()); } else { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.dumpDebugMode", - dump_debug_mode, - "ge.exec.dumpDebugMode is not set."})); - GELOGE(PARAM_INVALID, "[Check][dump_debug_mode] failed. Dump debug mode is not set."); - - return PARAM_INVALID; + GELOGW("Dump debug mode is not set."); + return; } if (dump_debug_mode == OP_DEBUG_AICORE) { @@ -466,17 +276,10 @@ Status DumpProperties::SetDumpDebugOptions() { is_train_op_debug_ = true; op_debug_mode_ = kAllOverflow; } else { - REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), - std::vector({ - "ge.exec.dumpDebugMode", - dump_debug_mode, - "ge.exec.dumpDebugMode is invalid."})); - GELOGE(PARAM_INVALID, "[Set][DumpDebugOptions] failed, ge.exec.dumpDebugMode is invalid."); - return PARAM_INVALID; + GELOGW("ge.exec.dumpDebugMode is invalid."); } } else { GELOGI("ge.exec.enableDumpDebug is false or is not set."); } - return SUCCESS; } } // namespace ge diff --git a/ge/common/dump/dump_properties.h b/ge/common/dump/dump_properties.h index cbfc362d..98487491 100644 --- a/ge/common/dump/dump_properties.h +++ b/ge/common/dump/dump_properties.h @@ -23,7 +23,6 @@ #include namespace ge { -using Status = uint32_t; class DumpProperties { public: DumpProperties() = default; @@ -34,7 +33,7 @@ class DumpProperties { DumpProperties &operator=(const DumpProperties &dump); - Status InitByOptions(); + void InitByOptions(); void AddPropertyValue(const std::string &model, const std::set &layers); @@ -96,20 +95,7 @@ class DumpProperties { private: void CopyFrom(const DumpProperties &other); - Status SetDumpDebugOptions(); - - Status SetDumpOptions(); - - void Split(const std::string &s, std::vector &result, const char *delchar); - - Status CheckDumpStep(const std::string &dump_step); - - Status CheckDumpMode(const std::string &dump_mode); - - Status CheckDumpPath(const std::string &input); - - Status CheckEnableDump(const std::string &input); - + void SetDumpDebugOptions(); std::string enable_dump_; std::string enable_dump_debug_; diff --git a/ge/session/inner_session.cc b/ge/session/inner_session.cc index 58b78f41..54e62d32 100755 --- a/ge/session/inner_session.cc +++ b/ge/session/inner_session.cc @@ -121,7 +121,7 @@ Status InnerSession::Initialize() { GE_CHK_RT_RET(rtSetDevice(GetContext().DeviceId())); DumpProperties dump_properties; - GE_CHK_STATUS_RET(dump_properties.InitByOptions(), "Init dump properties failed."); + dump_properties.InitByOptions(); GE_CHK_STATUS_RET(AddDumpProperties(dump_properties), "[Add][DumpProperties] failed."); ret = graph_manager_.Initialize(options_); diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 5b8958b4..f808bce7 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -780,7 +780,6 @@ set(MULTI_PARTS_TEST_FILES "common/util_unittest.cc" "common/dump_manager_unittest.cc" "common/dump_op_unittest.cc" - "common/dump_properties_unittest.cc" "common/dump_exception_unittest.cc" "common/opdebug_register_unittest.cc" "common/format_transfer_unittest.cc" diff --git a/tests/ut/ge/common/dump_properties_unittest.cc b/tests/ut/ge/common/dump_properties_unittest.cc deleted file mode 100644 index 57809013..00000000 --- a/tests/ut/ge/common/dump_properties_unittest.cc +++ /dev/null @@ -1,126 +0,0 @@ -/** - * 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 - -#define protected public -#define private public - -#include "common/dump/dump_properties.h" -#include "ge_local_context.h" -#include "ge/ge_api_types.h" -#include "common/debug/log.h" -#include "common/ge_inner_error_codes.h" - -namespace ge { -class UTEST_dump_properties : public testing::Test { - protected: - void SetUp() {} - void TearDown() {} -}; - -TEST_F(UTEST_dump_properties, check_dump_step) { - DumpProperties dp; - std::string dump_step{"0|3-5|10"}; - std::string unsupport_input1{"0|5-3|10"}; - std::string unsupport_input2{"one"}; - std::string unsupport_input3; - for (int i = 0; i < 200; ++i) { - unsupport_input3 += std::to_string(i) + "|"; - } - unsupport_input3.pop_back(); - Status st = dp.CheckDumpStep(dump_step); - EXPECT_EQ(st, SUCCESS); - st = dp.CheckDumpStep(unsupport_input1); - EXPECT_NE(st, SUCCESS); - st = dp.CheckDumpStep(unsupport_input2); - EXPECT_NE(st, SUCCESS); - st = dp.CheckDumpStep(unsupport_input3); - EXPECT_NE(st, SUCCESS); -} - -TEST_F(UTEST_dump_properties, check_dump_mode) { - DumpProperties dp; - std::string dump_mode_1{"input"}; - std::string dump_mode_2{"output"}; - std::string dump_mode_3{"all"}; - std::string unsupport_input1{"mode1"}; - Status st = dp.CheckDumpMode(dump_mode_1); - EXPECT_EQ(st, SUCCESS); - st = dp.CheckDumpMode(dump_mode_2); - EXPECT_EQ(st, SUCCESS); - st = dp.CheckDumpMode(dump_mode_3); - EXPECT_EQ(st, SUCCESS); - st = dp.CheckDumpMode(unsupport_input1); - EXPECT_NE(st, SUCCESS); -} - -TEST_F(UTEST_dump_properties, check_dump_path) { - DumpProperties dp; - std::string dump_path{"/tmp/"}; - std::string unsupport_input1{" \\unsupported"}; - Status st = dp.CheckDumpPath(dump_path); - EXPECT_EQ(st, SUCCESS); - st = dp.CheckDumpPath(unsupport_input1); - EXPECT_NE(st, SUCCESS); -} - -TEST_F(UTEST_dump_properties, check_enable_dump) { - DumpProperties dp; - std::string enable_dump_t{"1"}; - std::string enable_dump_f{"0"}; - std::string unsupport_input1{"true"}; - std::string unsupport_input2{"false"}; - Status st = dp.CheckEnableDump(enable_dump_t); - EXPECT_EQ(st, SUCCESS); - st = dp.CheckEnableDump(enable_dump_f); - EXPECT_EQ(st, SUCCESS); - st = dp.CheckEnableDump(unsupport_input1); - EXPECT_NE(st, SUCCESS); - st = dp.CheckEnableDump(unsupport_input2); - EXPECT_NE(st, SUCCESS); -} - -TEST_F(UTEST_dump_properties, init_by_options_success_1) { - DumpProperties dp; - std::map options {{OPTION_EXEC_ENABLE_DUMP, "1"}, - {OPTION_EXEC_DUMP_PATH, "/tmp/"}, - {OPTION_EXEC_DUMP_STEP, "0|1-3|10"}, - {OPTION_EXEC_DUMP_MODE, "all"}}; - GetThreadLocalContext().SetGlobalOption(options); - Status st = dp.InitByOptions(); - EXPECT_EQ(st, SUCCESS); -} - -TEST_F(UTEST_dump_properties, init_by_options_success_2) { - DumpProperties dp; - std::map options {{OPTION_EXEC_ENABLE_DUMP_DEBUG, "1"}, - {OPTION_EXEC_DUMP_PATH, "/tmp/"}, - {OPTION_EXEC_DUMP_DEBUG_MODE, "aicore_overflow"}}; - GetThreadLocalContext().SetGlobalOption(options); - Status st = dp.InitByOptions(); - EXPECT_EQ(st, SUCCESS); -} - -TEST_F(UTEST_dump_properties, init_by_options_failed) { - DumpProperties dp; - std::map options {{OPTION_EXEC_ENABLE_DUMP_DEBUG, "1"}, - {OPTION_EXEC_DUMP_PATH, "/tmp/"}}; - GetThreadLocalContext().SetGlobalOption(options); - Status st = dp.InitByOptions(); - EXPECT_NE(st, SUCCESS); -} -} // namespace ge \ No newline at end of file From 7fdb8aad95f00f2d360fba9bf727928f988d6adf Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Wed, 30 Jun 2021 19:51:10 +0800 Subject: [PATCH 37/50] Fix ut. --- ge/single_op/single_op.h | 1 + ge/single_op/single_op_model.cc | 42 +++---------------- ge/single_op/single_op_model.h | 2 - .../node_executor/node_executor_unittest.cc | 5 ++- 4 files changed, 10 insertions(+), 40 deletions(-) diff --git a/ge/single_op/single_op.h b/ge/single_op/single_op.h index 94d7227b..7e05dd5f 100755 --- a/ge/single_op/single_op.h +++ b/ge/single_op/single_op.h @@ -92,6 +92,7 @@ class DynamicSingleOp { rtStream_t stream_ = nullptr; size_t num_inputs_ = 0; size_t num_outputs_ = 0; + ComputeGraphPtr compute_graph_; }; } // namespace ge #endif // GE_SINGLE_OP_SINGLE_OP_H_ diff --git a/ge/single_op/single_op_model.cc b/ge/single_op/single_op_model.cc index e5d15beb..7f42f03c 100755 --- a/ge/single_op/single_op_model.cc +++ b/ge/single_op/single_op_model.cc @@ -529,44 +529,14 @@ Status SingleOpModel::BuildOp(StreamResource &resource, SingleOp &single_op) { return BuildTaskList(&resource, single_op); } -Status SingleOpModel::BuildModelTaskKernel(StreamResource *stream_resource, const TaskDef &task_def, - DynamicSingleOp &single_op) { - auto task_type = static_cast(task_def.type()); - const auto &context = task_type == RT_MODEL_TASK_KERNEL ? task_def.kernel().context() : - task_def.kernel_with_handle().context(); +Status SingleOpModel::BuildTaskListForDynamicOp(StreamResource *stream_resource, DynamicSingleOp &single_op) { + auto ge_model = model_helper_.GetGeModel(); + GE_CHECK_NOTNULL(ge_model); - auto kernel_type = static_cast(context.kernel_type()); - if (kernel_type == ccKernelType::TE) { - GELOGD("Building TBE task."); - TbeOpTask *tbe_task = nullptr; - GE_CHK_STATUS_RET_NOLOG(BuildKernelTask(task_def, &tbe_task)); - tbe_task->SetModelArgs(model_name_, model_id_); - if (tbe_task->tiling_buffer_ != nullptr) { - GELOGD("tiling buffer is not nullptr."); - tbe_task->stream_resource_ = stream_resource; - } - single_op.op_task_.reset(tbe_task); - } else if (kernel_type == ccKernelType::AI_CPU || kernel_type == ccKernelType::CUST_AI_CPU) { - GELOGD("Building AICPU_CC task"); - OpTask *task = nullptr; - uint64_t dynamic_singleop_kernel_id = aicpu_kernel_id++; - GELOGI("Build dynamic singleOp CCTask, kernel_id = %lu", dynamic_singleop_kernel_id); - GE_CHK_STATUS_RET_NOLOG(BuildCpuKernelTask(task_def.kernel(), &task, dynamic_singleop_kernel_id)); - task->SetModelArgs(model_name_, model_id_); - single_op.op_task_.reset(task); - } else { - GELOGE(ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID, - "[Check][Param:TaskDef]Only TBE, AI_CPU, CUST_AI_CPU kernel are supported, but got %u", - context.kernel_type()); - REPORT_INNER_ERROR("E19999", - "BuildModelTaskKernel fail for got:%u not supported, Only TBE, AI_CPU, CUST_AI_CPU kernel are supported.", - context.kernel_type()); - return ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID; - } - return SUCCESS; -} + auto compute_graph = GraphUtils::GetComputeGraph(ge_model->GetGraph()); + GE_CHECK_NOTNULL(compute_graph); + single_op.compute_graph_ = compute_graph; -Status SingleOpModel::BuildTaskListForDynamicOp(StreamResource *stream_resource, DynamicSingleOp &single_op) { if (tbe_tasks_.size() > 0) { const auto &task_def = tbe_tasks_[0]; GELOGD("Building TBE task."); diff --git a/ge/single_op/single_op_model.h b/ge/single_op/single_op_model.h index b5198e3d..45616d9a 100755 --- a/ge/single_op/single_op_model.h +++ b/ge/single_op/single_op_model.h @@ -71,8 +71,6 @@ class SingleOpModel { Status BuildKernelTask(const domi::TaskDef &task_def, TbeOpTask **task); Status BuildKernelExTask(const domi::KernelExDef &kernel_def, AiCpuTask **task, uint64_t kernel_id); Status BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTask **task, uint64_t kernel_id); - Status BuildModelTaskKernel(StreamResource *stream_resource, const domi::TaskDef &task_def, - DynamicSingleOp &single_op); static void ParseOpModelParams(ModelHelper &model_helper, SingleOpModelParam ¶m); void ParseArgTable(OpTask *task, SingleOp &op); diff --git a/tests/ut/ge/hybrid/node_executor/node_executor_unittest.cc b/tests/ut/ge/hybrid/node_executor/node_executor_unittest.cc index a6f5c2de..1d5bbb3d 100644 --- a/tests/ut/ge/hybrid/node_executor/node_executor_unittest.cc +++ b/tests/ut/ge/hybrid/node_executor/node_executor_unittest.cc @@ -87,6 +87,7 @@ TEST_F(NodeExecutorTest, TestGetOrCreateExecutor) { TEST_F(NodeExecutorTest, TestInitAndFinalize) { auto &manager = NodeExecutorManager::GetInstance(); manager.FinalizeExecutors(); + manager.FinalizeExecutors(); manager.EnsureInitialized(); manager.EnsureInitialized(); const NodeExecutor *executor = nullptr; @@ -97,7 +98,7 @@ TEST_F(NodeExecutorTest, TestInitAndFinalize) { manager.FinalizeExecutors(); ASSERT_FALSE(manager.executors_.empty()); manager.FinalizeExecutors(); - // ASSERT_TRUE(manager.executors_.empty()); - // ASSERT_TRUE(finalized); + ASSERT_TRUE(manager.executors_.empty()); + ASSERT_TRUE(finalized); } } // namespace ge From bf0ae87401ec1ef04fd803d79c832d53d35d1362 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Wed, 30 Jun 2021 20:09:47 +0800 Subject: [PATCH 38/50] Fix ut. --- ge/single_op/single_op_model.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ge/single_op/single_op_model.cc b/ge/single_op/single_op_model.cc index 7f42f03c..9a52a83d 100755 --- a/ge/single_op/single_op_model.cc +++ b/ge/single_op/single_op_model.cc @@ -536,7 +536,6 @@ Status SingleOpModel::BuildTaskListForDynamicOp(StreamResource *stream_resource, auto compute_graph = GraphUtils::GetComputeGraph(ge_model->GetGraph()); GE_CHECK_NOTNULL(compute_graph); single_op.compute_graph_ = compute_graph; - if (tbe_tasks_.size() > 0) { const auto &task_def = tbe_tasks_[0]; GELOGD("Building TBE task."); @@ -566,7 +565,7 @@ Status SingleOpModel::BuildTaskListForDynamicOp(StreamResource *stream_resource, GELOGI("Build dynamic singleOp TfTask, kernel_id = %lu", dynamic_singleop_kernel_id); GE_CHK_STATUS_RET_NOLOG(BuildKernelExTask(task_def.kernel_ex(), &aicpu_task, dynamic_singleop_kernel_id)); if (aicpu_task->GetUnknownType() == DEPEND_COMPUTE) { - if (aicpu_tasks_.size() < 2) { + if (aicpu_tasks_.size() < 2) { GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[Check][Task]The copy task of the fourth operator was not found."); REPORT_INNER_ERROR("E19999", "The copy task of the fourth operator was not found."); return ACL_ERROR_GE_PARAM_INVALID; From 4d1ec067f3d497f6ea95ddbfc7af8d0e6da836cb Mon Sep 17 00:00:00 2001 From: lianghao Date: Wed, 30 Jun 2021 19:48:29 +0800 Subject: [PATCH 39/50] FindLastBpFromBpNode --- ge/graph/build/task_generator.cc | 44 +++++++++---------- ge/graph/build/task_generator.h | 2 +- .../ge/graph/build/task_generator_unittest.cc | 4 +- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/ge/graph/build/task_generator.cc b/ge/graph/build/task_generator.cc index 5dee37d6..67289f73 100755 --- a/ge/graph/build/task_generator.cc +++ b/ge/graph/build/task_generator.cc @@ -793,7 +793,6 @@ Status TaskGenerator::AutoFindBpOpIndex(const ComputeGraphPtr &graph, ProfilingP GELOGI("Start AutoFindBpOpIndex"); NodePtr bp_node = nullptr; uint32_t current_idx = 0; - uint32_t netoutput_idx = 0; for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) { OpDescPtr op_desc = node->GetOpDesc(); GE_CHECK_NOTNULL(op_desc); @@ -811,7 +810,6 @@ Status TaskGenerator::AutoFindBpOpIndex(const ComputeGraphPtr &graph, ProfilingP if (op_desc->GetName() == NODE_NAME_NET_OUTPUT) { if (bp_node == nullptr) { bp_node = node; - netoutput_idx = current_idx - 1; } } if (graph->GetNeedIteration()) { @@ -836,34 +834,30 @@ Status TaskGenerator::AutoFindBpOpIndex(const ComputeGraphPtr &graph, ProfilingP if (bp_node == nullptr) { GELOGW("not find bp_node."); return SUCCESS; - } else if (bp_node->GetName() == NODE_NAME_NET_OUTPUT) { - profiling_point.bp_index = netoutput_idx; - GELOGI("First bp name %s, idx %u", bp_node->GetName().c_str(), netoutput_idx); - } else { - profiling_point.bp_index = FindLastBpFromBpNode(graph, bp_node); } - return SUCCESS; + return FindLastBpFromBpNode(graph, bp_node, profiling_point.bp_index); } -uint32_t TaskGenerator::FindLastBpFromBpNode(const ComputeGraphPtr &graph, const NodePtr &bp_node) const { - uint32_t last_bp = 0; +Status TaskGenerator::FindLastBpFromBpNode(const ComputeGraphPtr &graph, const NodePtr &target_node, + uint32_t &bp_index) const { + bp_index = 0; + auto target_desc = target_node->GetOpDesc(); + GE_CHECK_NOTNULL(target_desc); OpDescPtr bp_op_desc = nullptr; - for (auto &in_anchor : bp_node->GetAllInDataAnchors()) { - auto out_anchor = in_anchor->GetPeerOutAnchor(); - if (out_anchor == nullptr || out_anchor->GetOwnerNode() == nullptr) { - continue; - } - auto out_node_desc = out_anchor->GetOwnerNode()->GetOpDesc(); - GE_CHECK_NOTNULL(out_node_desc); - if (bp_op_desc == nullptr || ((out_node_desc->GetId()) > (bp_op_desc->GetId()))) { - bp_op_desc = out_node_desc; + for (auto &in_node : target_node->GetInAllNodes()) { + GE_CHECK_NOTNULL(in_node); + auto in_node_desc = in_node->GetOpDesc(); + GE_CHECK_NOTNULL(in_node_desc); + if ((bp_op_desc == nullptr || (in_node_desc->GetId() > bp_op_desc->GetId())) && + (in_node_desc->GetStreamId() == target_desc->GetStreamId())){ + bp_op_desc = in_node_desc; } - GELOGI("bp_op_desc is %s, id is %ld", bp_op_desc->GetName().c_str(), bp_op_desc->GetId()); } if (bp_op_desc == nullptr) { - return last_bp; + GELOGI("Did not find bp node."); + return SUCCESS; } uint32_t current_idx = 0; for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) { @@ -871,12 +865,14 @@ uint32_t TaskGenerator::FindLastBpFromBpNode(const ComputeGraphPtr &graph, const GE_CHECK_NOTNULL(op_desc); current_idx++; if (op_desc->GetName() == bp_op_desc->GetName()) { - last_bp = current_idx; - GELOGI("First bp name %s, idx %u", op_desc->GetName().c_str(), last_bp); + bp_index = current_idx; + GELOGI("Find bp name %s, idx %u", op_desc->GetName().c_str(), bp_index); break; } } - return last_bp; + GELOGI("Last bp node[%s], type[%s], index[%u], stream id[%ld]", bp_op_desc->GetName().c_str(), + bp_op_desc->GetType().c_str(), bp_index, bp_op_desc->GetStreamId()); + return SUCCESS; } Status TaskGenerator::FindFpOfEnv(const ComputeGraphPtr &graph, const std::string &fp_point_str, diff --git a/ge/graph/build/task_generator.h b/ge/graph/build/task_generator.h index 6f460906..5d204c3c 100755 --- a/ge/graph/build/task_generator.h +++ b/ge/graph/build/task_generator.h @@ -116,7 +116,7 @@ class TaskGenerator { Status AutoFindFpOpIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point) const; Status AutoFindBpOpIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point, vector &all_reduce_nodes) const; - uint32_t FindLastBpFromBpNode(const ComputeGraphPtr &graph, const NodePtr &bp_node) const; + Status FindLastBpFromBpNode(const ComputeGraphPtr &graph, const NodePtr &bp_node, uint32_t &bp_index) const; Status FindFpOfEnv(const ComputeGraphPtr &graph, const std::string &fp_point_str, ProfilingPoint &profiling_point) const; diff --git a/tests/ut/ge/graph/build/task_generator_unittest.cc b/tests/ut/ge/graph/build/task_generator_unittest.cc index f869f1e0..1e865050 100644 --- a/tests/ut/ge/graph/build/task_generator_unittest.cc +++ b/tests/ut/ge/graph/build/task_generator_unittest.cc @@ -116,7 +116,9 @@ TEST_F(UtestTaskGeneratorTest, FindLastBpFromBpNode) { TaskGenerator task_generator(nullptr, 0); auto net_output = graph->FindNode("Node_Output"); // netoutput has no data input, return default value 0 - EXPECT_EQ(task_generator.FindLastBpFromBpNode(graph, net_output), 0); + uint32_t bp_index = 0; + EXPECT_EQ(task_generator.FindLastBpFromBpNode(graph, net_output, bp_index), 0); + EXPECT_EQ(bp_index, 2); } TEST_F(UtestTaskGeneratorTest, UpdateOpIsVarAttr) { From 55189da9b32224951143b395713954ab66b2bf42 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Wed, 30 Jun 2021 21:01:46 +0800 Subject: [PATCH 40/50] Add Magic in single_op. --- ge/single_op/task/tbe_task_builder.cc | 25 ++++++++++++++++++- ge/single_op/task/tbe_task_builder.h | 1 + tests/ut/ge/hybrid/ge_hybrid_unittest.cc | 1 + .../ge/single_op/single_op_model_unittest.cc | 1 + .../ge/single_op/single_op_task_unittest.cc | 1 + 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ge/single_op/task/tbe_task_builder.cc b/ge/single_op/task/tbe_task_builder.cc index db8ecfe2..c1bafed8 100644 --- a/ge/single_op/task/tbe_task_builder.cc +++ b/ge/single_op/task/tbe_task_builder.cc @@ -104,7 +104,7 @@ Status TbeTaskBuilder::DoRegisterBinary(const OpKernelBin &kernel_bin, void **bi binary.version = 0; binary.data = kernel_bin.GetBinData(); binary.length = kernel_bin.GetBinDataSize(); - binary.magic = param.core_type == 0 ? RT_DEV_BINARY_MAGIC_ELF : RT_DEV_BINARY_MAGIC_ELF_AIVEC; + GE_CHK_STATUS_RET_NOLOG(GetMagic(binary.magic)); Status ret = 0; if (task_def_.type() == RT_MODEL_TASK_ALL_KERNEL) { ret = rtRegisterAllKernel(&binary, bin_handle); @@ -416,4 +416,27 @@ Status TbeTaskBuilder::InitTilingInfo(TbeOpTask &task) { task.EnableDynamicSupport(node_, tiling_buffer, static_cast(max_size)); return SUCCESS; } + +Status TbeTaskBuilder::GetMagic(uint32_t &magic) const { + std::string json_string; + GE_IF_BOOL_EXEC(AttrUtils::GetStr(op_desc_, TVM_ATTR_NAME_MAGIC, json_string), + GELOGD("Get original type of session_graph_id.")); + if (json_string == "RT_DEV_BINARY_MAGIC_ELF") { + magic = RT_DEV_BINARY_MAGIC_ELF; + } else if (json_string == "RT_DEV_BINARY_MAGIC_ELF_AIVEC") { + magic = RT_DEV_BINARY_MAGIC_ELF_AIVEC; + } else if (json_string == "RT_DEV_BINARY_MAGIC_ELF_AICUBE") { + magic = RT_DEV_BINARY_MAGIC_ELF_AICUBE; + } else { + REPORT_INNER_ERROR("E19999", "Attr:%s in op:%s(%s), value:%s check invalid", + TVM_ATTR_NAME_MAGIC.c_str(), op_desc_->GetName().c_str(), + op_desc_->GetType().c_str(), json_string.c_str()); + GELOGE(PARAM_INVALID, "[Check][Param] Attr:%s in op:%s(%s), value:%s check invalid", + TVM_ATTR_NAME_MAGIC.c_str(), op_desc_->GetName().c_str(), + op_desc_->GetType().c_str(), json_string.c_str()); + return PARAM_INVALID; + } + return SUCCESS; +} + } // namespace ge diff --git a/ge/single_op/task/tbe_task_builder.h b/ge/single_op/task/tbe_task_builder.h index a202cbf1..6252feea 100755 --- a/ge/single_op/task/tbe_task_builder.h +++ b/ge/single_op/task/tbe_task_builder.h @@ -105,6 +105,7 @@ class TbeTaskBuilder { const SingleOpModelParam ¶m); Status DoRegisterBinary(const OpKernelBin &kernel_bin, void **bin_handle, const SingleOpModelParam ¶m) const; Status DoRegisterMeta(void *bin_handle); + Status GetMagic(uint32_t &magic) const; static Status DoRegisterFunction(void *bin_handle, const char *stub_name, const char *kernel_name); diff --git a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc index 1d1c4fa9..d1c51c67 100644 --- a/tests/ut/ge/hybrid/ge_hybrid_unittest.cc +++ b/tests/ut/ge/hybrid/ge_hybrid_unittest.cc @@ -153,6 +153,7 @@ TEST_F(UtestGeHybrid, task_update_tiling_info) { ge::AttrUtils::SetStr(op_desc, "compile_info_json", "json"); ge::AttrUtils::SetBool(op_desc, "support_dynamicshape", true); ge::AttrUtils::SetInt(op_desc, "op_para_size", 1); + ge::AttrUtils::SetStr(op_desc, TVM_ATTR_NAME_MAGIC, "RT_DEV_BINARY_MAGIC_ELF"); auto node = graph->AddNode(op_desc); std::unique_ptr node_item; diff --git a/tests/ut/ge/single_op/single_op_model_unittest.cc b/tests/ut/ge/single_op/single_op_model_unittest.cc index 2c0073f5..23269814 100644 --- a/tests/ut/ge/single_op/single_op_model_unittest.cc +++ b/tests/ut/ge/single_op/single_op_model_unittest.cc @@ -338,6 +338,7 @@ TEST_F(UtestSingleOpModel, build_dynamic_task) { DynamicSingleOp single_op(0, &stream_mu, stream); model.model_helper_.model_ = ge_model; auto op_desc = std::make_shared("add", "Add"); + AttrUtils::SetStr(op_desc, TVM_ATTR_NAME_MAGIC, "RT_DEV_BINARY_MAGIC_ELF"); 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); diff --git a/tests/ut/ge/single_op/single_op_task_unittest.cc b/tests/ut/ge/single_op/single_op_task_unittest.cc index b0c98205..2424d209 100644 --- a/tests/ut/ge/single_op/single_op_task_unittest.cc +++ b/tests/ut/ge/single_op/single_op_task_unittest.cc @@ -54,6 +54,7 @@ TEST_F(UtestSingleOpTask, test_build_kernel_task) { auto graph = make_shared("graph"); auto op_desc = make_shared("Add", "Add"); + AttrUtils::SetStr(op_desc, TVM_ATTR_NAME_MAGIC, "RT_DEV_BINARY_MAGIC_ELF"); 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); From 47852ba2b4e641685ce98f0c39fe97e415261524 Mon Sep 17 00:00:00 2001 From: wangkai Date: Wed, 30 Jun 2021 22:05:07 +0800 Subject: [PATCH 41/50] add ace header targets Signed-off-by: wangkai --- ge/common/CMakeLists.txt | 2 ++ ge/executor/CMakeLists.txt | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/ge/common/CMakeLists.txt b/ge/common/CMakeLists.txt index 313f1ff3..1872b4c2 100755 --- a/ge/common/CMakeLists.txt +++ b/ge/common/CMakeLists.txt @@ -95,6 +95,7 @@ target_link_libraries(ge_common PRIVATE $<$>:$> $<$>:$> $<$>:$> + $<$>:$> static_mmpa -Wl,--no-as-needed graph @@ -155,6 +156,7 @@ target_link_libraries(ge_common_static PRIVATE $<$>:$> $<$>:$> $<$>:$> + $<$>:$> ascend_protobuf_static json c_sec diff --git a/ge/executor/CMakeLists.txt b/ge/executor/CMakeLists.txt index f258dffe..44ba3131 100755 --- a/ge/executor/CMakeLists.txt +++ b/ge/executor/CMakeLists.txt @@ -186,6 +186,8 @@ target_include_directories(ge_executor SYSTEM PRIVATE ${CMAKE_BINARY_DIR}/proto/graphengine_protos #### yellow zone #### $<$>:${GE_DEPEND_DIR}/inc> + $<$>:$> + $<$>:$> #### blue zone #### $<$:${GE_CODE_DIR}/third_party/fwkacllib/inc> $<$:${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain> @@ -251,6 +253,8 @@ target_link_libraries(ge_executor_shared PRIVATE $<$>:$> $<$>:$> $<$>:$> + $<$>:$> + $<$>:$> -Wl,--no-as-needed ge_common runtime From 977d507d027bcc8c56a8f0a48b4de3000417d428 Mon Sep 17 00:00:00 2001 From: wuweikang Date: Fri, 18 Jun 2021 09:32:57 +0800 Subject: [PATCH 42/50] check dump option --- ge/common/dump/dump_properties.cc | 243 ++++++++++++++++-- ge/common/dump/dump_properties.h | 18 +- ge/session/inner_session.cc | 2 +- tests/ut/ge/CMakeLists.txt | 1 + .../ut/ge/common/dump_properties_unittest.cc | 126 +++++++++ 5 files changed, 364 insertions(+), 26 deletions(-) create mode 100644 tests/ut/ge/common/dump_properties_unittest.cc diff --git a/ge/common/dump/dump_properties.cc b/ge/common/dump/dump_properties.cc index ef755540..84bdb7bf 100644 --- a/ge/common/dump/dump_properties.cc +++ b/ge/common/dump/dump_properties.cc @@ -18,6 +18,7 @@ #include #include +#include #include "common/ge/ge_util.h" #include "framework/common/util.h" @@ -37,6 +38,159 @@ const uint32_t kAtomicOverflow = (0x1 << 1); const uint32_t kAllOverflow = (kAicoreOverflow | kAtomicOverflow); } // namespace namespace ge { +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::Split(const std::string &s, + std::vector &result, + const char *delchar) { + if (s.empty()) { + return; + } + result.clear(); + + char *buffer = new (std::nothrow)char[s.size() + 1]; + if (buffer == nullptr) { + GELOGE(FAILED, "[Split][string] failed while malloc memory, string value is:%s", s.c_str()); + REPORT_CALL_ERROR("E19999", "Memory malloc may fail when split string, get fatal exception, " + "string value is:%s", s.c_str()); + return; + } + buffer[s.size()] = '\0'; + errno_t e = strcpy_s(buffer, s.size() + 1, s.c_str()); + if (e != EOK) { + delete[] buffer; + return; + } + char *context = nullptr; + char *p = strtok_s(buffer, delchar, &context); + while (p != nullptr) { + result.emplace_back(p); + p = strtok_s(nullptr, delchar, &context); + } + delete[] buffer; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckDumpStep(const std::string &dump_step) { + std::string modified_dum_step = dump_step + "|"; + std::smatch result; + std::vector match_vecs; + std::regex pattern(R"((\d{1,}-\d{1,}\||\d{1,}\|)+)"); + if (regex_match(modified_dum_step, result, pattern)) { + Split(result.str(), match_vecs, "|"); + if (match_vecs.empty()) { + REPORT_CALL_ERROR("E19999", "Split may get fatal exception, dump_step:%s.", dump_step.c_str()); + GELOGE(FAILED, "[Check][Param] failed. Split may get fatal exception, ge.exec.dumpStep:%s.", dump_step.c_str()); + return FAILED; + } + // 100 is the max sets of dump steps. + if (match_vecs.size() > 100) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpStep", + dump_step.c_str(), + " is not supported, only support dump <= 100 sets of data"})); + GELOGE(PARAM_INVALID, "[Check][Param] get dump_step value:%s, " + "dump_step only support dump <= 100 sets of data.", dump_step.c_str()); + return PARAM_INVALID; + } + for (const auto &match_vec : match_vecs) { + std::vector vec_after_split; + Split(match_vec, vec_after_split, "-"); + if (match_vecs.empty()) { + REPORT_CALL_ERROR("E19999", "Split may get fatal exception."); + GELOGE(FAILED, "[Check][Param] failed, split may get fatal exception."); + return FAILED; + } + if (vec_after_split.size() > 1) { + if (std::atoi(vec_after_split[0].c_str()) >= std::atoi(vec_after_split[1].c_str())) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpStep", + dump_step.c_str(), + " is not supported." + "in range steps, the first step is >= second step, correct example:'0|5|10-20"})); + GELOGE(PARAM_INVALID, "[Check][Param] get dump_step value:%s, " + "in range steps, the first step is >= second step, correct example:'0|5|10-20'", dump_step.c_str()); + return PARAM_INVALID; + } + } + } + } else { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpStep", + dump_step.c_str(), + " is not supported, correct example:'0|5|10|50-100."})); + GELOGE(PARAM_INVALID, "[Check][Param] get dump_step value:%s, " + "dump_step string style is error, correct example:'0|5|10|50-100.'", dump_step.c_str()); + return PARAM_INVALID; + } + return SUCCESS; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckDumpMode(const std::string &dump_mode) { + const std::set dump_mode_list = {"input", "output", "all"}; + std::set::iterator iter; + + if ((iter = dump_mode_list.find(dump_mode)) == dump_mode_list.end()) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpMode", + dump_mode.c_str(), + " is not supported, should be one of the following:[input, output, all]"})); + GELOGE(PARAM_INVALID, "[Check][Param] the dump_debug_mode:%s, is is not supported," + "should be one of the following:[input, output, all].", dump_mode.c_str()); + return PARAM_INVALID; + } + return SUCCESS; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckDumpPath(const std::string &input) { + if (mmIsDir(input.c_str()) != EN_OK) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpPath", + input.c_str(), + " is not a directory."})); + GELOGE(PARAM_INVALID, "[Check][Param] the path:%s, is not directory.", input.c_str()); + return PARAM_INVALID; + } + char trusted_path[MMPA_MAX_PATH] = { "\0" }; + if (mmRealPath(input.c_str(), trusted_path, MMPA_MAX_PATH) != EN_OK) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpPath", + input.c_str(), + " dumpPath invalid."})); + GELOGE(PARAM_INVALID, "[Check][Param] the dumpPath:%s, is invalid.", input.c_str()); + return PARAM_INVALID; + } + if (mmAccess2(trusted_path, M_R_OK | M_W_OK) != EN_OK) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpPath", + input.c_str(), + " does't have read, write permissions."})); + GELOGE(PARAM_INVALID, "[Check][Param] the path:%s, does't have read, write permissions.", input.c_str()); + return PARAM_INVALID; + } + return SUCCESS; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::CheckEnableDump(const std::string &input) { + std::set enable_dump_option_list = {"1", "0"}; + auto it = enable_dump_option_list.find(input); + if (it == enable_dump_option_list.end()) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.enableDump", + input.c_str(), + " only support 1 or 0."})); + GELOGE(PARAM_INVALID, "[Check][Param] Not support ge.exec.enableDump or ge.exec.enableDumpDebug format:%s, " + "only support 1 or 0.", input.c_str()); + return PARAM_INVALID; + } + return SUCCESS; +} + FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties::DumpProperties(const DumpProperties &other) { CopyFrom(other); } @@ -47,7 +201,26 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties &DumpProperties: return *this; } -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::InitByOptions() { +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::SetDumpOptions() { + if (enable_dump_ == kEnableFlag) { + std::string dump_step; + if (GetContext().GetOption(OPTION_EXEC_DUMP_STEP, dump_step) == GRAPH_SUCCESS) { + GE_CHK_STATUS_RET(CheckDumpStep(dump_step), "[Check][dump_step] failed."); + GELOGI("Get dump step %s successfully", dump_step.c_str()); + SetDumpStep(dump_step); + } + string dump_mode = "output"; + if (GetContext().GetOption(OPTION_EXEC_DUMP_MODE, dump_mode) == GRAPH_SUCCESS) { + GELOGI("Get dump mode %s successfully", dump_mode.c_str()); + GE_CHK_STATUS_RET(CheckDumpMode(dump_mode), "[Check][dump_mode] failed."); + SetDumpMode(dump_mode); + } + AddPropertyValue(DUMP_ALL_MODEL, {}); + } + return SUCCESS; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpProperties::InitByOptions() { enable_dump_.clear(); enable_dump_debug_.clear(); dump_path_.clear(); @@ -57,17 +230,32 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::InitByOpti is_infer_op_debug_ = false; op_debug_mode_ = 0; - std::string enable_dump; + std::string enable_dump = std::to_string(false); (void)GetContext().GetOption(OPTION_EXEC_ENABLE_DUMP, enable_dump); enable_dump_ = enable_dump; + if (!enable_dump_.empty()) { + GE_CHK_STATUS_RET(CheckEnableDump(enable_dump_), "[Check][enable_dump] failed."); + } - std::string enable_dump_debug; + std::string enable_dump_debug = std::to_string(false); (void)GetContext().GetOption(OPTION_EXEC_ENABLE_DUMP_DEBUG, enable_dump_debug); enable_dump_debug_ = enable_dump_debug; - + if (!enable_dump_debug_.empty()) { + GE_CHK_STATUS_RET(CheckEnableDump(enable_dump_debug_), "[Check][enable_dump_debug] failed."); + } + if ((enable_dump_ == kEnableFlag) && (enable_dump_debug_ == kEnableFlag)) { + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.enableDump and ge.exec.enableDumpDebug", + enable_dump_ + ", " + enable_dump_debug, + "ge.exec.enableDump and ge.exec.enableDumpDebug cannot be set to 1 at the same time."})); + GELOGE(FAILED, "ge.exec.enableDump and ge.exec.enableDumpDebug cannot be both set to 1 at the same time."); + return FAILED; + } if ((enable_dump_ == kEnableFlag) || (enable_dump_debug_ == kEnableFlag)) { std::string dump_path; if (GetContext().GetOption(OPTION_EXEC_DUMP_PATH, dump_path) == GRAPH_SUCCESS) { + GE_CHK_STATUS_RET(CheckDumpPath(dump_path), "Check dump path failed."); if (!dump_path.empty() && dump_path[dump_path.size() - 1] != '/') { dump_path = dump_path + "/"; } @@ -75,25 +263,21 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::InitByOpti GELOGI("Get dump path %s successfully", dump_path.c_str()); SetDumpPath(dump_path); } else { - GELOGW("Dump path is not set"); + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpPath", + dump_path, + "ge.exec.dumpPath is not set."})); + GELOGE(FAILED, "[Check][dump_path] failed. Dump path is not set."); + return FAILED; } } - if (enable_dump_ == kEnableFlag) { - std::string dump_step; - if (GetContext().GetOption(OPTION_EXEC_DUMP_STEP, dump_step) == GRAPH_SUCCESS) { - GELOGI("Get dump step %s successfully", dump_step.c_str()); - SetDumpStep(dump_step); - } - string dump_mode; - if (GetContext().GetOption(OPTION_EXEC_DUMP_MODE, dump_mode) == GRAPH_SUCCESS) { - GELOGI("Get dump mode %s successfully", dump_mode.c_str()); - SetDumpMode(dump_mode); - } - AddPropertyValue(DUMP_ALL_MODEL, {}); - } + GE_CHK_STATUS_RET(SetDumpOptions(), "SetDumpOptions failed."); + + GE_CHK_STATUS_RET(SetDumpDebugOptions(), "SetDumpDebugOptions failed."); - SetDumpDebugOptions(); + return SUCCESS; } // The following is the new dump scenario of the fusion operator @@ -253,14 +437,20 @@ void DumpProperties::CopyFrom(const DumpProperties &other) { } } -void DumpProperties::SetDumpDebugOptions() { +Status DumpProperties::SetDumpDebugOptions() { if (enable_dump_debug_ == kEnableFlag) { std::string dump_debug_mode; if (GetContext().GetOption(OPTION_EXEC_DUMP_DEBUG_MODE, dump_debug_mode) == GRAPH_SUCCESS) { GELOGD("Get dump debug mode %s successfully", dump_debug_mode.c_str()); } else { - GELOGW("Dump debug mode is not set."); - return; + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpDebugMode", + dump_debug_mode, + "ge.exec.dumpDebugMode is not set."})); + GELOGE(PARAM_INVALID, "[Check][dump_debug_mode] failed. Dump debug mode is not set."); + + return PARAM_INVALID; } if (dump_debug_mode == OP_DEBUG_AICORE) { @@ -276,10 +466,17 @@ void DumpProperties::SetDumpDebugOptions() { is_train_op_debug_ = true; op_debug_mode_ = kAllOverflow; } else { - GELOGW("ge.exec.dumpDebugMode is invalid."); + REPORT_INPUT_ERROR("E10001", std::vector({"parameter", "value", "reason"}), + std::vector({ + "ge.exec.dumpDebugMode", + dump_debug_mode, + "ge.exec.dumpDebugMode is invalid."})); + GELOGE(PARAM_INVALID, "[Set][DumpDebugOptions] failed, ge.exec.dumpDebugMode is invalid."); + return PARAM_INVALID; } } else { GELOGI("ge.exec.enableDumpDebug is false or is not set."); } + return SUCCESS; } } // namespace ge diff --git a/ge/common/dump/dump_properties.h b/ge/common/dump/dump_properties.h index 98487491..cbfc362d 100644 --- a/ge/common/dump/dump_properties.h +++ b/ge/common/dump/dump_properties.h @@ -23,6 +23,7 @@ #include namespace ge { +using Status = uint32_t; class DumpProperties { public: DumpProperties() = default; @@ -33,7 +34,7 @@ class DumpProperties { DumpProperties &operator=(const DumpProperties &dump); - void InitByOptions(); + Status InitByOptions(); void AddPropertyValue(const std::string &model, const std::set &layers); @@ -95,7 +96,20 @@ class DumpProperties { private: void CopyFrom(const DumpProperties &other); - void SetDumpDebugOptions(); + Status SetDumpDebugOptions(); + + Status SetDumpOptions(); + + void Split(const std::string &s, std::vector &result, const char *delchar); + + Status CheckDumpStep(const std::string &dump_step); + + Status CheckDumpMode(const std::string &dump_mode); + + Status CheckDumpPath(const std::string &input); + + Status CheckEnableDump(const std::string &input); + std::string enable_dump_; std::string enable_dump_debug_; diff --git a/ge/session/inner_session.cc b/ge/session/inner_session.cc index aabbe19c..b3df08ce 100755 --- a/ge/session/inner_session.cc +++ b/ge/session/inner_session.cc @@ -109,7 +109,7 @@ Status InnerSession::Initialize() { GE_CHK_RT_RET(rtSetDevice(GetContext().DeviceId())); DumpProperties dump_properties; - dump_properties.InitByOptions(); + GE_CHK_STATUS_RET(dump_properties.InitByOptions(), "Init dump properties failed."); GE_CHK_STATUS_RET(AddDumpProperties(dump_properties), "[Add][DumpProperties] failed."); ret = graph_manager_.Initialize(options_); diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index cf573343..d7568ccc 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -774,6 +774,7 @@ set(MULTI_PARTS_TEST_FILES "common/util_unittest.cc" "common/dump_manager_unittest.cc" "common/dump_op_unittest.cc" + "common/dump_properties_unittest.cc" "common/dump_exception_unittest.cc" "common/opdebug_register_unittest.cc" "common/format_transfer_unittest.cc" diff --git a/tests/ut/ge/common/dump_properties_unittest.cc b/tests/ut/ge/common/dump_properties_unittest.cc new file mode 100644 index 00000000..57809013 --- /dev/null +++ b/tests/ut/ge/common/dump_properties_unittest.cc @@ -0,0 +1,126 @@ +/** + * 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 + +#define protected public +#define private public + +#include "common/dump/dump_properties.h" +#include "ge_local_context.h" +#include "ge/ge_api_types.h" +#include "common/debug/log.h" +#include "common/ge_inner_error_codes.h" + +namespace ge { +class UTEST_dump_properties : public testing::Test { + protected: + void SetUp() {} + void TearDown() {} +}; + +TEST_F(UTEST_dump_properties, check_dump_step) { + DumpProperties dp; + std::string dump_step{"0|3-5|10"}; + std::string unsupport_input1{"0|5-3|10"}; + std::string unsupport_input2{"one"}; + std::string unsupport_input3; + for (int i = 0; i < 200; ++i) { + unsupport_input3 += std::to_string(i) + "|"; + } + unsupport_input3.pop_back(); + Status st = dp.CheckDumpStep(dump_step); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckDumpStep(unsupport_input1); + EXPECT_NE(st, SUCCESS); + st = dp.CheckDumpStep(unsupport_input2); + EXPECT_NE(st, SUCCESS); + st = dp.CheckDumpStep(unsupport_input3); + EXPECT_NE(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, check_dump_mode) { + DumpProperties dp; + std::string dump_mode_1{"input"}; + std::string dump_mode_2{"output"}; + std::string dump_mode_3{"all"}; + std::string unsupport_input1{"mode1"}; + Status st = dp.CheckDumpMode(dump_mode_1); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckDumpMode(dump_mode_2); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckDumpMode(dump_mode_3); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckDumpMode(unsupport_input1); + EXPECT_NE(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, check_dump_path) { + DumpProperties dp; + std::string dump_path{"/tmp/"}; + std::string unsupport_input1{" \\unsupported"}; + Status st = dp.CheckDumpPath(dump_path); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckDumpPath(unsupport_input1); + EXPECT_NE(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, check_enable_dump) { + DumpProperties dp; + std::string enable_dump_t{"1"}; + std::string enable_dump_f{"0"}; + std::string unsupport_input1{"true"}; + std::string unsupport_input2{"false"}; + Status st = dp.CheckEnableDump(enable_dump_t); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckEnableDump(enable_dump_f); + EXPECT_EQ(st, SUCCESS); + st = dp.CheckEnableDump(unsupport_input1); + EXPECT_NE(st, SUCCESS); + st = dp.CheckEnableDump(unsupport_input2); + EXPECT_NE(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, init_by_options_success_1) { + DumpProperties dp; + std::map options {{OPTION_EXEC_ENABLE_DUMP, "1"}, + {OPTION_EXEC_DUMP_PATH, "/tmp/"}, + {OPTION_EXEC_DUMP_STEP, "0|1-3|10"}, + {OPTION_EXEC_DUMP_MODE, "all"}}; + GetThreadLocalContext().SetGlobalOption(options); + Status st = dp.InitByOptions(); + EXPECT_EQ(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, init_by_options_success_2) { + DumpProperties dp; + std::map options {{OPTION_EXEC_ENABLE_DUMP_DEBUG, "1"}, + {OPTION_EXEC_DUMP_PATH, "/tmp/"}, + {OPTION_EXEC_DUMP_DEBUG_MODE, "aicore_overflow"}}; + GetThreadLocalContext().SetGlobalOption(options); + Status st = dp.InitByOptions(); + EXPECT_EQ(st, SUCCESS); +} + +TEST_F(UTEST_dump_properties, init_by_options_failed) { + DumpProperties dp; + std::map options {{OPTION_EXEC_ENABLE_DUMP_DEBUG, "1"}, + {OPTION_EXEC_DUMP_PATH, "/tmp/"}}; + GetThreadLocalContext().SetGlobalOption(options); + Status st = dp.InitByOptions(); + EXPECT_NE(st, SUCCESS); +} +} // namespace ge \ No newline at end of file From 2daa03a052674a47a576fd834b20fc2e8cbf1db6 Mon Sep 17 00:00:00 2001 From: lianghuikang <505519763@qq.com> Date: Wed, 30 Jun 2021 09:08:41 +0800 Subject: [PATCH 43/50] op_select_implmode support high_precision_for_all and high_performance_for_all --- ge/ir_build/option_utils.cc | 9 +++++++-- ge/offline/main.cc | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ge/ir_build/option_utils.cc b/ge/ir_build/option_utils.cc index 16586c4e..7287fe91 100755 --- a/ge/ir_build/option_utils.cc +++ b/ge/ir_build/option_utils.cc @@ -50,6 +50,8 @@ const std::set kBufferOptimizeSupportOption = {"l1_optimize", "l2_o const char *const kBufferOptimizeSupport = "only support l2_optimize, off_optimize"; const char *const IR_OPTION_OP_SELECT_IMPLMODE_DEFAULT = "high_performance"; const char *const IR_OPTION_OP_SELECT_IMPLMODE_PRECISON = "high_precision"; +const char *const IR_OPTION_OP_SELECT_IMPLMODE_HIGH_PRECISION_FOR_ALL = "high_precision_for_all"; +const char *const IR_OPTION_OP_SELECT_IMPLMODE_HIGH_PERFORMANCE_FOR_ALL = "high_performance_for_all"; const char *const kInputShapeSample1 = "\"input_name1:n1,c1,h1,w1\""; const char *const kInputShapeSample2 = "\"input_name1:1,3,224,224\""; const char *const kSplitError1 = "size not equal to 2 split by \":\""; @@ -57,7 +59,8 @@ const char *const kEmptyError = "can not be empty"; const char *const kFloatNumError = "exist float number"; const char *const kDigitError = "is not digit"; const char *const kCompressWeightError = "it must be appointed when appoint parameter[--optypelist_for_implmode]"; -const char *const kSelectImplmodeError = "only support high_performance, high_precision"; +const char *const kSelectImplmodeError = "only support high_performance, high_precision, " + "high_precision_for_all, high_performance_for_all"; const char *const kDynamicBatchSizeError = "It can only contains digit, \",\", \" \""; const char *const kDynamicImageSizeError = "It can only contains digit, \",\", \" \" and \";\""; const char *const kKeepDtypeError = "file not found"; @@ -782,7 +785,9 @@ Status CheckImplmodeParamValid(const std::string &optypelist_for_implmode, std:: op_select_implmode = IR_OPTION_OP_SELECT_IMPLMODE_DEFAULT; } else { if (op_select_implmode != IR_OPTION_OP_SELECT_IMPLMODE_DEFAULT && - op_select_implmode != IR_OPTION_OP_SELECT_IMPLMODE_PRECISON) { + op_select_implmode != IR_OPTION_OP_SELECT_IMPLMODE_PRECISON && + op_select_implmode != IR_OPTION_OP_SELECT_IMPLMODE_HIGH_PRECISION_FOR_ALL && + op_select_implmode != IR_OPTION_OP_SELECT_IMPLMODE_HIGH_PERFORMANCE_FOR_ALL) { ErrorManager::GetInstance().ATCReportErrMessage("E10001", {"parameter", "value", "reason"}, {"--op_select_implmode", op_select_implmode.c_str(), kSelectImplmodeError}); diff --git a/ge/offline/main.cc b/ge/offline/main.cc index 4837653f..bc3b823d 100755 --- a/ge/offline/main.cc +++ b/ge/offline/main.cc @@ -143,7 +143,8 @@ DEFINE_string(output_type, "", DEFINE_string(op_select_implmode, "", "Optional; op select implmode! " - "Support high_precision, high_performance."); + "Support high_precision, high_performance, " + "high_precision_for_all, high_performance_for_all."); DEFINE_string(optypelist_for_implmode, "", "Optional; Nodes need use implmode selected in op_select_implmode " @@ -311,8 +312,8 @@ class GFlagUtils { "scenarios by using a configuration file.\n" " --auto_tune_mode Set tune mode. E.g.: \"GA,RL\", support configure multiple, spit by ,\n" " --op_bank_path Set the path of the custom repository generated after operator tuning with Auto Tune.\n" - " --op_select_implmode Set op select implmode. Support high_precision, high_performance. " - "default: high_performance\n" + " --op_select_implmode Set op select implmode. Support high_precision, high_performance, " + "high_precision_for_all, high_performance_for_all. default: high_performance\n" " --optypelist_for_implmode Appoint which op to select implmode, cooperated with op_select_implmode.\n" " Separate multiple nodes with commas (,). Use double quotation marks (\") " "to enclose each argument. E.g.: \"node_name1,node_name2\"\n" From 1cc845d733e9146317b2c5f99ed2a31f9cfa9761 Mon Sep 17 00:00:00 2001 From: wqtshg Date: Thu, 1 Jul 2021 17:47:37 +0800 Subject: [PATCH 44/50] delete useless code --- ge/graph/build/model_builder.cc | 1 - ge/graph/manager/graph_var_manager.cc | 49 ------------------ ge/graph/manager/graph_var_manager.h | 15 ------ ge/graph/manager/trans_var_data_utils.cc | 66 ------------------------ ge/graph/manager/trans_var_data_utils.h | 11 ---- 5 files changed, 142 deletions(-) diff --git a/ge/graph/build/model_builder.cc b/ge/graph/build/model_builder.cc index e35e4e7d..2816f170 100755 --- a/ge/graph/build/model_builder.cc +++ b/ge/graph/build/model_builder.cc @@ -32,7 +32,6 @@ #include "graph/ge_attr_value.h" #include "graph/ge_context.h" #include "external/graph/ge_error_codes.h" -#include "graph/manager/graph_mem_allocator.h" #include "graph/manager/graph_var_manager.h" #include "graph/optimize/common/params.h" #include "external/graph/types.h" diff --git a/ge/graph/manager/graph_var_manager.cc b/ge/graph/manager/graph_var_manager.cc index ced8465f..89a4e45b 100755 --- a/ge/graph/manager/graph_var_manager.cc +++ b/ge/graph/manager/graph_var_manager.cc @@ -194,35 +194,6 @@ ge::Status VarResource::GetBroadCastInfo(uint32_t graph_id, const string &var_na return SUCCESS; } -ge::Status VarResource::SyncVarData2BroadCast(uint32_t graph_id, const std::string &var_name, - const GeTensorDesc &var_tensor_desc, uint8_t *base_ptr) { - GE_CHECK_NOTNULL(base_ptr); - GELOGI("SyncVarData2BroadCast graph_id: %u, var_name: %s.", graph_id, var_name.c_str()); - - VarBroadCastInfo var_broadcast_info = var_broad_cast_info_[graph_id][var_name]; - uint8_t *dst_addr = base_ptr + var_broadcast_info.input_offset; - - return ge::TransVarDataUtils::SyncVarData2BroadCast(var_name, var_tensor_desc, dst_addr, - var_broadcast_info.input_size, session_id_); -} - -ge::Status VarResource::SyncBroadCastData2Var(uint32_t graph_id, const std::string &var_name, - const GeTensorDesc &var_tensor_desc, uint8_t *base_ptr) { - GELOGI("SyncBroadCastData2Var var_name: %s", var_name.c_str()); - - VarBroadCastInfo var_broadcast_info = var_broad_cast_info_[graph_id][var_name]; - // subgraph base_ptr could be nullptr, task it as base 0 - uint8_t *dst_addr = base_ptr + var_broadcast_info.output_offset; - - return ge::TransVarDataUtils::SyncBroadCastData2Var(dst_addr, var_broadcast_info.output_size, var_name, - var_tensor_desc, session_id_); -} - -ge::Status VarResource::SyncVarData(uint32_t graph_id, const std::string &var_name, - const GeTensorDesc &var_tensor_desc, uint8_t *base_ptr) { - return SyncVarData2BroadCast(graph_id, var_name, var_tensor_desc, base_ptr); -} - bool VarResource::IsVarAddr(const int64_t &offset) { return var_offset_map_.count(offset) > 0; } rtMemType_t VarResource::GetVarMemType(const int64_t &offset) { @@ -638,16 +609,6 @@ bool VarManager::IsVarExist(const std::string &var_name) { return var_resource_->IsVarExist(var_name); } -ge::Status VarManager::SyncVarData(uint32_t graph_id, const std::string &var_name, const GeTensorDesc &var_tensor_desc, - uint8_t *base_ptr) { - std::lock_guard lock(mutex_); - if (var_resource_ == nullptr) { - GELOGW("VarManager has not been init."); - return ge::INTERNAL_ERROR; - } - return var_resource_->SyncVarData(graph_id, var_name, var_tensor_desc, base_ptr); -} - ge::Status VarManager::GetCurVarDesc(const std::string &var_name, ge::GeTensorDesc &tensor_desc) { std::lock_guard lock(mutex_); GELOGI("VarManager::GetCurVarDesc var_name = %s.", var_name.c_str()); @@ -701,16 +662,6 @@ ge::Status VarManager::RenewCurVarDesc(const std::string &var_name, ge::OpDescPt return var_resource_->RenewCurVarDesc(var_name, std::move(op_desc)); } -ge::Status VarManager::SyncBroadCastData2Var(uint32_t graph_id, const std::string &var_name, - const GeTensorDesc &var_tensor_desc, uint8_t *base_ptr) { - std::lock_guard lock(mutex_); - if (var_resource_ == nullptr) { - GELOGW("VarManager has not been init."); - return ge::INTERNAL_ERROR; - } - return var_resource_->SyncBroadCastData2Var(graph_id, var_name, var_tensor_desc, base_ptr); -} - bool VarManager::IsVarAddr(const int64_t &offset) { std::lock_guard lock(mutex_); if (var_resource_ == nullptr) { diff --git a/ge/graph/manager/graph_var_manager.h b/ge/graph/manager/graph_var_manager.h index 736466c4..f2b68e79 100755 --- a/ge/graph/manager/graph_var_manager.h +++ b/ge/graph/manager/graph_var_manager.h @@ -118,15 +118,6 @@ class VarResource { ge::Status GetBroadCastInfo(uint32_t graph_id, const string &var_name, VarBroadCastInfo &broad_cast_info); - ge::Status SyncVarData2BroadCast(uint32_t graph_id, const std::string &var_name, - const GeTensorDesc &var_tensor_desc, uint8_t *base_ptr); - - ge::Status SyncBroadCastData2Var(uint32_t graph_id, const std::string &var_name, - const GeTensorDesc &var_tensor_desc, uint8_t *base_ptr); - - ge::Status SyncVarData(uint32_t graph_id, const std::string &var_name, const GeTensorDesc &var_tensor_desc, - uint8_t *base_ptr); - Status SetTransRoad(const std::string &var_name, const VarTransRoad &trans_road) { if (var_to_trans_road_.find(var_name) != var_to_trans_road_.end()) { GELOGW("Var name: %s has already set.", var_name.c_str()); @@ -234,16 +225,10 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY VarManager { ge::Status GetVarAddr(const std::string &var_name, const ge::GeTensorDesc &tensor_desc, uint8_t **dev_ptr); - ge::Status SyncVarData(uint32_t graph_id, const std::string &var_name, const GeTensorDesc &var_tensor_desc, - uint8_t *base_ptr); - ge::Status SaveBroadCastInfo(uint32_t graph_id, const VarBroadCastInfo &broad_cast_info); ge::Status GetBroadCastInfo(uint32_t graph_id, const string &var_name, VarBroadCastInfo &broad_cast_info); - ge::Status SyncBroadCastData2Var(uint32_t graph_id, const std::string &var_name, const GeTensorDesc &var_tensor_desc, - uint8_t *base_ptr); - ge::Status GetCurVarDesc(const std::string &var_name, ge::GeTensorDesc &tensor_desc); ge::Status RenewCurVarDesc(const std::string &var_name, ge::OpDescPtr op_desc); diff --git a/ge/graph/manager/trans_var_data_utils.cc b/ge/graph/manager/trans_var_data_utils.cc index 4c25dff1..2e6ce454 100644 --- a/ge/graph/manager/trans_var_data_utils.cc +++ b/ge/graph/manager/trans_var_data_utils.cc @@ -415,72 +415,6 @@ Status CopyTensorFromSrcVarNode(const NodePtr &var_src, return SUCCESS; } } // namespace -Status TransVarDataUtils::SyncVarData2BroadCast(const string &var_name, const ge::GeTensorDesc &src_tensor_desc, - uint8_t *dst_addr, int64_t dst_addr_size, uint64_t session_id) { - GE_CHK_BOOL_RET_STATUS(dst_addr != nullptr, FAILED, "[Check][Param] dst addr is nullptr."); - uint8_t *src_host_addr = nullptr; - int64_t src_addr_size = 0; - GE_MAKE_GUARD_RTMEM(src_host_addr); - GE_CHK_STATUS_RET(SyncTensorToHost(var_name, src_tensor_desc, &src_host_addr, src_addr_size, session_id)); - - GELOGI("src_addr_size: %ld, dst_addr_size: %ld", src_addr_size, dst_addr_size); - GE_CHK_BOOL_RET_STATUS(src_addr_size == dst_addr_size, FAILED, - "[Check][Param] src_addr_size:%ld not equal to dst_addr_size:%ld", - src_addr_size, dst_addr_size); - - GE_CHK_RT_RET(rtMemcpy(dst_addr, dst_addr_size, src_host_addr, src_addr_size, RT_MEMCPY_HOST_TO_DEVICE)); - return SUCCESS; -} - -Status TransVarDataUtils::SyncBroadCastData2Var(uint8_t *src_addr, int64_t src_addr_size, const string &var_name, - const ge::GeTensorDesc &dst_tensor_desc, uint64_t session_id) { - GE_CHK_BOOL_RET_STATUS(src_addr != nullptr, FAILED, "[Check][Param] src addr is nullptr. "); - uint8_t *host_addr = nullptr; - GE_MAKE_GUARD_RTMEM(host_addr); - GE_CHK_RT_RET(rtMallocHost(reinterpret_cast(&host_addr), src_addr_size)); - GE_CHK_RT_RET(rtMemcpy(host_addr, src_addr_size, src_addr, src_addr_size, RT_MEMCPY_DEVICE_TO_HOST)); - - GE_CHK_STATUS_RET( - SyncTensorToDevice(var_name, reinterpret_cast(host_addr), src_addr_size, dst_tensor_desc, session_id)); - - return SUCCESS; -} - -Status TransVarDataUtils::SyncTensorToHost(const string &var_name, const ge::GeTensorDesc &src_tensor_desc, - uint8_t **host_addr, int64_t &src_tensor_size, uint64_t session_id) { - GE_CHK_STATUS_RET(ge::TensorUtils::GetSize(src_tensor_desc, src_tensor_size), "[Get][Size] from TensorDesc failed"); - - uint8_t *src_addr = nullptr; - GE_CHK_STATUS_RET(VarManager::Instance(session_id)->GetVarAddr(var_name, src_tensor_desc, &src_addr)); - uint8_t *mem_addr = - src_addr - - static_cast(static_cast(VarManager::Instance(session_id)->GetVarMemLogicBase())) + - static_cast( - reinterpret_cast(VarManager::Instance(session_id)->GetVarMemoryBase(RT_MEMORY_HBM))); - GE_CHK_RT_RET(rtMallocHost(reinterpret_cast(host_addr), src_tensor_size)); - - GE_CHK_RT_RET(rtMemcpy(*host_addr, src_tensor_size, mem_addr, src_tensor_size, RT_MEMCPY_DEVICE_TO_HOST)); - - GELOGI("SyncTensorToHost var_name %s, src_tensor_size %ld", var_name.c_str(), src_tensor_size); - return SUCCESS; -} - -Status TransVarDataUtils::SyncTensorToDevice(const string &var_name, const uint8_t *host_addr, uint32_t addr_size, - const ge::GeTensorDesc &dst_tensor_desc, uint64_t session_id) { - uint8_t *dst_addr = nullptr; - GE_CHK_STATUS_RET(VarManager::Instance(session_id)->GetVarAddr(var_name, dst_tensor_desc, &dst_addr)); - uint8_t *mem_addr = - dst_addr - - static_cast(static_cast(VarManager::Instance(session_id)->GetVarMemLogicBase())) + - static_cast( - reinterpret_cast(VarManager::Instance(session_id)->GetVarMemoryBase(RT_MEMORY_HBM))); - GE_CHK_RT_RET(rtMemcpy(mem_addr, addr_size, host_addr, addr_size, RT_MEMCPY_HOST_TO_DEVICE)); - - GELOGI("SyncTensorToDevice var_name %s, addr_size %u", var_name.c_str(), addr_size); - - return SUCCESS; -} - Status TransVarDataUtils::TransAllVarData(const vector &variable_nodes, uint64_t session_id, rtContext_t context, diff --git a/ge/graph/manager/trans_var_data_utils.h b/ge/graph/manager/trans_var_data_utils.h index d5096ef2..174efbb3 100755 --- a/ge/graph/manager/trans_var_data_utils.h +++ b/ge/graph/manager/trans_var_data_utils.h @@ -29,11 +29,6 @@ namespace ge { class TransVarDataUtils { public: - static ge::Status SyncVarData2BroadCast(const string &var_name, const ge::GeTensorDesc &src_tensor_desc, - uint8_t *dst_addr, int64_t dst_addr_size, uint64_t session_id_); - static ge::Status SyncBroadCastData2Var(uint8_t *src_addr, int64_t src_addr_size, const string &var_name, - const ge::GeTensorDesc &dst_tensor_desc, uint64_t session_id_); - static ge::Status TransAllVarData(const std::vector &variable_nodes, uint64_t session_id, rtContext_t context, @@ -41,12 +36,6 @@ class TransVarDataUtils { uint32_t thread_num = 16); static ge::Status CopyVarData(const ComputeGraphPtr &compute_graph, uint64_t session_id, uint32_t device_id); - - private: - static ge::Status SyncTensorToHost(const string &var_name, const ge::GeTensorDesc &src_tensor_desc, - uint8_t **host_addr, int64_t &addr_size, uint64_t session_id_); - static ge::Status SyncTensorToDevice(const string &var_name, const uint8_t *host_addr, uint32_t addr_size, - const ge::GeTensorDesc &dst_tensor_desc, uint64_t session_id_); }; } // namespace ge From 2400e65904de4e5d20731f41421853360542e04c Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Thu, 1 Jul 2021 17:49:37 +0800 Subject: [PATCH 45/50] Do not create context in hydrid executor init func. --- ge/hybrid/executor/hybrid_model_executor.cc | 4 ---- ge/hybrid/executor/hybrid_model_pipeline_executor.cc | 1 - ge/hybrid/executor/worker/task_compile_engine.cc | 11 +++++++++-- metadef | 2 +- parser | 2 +- .../executor/worker/execution_engine_unittest.cc | 12 ++++++++++++ 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ge/hybrid/executor/hybrid_model_executor.cc b/ge/hybrid/executor/hybrid_model_executor.cc index 58da451c..2bb683c7 100755 --- a/ge/hybrid/executor/hybrid_model_executor.cc +++ b/ge/hybrid/executor/hybrid_model_executor.cc @@ -33,9 +33,6 @@ HybridModelExecutor::HybridModelExecutor(HybridModel *model, uint32_t device_id, } HybridModelExecutor::~HybridModelExecutor() { - if (context_.rt_gen_context != nullptr) { - (void) rtCtxDestroy(context_.rt_gen_context); - } } Status HybridModelExecutor::Init() { @@ -139,7 +136,6 @@ Status HybridModelExecutor::Cleanup() { Status HybridModelExecutor::InitExecutionContext() { GE_CHK_RT_RET(rtCtxGetCurrent(&context_.rt_context)); - GE_CHK_RT_RET(rtCtxCreate(&context_.rt_gen_context, RT_CTX_GEN_MODE, 0)); GE_CHK_RT_RET(rtCtxSetCurrent(context_.rt_context)); context_.global_step = model_->GetGlobalStep(); diff --git a/ge/hybrid/executor/hybrid_model_pipeline_executor.cc b/ge/hybrid/executor/hybrid_model_pipeline_executor.cc index 45e61138..b5e66628 100644 --- a/ge/hybrid/executor/hybrid_model_pipeline_executor.cc +++ b/ge/hybrid/executor/hybrid_model_pipeline_executor.cc @@ -191,7 +191,6 @@ HybridModelPipelineExecutor::HybridModelPipelineExecutor(HybridModel *model, uin } Status StageExecutor::InitExecutionContext() { - GE_CHK_RT_RET(rtCtxCreate(&context_.rt_gen_context, RT_CTX_GEN_MODE, 0)); GE_CHK_RT_RET(rtCtxSetCurrent(context_.rt_context)); context_.model = model_; diff --git a/ge/hybrid/executor/worker/task_compile_engine.cc b/ge/hybrid/executor/worker/task_compile_engine.cc index f7da9acd..491e0997 100755 --- a/ge/hybrid/executor/worker/task_compile_engine.cc +++ b/ge/hybrid/executor/worker/task_compile_engine.cc @@ -21,10 +21,17 @@ namespace ge { namespace hybrid { Status TaskCompileEngine::Compile(NodeState &node_state, GraphExecutionContext *context) { - const auto &node_item = *node_state.GetNodeItem(); GE_CHECK_NOTNULL(context); + rtContext_t rt_gen_context = nullptr; + GE_CHK_RT_RET(rtCtxCreate(&rt_gen_context, RT_CTX_GEN_MODE, 0)); + std::function callback = [&]() { + (void) rtCtxDestroy(rt_gen_context); + GE_CHK_RT(rtCtxSetCurrent(context->rt_context)); + }; + GE_MAKE_GUARD(rt_gen_context, callback); + + const auto &node_item = *node_state.GetNodeItem(); RECORD_COMPILE_EVENT(context, node_item.NodeName().c_str(), "[Compile] Start"); - GE_CHK_RT_RET(rtCtxSetCurrent(context->rt_gen_context)); if (context->ge_context != nullptr) { GetThreadLocalContext() = *context->ge_context; diff --git a/metadef b/metadef index f3f137de..9e4a51a9 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit f3f137de034885f0c7394d7f04b41b08d450d2d2 +Subproject commit 9e4a51a9602195b82e326b853f5adbfefc3972b6 diff --git a/parser b/parser index 15a27afe..79536a19 160000 --- a/parser +++ b/parser @@ -1 +1 @@ -Subproject commit 15a27afefe45f2abdb78787d629163aab9437599 +Subproject commit 79536a196f89cf7a1f5852ff7304b9a7d7b12eff diff --git a/tests/ut/ge/hybrid/executor/worker/execution_engine_unittest.cc b/tests/ut/ge/hybrid/executor/worker/execution_engine_unittest.cc index 07701f4d..96641c59 100644 --- a/tests/ut/ge/hybrid/executor/worker/execution_engine_unittest.cc +++ b/tests/ut/ge/hybrid/executor/worker/execution_engine_unittest.cc @@ -27,6 +27,7 @@ #include "hybrid/executor/hybrid_model_executor.h" #include "hybrid/executor/worker/execution_engine.h" #include "hybrid/executor/subgraph_executor.h" +#include "hybrid/executor/worker/task_compile_engine.h" #undef private #undef protected @@ -45,7 +46,14 @@ class UtestExecutionEngine : public testing::Test { }; namespace { const int kIntBase = 10; +class CompileNodeExecutor : public NodeExecutor { + public: + Status CompileTask(const HybridModel &model, const NodePtr &node, std::shared_ptr &task) const override { + return SUCCESS; + } +}; } + static ge::OpDescPtr CreateOpDesc(string name = "", string type = "") { auto op_desc = std::make_shared(name, type); op_desc->SetStreamId(0); @@ -128,4 +136,8 @@ TEST_F(UtestExecutionEngine, ExecuteAsync_without_callback_and_kernel_task) { executor.InitCallback(node_state.get(), callback); ExecutionEngine execution_engine; EXPECT_EQ(execution_engine.ExecuteAsync(*node_state, node_state->GetTaskContext(), execution_context, callback), INTERNAL_ERROR); + + CompileNodeExecutor node_executor; + node_item->node_executor = &node_executor; + EXPECT_EQ(TaskCompileEngine::Compile(*node_state, &execution_context), SUCCESS); } From 41ffa8bed108b57bb472843db88800c1ad105a85 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Thu, 1 Jul 2021 17:52:32 +0800 Subject: [PATCH 46/50] Update submodule. --- metadef | 2 +- parser | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/metadef b/metadef index 9e4a51a9..9c9907b7 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit 9e4a51a9602195b82e326b853f5adbfefc3972b6 +Subproject commit 9c9907b76a457f456072af96b8cbcfb7943beccc diff --git a/parser b/parser index 79536a19..15a27afe 160000 --- a/parser +++ b/parser @@ -1 +1 @@ -Subproject commit 79536a196f89cf7a1f5852ff7304b9a7d7b12eff +Subproject commit 15a27afefe45f2abdb78787d629163aab9437599 From 70a9868d3b3e66fde3200960f8e659318c9da944 Mon Sep 17 00:00:00 2001 From: lianghao Date: Thu, 1 Jul 2021 18:02:40 +0800 Subject: [PATCH 47/50] IsEnterFeedNode --- ge/hybrid/model/node_item.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ge/hybrid/model/node_item.cc b/ge/hybrid/model/node_item.cc index 8e87c6e2..77bd8efd 100644 --- a/ge/hybrid/model/node_item.cc +++ b/ge/hybrid/model/node_item.cc @@ -24,6 +24,8 @@ namespace ge { namespace hybrid { namespace { +const uint8_t kMaxTransCount = 3; +const uint32_t kTransOpIoSize = 1; const char *const kAttrNameOriginalFusionGraph = "_original_fusion_graph"; const char *const kNodeTypeRetVal = "_RetVal"; const std::set kControlOpTypes{ @@ -39,6 +41,25 @@ const std::set kMergeOpTypes{ MERGE, REFMERGE, STREAMMERGE }; +bool IsEnterFeedNode(NodePtr node) { + // For: Enter -> node + // For: Enter -> Cast -> node + // For: Enter -> TransData -> Cast -> node + for (uint8_t i = 0; i < kMaxTransCount; ++i) { + if (kEnterOpTypes.count(NodeUtils::GetNodeType(node)) > 0) { + GELOGD("Node[%u] is Enter feed node.", node->GetName().c_str()); + return true; + } + + const auto all_nodes = node->GetInDataNodes(); + if (all_nodes.size() != kTransOpIoSize || node->GetAllInDataAnchorsSize() != kTransOpIoSize) { + return false; + } + node = all_nodes.at(0); + } + return false; +} + Status ParseInputMapping(Node &node, OpDesc &op_desc, FusedSubgraph &fused_subgraph) { uint32_t parent_index = 0; if (!AttrUtils::GetInt(op_desc, ATTR_NAME_PARENT_NODE_INDEX, parent_index)) { @@ -399,7 +420,7 @@ void NodeItem::SetDataSend(NodeItem *node_item, int anchor_index) { data_anchors.emplace(anchor_index); } // If Enter feed Not Merge, take as root Node. - if (IsEnterOp() && (node_item->node_type != STREAMMERGE)) { + if (IsEnterFeedNode(node) && (node_item->node_type != STREAMMERGE)) { auto &data_anchors = node_item->enter_data_[this]; data_anchors.emplace(anchor_index); } @@ -419,7 +440,7 @@ void NodeItem::SetCtrlSend(NodeItem *node_item, uint32_t switch_index) { node_item->root_ctrl_.emplace(this); } // If Enter feed control signal, take as root Node. - if (IsEnterOp() && (node_item->node_type != STREAMMERGE && node_item->node_type != STREAMACTIVE)) { + if (IsEnterFeedNode(node) && (node_item->node_type != STREAMMERGE && node_item->node_type != STREAMACTIVE)) { node_item->enter_ctrl_.emplace(this); } GELOGI("Node[%s] will control node[%s]", NodeName().c_str(), node_item->NodeName().c_str()); From 1db4cac78d33622b6c54fedbb8d59b8d70f1fe66 Mon Sep 17 00:00:00 2001 From: WeiGangqiang Date: Tue, 29 Jun 2021 10:04:43 +0800 Subject: [PATCH 48/50] add graph check framework --- .clang-format | 3 +- metadef | 2 +- scripts/env/Dockerfile | 15 ++ scripts/env/ge_env.sh | 4 +- tests/depends/cce/CMakeLists.txt | 1 + tests/framework/CMakeLists.txt | 13 -- .../include/easy_graph/builder/graph_dsl.h | 22 ++- .../easy_graph/src/layout/graph_layout.cc | 8 +- .../ge_graph_dsl/assert/assert_error.h | 37 +++++ .../include/ge_graph_dsl/assert/check_utils.h | 32 +++++ .../ge_graph_dsl/assert/filter_scope_guard.h} | 49 ++++--- .../ge_graph_dsl/assert/graph_assert.h | 59 ++++++++ .../ge_graph_dsl/op_desc/op_desc_cfg.h | 6 +- .../ge_graph_dsl/src/assert/assert_error.cc | 26 ++++ .../ge_graph_dsl/src/assert/check_utils.cc | 34 +++++ .../src/assert/filter_scope_guard.cc | 31 +++++ .../ge_graph_dsl/src/assert/ge_dump_filter.h | 33 +++++ .../src/assert/ge_graph_check_dumper.cc | 79 +++++++++++ .../src/assert/ge_graph_check_dumper.h | 49 +++++++ .../src/assert/ge_graph_checker.h | 32 +++++ .../src/assert/ge_graph_default_checker.cc | 28 ++++ .../src/assert/ge_graph_default_checker.h | 41 ++++++ .../src/{ => op_desc}/op_desc_cfg_box.cc | 0 .../src/{ => op_desc}/op_desc_cfg_repo.cc | 17 ++- .../src/{ => op_desc}/op_desc_ptr_box.cc | 4 +- .../ge_graph_visitor.cc} | 12 +- .../src/{ => vistor}/ge_subgraph_vistor.cc | 0 .../src/{ => vistor}/graph_dsl.cc | 0 .../ge_graph_dsl/tests/CMakeLists.txt | 2 +- .../ge_graph_dsl/tests/check_graph_test.cc | 129 ++++++++++++++++++ .../ge_graph_dsl/tests/graph_dsl_test.cc | 44 +++--- .../ge_graph_dsl/tests/stub/optype_stub.cc | 6 + .../tests/test_main.cc} | 47 ++++--- .../utils/builder/graph_builder_utils.cc | 48 ------- .../utils/builder/graph_builder_utils.h | 55 -------- tests/st/testcase/CMakeLists.txt | 2 +- tests/st/testcase/test_framework_dummy.cc | 127 +++++++---------- tests/st/testcase/test_ge_opt_info.cc | 20 +-- tests/st/testcase/test_main.cc | 4 +- tests/ut/common/graph/CMakeLists.txt | 1 + tests/ut/ge/CMakeLists.txt | 1 + 41 files changed, 811 insertions(+), 312 deletions(-) create mode 100644 tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/assert_error.h create mode 100644 tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/check_utils.h rename tests/framework/{utils/builder/tensor_builder_utils.cc => ge_graph_dsl/include/ge_graph_dsl/assert/filter_scope_guard.h} (68%) create mode 100644 tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/graph_assert.h create mode 100644 tests/framework/ge_graph_dsl/src/assert/assert_error.cc create mode 100644 tests/framework/ge_graph_dsl/src/assert/check_utils.cc create mode 100644 tests/framework/ge_graph_dsl/src/assert/filter_scope_guard.cc create mode 100644 tests/framework/ge_graph_dsl/src/assert/ge_dump_filter.h create mode 100644 tests/framework/ge_graph_dsl/src/assert/ge_graph_check_dumper.cc create mode 100644 tests/framework/ge_graph_dsl/src/assert/ge_graph_check_dumper.h create mode 100644 tests/framework/ge_graph_dsl/src/assert/ge_graph_checker.h create mode 100644 tests/framework/ge_graph_dsl/src/assert/ge_graph_default_checker.cc create mode 100644 tests/framework/ge_graph_dsl/src/assert/ge_graph_default_checker.h rename tests/framework/ge_graph_dsl/src/{ => op_desc}/op_desc_cfg_box.cc (100%) rename tests/framework/ge_graph_dsl/src/{ => op_desc}/op_desc_cfg_repo.cc (53%) rename tests/framework/ge_graph_dsl/src/{ => op_desc}/op_desc_ptr_box.cc (97%) rename tests/framework/ge_graph_dsl/src/{ge_graph_vistor.cc => vistor/ge_graph_visitor.cc} (89%) rename tests/framework/ge_graph_dsl/src/{ => vistor}/ge_subgraph_vistor.cc (100%) rename tests/framework/ge_graph_dsl/src/{ => vistor}/graph_dsl.cc (100%) create mode 100644 tests/framework/ge_graph_dsl/tests/check_graph_test.cc rename tests/framework/{utils/builder/tensor_builder_utils.h => ge_graph_dsl/tests/test_main.cc} (73%) delete mode 100644 tests/framework/utils/builder/graph_builder_utils.cc delete mode 100644 tests/framework/utils/builder/graph_builder_utils.h diff --git a/.clang-format b/.clang-format index e7f9d935..6faea40d 100644 --- a/.clang-format +++ b/.clang-format @@ -52,7 +52,6 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true -DerivePointerAlignment: true DisableFormat: false ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true @@ -94,7 +93,7 @@ PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 200 -PointerAlignment: Left +PointerAlignment: Right RawStringFormats: - Language: Cpp Delimiters: diff --git a/metadef b/metadef index f3f137de..9c9907b7 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit f3f137de034885f0c7394d7f04b41b08d450d2d2 +Subproject commit 9c9907b76a457f456072af96b8cbcfb7943beccc diff --git a/scripts/env/Dockerfile b/scripts/env/Dockerfile index af02f7bb..923a1453 100755 --- a/scripts/env/Dockerfile +++ b/scripts/env/Dockerfile @@ -38,5 +38,20 @@ RUN wget https://github.com/ccup/lcov/archive/refs/tags/add_lcov.tar.gz -O add_l ENV PROJECT_HOME=/code/Turing/graphEngine +RUN mkdir /var/run/sshd +RUN echo "root:root" | chpasswd +RUN sed -i 's/\#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config +RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd + +ENV NOTVISIBLE "in users profile" +RUN echo "export VISIBLE=now" >> /etc/profile + +EXPOSE 22 7777 + +RUN useradd -ms /bin/bash debugger +RUN echo "debugger:ge123" | chpasswd + +CMD ["/usr/sbin/sshd" "-D" "&"] + RUN echo "alias ge=/code/Turing/graphEngine/scripts/ge.sh">>~/.bashrc diff --git a/scripts/env/ge_env.sh b/scripts/env/ge_env.sh index 18c6aa5d..10ca810f 100755 --- a/scripts/env/ge_env.sh +++ b/scripts/env/ge_env.sh @@ -21,7 +21,7 @@ MOUNT_PROJECT_HOME=$(cd $PROJECT_HOME || return; pwd) DOCKER_BUILD_ENV_NAME=${MOUNT_PROJECT_HOME#*/} DOCKER_BUILD_ENV_NAME=${DOCKER_BUILD_ENV_NAME//\//\_} -DOCKER_IMAGE_TAG=ge_build_env.1.0.6 +DOCKER_IMAGE_TAG=ge_build_env.1.0.9 DOCKER_IAMGE_NAME=joycode2art/turing DOCKER_FULL_IMAGE_NAME=${DOCKER_IAMGE_NAME}:${DOCKER_IMAGE_TAG} @@ -61,7 +61,7 @@ function enter_docker_env(){ if test -z "$(docker images |grep ${DOCKER_IAMGE_NAME} | grep ${DOCKER_IMAGE_TAG})"; then echo "please run 'ge env --pull' to download images first!" elif test -z "$(docker ps -a |grep ${DOCKER_BUILD_ENV_NAME})"; then - $docker_cmd run -it -v ${MOUNT_PROJECT_HOME}:/code/Turing/graphEngine --workdir ${docker_work_dir} --name ${DOCKER_BUILD_ENV_NAME} ${DOCKER_FULL_IMAGE_NAME} ${docker_bash_dir} + $docker_cmd run -p 7002:22 -p 7003:7777 --privileged=true -it -v ${MOUNT_PROJECT_HOME}:/code/Turing/graphEngine --workdir ${docker_work_dir} --name ${DOCKER_BUILD_ENV_NAME} ${DOCKER_FULL_IMAGE_NAME} ${docker_bash_dir} elif test -z "$(docker ps |grep ${DOCKER_BUILD_ENV_NAME})"; then $docker_cmd start ${DOCKER_BUILD_ENV_NAME} $docker_cmd exec -w ${docker_work_dir} -it ${DOCKER_BUILD_ENV_NAME} ${docker_bash_dir} diff --git a/tests/depends/cce/CMakeLists.txt b/tests/depends/cce/CMakeLists.txt index 7550c63f..05fa8133 100644 --- a/tests/depends/cce/CMakeLists.txt +++ b/tests/depends/cce/CMakeLists.txt @@ -60,6 +60,7 @@ set(SRCS "${GE_CODE_DIR}/metadef/graph/detail/attributes_holder.cc" "${GE_CODE_DIR}/metadef/graph/utils/anchor_utils.cc" "${GE_CODE_DIR}/metadef/graph/utils/graph_utils.cc" + "${GE_CODE_DIR}/metadef/graph/utils/dumper/ge_graph_dumper.cc" "${GE_CODE_DIR}/metadef/graph/utils/node_utils.cc" "${GE_CODE_DIR}/metadef/graph/utils/op_desc_utils.cc" "${GE_CODE_DIR}/metadef/graph/utils/type_utils.cc" diff --git a/tests/framework/CMakeLists.txt b/tests/framework/CMakeLists.txt index 8a2218b4..bbab454b 100644 --- a/tests/framework/CMakeLists.txt +++ b/tests/framework/CMakeLists.txt @@ -17,16 +17,3 @@ include(cmake/graphengine.cmake) add_subdirectory(easy_graph) add_subdirectory(ge_graph_dsl) add_subdirectory(ge_running_env) - -file(GLOB_RECURSE UTILS_SRC CONFIGURE_DEPENDS - "utils/*.cc" - ) - -add_library(framework STATIC ${UTILS_SRC}) - -target_include_directories(framework - PUBLIC utils/ -) - -set_target_properties(framework PROPERTIES CXX_STANDARD 11) -target_link_libraries(framework PUBLIC ge_graph_dsl ge_with_env) diff --git a/tests/framework/easy_graph/include/easy_graph/builder/graph_dsl.h b/tests/framework/easy_graph/include/easy_graph/builder/graph_dsl.h index 4d430983..46bfe324 100644 --- a/tests/framework/easy_graph/include/easy_graph/builder/graph_dsl.h +++ b/tests/framework/easy_graph/include/easy_graph/builder/graph_dsl.h @@ -26,16 +26,32 @@ EG_NS_BEGIN //////////////////////////////////////////////////////////////// namespace detail { -template +template Graph BuildGraph(const char *name, GRAPH_BUILDER builderInDSL) { GraphBuilder builder(name); builderInDSL(builder); return std::move(*builder); } + +struct GraphDefiner { + GraphDefiner(const char *defaultName, const char *specifiedName = nullptr) { + name = specifiedName ? specifiedName : defaultName; + } + + template + auto operator|(USER_BUILDER &&userBuilder) { + GraphBuilder graphBuilder{name}; + std::forward(userBuilder)(graphBuilder); + return *graphBuilder; + } + + private: + const char *name; +}; + } // namespace detail -#define HAS_NAME(...) NOT_EMPTY_SELECT(__VA_ARGS__) -#define DEF_GRAPH(G, ...) ::EG_NS::Graph G = ::EG_NS::detail::BuildGraph(HAS_NAME(__VA_ARGS__)(__VA_ARGS__, #G), [&](::EG_NS::GraphBuilder& BUILDER) +#define DEF_GRAPH(G, ...) ::EG_NS::Graph G = ::EG_NS::detail::GraphDefiner(#G, ##__VA_ARGS__) | [&](auto &&BUILDER) #define DATA_CHAIN(...) ::EG_NS::ChainBuilder(BUILDER, ::EG_NS::EdgeType::DATA)->__VA_ARGS__ #define CTRL_CHAIN(...) ::EG_NS::ChainBuilder(BUILDER, ::EG_NS::EdgeType::CTRL)->__VA_ARGS__ #define CHAIN(...) DATA_CHAIN(__VA_ARGS__) diff --git a/tests/framework/easy_graph/src/layout/graph_layout.cc b/tests/framework/easy_graph/src/layout/graph_layout.cc index 340acf67..716bed8a 100644 --- a/tests/framework/easy_graph/src/layout/graph_layout.cc +++ b/tests/framework/easy_graph/src/layout/graph_layout.cc @@ -16,10 +16,15 @@ #include "easy_graph/layout/graph_layout.h" #include "easy_graph/layout/layout_executor.h" +#include "easy_graph/layout/engines/graph_easy/graph_easy_executor.h" #include "easy_graph/graph/graph.h" EG_NS_BEGIN +namespace { +GraphEasyExecutor default_executor; +} + void GraphLayout::Config(LayoutExecutor &executor, const LayoutOption *opts) { this->executor_ = &executor; options_ = opts; @@ -27,8 +32,7 @@ void GraphLayout::Config(LayoutExecutor &executor, const LayoutOption *opts) { Status GraphLayout::Layout(const Graph &graph, const LayoutOption *opts) { const LayoutOption *options = opts ? opts : this->options_; - if (!executor_) - return EG_UNIMPLEMENTED; + if (!executor_) return static_cast(default_executor).Layout(graph, options); return executor_->Layout(graph, options); } diff --git a/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/assert_error.h b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/assert_error.h new file mode 100644 index 00000000..7f5d5086 --- /dev/null +++ b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/assert_error.h @@ -0,0 +1,37 @@ +/** + * Copyright 2021 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. + */ +#ifndef D52AA06185E34BBFB714FFBCDAB0D53A +#define D52AA06185E34BBFB714FFBCDAB0D53A + +#include "ge_graph_dsl/ge.h" +#include +#include + +GE_NS_BEGIN + +struct AssertError : std::exception { + AssertError(const char *file, int line, const std::string &info); + + private: + const char *what() const noexcept override; + + private: + std::string info; +}; + +GE_NS_END + +#endif \ No newline at end of file diff --git a/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/check_utils.h b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/check_utils.h new file mode 100644 index 00000000..fa0ae783 --- /dev/null +++ b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/check_utils.h @@ -0,0 +1,32 @@ +/** + * Copyright 2021 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. + */ +#ifndef INC_31309AA0A4E44C009C22AD9351BF3410 +#define INC_31309AA0A4E44C009C22AD9351BF3410 + +#include "ge_graph_dsl/ge.h" +#include "graph/compute_graph.h" + +GE_NS_BEGIN + +using GraphCheckFun = std::function; +struct CheckUtils { + static bool CheckGraph(const std::string &phase_id, const GraphCheckFun &fun); + static void init(); +}; + +GE_NS_END + +#endif \ No newline at end of file diff --git a/tests/framework/utils/builder/tensor_builder_utils.cc b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/filter_scope_guard.h similarity index 68% rename from tests/framework/utils/builder/tensor_builder_utils.cc rename to tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/filter_scope_guard.h index f99b9107..a208c02e 100644 --- a/tests/framework/utils/builder/tensor_builder_utils.cc +++ b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/filter_scope_guard.h @@ -1,17 +1,32 @@ -/** - * Copyright 2021 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 "tensor_builder_utils.h" +/** + * Copyright 2021 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. + */ +#ifndef C8B32320BD4943D588594B82FFBF2685 +#define C8B32320BD4943D588594B82FFBF2685 + +#include +#include +#include "ge_graph_dsl/ge.h" + +GE_NS_BEGIN + +struct FilterScopeGuard { + FilterScopeGuard(const std::vector &); + ~FilterScopeGuard(); +}; + +GE_NS_END + +#endif diff --git a/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/graph_assert.h b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/graph_assert.h new file mode 100644 index 00000000..663907a0 --- /dev/null +++ b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/assert/graph_assert.h @@ -0,0 +1,59 @@ +/** + * Copyright 2021 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. + */ +#ifndef AD954C4ADF5B44F5B1CC8BCD72EE9ED6 +#define AD954C4ADF5B44F5B1CC8BCD72EE9ED6 + +#include "ge_graph_dsl/ge.h" +#include "ge_graph_dsl/assert/check_utils.h" +#include "ge_graph_dsl/assert/assert_error.h" +#include "ge_graph_dsl/assert/filter_scope_guard.h" + +GE_NS_BEGIN + +#ifdef GTEST_MESSAGE_AT_ +#define GRAPH_CHECK_MESSAGE(file, line, message) \ + GTEST_MESSAGE_AT_(file, line, message, ::testing::TestPartResult::kFatalFailure) +#elif +#define GRAPH_CHECK_MESSAGE(file, line, message) throw AssertError(file, line, message) +#endif + +namespace detail { +struct GraphAssert { + GraphAssert(const char *file, unsigned int line, const std::string &phase_id) + : file_(file), line_(line), phase_id_(phase_id) {} + + void operator|(const ::GE_NS::GraphCheckFun &check_fun) { + bool ret = ::GE_NS::CheckUtils::CheckGraph(phase_id_, check_fun); + if (!ret) { + auto message = "expect dump graph in phase: [" + phase_id_ + "], while not find the dump graph! "; + GRAPH_CHECK_MESSAGE(file_, line_, message.c_str()); + } + } + + private: + const char *file_; + unsigned int line_; + const std::string phase_id_; +}; +} // namespace detail + +#define DUMP_GRAPH_WHEN(...) ::GE_NS::FilterScopeGuard guard__COUNTER__({__VA_ARGS__}); +#define CHECK_GRAPH(phase_id) \ + ::GE_NS::detail::GraphAssert(__FILE__, __LINE__, #phase_id) | [&](const ::GE_NS::ComputeGraphPtr &graph) + +GE_NS_END + +#endif \ No newline at end of file diff --git a/tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg.h b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg.h index bb2326ec..99eafa7f 100644 --- a/tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg.h +++ b/tests/framework/ge_graph_dsl/include/ge_graph_dsl/op_desc/op_desc_cfg.h @@ -33,14 +33,12 @@ struct OpDescCfg { std::vector shape_; }; - OpDescCfg(const OpType &type, int in_cnt = 0, int out_cnt = 0, Format format = FORMAT_NCHW, + OpDescCfg(const OpType &type, int in_cnt = 1, int out_cnt = 1, Format format = FORMAT_NCHW, DataType data_type = DT_FLOAT, std::vector shape = {1, 1, 224, 224}) : type_(type), in_cnt_(in_cnt), out_cnt_(out_cnt), default_tensor_(format, data_type, shape) {} protected: - OpType GetType() const { - return type_; - } + OpType GetType() const { return type_; } OpType type_; int in_cnt_; int out_cnt_; diff --git a/tests/framework/ge_graph_dsl/src/assert/assert_error.cc b/tests/framework/ge_graph_dsl/src/assert/assert_error.cc new file mode 100644 index 00000000..5b74d852 --- /dev/null +++ b/tests/framework/ge_graph_dsl/src/assert/assert_error.cc @@ -0,0 +1,26 @@ +/** + * Copyright 2021 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 "ge_graph_dsl/assert/assert_error.h" + +GE_NS_BEGIN + +AssertError::AssertError(const char *file, int line, const std::string &info) { + this->info = std::string(file) + ":" + std::to_string(line) + "\n" + info; +} + +const char *AssertError::what() const noexcept { return info.c_str(); } + +GE_NS_END diff --git a/tests/framework/ge_graph_dsl/src/assert/check_utils.cc b/tests/framework/ge_graph_dsl/src/assert/check_utils.cc new file mode 100644 index 00000000..56bc6e81 --- /dev/null +++ b/tests/framework/ge_graph_dsl/src/assert/check_utils.cc @@ -0,0 +1,34 @@ +/** + * Copyright 2021 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 "ge_graph_dsl/assert/check_utils.h" +#include "graph/utils/dumper/ge_graph_dumper.h" +#include "ge_graph_default_checker.h" +#include "ge_graph_check_dumper.h" + +GE_NS_BEGIN + +bool CheckUtils::CheckGraph(const std::string &phase_id, const GraphCheckFun &fun) { + auto &dumper = dynamic_cast(GraphDumperRegistry::GetDumper()); + return dumper.CheckFor(GeGraphDefaultChecker(phase_id, fun)); +} + +void CheckUtils::init() { + static GeGraphCheckDumper checkDumper; + GraphDumperRegistry::Register(checkDumper); +} + +GE_NS_END diff --git a/tests/framework/ge_graph_dsl/src/assert/filter_scope_guard.cc b/tests/framework/ge_graph_dsl/src/assert/filter_scope_guard.cc new file mode 100644 index 00000000..4aa4795d --- /dev/null +++ b/tests/framework/ge_graph_dsl/src/assert/filter_scope_guard.cc @@ -0,0 +1,31 @@ +/** + * Copyright 2021 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 "ge_graph_dsl/assert/filter_scope_guard.h" +#include "graph/utils/dumper/ge_graph_dumper.h" +#include "ge_dump_filter.h" + +GE_NS_BEGIN + +namespace { +GeDumpFilter &GetDumpFilter() { return dynamic_cast(GraphDumperRegistry::GetDumper()); } +} // namespace + +FilterScopeGuard::FilterScopeGuard(const std::vector &filter) { GetDumpFilter().Update(filter); } + +FilterScopeGuard::~FilterScopeGuard() { GetDumpFilter().Reset(); } + +GE_NS_END \ No newline at end of file diff --git a/tests/framework/ge_graph_dsl/src/assert/ge_dump_filter.h b/tests/framework/ge_graph_dsl/src/assert/ge_dump_filter.h new file mode 100644 index 00000000..47967c91 --- /dev/null +++ b/tests/framework/ge_graph_dsl/src/assert/ge_dump_filter.h @@ -0,0 +1,33 @@ +/** + * Copyright 2021 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. + */ +#ifndef INC_4C6224E8F7474EF89B18CCB0E4B19FD6 +#define INC_4C6224E8F7474EF89B18CCB0E4B19FD6 + +#include +#include +#include "ge_graph_dsl/ge.h" +#include "easy_graph/infra/keywords.h" + +GE_NS_BEGIN + +INTERFACE(GeDumpFilter) { + ABSTRACT(void Update(const std::vector &)); + ABSTRACT(void Reset()); +}; + +GE_NS_END + +#endif diff --git a/tests/framework/ge_graph_dsl/src/assert/ge_graph_check_dumper.cc b/tests/framework/ge_graph_dsl/src/assert/ge_graph_check_dumper.cc new file mode 100644 index 00000000..ba72cf86 --- /dev/null +++ b/tests/framework/ge_graph_dsl/src/assert/ge_graph_check_dumper.cc @@ -0,0 +1,79 @@ +/** + * Copyright 2021 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 "ge_graph_check_dumper.h" +#include "graph/model.h" +#include "graph/buffer.h" +#include "graph/utils/graph_utils.h" +#include "ge_graph_default_checker.h" + +GE_NS_BEGIN + +GeGraphCheckDumper::GeGraphCheckDumper() { Reset(); } + +bool GeGraphCheckDumper::IsNeedDump(const std::string &suffix) const { + auto iter = std::find(suffixes_.begin(), suffixes_.end(), suffix); + return (iter != suffixes_.end()); +} + +void GeGraphCheckDumper::Dump(const ge::ComputeGraphPtr &graph, const std::string &suffix) { + if (!IsNeedDump(suffix)) { + return; + } + auto iter = buffers_.find(suffix); + if (iter != buffers_.end()) { + DumpGraph(graph, iter->second); + } else { + buffers_[suffix] = Buffer(); + DumpGraph(graph, buffers_.at(suffix)); + } +} + +bool GeGraphCheckDumper::CheckFor(const GeGraphChecker &checker) { + auto iter = buffers_.find(checker.PhaseId()); + if (iter == buffers_.end()) { + return false; + } + DoCheck(checker, iter->second); + return true; +} + +void GeGraphCheckDumper::DoCheck(const GeGraphChecker &checker, ::GE_NS::Buffer &buffer) { + Model model("", ""); + Model::Load(buffer.GetData(), buffer.GetSize(), model); + auto load_graph = model.GetGraph(); + checker.Check(GraphUtils::GetComputeGraph(load_graph)); +} + +void GeGraphCheckDumper::DumpGraph(const ge::ComputeGraphPtr &graph, ::GE_NS::Buffer &buffer) { + Model model("", ""); + buffer.clear(); + model.SetGraph(GraphUtils::CreateGraphFromComputeGraph(graph)); + model.Save(buffer, true); +} + +void GeGraphCheckDumper::Update(const std::vector &new_suffixes_) { + suffixes_ = new_suffixes_; + buffers_.clear(); +} + +void GeGraphCheckDumper::Reset() { + static std::vector default_suffixes_{"PreRunAfterBuild"}; + suffixes_ = default_suffixes_; + buffers_.clear(); +} + +GE_NS_END \ No newline at end of file diff --git a/tests/framework/ge_graph_dsl/src/assert/ge_graph_check_dumper.h b/tests/framework/ge_graph_dsl/src/assert/ge_graph_check_dumper.h new file mode 100644 index 00000000..5eda52ea --- /dev/null +++ b/tests/framework/ge_graph_dsl/src/assert/ge_graph_check_dumper.h @@ -0,0 +1,49 @@ +/** + * Copyright 2021 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. + */ +#ifndef INC_8EFED0015C27464897BF64531355C810 +#define INC_8EFED0015C27464897BF64531355C810 + +#include "ge_graph_dsl/ge.h" +#include "graph/utils/dumper/ge_graph_dumper.h" +#include "ge_dump_filter.h" +#include + +GE_NS_BEGIN + +struct GeGraphChecker; + +struct GeGraphCheckDumper : GeGraphDumper, GeDumpFilter { + GeGraphCheckDumper(); + virtual void Dump(const ge::ComputeGraphPtr &graph, const std::string &suffix); + bool CheckFor(const GeGraphChecker &checker); + + private: + void DoCheck(const GeGraphChecker &checker, ::GE_NS::Buffer &buffer); + void DumpGraph(const ge::ComputeGraphPtr &graph, ::GE_NS::Buffer &buffer); + + private: + void Update(const std::vector &) override; + void Reset() override; + bool IsNeedDump(const std::string &suffix) const; + + private: + std::map buffers_; + std::vector suffixes_; +}; + +GE_NS_END + +#endif \ No newline at end of file diff --git a/tests/framework/ge_graph_dsl/src/assert/ge_graph_checker.h b/tests/framework/ge_graph_dsl/src/assert/ge_graph_checker.h new file mode 100644 index 00000000..c6b25b65 --- /dev/null +++ b/tests/framework/ge_graph_dsl/src/assert/ge_graph_checker.h @@ -0,0 +1,32 @@ +/** + * Copyright 2021 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. + */ +#ifndef INC_5960A8F437324904BEE0690271258762 +#define INC_5960A8F437324904BEE0690271258762 + +#include "ge_graph_dsl/ge.h" +#include "easy_graph/infra/keywords.h" +#include "graph/compute_graph.h" + +GE_NS_BEGIN + +INTERFACE(GeGraphChecker) { + ABSTRACT(const std::string &PhaseId() const); + ABSTRACT(void Check(const ge::ComputeGraphPtr &graph) const); +}; + +GE_NS_END + +#endif \ No newline at end of file diff --git a/tests/framework/ge_graph_dsl/src/assert/ge_graph_default_checker.cc b/tests/framework/ge_graph_dsl/src/assert/ge_graph_default_checker.cc new file mode 100644 index 00000000..4aa48ac6 --- /dev/null +++ b/tests/framework/ge_graph_dsl/src/assert/ge_graph_default_checker.cc @@ -0,0 +1,28 @@ +/** + * Copyright 2021 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 "ge_graph_default_checker.h" + +GE_NS_BEGIN + +GeGraphDefaultChecker::GeGraphDefaultChecker(const std::string &phase_id, const GraphCheckFun &check_fun) + : phase_id_(phase_id), check_fun_(check_fun) {} + +const std::string &GeGraphDefaultChecker::PhaseId() const { return phase_id_; } + +void GeGraphDefaultChecker::Check(const ge::ComputeGraphPtr &graph) const { return check_fun_(graph); } + +GE_NS_END \ No newline at end of file diff --git a/tests/framework/ge_graph_dsl/src/assert/ge_graph_default_checker.h b/tests/framework/ge_graph_dsl/src/assert/ge_graph_default_checker.h new file mode 100644 index 00000000..af8f3fbe --- /dev/null +++ b/tests/framework/ge_graph_dsl/src/assert/ge_graph_default_checker.h @@ -0,0 +1,41 @@ +/** + * Copyright 2021 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. + */ +#ifndef BCF4D96BE9FC48938DE7B7E93B551C54 +#define BCF4D96BE9FC48938DE7B7E93B551C54 + +#include "ge_graph_dsl/ge.h" +#include "ge_graph_checker.h" +#include "graph/compute_graph.h" + +GE_NS_BEGIN + +using GraphCheckFun = std::function; + +struct GeGraphDefaultChecker : GeGraphChecker { + GeGraphDefaultChecker(const std::string &, const GraphCheckFun &); + + private: + const std::string &PhaseId() const override; + void Check(const ge::ComputeGraphPtr &graph) const override; + + private: + const std::string phase_id_; + const GraphCheckFun check_fun_; +}; + +GE_NS_END + +#endif \ No newline at end of file diff --git a/tests/framework/ge_graph_dsl/src/op_desc_cfg_box.cc b/tests/framework/ge_graph_dsl/src/op_desc/op_desc_cfg_box.cc similarity index 100% rename from tests/framework/ge_graph_dsl/src/op_desc_cfg_box.cc rename to tests/framework/ge_graph_dsl/src/op_desc/op_desc_cfg_box.cc diff --git a/tests/framework/ge_graph_dsl/src/op_desc_cfg_repo.cc b/tests/framework/ge_graph_dsl/src/op_desc/op_desc_cfg_repo.cc similarity index 53% rename from tests/framework/ge_graph_dsl/src/op_desc_cfg_repo.cc rename to tests/framework/ge_graph_dsl/src/op_desc/op_desc_cfg_repo.cc index e7fa018f..19dfa4a5 100644 --- a/tests/framework/ge_graph_dsl/src/op_desc_cfg_repo.cc +++ b/tests/framework/ge_graph_dsl/src/op_desc/op_desc_cfg_repo.cc @@ -23,15 +23,22 @@ GE_NS_BEGIN namespace { -#define OP_CFG(optype, ...) \ - { \ - optype, OpDescCfg { \ - optype, __VA_ARGS__ \ - } \ +#define OP_CFG(optype, ...) \ + { \ + optype, OpDescCfg { optype, __VA_ARGS__ } \ } static std::map cfg_repo{OP_CFG(DATA, 1, 1, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}), OP_CFG(ADD, 2, 1, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}), + OP_CFG(ENTER, 1, 1, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}), + OP_CFG(MERGE, 2, 1, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}), + OP_CFG(CONSTANT, 0, 1, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}), + OP_CFG(LESS, 2, 1, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}), + OP_CFG(LOOPCOND, 1, 1, FORMAT_NCHW, DT_BOOL, {1, 1, 224, 224}), + OP_CFG(SWITCH, 2, 2, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}), + OP_CFG(EXIT, 1, 1, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}), + OP_CFG(NEXTITERATION, 1, 1, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}), + OP_CFG(NETOUTPUT, 2, 2, FORMAT_NCHW, DT_FLOAT, {1, 1, 224, 224}), OP_CFG(VARIABLE, 1, 1)}; } // namespace diff --git a/tests/framework/ge_graph_dsl/src/op_desc_ptr_box.cc b/tests/framework/ge_graph_dsl/src/op_desc/op_desc_ptr_box.cc similarity index 97% rename from tests/framework/ge_graph_dsl/src/op_desc_ptr_box.cc rename to tests/framework/ge_graph_dsl/src/op_desc/op_desc_ptr_box.cc index 23d4773c..1564e019 100644 --- a/tests/framework/ge_graph_dsl/src/op_desc_ptr_box.cc +++ b/tests/framework/ge_graph_dsl/src/op_desc/op_desc_ptr_box.cc @@ -19,6 +19,4 @@ USING_GE_NS -OpDescPtr OpDescPtrBox::Build(const ::EG_NS::NodeId &id) const { - return op_; -} +OpDescPtr OpDescPtrBox::Build(const ::EG_NS::NodeId &id) const { return op_; } diff --git a/tests/framework/ge_graph_dsl/src/ge_graph_vistor.cc b/tests/framework/ge_graph_dsl/src/vistor/ge_graph_visitor.cc similarity index 89% rename from tests/framework/ge_graph_dsl/src/ge_graph_vistor.cc rename to tests/framework/ge_graph_dsl/src/vistor/ge_graph_visitor.cc index d8bc2aab..c1dca646 100644 --- a/tests/framework/ge_graph_dsl/src/ge_graph_vistor.cc +++ b/tests/framework/ge_graph_dsl/src/vistor/ge_graph_visitor.cc @@ -36,17 +36,11 @@ GE_NS_BEGIN GeGraphVisitor::GeGraphVisitor() : build_graph_(std::make_shared("")) {} -void GeGraphVisitor::reset(const ComputeGraphPtr &graph) { - build_graph_ = graph; -} +void GeGraphVisitor::reset(const ComputeGraphPtr &graph) { build_graph_ = graph; } -Graph GeGraphVisitor::BuildGeGraph() const { - return GraphUtils::CreateGraphFromComputeGraph(build_graph_); -} +Graph GeGraphVisitor::BuildGeGraph() const { return GraphUtils::CreateGraphFromComputeGraph(build_graph_); } -ComputeGraphPtr GeGraphVisitor::BuildComputeGraph() const { - return build_graph_; -} +ComputeGraphPtr GeGraphVisitor::BuildComputeGraph() const { return build_graph_; } Status GeGraphVisitor::Visit(const ::EG_NS::Graph &graph) { build_graph_->SetName(graph.GetName()); diff --git a/tests/framework/ge_graph_dsl/src/ge_subgraph_vistor.cc b/tests/framework/ge_graph_dsl/src/vistor/ge_subgraph_vistor.cc similarity index 100% rename from tests/framework/ge_graph_dsl/src/ge_subgraph_vistor.cc rename to tests/framework/ge_graph_dsl/src/vistor/ge_subgraph_vistor.cc diff --git a/tests/framework/ge_graph_dsl/src/graph_dsl.cc b/tests/framework/ge_graph_dsl/src/vistor/graph_dsl.cc similarity index 100% rename from tests/framework/ge_graph_dsl/src/graph_dsl.cc rename to tests/framework/ge_graph_dsl/src/vistor/graph_dsl.cc diff --git a/tests/framework/ge_graph_dsl/tests/CMakeLists.txt b/tests/framework/ge_graph_dsl/tests/CMakeLists.txt index 40097d8b..65482679 100644 --- a/tests/framework/ge_graph_dsl/tests/CMakeLists.txt +++ b/tests/framework/ge_graph_dsl/tests/CMakeLists.txt @@ -26,7 +26,7 @@ target_compile_options(ge_graph_dsl_test PRIVATE ) set_target_properties(ge_graph_dsl_test PROPERTIES CXX_STANDARD 17) -target_link_libraries(ge_graph_dsl_test PUBLIC gtest gtest_main ge_graph_dsl) +target_link_libraries(ge_graph_dsl_test PUBLIC gtest ge_graph_dsl) include(CTest) enable_testing() diff --git a/tests/framework/ge_graph_dsl/tests/check_graph_test.cc b/tests/framework/ge_graph_dsl/tests/check_graph_test.cc new file mode 100644 index 00000000..731b7eed --- /dev/null +++ b/tests/framework/ge_graph_dsl/tests/check_graph_test.cc @@ -0,0 +1,129 @@ +/** + * Copyright 2021 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 "gtest/gtest.h" +#include "easy_graph/layout/graph_layout.h" +#include "easy_graph/layout/engines/graph_easy/graph_easy_option.h" +#include "easy_graph/layout/engines/graph_easy/graph_easy_executor.h" +#include "ge_graph_dsl/graph_dsl.h" +#include "graph/debug/ge_attr_define.h" +#include "graph/utils/dumper/ge_graph_dumper.h" +#include "framework/common/types.h" +#include "ge_graph_dsl/assert/graph_assert.h" +#include "graph/model.h" +#include "graph/buffer.h" + +USING_GE_NS + +class CheckGraphTest : public testing::Test { + private: + EG_NS::GraphEasyExecutor executor; + + protected: + void SetUp() { EG_NS::GraphLayout::GetInstance().Config(executor, nullptr); } + void TearDown() {} +}; + +TEST_F(CheckGraphTest, test_ge_graph_dump_is_work) { + DEF_GRAPH(g1) { CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); }; + + DUMP_GRAPH_WHEN("after_build"); + GraphDumperRegistry::GetDumper().Dump(ToComputeGraph(g1), "after_build"); + + CHECK_GRAPH(after_build) { + ASSERT_EQ(graph->GetName(), "g1"); + ASSERT_EQ(graph->GetAllNodesSize(), 2); + }; +} + +TEST_F(CheckGraphTest, test_ge_graph_dump_two_phase) { + DEF_GRAPH(g1) { CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); }; + DEF_GRAPH(g2) { + CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); + CTRL_CHAIN(NODE("data2", DATA)->NODE("add", ADD)); + }; + + DUMP_GRAPH_WHEN("before_build", "after_build"); + + GraphDumperRegistry::GetDumper().Dump(ToComputeGraph(g1), "before_build"); + GraphDumperRegistry::GetDumper().Dump(ToComputeGraph(g2), "after_build"); + + CHECK_GRAPH(before_build) { + ASSERT_EQ(graph->GetName(), "g1"); + ASSERT_EQ(graph->GetAllNodesSize(), 2); + }; + + CHECK_GRAPH(after_build) { + ASSERT_EQ(graph->GetName(), "g2"); + ASSERT_EQ(graph->GetAllNodesSize(), 3); + }; +} + +TEST_F(CheckGraphTest, test_ge_graph_dump_one_phase_two_times) { + DEF_GRAPH(g1) { CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); }; + DEF_GRAPH(g2) { + CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); + CTRL_CHAIN(NODE("data2", DATA)->NODE("add", ADD)); + }; + + DUMP_GRAPH_WHEN("before_build") + + GraphDumperRegistry::GetDumper().Dump(ToComputeGraph(g1), "before_build"); + GraphDumperRegistry::GetDumper().Dump(ToComputeGraph(g2), "before_build"); + + CHECK_GRAPH(before_build) { + ASSERT_EQ(graph->GetName(), "g2"); + ASSERT_EQ(graph->GetAllNodesSize(), 3); + }; +} + +TEST_F(CheckGraphTest, test_check_phases_is_work) { + DEF_GRAPH(g1) { CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); }; + + DUMP_GRAPH_WHEN("before_build"); + GraphDumperRegistry::GetDumper().Dump(ToComputeGraph(g1), "after_build"); + auto ret = ::GE_NS::CheckUtils::CheckGraph("after_build", [&](const ::GE_NS::ComputeGraphPtr &graph) {}); + ASSERT_FALSE(ret); +} + +TEST_F(CheckGraphTest, test_check_one_phase_dump_another_not_dump) { + DEF_GRAPH(g1) { CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); }; + + DUMP_GRAPH_WHEN("before_build"); + GraphDumperRegistry::GetDumper().Dump(ToComputeGraph(g1), "before_build"); + GraphDumperRegistry::GetDumper().Dump(ToComputeGraph(g1), "after_build"); + + CHECK_GRAPH(before_build) { + ASSERT_EQ(graph->GetName(), "g1"); + ASSERT_EQ(graph->GetAllNodesSize(), 2); + }; +} + +TEST_F(CheckGraphTest, test_model_serialize_and_unserialize_success) { + DEF_GRAPH(g1) { CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); }; + auto ge_graph = ToGeGraph(g1); + + ge::Model model("", ""); + model.SetGraph(ge_graph); + Buffer buffer; + model.Save(buffer, true); + + ge::Model loadModel("", ""); + Model::Load(buffer.GetData(), buffer.GetSize(), loadModel); + auto load_graph = loadModel.GetGraph(); + + ASSERT_EQ(load_graph.GetName(), "g1"); + ASSERT_EQ(load_graph.GetAllNodes().size(), 2); +} diff --git a/tests/framework/ge_graph_dsl/tests/graph_dsl_test.cc b/tests/framework/ge_graph_dsl/tests/graph_dsl_test.cc index f7e55e3d..a8240b32 100644 --- a/tests/framework/ge_graph_dsl/tests/graph_dsl_test.cc +++ b/tests/framework/ge_graph_dsl/tests/graph_dsl_test.cc @@ -37,17 +37,13 @@ class GraphDslTest : public testing::Test { EG_NS::GraphEasyExecutor executor; protected: - void SetUp() { - EG_NS::GraphLayout::GetInstance().Config(executor, nullptr); - } + void SetUp() { EG_NS::GraphLayout::GetInstance().Config(executor, nullptr); } void TearDown() {} }; TEST_F(GraphDslTest, test_build_graph_from_optype_with_name) { - DEF_GRAPH(g1) { - CHAIN(NODE("data1", DATA)->NODE("add", ADD)); - }); + DEF_GRAPH(g1) { CHAIN(NODE("data1", DATA)->NODE("add", ADD)); }; auto geGraph = ToGeGraph(g1); auto computeGraph = ToComputeGraph(g1); @@ -57,9 +53,7 @@ TEST_F(GraphDslTest, test_build_graph_from_optype_with_name) { } TEST_F(GraphDslTest, test_build_graph_with_name) { - DEF_GRAPH(g1, "sample_graph") { - CHAIN(NODE("data1", DATA)->NODE("add", ADD)); - }); + DEF_GRAPH(g1, "sample_graph") { CHAIN(NODE("data1", DATA)->NODE("add", ADD)); }; auto geGraph = ToGeGraph(g1); @@ -72,7 +66,7 @@ TEST_F(GraphDslTest, test_build_from_from_op_desc_ptr) { auto data = std::make_shared("data1", DATA); auto add = std::make_shared("Add", ADD); CHAIN(NODE(data)->NODE(add)); - }); + }; auto geGraph = ToGeGraph(g1); @@ -84,7 +78,7 @@ TEST_F(GraphDslTest, test_build_from_op_desc_cfg) { auto datCfg = OP_CFG(DATA).InCnt(1).OutCnt(1); auto addCfg = OP_CFG(DATA).InCnt(1).OutCnt(1); CHAIN(NODE("data1", datCfg)->NODE("add", addCfg)); - }); + }; auto geGraph = ToGeGraph(g1); @@ -92,9 +86,7 @@ TEST_F(GraphDslTest, test_build_from_op_desc_cfg) { } TEST_F(GraphDslTest, test_build_from_op_desc_cfg_inline) { - DEF_GRAPH(g1) { - CHAIN(NODE("data1", OP_CFG(DATA).InCnt(1).OutCnt(1))->NODE("add", OP_CFG(ADD).InCnt(2).OutCnt(1))); - }); + DEF_GRAPH(g1) { CHAIN(NODE("data1", OP_CFG(DATA).InCnt(1).OutCnt(1))->NODE("add", OP_CFG(ADD).InCnt(2).OutCnt(1))); }; auto geGraph = ToGeGraph(g1); @@ -102,9 +94,7 @@ TEST_F(GraphDslTest, test_build_from_op_desc_cfg_inline) { } TEST_F(GraphDslTest, test_build_from_control_chain) { - DEF_GRAPH(g1) { - CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); - }); + DEF_GRAPH(g1) { CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); }; auto geGraph = ToGeGraph(g1); @@ -112,9 +102,7 @@ TEST_F(GraphDslTest, test_build_from_control_chain) { } TEST_F(GraphDslTest, test_build_from_data_chain) { - DEF_GRAPH(g1) { - DATA_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); - }); + DEF_GRAPH(g1) { DATA_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); }; auto geGraph = ToGeGraph(g1); @@ -125,7 +113,7 @@ TEST_F(GraphDslTest, test_build_from_data_chain_with_edge) { DEF_GRAPH(g1) { CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); CHAIN(NODE("data1", DATA)->EDGE(2, 2)->NODE("add")); - }); + }; auto geGraph = ToGeGraph(g1); @@ -136,7 +124,7 @@ TEST_F(GraphDslTest, test_build_graph_reused_before_node) { DEF_GRAPH(g1) { CTRL_CHAIN(NODE("data1", DATA)->NODE("add", ADD)); CHAIN(NODE("data1")->EDGE(2, 2)->NODE("add")); - }); + }; auto geGraph = ToGeGraph(g1); @@ -147,7 +135,7 @@ TEST_F(GraphDslTest, test_build_graph_with_constant_folding) { DEF_GRAPH(g1) { CHAIN(NODE("data1", DATA)->NODE("add", ADD)); CHAIN(NODE("data2", DATA)->NODE("add")); - }); + }; auto geGraph = ToGeGraph(g1); @@ -168,7 +156,7 @@ TEST_F(GraphDslTest, test_build_complex_normal_graph_build_suggested) { ->NODE("Add4") ->NODE("Add5") ->NODE("net_output", NETOUTPUT)); - }); + }; auto geGraph = ToGeGraph(g1); @@ -187,7 +175,7 @@ TEST_F(GraphDslTest, test_build_complex_mult_normal_graph_build) { CHAIN(NODE("add2")->NODE("net_output")); CHAIN(NODE("add3")->NODE("net_output")); CTRL_CHAIN(NODE("add1")->NODE("add2")->NODE("add3")); - }); + }; auto geGraph = ToGeGraph(g1); @@ -198,17 +186,17 @@ TEST_F(GraphDslTest, test_build_graph_with_sub_graph) { DEF_GRAPH(sub_1) { CHAIN(NODE("data_i", DATA)->NODE("less", LESS)->NODE("netoutput", NETOUTPUT)); CHAIN(NODE("const_5", CONSTANTOP)->NODE("less")); - }); + }; DEF_GRAPH(sub_2) { CHAIN(NODE("data_a", DATA)->NODE("mul", MUL)->NODE("netoutput", NETOUTPUT)); CHAIN(NODE("const_2", CONSTANTOP)->NODE("mul")); - }); + }; DEF_GRAPH(g1) { CHAIN(NODE("data_a", DATA)->NODE("while", WHILE, sub_1, sub_2)->NODE("netoutput", NETOUTPUT)); CHAIN(NODE("data_i", DATA)->NODE("while")); - }); + }; sub_1.Layout(); sub_2.Layout(); diff --git a/tests/framework/ge_graph_dsl/tests/stub/optype_stub.cc b/tests/framework/ge_graph_dsl/tests/stub/optype_stub.cc index 071f8c36..533e8198 100644 --- a/tests/framework/ge_graph_dsl/tests/stub/optype_stub.cc +++ b/tests/framework/ge_graph_dsl/tests/stub/optype_stub.cc @@ -30,5 +30,11 @@ REGISTER_OPTYPE_DEFINE(MUL, "Mul"); REGISTER_OPTYPE_DEFINE(NETOUTPUT, "NetOutput"); REGISTER_OPTYPE_DEFINE(ADD, "Add"); REGISTER_OPTYPE_DEFINE(WHILE, "While"); +REGISTER_OPTYPE_DEFINE(ENTER, "Enter"); +REGISTER_OPTYPE_DEFINE(MERGE, "Merge"); +REGISTER_OPTYPE_DEFINE(LOOPCOND, "Loopcond"); +REGISTER_OPTYPE_DEFINE(SWITCH, "Switch"); +REGISTER_OPTYPE_DEFINE(EXIT, "Exit"); +REGISTER_OPTYPE_DEFINE(NEXTITERATION, "Nextiteration"); GE_NS_END diff --git a/tests/framework/utils/builder/tensor_builder_utils.h b/tests/framework/ge_graph_dsl/tests/test_main.cc similarity index 73% rename from tests/framework/utils/builder/tensor_builder_utils.h rename to tests/framework/ge_graph_dsl/tests/test_main.cc index 73656e4a..eb6112f2 100644 --- a/tests/framework/utils/builder/tensor_builder_utils.h +++ b/tests/framework/ge_graph_dsl/tests/test_main.cc @@ -1,22 +1,25 @@ -/** - * Copyright 2021 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. - */ - -#ifndef GRAPHENGINE_LLT_ST_TENSOR_BUILDER_UTILS_H -#define GRAPHENGINE_LLT_ST_TENSOR_BUILDER_UTILS_H - -class tensor_builder_utils {}; - -#endif // GRAPHENGINE_LLT_ST_TENSOR_BUILDER_UTILS_H +/** + * Copyright 2021 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 "ge_graph_dsl/assert/check_utils.h" + +int main(int argc, char **argv) { + ::GE_NS::CheckUtils::init(); + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} diff --git a/tests/framework/utils/builder/graph_builder_utils.cc b/tests/framework/utils/builder/graph_builder_utils.cc deleted file mode 100644 index c5555235..00000000 --- a/tests/framework/utils/builder/graph_builder_utils.cc +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2021 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 "graph_builder_utils.h" -#include "inc/external/graph/operator.h" -#include "inc/external/graph/operator_factory.h" -#include "graph/utils/graph_utils.h" - -namespace ge { -namespace st { -NodePtr ComputeGraphBuilder::AddNode(const std::string &name, const std::string &type, int in_cnt, int out_cnt, - Format format, DataType data_type, std::vector shape) { - auto tensor_desc = std::make_shared(); - tensor_desc->SetShape(GeShape(std::move(shape))); - tensor_desc->SetFormat(format); - tensor_desc->SetDataType(data_type); - - auto op_desc = std::make_shared(name, type); - for (int i = 0; i < in_cnt; ++i) { - op_desc->AddInputDesc(tensor_desc->Clone()); - } - for (int i = 0; i < out_cnt; ++i) { - op_desc->AddOutputDesc(tensor_desc->Clone()); - } - - return graph_->AddNode(op_desc); -} -void ComputeGraphBuilder::AddDataEdge(NodePtr &src_node, int src_idx, NodePtr &dst_node, int dst_idx) { - GraphUtils::AddEdge(src_node->GetOutDataAnchor(src_idx), dst_node->GetInDataAnchor(dst_idx)); -} -void ComputeGraphBuilder::AddControlEdge(NodePtr &src_node, NodePtr &dst_node) { - GraphUtils::AddEdge(src_node->GetOutControlAnchor(), dst_node->GetInControlAnchor()); -} -} // namespace st -} // namespace ge diff --git a/tests/framework/utils/builder/graph_builder_utils.h b/tests/framework/utils/builder/graph_builder_utils.h deleted file mode 100644 index 4627f082..00000000 --- a/tests/framework/utils/builder/graph_builder_utils.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2021 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. - */ - -#ifndef GRAPHENGINE_LLT_ST_GRAPH_BUILDER_H -#define GRAPHENGINE_LLT_ST_GRAPH_BUILDER_H - -#include -#include - -#include "graph/compute_graph.h" -#include "graph/utils/graph_utils.h" -#include "graph/graph.h" -#include "graph/node.h" - -namespace ge { -namespace st { -class ComputeGraphBuilder { - public: - explicit ComputeGraphBuilder(const std::string &name) { - graph_ = std::make_shared(name); - } - NodePtr AddNode(const std::string &name, const std::string &type, int in_cnt, int out_cnt, - Format format = FORMAT_NCHW, DataType data_type = DT_FLOAT, - std::vector shape = {1, 1, 224, 224}); - void AddDataEdge(NodePtr &src_node, int src_idx, NodePtr &dst_node, int dst_idx); - void AddControlEdge(NodePtr &src_node, NodePtr &dst_node); - ComputeGraphPtr GetComputeGraph() { - graph_->TopologicalSorting(); - return graph_; - } - Graph GetGraph() { - graph_->TopologicalSorting(); - return GraphUtils::CreateGraphFromComputeGraph(graph_); - } - - private: - ComputeGraphPtr graph_; -}; -} // namespace st -} // namespace ge - -#endif // GRAPHENGINE_LLT_ST_GRAPH_BUILDER_H diff --git a/tests/st/testcase/CMakeLists.txt b/tests/st/testcase/CMakeLists.txt index b3663708..56b3f41b 100644 --- a/tests/st/testcase/CMakeLists.txt +++ b/tests/st/testcase/CMakeLists.txt @@ -8,7 +8,7 @@ target_include_directories(graph_engine_test set_target_properties(graph_engine_test PROPERTIES CXX_STANDARD 17) -target_link_libraries(graph_engine_test PRIVATE gtest framework) +target_link_libraries(graph_engine_test PRIVATE gtest ge_graph_dsl ge_with_env) include(CTest) enable_testing() diff --git a/tests/st/testcase/test_framework_dummy.cc b/tests/st/testcase/test_framework_dummy.cc index 0abdd18b..8f13bb78 100644 --- a/tests/st/testcase/test_framework_dummy.cc +++ b/tests/st/testcase/test_framework_dummy.cc @@ -15,23 +15,12 @@ */ #include -#include #include "external/ge/ge_api.h" -#include "ge_running_env/fake_engine.h" #include "graph/debug/ge_attr_define.h" #include "framework/common/types.h" - -#include "builder/graph_builder_utils.h" #include "ge_running_env/ge_running_env_faker.h" - -#include "graph/operator_reg.h" -#include "graph/operator.h" -#define protected public -#define private public -#include "graph/utils/op_desc_utils.h" #include "ge_graph_dsl/graph_dsl.h" -#undef protected -#undef private +#include "ge_graph_dsl/assert/graph_assert.h" using namespace std; using namespace ge; @@ -57,76 +46,58 @@ namespace { * **/ Graph BuildV1ControlFlowGraph() { - // build graph - st::ComputeGraphBuilder graphBuilder("g1"); - auto data_i = graphBuilder.AddNode("data_i", DATA, 1, 1); - auto enter_i = graphBuilder.AddNode("enter_i", ENTER, 1, 1); - ge::AttrUtils::SetStr(enter_i->GetOpDesc(), ENTER_ATTR_FRAME_NAME, "1"); - auto merge_i = graphBuilder.AddNode("merge_i", MERGE, 2, 1); - auto const_5 = graphBuilder.AddNode("const_5", CONSTANT, 0, 1); - auto less = graphBuilder.AddNode("less", LESS, 2, 1); - auto loopcond = graphBuilder.AddNode("loopcond", LOOPCOND, 1, 1, FORMAT_NCHW, DT_BOOL); - auto switch_i = graphBuilder.AddNode("switch_i", SWITCH, 2, 2); - auto exit_i = graphBuilder.AddNode("switch_i", EXIT, 1, 1); - auto const_1 = graphBuilder.AddNode("const_1", CONSTANT, 0, 1); - auto add = graphBuilder.AddNode("add", ADD, 2, 1); - auto next_iteration_i = graphBuilder.AddNode("next_iteration_i", NEXTITERATION, 1, 1); - - auto data_a = graphBuilder.AddNode("data_a", DATA, 1, 1); - auto enter_a = graphBuilder.AddNode("enter_a", ENTER, 1, 1); - ge::AttrUtils::SetStr(enter_a->GetOpDesc(), ENTER_ATTR_FRAME_NAME, "1"); - auto merge_a = graphBuilder.AddNode("merge_a", MERGE, 2, 1); - auto switch_a = graphBuilder.AddNode("switch_a", SWITCH, 2, 2); - auto exit_a = graphBuilder.AddNode("exit_a", EXIT, 1, 1); - auto mul = graphBuilder.AddNode("mul", MUL, 2, 1); - auto const_2 = graphBuilder.AddNode("const_2", CONSTANT, 0, 1); - auto next_iteration_a = graphBuilder.AddNode("next_iteration_a", NEXTITERATION, 1, 1); - auto netoutput = graphBuilder.AddNode("netoutput", NETOUTPUT, 2, 2); - // i = i+1 - graphBuilder.AddDataEdge(data_i, 0, enter_i, 0); - graphBuilder.AddDataEdge(enter_i, 0, merge_i, 0); - graphBuilder.AddDataEdge(next_iteration_i, 0, merge_i, 1); - graphBuilder.AddDataEdge(merge_i, 0, less, 0); - graphBuilder.AddDataEdge(const_5, 0, less, 1); - graphBuilder.AddDataEdge(less, 0, loopcond, 0); - graphBuilder.AddDataEdge(loopcond, 0, switch_i, 1); - graphBuilder.AddDataEdge(merge_i, 0, switch_i, 0); - graphBuilder.AddDataEdge(switch_i, 0, exit_i, 0); - graphBuilder.AddDataEdge(switch_i, 1, add, 0); - graphBuilder.AddDataEdge(const_1, 0, add, 1); - graphBuilder.AddDataEdge(add, 0, next_iteration_i, 0); - graphBuilder.AddDataEdge(exit_i, 0, netoutput, 1); - // a=a*2 - graphBuilder.AddDataEdge(data_a, 0, enter_a, 0); - graphBuilder.AddDataEdge(enter_a, 0, merge_a, 0); - graphBuilder.AddDataEdge(next_iteration_a, 0, merge_a, 1); - graphBuilder.AddDataEdge(loopcond, 0, switch_a, 1); - graphBuilder.AddDataEdge(merge_a, 0, switch_a, 0); - graphBuilder.AddDataEdge(switch_a, 0, exit_a, 0); - graphBuilder.AddDataEdge(switch_a, 1, mul, 0); - graphBuilder.AddDataEdge(const_2, 0, mul, 1); - graphBuilder.AddDataEdge(mul, 0, next_iteration_a, 0); - graphBuilder.AddDataEdge(exit_a, 0, netoutput, 0); - // set const weight int64_t dims_size = 1; vector data_vec = {5}; for_each(data_vec.begin(), data_vec.end(), [&](int64_t &data) { dims_size *= data; }); vector data_value_vec(dims_size, 1); GeTensorDesc data_tensor_desc(GeShape(data_vec), FORMAT_NCHW, DT_INT32); - GeTensorPtr data_tensor = - make_shared(data_tensor_desc, (uint8_t *)data_value_vec.data(), data_value_vec.size() * sizeof(int32_t)); - OpDescUtils::SetWeights(const_5->GetOpDesc(), data_tensor); - OpDescUtils::SetWeights(const_2->GetOpDesc(), data_tensor); - OpDescUtils::SetWeights(const_1->GetOpDesc(), data_tensor); + GeTensorPtr data_tensor = make_shared(data_tensor_desc, (uint8_t *)data_value_vec.data(), + data_value_vec.size() * sizeof(int32_t)); - return graphBuilder.GetGraph(); + auto enter = OP_CFG(ENTER).Attr(ENTER_ATTR_FRAME_NAME, "1"); + auto const_op = OP_CFG(CONSTANT).Weight(data_tensor); + + DEF_GRAPH(g1) { + CHAIN(NODE("data_i", DATA) + ->NODE("enter_i", enter) + ->EDGE(0, 0) + ->NODE("merge_i", MERGE) + ->NODE("less", LESS) + ->NODE("loopcond", LOOPCOND)); + CHAIN(NODE("const_1", const_op) + ->EDGE(0, 1) + ->NODE("add", ADD) + ->NODE("iteration_i", NEXTITERATION) + ->EDGE(0, 1) + ->NODE("merge_i")); + CHAIN(NODE("const_5", const_op)->EDGE(0, 1)->NODE("less")); + CHAIN(NODE("loopcond") + ->EDGE(0, 1) + ->NODE("switch_i", SWITCH) + ->EDGE(0, 0) + ->NODE("exit_i", EXIT) + ->EDGE(0, 1) + ->NODE("netoutput", NETOUTPUT)); + CHAIN(NODE("merge_i")->EDGE(0, 0)->NODE("switch_i")->EDGE(1, 0)->NODE("add")); + CHAIN(NODE("data_a", DATA) + ->NODE("enter_a", enter) + ->NODE("merge_a", MERGE) + ->NODE("switch_a", SWITCH) + ->NODE("exit_a", EXIT) + ->EDGE(0, 0) + ->NODE("netoutput")); + CHAIN(NODE("iteration_a", NEXTITERATION)->EDGE(0, 1)->NODE("merge_a")); + CHAIN(NODE("loopcond")->EDGE(0, 1)->NODE("switch_a")->EDGE(1, 0)->NODE("mul", MUL)); + CHAIN(NODE("const_2", const_op)->EDGE(0, 1)->NODE("mul")->EDGE(0, 0)->NODE("iteration_a")); + }; + return ToGeGraph(g1); } } // namespace class FrameworkTest : public testing::Test { protected: + GeRunningEnvFaker ge_env; void SetUp() { ge_env.InstallDefault(); } void TearDown() {} - GeRunningEnvFaker ge_env; }; /// data data @@ -136,19 +107,19 @@ TEST_F(FrameworkTest, test_framework_add) { DEF_GRAPH(g1) { CHAIN(NODE("data1", DATA)->NODE("add", ADD)); CHAIN(NODE("data2", DATA)->NODE("add")); - }); + }; - auto graph = ToGeGraph(g1); - // new session & add graph map options; Session session(options); - auto ret = session.AddGraph(1, graph, options); - EXPECT_EQ(ret, SUCCESS); - // build input tensor + session.AddGraph(1, ToGeGraph(g1), options); std::vector inputs; - // build_graph through session - ret = session.BuildGraph(1, inputs); + auto ret = session.BuildGraph(1, inputs); + EXPECT_EQ(ret, SUCCESS); + CHECK_GRAPH(PreRunAfterBuild) { + ASSERT_EQ(graph->GetName(), "g1_1"); + ASSERT_EQ(graph->GetAllNodesSize(), 4); + }; } /** data a = 2; diff --git a/tests/st/testcase/test_ge_opt_info.cc b/tests/st/testcase/test_ge_opt_info.cc index 457473b1..2e8e5382 100644 --- a/tests/st/testcase/test_ge_opt_info.cc +++ b/tests/st/testcase/test_ge_opt_info.cc @@ -15,24 +15,12 @@ */ #include -#include "easy_graph/graph/box.h" -#include "easy_graph/graph/node.h" +#include "external/ge/ge_api.h" #include "easy_graph/builder/graph_dsl.h" -#include "easy_graph/builder/box_builder.h" -#include "easy_graph/layout/graph_layout.h" -#include "easy_graph/layout/engines/graph_easy/graph_easy_option.h" -#include "easy_graph/layout/engines/graph_easy/graph_easy_executor.h" -#include "graph/graph.h" #include "graph/compute_graph.h" #include "framework/common/types.h" -#include "graph/debug/ge_attr_define.h" +#include "graph/ge_local_context.h" #include "ge_graph_dsl/graph_dsl.h" -#include "ge_graph_dsl/op_desc/op_desc_cfg_box.h" -#define protected public -#define private public -#include "ge_opt_info/ge_opt_info.h" -#undef private -#undef protected namespace ge { class STEST_opt_info : public testing::Test { @@ -52,7 +40,7 @@ TEST_F(STEST_opt_info, get_opt_info_all) { DEF_GRAPH(g1) { CHAIN(NODE("data1", DATA)->NODE("add", ADD)); CHAIN(NODE("data2", DATA)->NODE("add")); - }); + }; auto graph = ToGeGraph(g1); @@ -95,7 +83,7 @@ TEST_F(STEST_opt_info, get_opt_info_success) { DEF_GRAPH(g1) { CHAIN(NODE("data1", DATA)->NODE("add", ADD)); CHAIN(NODE("data2", DATA)->NODE("add")); - }); + }; auto graph = ToGeGraph(g1); diff --git a/tests/st/testcase/test_main.cc b/tests/st/testcase/test_main.cc index a39c68aa..a7a71954 100644 --- a/tests/st/testcase/test_main.cc +++ b/tests/st/testcase/test_main.cc @@ -15,9 +15,8 @@ */ #include - -#include "common/debug/log.h" #include "external/ge/ge_api.h" +#include "ge_graph_dsl/assert/check_utils.h" #include "ge_running_env/include/ge_running_env/ge_running_env_faker.h" using namespace std; @@ -31,6 +30,7 @@ int main(int argc, char **argv) { std::cout << "ge init failed , ret code:" << init_status << endl; } GeRunningEnvFaker::BackupEnv(); + CheckUtils::init(); testing::InitGoogleTest(&argc, argv); int ret = RUN_ALL_TESTS(); return ret; diff --git a/tests/ut/common/graph/CMakeLists.txt b/tests/ut/common/graph/CMakeLists.txt index 73780967..ccf9ce5e 100644 --- a/tests/ut/common/graph/CMakeLists.txt +++ b/tests/ut/common/graph/CMakeLists.txt @@ -90,6 +90,7 @@ set(SRC_FILES "${GE_CODE_DIR}/metadef/graph/detail/attributes_holder.cc" "${GE_CODE_DIR}/metadef/graph/utils/anchor_utils.cc" "${GE_CODE_DIR}/metadef/graph/utils/graph_utils.cc" + "${GE_CODE_DIR}/metadef/graph/utils/dumper/ge_graph_dumper.cc" "${GE_CODE_DIR}/metadef/graph/utils/node_utils.cc" "${GE_CODE_DIR}/metadef/graph/utils/op_desc_utils.cc" "${GE_CODE_DIR}/metadef/graph/utils/type_utils.cc" diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 5b8958b4..d8fcd6c3 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -102,6 +102,7 @@ set(GRAPH_SRC_FILES "${GE_CODE_DIR}/metadef/graph/detail/attributes_holder.cc" "${GE_CODE_DIR}/metadef/graph/utils/anchor_utils.cc" "${GE_CODE_DIR}/metadef/graph/utils/graph_utils.cc" + "${GE_CODE_DIR}/metadef/graph/utils/dumper/ge_graph_dumper.cc" "${GE_CODE_DIR}/metadef/graph/utils/ge_ir_utils.cc" "${GE_CODE_DIR}/metadef/graph/utils/node_utils.cc" "${GE_CODE_DIR}/metadef/graph/utils/op_desc_utils.cc" From 08bedf29f6490261c1e99140250610c94f30c411 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Thu, 1 Jul 2021 19:04:59 +0800 Subject: [PATCH 49/50] Update submodule. --- metadef | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadef b/metadef index 9c9907b7..f3f137de 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit 9c9907b76a457f456072af96b8cbcfb7943beccc +Subproject commit f3f137de034885f0c7394d7f04b41b08d450d2d2 From 3de58133d1d3e88d912dcc32fa07ac137bbc9a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=9B=E6=A5=A0?= Date: Fri, 2 Jul 2021 10:22:54 +0800 Subject: [PATCH 50/50] fix the chmod error when unpack .run files --- scripts/update/ge_update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update/ge_update.sh b/scripts/update/ge_update.sh index d6bcd043..57266d06 100755 --- a/scripts/update/ge_update.sh +++ b/scripts/update/ge_update.sh @@ -38,7 +38,7 @@ function extract_deps_so_community() { echo "begin to extract .run file ........." chmod +x ./${DRIVER_RUN_NAME_C} - chmod +X ./${PACKAGE_NAME_C} + chmod +x ./${PACKAGE_NAME_C} [ -n "${DEP_TMP_DIR}" ] && rm -rf "${DEP_TMP_DIR}" ./${DRIVER_RUN_NAME_C} --noexec --extract=${DEP_TMP_DIR}/driver ./${PACKAGE_NAME_C} --noexec --extract=${DEP_TMP_DIR}/Packages_tmp