From 881a165c5d1808b699a4327761d743bb33f20fc6 Mon Sep 17 00:00:00 2001 From: l00444296 Date: Mon, 7 Dec 2020 21:02:16 +0800 Subject: [PATCH 1/8] Feature: Get default from ge ir graph while no user input shape --- ge/ir_build/ge_ir_build.cc | 48 ++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index 77d5be51..e997d922 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -225,7 +225,8 @@ class Impl { ~Impl() { (void)generator_.Finalize(); }; graphStatus CheckOptions(const std::map &options); graphStatus CreateInputsForIRBuild(const ge::Graph &graph, vector &inputs); - graphStatus Init(const std::map &options); + graphStatus GetDefaultInputShape(const Graph &graph, string &default_shape); + graphStatus Init(const Graph &graph, const std::map &options); graphStatus BuildModel(const Graph &graph, const std::map &options, ModelBufferData &ge_models); graphStatus InitDomiOmgContext(const string &input_shape, const string &input_format, const string &net_format, @@ -278,7 +279,41 @@ graphStatus Impl::CheckOptions(const std::map &options return GRAPH_SUCCESS; } -graphStatus Impl::Init(const std::map &options) { +graphStatus Impl::GetDefaultInputShape(const Graph &graph, string &default_shape) { + 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) { + string data_op_name = op->GetName(); + GELOGD("Data op name: %s, data op inputDesc size: %zu", data_op_name.c_str(), op->GetAllInputsDesc().size()); + ge::GeTensorDesc tensor = op->GetInputDesc(0); + ge::GeShape data_shape = tensor.GetShape(); + GELOGD("Data op get shape from InputDesc in ge ir graph."); + + string tmp_shape_str; + std::vector tmp_shape = data_shape.GetDims(); + if (tmp_shape.size() == 0) { + GELOGE(GRAPH_PARAM_INVALID, "Data op: %s has zero shapr dims!", data_op_name.c_str()); + return GRAPH_PARAM_INVALID; + } + + tmp_shape_str += data_op_name + ":"; + for (auto tmp_dim : tmp_shape) { + tmp_shape_str += to_string((long)tmp_dim) + ","; + } + tmp_shape_str = tmp_shape_str.substr(0, tmp_shape_str.size() - 1); + tmp_shape_str += ";"; + default_shape += tmp_shape_str(); + GELOGD("Data op name: %s, data shape: %s", data_op_name.c_str(), tmp_shape_str.c_str()); + } + } + GELOGI("Get default data op shape from ge ir graph: %s", default_shape.c_str()); +} + +graphStatus Impl::Init(const Graph &graph, const std::map &options) { // 1. check options graphStatus ret = CheckOptions(options); if (ret != GRAPH_SUCCESS) { @@ -296,7 +331,12 @@ graphStatus Impl::Init(const std::map &options) { GE_CHK_BOOL_RET_STATUS_NOLOG(ge::CheckLogParamValidAndSetLogLevel(log) == 0, GRAPH_PARAM_INVALID); options_[ge::ir_option::LOG_LEVEL] = log; - string input_shape = options_.find("input_shape") == options_.end() ? "" : options_["input_shape"]; + string input_shape; + if (options_.find("input_shape") == options_.end()) { + GE_CHK_BOOL_RET_STATUS_NOLOG(GetDefaultInputShape(graph, input_shape), GRAPH_PARAM_INVALID); + } else { + input_shape = options_["input_shape"]; + } string input_format = options_.find("input_format") == options_.end() ? "" : options_["input_format"]; string net_format = options_.find("net_format") == options_.end() ? "" : options_["net_format"]; string dynamic_batch_size = options_.find(ge::ir_option::DYNAMIC_BATCH_SIZE) == options_.end() @@ -416,7 +456,7 @@ graphStatus Impl::CreateInputsForIRBuild(const ge::Graph &graph, vector &options, ModelBufferData &model) { // 1. init GeGenerator with user optios - graphStatus ret = Init(options); + graphStatus ret = Init(graph, options); if (ret != GRAPH_SUCCESS) { GELOGE(ret, "Build ir model Init failed!"); return ret; From b0b8ca9d35811e05ba9208c5abc8c306aed77ff5 Mon Sep 17 00:00:00 2001 From: l00444296 Date: Mon, 7 Dec 2020 21:05:36 +0800 Subject: [PATCH 2/8] Feature: Get default from ge ir graph while no user input shape --- 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 e997d922..22a0165a 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -306,7 +306,7 @@ graphStatus Impl::GetDefaultInputShape(const Graph &graph, string &default_shape } tmp_shape_str = tmp_shape_str.substr(0, tmp_shape_str.size() - 1); tmp_shape_str += ";"; - default_shape += tmp_shape_str(); + default_shape += tmp_shape_str; GELOGD("Data op name: %s, data shape: %s", data_op_name.c_str(), tmp_shape_str.c_str()); } } From 261a6004fa8c0e71c81eae959756f553cc9c430b Mon Sep 17 00:00:00 2001 From: l00444296 Date: Tue, 8 Dec 2020 14:00:22 +0800 Subject: [PATCH 3/8] Feature: Get default from ge ir graph while no user input shape --- 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 22a0165a..b0f1b25e 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -311,6 +311,7 @@ graphStatus Impl::GetDefaultInputShape(const Graph &graph, string &default_shape } } GELOGI("Get default data op shape from ge ir graph: %s", default_shape.c_str()); + return GRAPH_SUCCESS; } graphStatus Impl::Init(const Graph &graph, const std::map &options) { From 07800ed03c601c28edc79a97543f1133177d5f60 Mon Sep 17 00:00:00 2001 From: l00444296 Date: Tue, 8 Dec 2020 14:26:01 +0800 Subject: [PATCH 4/8] Feature: Get default from ge ir graph while no user input shape --- ge/ir_build/ge_ir_build.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index b0f1b25e..fbacf527 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -334,7 +334,8 @@ graphStatus Impl::Init(const Graph &graph, const std::map Date: Tue, 8 Dec 2020 14:56:26 +0800 Subject: [PATCH 5/8] Feature: Get default from ge ir graph while no user input shape --- 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 fbacf527..2035dbe0 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -310,6 +310,7 @@ graphStatus Impl::GetDefaultInputShape(const Graph &graph, string &default_shape GELOGD("Data op name: %s, data shape: %s", data_op_name.c_str(), tmp_shape_str.c_str()); } } + default_shape = (default_shape.empty() ? default_shape : default_shape.substr(0, default_shape.size() - 1)); GELOGI("Get default data op shape from ge ir graph: %s", default_shape.c_str()); return GRAPH_SUCCESS; } From a2da82c86fd78c0e199d87fdbf4137b370b53dcd Mon Sep 17 00:00:00 2001 From: l00444296 Date: Tue, 8 Dec 2020 15:33:42 +0800 Subject: [PATCH 6/8] Feature: Get default from ge ir graph while no user input shape --- ge/ir_build/ge_ir_build.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index 2035dbe0..518ab49b 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -36,6 +36,7 @@ #include "model/ge_model.h" #include "graph/shape_refiner.h" #include "graph/opsproto_manager.h" +#include "graph/utils/type_utils.h" using std::string; using namespace std; @@ -225,7 +226,7 @@ class Impl { ~Impl() { (void)generator_.Finalize(); }; graphStatus CheckOptions(const std::map &options); graphStatus CreateInputsForIRBuild(const ge::Graph &graph, vector &inputs); - graphStatus GetDefaultInputShape(const Graph &graph, string &default_shape); + graphStatus GetDefaultInputShapeAndFormat(const Graph &graph, string &default_shape, string &input_format); graphStatus Init(const Graph &graph, const std::map &options); graphStatus BuildModel(const Graph &graph, const std::map &options, ModelBufferData &ge_models); @@ -279,7 +280,7 @@ graphStatus Impl::CheckOptions(const std::map &options return GRAPH_SUCCESS; } -graphStatus Impl::GetDefaultInputShape(const Graph &graph, string &default_shape) { +graphStatus Impl::GetDefaultInputShapeAndFormat(const Graph &graph, string &default_shape, string &input_format) { auto compute_graph = ge::GraphUtils::GetComputeGraph(graph); GE_CHECK_NOTNULL(compute_graph); for (ge::NodePtr &input_node : compute_graph->GetDirectNode()) { @@ -307,7 +308,11 @@ graphStatus Impl::GetDefaultInputShape(const Graph &graph, string &default_shape tmp_shape_str = tmp_shape_str.substr(0, tmp_shape_str.size() - 1); tmp_shape_str += ";"; default_shape += tmp_shape_str; - GELOGD("Data op name: %s, data shape: %s", data_op_name.c_str(), tmp_shape_str.c_str()); + + ge::Format data_format = tensor.GetFormat(); + input_format.assign(ge::TypeUtils::FormatToSerialString(data_format)); + GELOGD("Data op name: %s, data shape: %s, data format: %s.", data_op_name.c_str(), tmp_shape_str.c_str(), + input_format.c_str()); } } default_shape = (default_shape.empty() ? default_shape : default_shape.substr(0, default_shape.size() - 1)); @@ -334,13 +339,14 @@ graphStatus Impl::Init(const Graph &graph, const std::map Date: Tue, 8 Dec 2020 17:32:32 +0800 Subject: [PATCH 7/8] Feature: Get default from ge ir graph while no user input shape --- ge/ir_build/ge_ir_build.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index 518ab49b..06954ed5 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -297,17 +297,16 @@ graphStatus Impl::GetDefaultInputShapeAndFormat(const Graph &graph, string &defa string tmp_shape_str; std::vector tmp_shape = data_shape.GetDims(); if (tmp_shape.size() == 0) { - GELOGE(GRAPH_PARAM_INVALID, "Data op: %s has zero shapr dims!", data_op_name.c_str()); - return GRAPH_PARAM_INVALID; - } - - tmp_shape_str += data_op_name + ":"; - for (auto tmp_dim : tmp_shape) { - tmp_shape_str += to_string((long)tmp_dim) + ","; + GELOGW("Data op: %s has zero shape dims!", data_op_name.c_str()); + } else { + tmp_shape_str += data_op_name + ":"; + for (auto tmp_dim : tmp_shape) { + tmp_shape_str += to_string((long)tmp_dim) + ","; + } + tmp_shape_str = tmp_shape_str.substr(0, tmp_shape_str.size() - 1); + tmp_shape_str += ";"; + default_shape += tmp_shape_str; } - tmp_shape_str = tmp_shape_str.substr(0, tmp_shape_str.size() - 1); - tmp_shape_str += ";"; - default_shape += tmp_shape_str; ge::Format data_format = tensor.GetFormat(); input_format.assign(ge::TypeUtils::FormatToSerialString(data_format)); @@ -316,7 +315,7 @@ graphStatus Impl::GetDefaultInputShapeAndFormat(const Graph &graph, string &defa } } default_shape = (default_shape.empty() ? default_shape : default_shape.substr(0, default_shape.size() - 1)); - GELOGI("Get default data op shape from ge ir graph: %s", default_shape.c_str()); + GELOGI("Get default data op shape: %s, format: %s from ge ir graph.", default_shape.c_str(), input_format.c_str()); return GRAPH_SUCCESS; } From 4382d783928727ba800e7b2b69d653f46dca0a73 Mon Sep 17 00:00:00 2001 From: l00444296 Date: Tue, 8 Dec 2020 20:39:36 +0800 Subject: [PATCH 8/8] Feature: Get default from ge ir graph while no user input shape --- ge/ir_build/ge_ir_build.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ge/ir_build/ge_ir_build.cc b/ge/ir_build/ge_ir_build.cc index 06954ed5..a206a164 100644 --- a/ge/ir_build/ge_ir_build.cc +++ b/ge/ir_build/ge_ir_build.cc @@ -295,8 +295,8 @@ graphStatus Impl::GetDefaultInputShapeAndFormat(const Graph &graph, string &defa GELOGD("Data op get shape from InputDesc in ge ir graph."); string tmp_shape_str; - std::vector tmp_shape = data_shape.GetDims(); - if (tmp_shape.size() == 0) { + const std::vector &tmp_shape = data_shape.GetDims(); + if (tmp_shape.empty()) { GELOGW("Data op: %s has zero shape dims!", data_op_name.c_str()); } else { tmp_shape_str += data_op_name + ":"; @@ -341,7 +341,7 @@ graphStatus Impl::Init(const Graph &graph, const std::map