|
|
@@ -226,10 +226,7 @@ class Impl { |
|
|
|
}; |
|
|
|
~Impl() { (void)generator_.Finalize(); }; |
|
|
|
graphStatus CheckOptions(const std::map<std::string, std::string> &options); |
|
|
|
graphStatus CheckInputFormat(const string &input_format); |
|
|
|
graphStatus CreateInputsForIRBuild(const ge::Graph &graph, vector<ge::GeTensor> &inputs); |
|
|
|
graphStatus GetDefaultInputShape(const Graph &graph, string &default_shape, bool &dynamic_shape_flag); |
|
|
|
graphStatus GetDefaultInputFormat(const Graph &graph, string &default_format); |
|
|
|
graphStatus UpdateDataOpAttr(const Graph &graph); |
|
|
|
graphStatus Init(const Graph &graph, const std::map<std::string, std::string> &options); |
|
|
|
graphStatus BuildModel(const Graph &graph, const std::map<std::string, std::string> &options, |
|
|
@@ -323,106 +320,6 @@ graphStatus Impl::CheckOptions(const std::map<std::string, std::string> &options |
|
|
|
return GRAPH_SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|
graphStatus Impl::CheckInputFormat(const string &input_format) { |
|
|
|
if (!input_format.empty()) { |
|
|
|
auto iter = ge::input_format_str_to_geformat.find(input_format); |
|
|
|
if (iter == ge::input_format_str_to_geformat.end()) { |
|
|
|
GELOGE(GRAPH_PARAM_INVALID, "Input format %s not support , expect ND/NCHW/NHWC/CHWN/NC1HWC0/NHWC1C0.", |
|
|
|
input_format.c_str()); |
|
|
|
return GRAPH_PARAM_INVALID; |
|
|
|
} |
|
|
|
} |
|
|
|
return GRAPH_SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|
graphStatus Impl::GetDefaultInputFormat(const Graph &graph, string &default_format) { |
|
|
|
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."); |
|
|
|
|
|
|
|
const std::vector<int64_t> &tmp_shape = data_shape.GetDims(); |
|
|
|
if (tmp_shape.empty()) { |
|
|
|
GELOGD("Data op: %s has zero shape dims!", data_op_name.c_str()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
bool is_dynamic_input = false; |
|
|
|
for (auto tmp_dim : tmp_shape) { |
|
|
|
if (tmp_dim < 0) { |
|
|
|
is_dynamic_input = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (is_dynamic_input) { |
|
|
|
string tmp_data_format = ge::TypeUtils::FormatToSerialString(tensor.GetFormat()); |
|
|
|
if (!default_format.empty() && tmp_data_format!=default_format) { |
|
|
|
GELOGE(GRAPH_PARAM_INVALID, "All data op with dynamic shape has no default format!"); |
|
|
|
return GRAPH_PARAM_INVALID; |
|
|
|
} else if (default_format.empty()) { |
|
|
|
default_format.assign(tmp_data_format); |
|
|
|
} |
|
|
|
GELOGD("Data op name: %s, data format: %s.", data_op_name.c_str(), default_format.c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
GELOGI("Get default data op format: %s from ge ir graph.", default_format.c_str()); |
|
|
|
return GRAPH_SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|
graphStatus Impl::GetDefaultInputShape(const Graph &graph, string &default_shape, bool &dynamic_shape_flag) { |
|
|
|
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."); |
|
|
|
|
|
|
|
const std::vector<int64_t> &tmp_shape = data_shape.GetDims(); |
|
|
|
if (tmp_shape.empty()) { |
|
|
|
GELOGW("Data op: %s has zero shape dims!", data_op_name.c_str()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
string tmp_shape_str; |
|
|
|
bool is_dynamic_input = false; |
|
|
|
|
|
|
|
tmp_shape_str += data_op_name + ":"; |
|
|
|
for (auto tmp_dim : tmp_shape) { |
|
|
|
if (tmp_dim < 0) { |
|
|
|
is_dynamic_input = true; |
|
|
|
} |
|
|
|
tmp_shape_str += to_string((long)tmp_dim) + ","; |
|
|
|
} |
|
|
|
tmp_shape_str = tmp_shape_str.substr(0, tmp_shape_str.size() - 1); |
|
|
|
tmp_shape_str += ";"; |
|
|
|
|
|
|
|
if (is_dynamic_input) { |
|
|
|
dynamic_shape_flag = true; |
|
|
|
default_shape += tmp_shape_str; |
|
|
|
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: %s from ge ir graph.", default_shape.c_str()); |
|
|
|
return GRAPH_SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|
graphStatus Impl::Init(const Graph &graph, const std::map<std::string, std::string> &options) { |
|
|
|
// 1. check options |
|
|
|
graphStatus ret = CheckOptions(options); |
|
|
@@ -444,24 +341,8 @@ graphStatus Impl::Init(const Graph &graph, const std::map<std::string, std::stri |
|
|
|
GE_CHK_BOOL_RET_STATUS_NOLOG(ge::CheckLogParamValidAndSetLogLevel(log) == 0, GRAPH_PARAM_INVALID); |
|
|
|
options_[ge::ir_option::LOG_LEVEL] = log; |
|
|
|
|
|
|
|
string default_input_shape; |
|
|
|
bool dynamic_shape_flag = false; |
|
|
|
string input_shape = options_.find("input_shape") == options_.end() ? "" : options_["input_shape"]; |
|
|
|
if (input_shape.empty()) { |
|
|
|
GE_CHK_BOOL_EXEC(GetDefaultInputShape(graph, default_input_shape, dynamic_shape_flag) == ge::SUCCESS, |
|
|
|
return ge::GRAPH_PARAM_INVALID, "Get default data op shape from graph failed!"); |
|
|
|
input_shape.assign(default_input_shape); |
|
|
|
} |
|
|
|
|
|
|
|
string default_input_format; |
|
|
|
string input_format = options_.find("input_format") == options_.end() ? "" : options_["input_format"]; |
|
|
|
if (!input_format.empty()) { |
|
|
|
GE_CHK_BOOL_RET_STATUS_NOLOG(CheckInputFormat(input_format) == GRAPH_SUCCESS, GRAPH_PARAM_INVALID); |
|
|
|
} else if (dynamic_shape_flag) { |
|
|
|
GE_CHK_BOOL_EXEC(GetDefaultInputFormat(graph, default_input_format) == ge::SUCCESS, return ge::GRAPH_PARAM_INVALID, |
|
|
|
"Get default data op format from graph failed!"); |
|
|
|
input_format.assign(default_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() |
|
|
|
? "" |
|
|
|