From 975a8579e179007a05403096198b7f24a18f081b Mon Sep 17 00:00:00 2001 From: wxl Date: Wed, 9 Dec 2020 09:56:06 +0800 Subject: [PATCH 01/10] ir build optimize --- ge/ir_build/ge_ir_build.cc | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index a206a164..c3e557c8 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -385,7 +385,6 @@ graphStatus Impl::Init(const Graph &graph, const std::map(string(IR_OPTION_MODE), to_string(0))); - options_.insert(std::pair(string(IR_OPTION_TARGET), "mini")); options_.insert(std::pair(string(ge::RUN_FLAG), to_string(0))); options_.insert(std::pair(string(ge::TRAIN_FLAG), to_string(0))); options_.insert(std::pair(string(ge::SAVE_ORIGINAL_MODEL), to_string(0))); @@ -425,39 +424,52 @@ void Impl::UpdateThreadContext() { graphStatus Impl::CreateInputsForIRBuild(const ge::Graph &graph, vector &inputs) { auto compute_graph = ge::GraphUtils::GetComputeGraph(graph); GE_CHECK_NOTNULL(compute_graph); - int64_t index = 0; for (ge::NodePtr &input_node : compute_graph->GetDirectNode()) { GE_CHECK_NOTNULL(input_node); ge::OpDescPtr op = input_node->GetOpDesc(); GE_CHECK_NOTNULL(op); if (op->GetType() == DATA) { - (void)AttrUtils::SetInt(op, ATTR_NAME_INDEX, index++); GELOGD("Data op inputDesc size: %zu", op->GetAllInputsDesc().size()); - ge::GeTensorDesc tensor = op->GetInputDesc(0); + auto tensor = op->MutableInputDesc(0); string data_op_name = op->GetName(); GELOGD("Data op name: %s", data_op_name.c_str()); ge::GeShape data_shape; auto iter = omg_context_.input_dims.find(data_op_name); if (iter != omg_context_.input_dims.end()) { data_shape = ge::GeShape(iter->second); - GELOGD("Data op get shape from Context."); + tensor->SetShape(data_shape); + GELOGD("Data op get shape from Context and update [%s] shape info", data_op_name.c_str()); } else { - data_shape = tensor.GetShape(); + data_shape = tensor->GetShape(); GELOGD("Data op get shape from InputDesc in ge ir graph."); } // If user point input format, do work for all data ops; else do according to tensor_desc auto data_format = omg_context_.format != domi::DOMI_TENSOR_ND ? - ge::TypeUtils::DomiFormatToFormat(omg_context_.format) : tensor.GetFormat(); - ge::DataType data_type = tensor.GetDataType(); + ge::TypeUtils::DomiFormatToFormat(omg_context_.format) : tensor->GetFormat(); + ge::DataType data_type = tensor->GetDataType(); string data_type_str = ge::TypeUtils::DataTypeToSerialString(data_type); GELOGD("Data op get data type:%s from InputDesc in ge ir graph.", data_type_str.c_str()); ge::GeTensor inputTensor; ge::GeTensorDesc desc(data_shape, ge::Format(data_format), data_type); inputTensor.SetTensorDesc(desc); - inputs.push_back(inputTensor); + int64_t index = 0; + if (AttrUtils::GetInt(op, ATTR_NAME_INDEX, index)) { + AttrUtils::SetInt(desc, ATTR_NAME_INDEX, index); + } else { + GELOGE(GRAPH_PARAM_INVALID, "Get attr name idx failed!"); + return GRAPH_PARAM_INVALID; + } + inputs.emplace_back(inputTensor); } } + std::sort(inputs.begin(), input.end(), [](ge::GeTensor &a, ge::GeTensor &b) { + int64_t data_idx_a = 0; + int64_t data_idx_b = 0; + AttrUtils::GetInt(a.MutableTensorDesc(), ATTR_NAME_INDEX, data_idx_a); + AttrUtils::GetInt(b.MutableTensorDesc(), ATTR_NAME_INDEX, data_idx_b); + return data_idx_a <= data_idx_b; + }); GELOGD("CreateInputsForIRBuild, inputs size: %zu", inputs.size()); return GRAPH_SUCCESS; } From a755e711d1befaa5162ede069023ad705eda79d3 Mon Sep 17 00:00:00 2001 From: wxl Date: Wed, 9 Dec 2020 10:00:33 +0800 Subject: [PATCH 02/10] ir build optimize --- ge/ir_build/ge_ir_build.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index c3e557c8..b3be6acd 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -463,7 +463,7 @@ graphStatus Impl::CreateInputsForIRBuild(const ge::Graph &graph, vector Date: Wed, 9 Dec 2020 10:05:02 +0800 Subject: [PATCH 03/10] ir build optimize --- ge/ir_build/ge_ir_build.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index b3be6acd..34663493 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -463,7 +463,7 @@ graphStatus Impl::CreateInputsForIRBuild(const ge::Graph &graph, vector Date: Wed, 9 Dec 2020 14:11:41 +0800 Subject: [PATCH 04/10] ir build optimize --- ge/ir_build/ge_ir_build.cc | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index 34663493..6dfda036 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -50,6 +50,9 @@ const std::string IR_OPTION_LOG_LEVEL_DEFAULT = "default"; const std::string IR_OPTION_BUFFER_OPTIMIZE_DEFAULT = "l2_optimize"; const std::string IR_OPTION_DISABLE_REUSE_MEMORY_DEFAULT = "0"; const std::string IR_OPTION_ENABLE_COMPRESS_WEIGHT_DEFAULT = "false"; + +const std::string kInputShape = "input_shape"; +const std::string kInputFormat = "input_format"; } // namespace static graphStatus CheckGlobalOptions(std::map &global_options) { @@ -232,6 +235,7 @@ class Impl { ModelBufferData &ge_models); graphStatus InitDomiOmgContext(const string &input_shape, const string &input_format, const string &net_format, bool is_dynamic_input); + graphStatus UpdateDataOp(const Graph &graph); void SetRtSocVersion(); void UpdateThreadContext(); void LoadOpsProto(); @@ -242,6 +246,36 @@ class Impl { OmgContext omg_context_; }; +graphStatus Impl::UpdateDataOpAttr(const Graph &graph) { + GELOGD("Enter Update Data Attr Process!"); + if (options_.find(kInputShape) == options_.end()) { + return GRAPH_SUCCESS; + } + unordered_map> shape_map; + vector>> user_shape_map; + GE_CHK_BOOL_EXEC(ParseInputShape(options_[kInputShape], shape_map, user_shape_map, true), + return GRAPH_PARAM_INVALID, "parse input shape failed!"); + auto compute_graph = ge::GraphUtils::GetComputeGraph(graph); + GE_CHECK_NOTNULL(compute_graph); + for (ge::NodePtr &input_node : compute_graph->GetDirectNode()) { + GE_CHECK_NOTNULL(input_node); + ge::OpDescPtr op = input_node->GetOpDesc(); + GE_CHECK_NOTNULL(op); + if (op->GetType() == DATA) { + auto tensor = op->MutableInputDesc(0); + string data_op_name = op->GetName(); + auto iter = shape_map.find(data_op_name); + if (iter != shape_map.end()) { + tensor->SetShape(ge::GeShape(iter->second)); + GELOGD("update input [%s] shape info", data_op_name.c_str()); + } else { + GELOGI("no need update input [%s] attr because not found from input_shape.", data_op_name.c_str()); + } + } + } + return GRAPH_SUCCESS; +} + graphStatus Impl::CheckOptions(const std::map &options) { for (auto &ele : options) { auto it = ge::ir_option::ir_builder_suppported_options.find(ele.first); @@ -437,7 +471,6 @@ graphStatus Impl::CreateInputsForIRBuild(const ge::Graph &graph, vectorsecond); - tensor->SetShape(data_shape); GELOGD("Data op get shape from Context and update [%s] shape info", data_op_name.c_str()); } else { data_shape = tensor->GetShape(); From ae3c7823efa9c8b61d8aefa66d44590ea3e52a7a Mon Sep 17 00:00:00 2001 From: wxl Date: Wed, 9 Dec 2020 14:22:29 +0800 Subject: [PATCH 05/10] ir build optimize --- ge/ir_build/ge_ir_build.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index 6dfda036..bfc81c7e 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -235,7 +235,7 @@ class Impl { ModelBufferData &ge_models); graphStatus InitDomiOmgContext(const string &input_shape, const string &input_format, const string &net_format, bool is_dynamic_input); - graphStatus UpdateDataOp(const Graph &graph); + graphStatus UpdateDataOpAttr(const Graph &graph); void SetRtSocVersion(); void UpdateThreadContext(); void LoadOpsProto(); From 18ab1af64676452483696399671ab67d56b61872 Mon Sep 17 00:00:00 2001 From: wxl Date: Wed, 9 Dec 2020 21:31:11 +0800 Subject: [PATCH 06/10] ir build optimize --- ge/ir_build/ge_ir_build.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index bfc81c7e..1128207a 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -262,11 +262,13 @@ graphStatus Impl::UpdateDataOpAttr(const Graph &graph) { ge::OpDescPtr op = input_node->GetOpDesc(); GE_CHECK_NOTNULL(op); if (op->GetType() == DATA) { - auto tensor = op->MutableInputDesc(0); + auto tensor_input = op->MutableInputDesc(0); + auto tensor_output = op->MutableOutputDesc(0); string data_op_name = op->GetName(); auto iter = shape_map.find(data_op_name); if (iter != shape_map.end()) { - tensor->SetShape(ge::GeShape(iter->second)); + tensor_input->SetShape(ge::GeShape(iter->second)); + tensor_output->SetShape(ge::GeShape(iter->second)); GELOGD("update input [%s] shape info", data_op_name.c_str()); } else { GELOGI("no need update input [%s] attr because not found from input_shape.", data_op_name.c_str()); @@ -360,7 +362,10 @@ graphStatus Impl::Init(const Graph &graph, const std::map Date: Thu, 10 Dec 2020 09:29:26 +0800 Subject: [PATCH 07/10] ir build optimize --- ge/ir_build/ge_ir_build.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index 1128207a..289b0b9e 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -470,6 +470,7 @@ graphStatus Impl::CreateInputsForIRBuild(const ge::Graph &graph, vectorGetType() == DATA) { GELOGD("Data op inputDesc size: %zu", op->GetAllInputsDesc().size()); auto tensor = op->MutableInputDesc(0); + GE_CHECK_NOTNULL(tensor); string data_op_name = op->GetName(); GELOGD("Data op name: %s", data_op_name.c_str()); ge::GeShape data_shape; From 16efa936d4cae6bb0be1cff120f2cc20f9379a9c Mon Sep 17 00:00:00 2001 From: wxl Date: Thu, 10 Dec 2020 09:52:07 +0800 Subject: [PATCH 08/10] ir build optimize --- ge/ir_build/ge_ir_build.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index 289b0b9e..6ff3e5e1 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -53,6 +53,8 @@ const std::string IR_OPTION_ENABLE_COMPRESS_WEIGHT_DEFAULT = "false"; const std::string kInputShape = "input_shape"; const std::string kInputFormat = "input_format"; +const std::string kReUseMemEnable = "1"; +const std::string kReUseMemDisEnable = "0"; } // namespace static graphStatus CheckGlobalOptions(std::map &global_options) { @@ -313,6 +315,12 @@ graphStatus Impl::CheckOptions(const std::map &options return GRAPH_PARAM_INVALID; } } + // Check option EXEC_DISABLE_REUSED_MEMORY + it = options_.find(EXEC_DISABLE_REUSED_MEMORY); + if (it != options_.end() && it->second != kReUseMemEnable && it->second != kReUseMemDisEnable) { + GELOGE(GRAPH_PARAM_INVALID, "option(EXEC_DISABLE_REUSED_MEMORY) value[%s] is invalid ", it->second.c_str()); + return GRAPH_PARAM_INVALID; + } return GRAPH_SUCCESS; } From d6388feddecc7d5f9086ae991c7bf67929c5d4df Mon Sep 17 00:00:00 2001 From: wxl Date: Thu, 10 Dec 2020 11:36:05 +0800 Subject: [PATCH 09/10] ir build optimize --- ge/ir_build/ge_ir_build.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index 6ff3e5e1..b353a72a 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -316,7 +316,7 @@ graphStatus Impl::CheckOptions(const std::map &options } } // Check option EXEC_DISABLE_REUSED_MEMORY - it = options_.find(EXEC_DISABLE_REUSED_MEMORY); + it = options_.find(ge::ir_option::EXEC_DISABLE_REUSED_MEMORY); if (it != options_.end() && it->second != kReUseMemEnable && it->second != kReUseMemDisEnable) { GELOGE(GRAPH_PARAM_INVALID, "option(EXEC_DISABLE_REUSED_MEMORY) value[%s] is invalid ", it->second.c_str()); return GRAPH_PARAM_INVALID; From c60279ac6284f1c7fc0ade65a100298290e19860 Mon Sep 17 00:00:00 2001 From: wxl Date: Thu, 10 Dec 2020 14:05:48 +0800 Subject: [PATCH 10/10] ir build optimize --- ge/ir_build/ge_ir_build.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index b353a72a..f9c4e259 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -266,6 +266,8 @@ graphStatus Impl::UpdateDataOpAttr(const Graph &graph) { if (op->GetType() == DATA) { auto tensor_input = op->MutableInputDesc(0); auto tensor_output = op->MutableOutputDesc(0); + GE_CHECK_NOTNULL(tensor_input); + GE_CHECK_NOTNULL(tensor_output); string data_op_name = op->GetName(); auto iter = shape_map.find(data_op_name); if (iter != shape_map.end()) { @@ -317,8 +319,7 @@ graphStatus Impl::CheckOptions(const std::map &options } // Check option EXEC_DISABLE_REUSED_MEMORY it = options_.find(ge::ir_option::EXEC_DISABLE_REUSED_MEMORY); - if (it != options_.end() && it->second != kReUseMemEnable && it->second != kReUseMemDisEnable) { - GELOGE(GRAPH_PARAM_INVALID, "option(EXEC_DISABLE_REUSED_MEMORY) value[%s] is invalid ", it->second.c_str()); + if (it != options_.end() && (CheckDisableReuseMemoryParamValid(it->second) != GRAPH_SUCCESS)) { return GRAPH_PARAM_INVALID; } return GRAPH_SUCCESS;