From 96ecc01cbe7286888b57852226771d7a9e1f3e1a Mon Sep 17 00:00:00 2001 From: wjm Date: Thu, 10 Jun 2021 11:47:43 +0800 Subject: [PATCH 01/25] 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/25] 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 75429f81a033a9de1b975936948aa6310b68523c Mon Sep 17 00:00:00 2001 From: wqtshg Date: Fri, 25 Jun 2021 10:22:30 +0800 Subject: [PATCH 03/25] 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 c7e8fc988d24c951dc1942847878e2b339e0e961 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Mon, 28 Jun 2021 19:26:20 +0800 Subject: [PATCH 04/25] 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 e1c506026cc082fed10f63630bfb3c2275ce245b Mon Sep 17 00:00:00 2001 From: wangxiaotian22 Date: Tue, 29 Jun 2021 21:08:22 +0800 Subject: [PATCH 05/25] 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 06/25] 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 07/25] 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 08/25] 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 09/25] 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 10/25] 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 11/25] 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 12/25] =?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 13/25] 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 14/25] 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 15/25] 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 16/25] 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 17/25] 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 18/25] 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 19/25] 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 20/25] 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 21/25] 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 22/25] 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 23/25] 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 24/25] 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 25/25] 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