From: @wan_xuelei Reviewed-by: @xchu42,@wqtshg Signed-off-by: @wqtshgtags/v1.2.0
@@ -36,7 +36,6 @@ | |||||
#include "model/ge_model.h" | #include "model/ge_model.h" | ||||
#include "graph/shape_refiner.h" | #include "graph/shape_refiner.h" | ||||
#include "graph/opsproto_manager.h" | #include "graph/opsproto_manager.h" | ||||
#include "graph/utils/type_utils.h" | |||||
using std::string; | using std::string; | ||||
using namespace std; | using namespace std; | ||||
@@ -50,6 +49,8 @@ const std::string IR_OPTION_LOG_LEVEL_DEFAULT = "default"; | |||||
const std::string IR_OPTION_BUFFER_OPTIMIZE_DEFAULT = "l2_optimize"; | 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_DISABLE_REUSE_MEMORY_DEFAULT = "0"; | ||||
const std::string IR_OPTION_ENABLE_COMPRESS_WEIGHT_DEFAULT = "false"; | const std::string IR_OPTION_ENABLE_COMPRESS_WEIGHT_DEFAULT = "false"; | ||||
const std::string kInputShape = "input_shape"; | |||||
const std::string kInputFormat = "input_format"; | |||||
} // namespace | } // namespace | ||||
static graphStatus CheckGlobalOptions(std::map<std::string, std::string> &global_options) { | static graphStatus CheckGlobalOptions(std::map<std::string, std::string> &global_options) { | ||||
@@ -227,6 +228,7 @@ class Impl { | |||||
graphStatus CheckOptions(const std::map<std::string, std::string> &options); | graphStatus CheckOptions(const std::map<std::string, std::string> &options); | ||||
graphStatus CreateInputsForIRBuild(const ge::Graph &graph, vector<ge::GeTensor> &inputs); | graphStatus CreateInputsForIRBuild(const ge::Graph &graph, vector<ge::GeTensor> &inputs); | ||||
graphStatus GetDefaultInputShape(const Graph &graph, string &default_shape); | graphStatus GetDefaultInputShape(const Graph &graph, string &default_shape); | ||||
graphStatus UpdateDataOpAttr(const Graph &graph); | |||||
graphStatus Init(const Graph &graph, const std::map<std::string, std::string> &options); | 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, | graphStatus BuildModel(const Graph &graph, const std::map<std::string, std::string> &options, | ||||
ModelBufferData &ge_models); | ModelBufferData &ge_models); | ||||
@@ -242,6 +244,40 @@ class Impl { | |||||
OmgContext omg_context_; | 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<string, vector<int64_t>> shape_map; | |||||
vector<pair<string, vector<int64_t>>> 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_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()) { | |||||
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()); | |||||
} | |||||
} | |||||
} | |||||
return GRAPH_SUCCESS; | |||||
} | |||||
graphStatus Impl::CheckOptions(const std::map<std::string, std::string> &options) { | graphStatus Impl::CheckOptions(const std::map<std::string, std::string> &options) { | ||||
for (auto &ele : options) { | for (auto &ele : options) { | ||||
auto it = ge::ir_option::ir_builder_suppported_options.find(ele.first); | auto it = ge::ir_option::ir_builder_suppported_options.find(ele.first); | ||||
@@ -277,6 +313,11 @@ graphStatus Impl::CheckOptions(const std::map<std::string, std::string> &options | |||||
return GRAPH_PARAM_INVALID; | return GRAPH_PARAM_INVALID; | ||||
} | } | ||||
} | } | ||||
// Check option EXEC_DISABLE_REUSED_MEMORY | |||||
it = options_.find(ge::ir_option::EXEC_DISABLE_REUSED_MEMORY); | |||||
if (it != options_.end() && (CheckDisableReuseMemoryParamValid(it->second) != GRAPH_SUCCESS)) { | |||||
return GRAPH_PARAM_INVALID; | |||||
} | |||||
return GRAPH_SUCCESS; | return GRAPH_SUCCESS; | ||||
} | } | ||||
@@ -323,7 +364,10 @@ graphStatus Impl::Init(const Graph &graph, const std::map<std::string, std::stri | |||||
GELOGE(ret, "User input options are illegal! Please check!"); | GELOGE(ret, "User input options are illegal! Please check!"); | ||||
return ret; | return ret; | ||||
} | } | ||||
ret = UpdateDataOpAttr(graph); | |||||
if (ret != GRAPH_SUCCESS) { | |||||
return ret; | |||||
} | |||||
std::string build_mode = (options_.find(BUILD_MODE) == options_.end() || options_[BUILD_MODE] == BUILD_MODE_NORMAL) | std::string build_mode = (options_.find(BUILD_MODE) == options_.end() || options_[BUILD_MODE] == BUILD_MODE_NORMAL) | ||||
? "" : options_[BUILD_MODE]; | ? "" : options_[BUILD_MODE]; | ||||
options_[BUILD_MODE] = build_mode; | options_[BUILD_MODE] = build_mode; | ||||
@@ -27,6 +27,7 @@ | |||||
#include "common/ge_inner_error_codes.h" | #include "common/ge_inner_error_codes.h" | ||||
#include "framework/common/util.h" | #include "framework/common/util.h" | ||||
#include "graph/utils/tensor_utils.h" | #include "graph/utils/tensor_utils.h" | ||||
#include "graph/utils/type_utils.h" | |||||
#include "graph/utils/op_desc_utils.h" | #include "graph/utils/op_desc_utils.h" | ||||
#include "graph/operator_factory_impl.h" | #include "graph/operator_factory_impl.h" | ||||
@@ -176,6 +177,7 @@ T GetValue(const map<string, T> &dict, string &key, T default_val) { | |||||
} | } | ||||
void from_json(const Json &j, SingleOpTensorDesc &desc) { | void from_json(const Json &j, SingleOpTensorDesc &desc) { | ||||
bool is_tensor_valid = true; | |||||
desc.dims = j.at(kKeyShape).get<vector<int64_t>>(); | desc.dims = j.at(kKeyShape).get<vector<int64_t>>(); | ||||
auto it = j.find(kKeyShapeRange); | auto it = j.find(kKeyShapeRange); | ||||
if (it != j.end()) { | if (it != j.end()) { | ||||
@@ -189,9 +191,12 @@ void from_json(const Json &j, SingleOpTensorDesc &desc) { | |||||
string type_str = j.at(kKeyType).get<string>(); | string type_str = j.at(kKeyType).get<string>(); | ||||
desc.format = GetValue(kFormatDict, format_str, FORMAT_RESERVED); | desc.format = GetValue(kFormatDict, format_str, FORMAT_RESERVED); | ||||
desc.type = GetValue(kDataTypeDict, type_str, DT_UNDEFINED); | desc.type = GetValue(kDataTypeDict, type_str, DT_UNDEFINED); | ||||
is_tensor_valid = is_tensor_valid && ge::TypeUtils::IsFormatValid(format_str); | |||||
is_tensor_valid = is_tensor_valid && ge::TypeUtils::IsDataTypeValid(type_str); | |||||
it = j.find(kKeyOriginFormat); | it = j.find(kKeyOriginFormat); | ||||
if (it != j.end()) { | if (it != j.end()) { | ||||
string origin_format_str = j.at(kKeyOriginFormat).get<string>(); | string origin_format_str = j.at(kKeyOriginFormat).get<string>(); | ||||
is_tensor_valid = is_tensor_valid && ge::TypeUtils::IsFormatValid(origin_format_str); | |||||
desc.ori_format = GetValue(kFormatDict, origin_format_str, FORMAT_RESERVED); | desc.ori_format = GetValue(kFormatDict, origin_format_str, FORMAT_RESERVED); | ||||
} | } | ||||
auto tensor_name = j.find(kKeyName); | auto tensor_name = j.find(kKeyName); | ||||
@@ -202,6 +207,9 @@ void from_json(const Json &j, SingleOpTensorDesc &desc) { | |||||
if (dynamic_input_name != j.end()) { | if (dynamic_input_name != j.end()) { | ||||
desc.dynamic_input_name = dynamic_input_name->get<string>(); | desc.dynamic_input_name = dynamic_input_name->get<string>(); | ||||
} | } | ||||
if (!is_tensor_valid) { | |||||
desc.SetValidFlag(is_tensor_valid); | |||||
} | |||||
} | } | ||||
void from_json(const Json &j, SingleOpAttr &attr) { | void from_json(const Json &j, SingleOpAttr &attr) { | ||||
@@ -305,6 +313,12 @@ bool SingleOpParser::Validate(const SingleOpDesc &op_desc) { | |||||
int index = 0; | int index = 0; | ||||
for (auto &tensor_desc : op_desc.input_desc) { | for (auto &tensor_desc : op_desc.input_desc) { | ||||
if (!tensor_desc.GetValidFlag()) { | |||||
ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "type", "index"}, | |||||
{"intput", "datatype or format", std::to_string(index)}); | |||||
GELOGE(PARAM_INVALID, "Input's dataType or format is invalid when the index is %d", index); | |||||
return false; | |||||
} | |||||
if ((tensor_desc.type == DT_UNDEFINED && tensor_desc.format != FORMAT_RESERVED) || | if ((tensor_desc.type == DT_UNDEFINED && tensor_desc.format != FORMAT_RESERVED) || | ||||
(tensor_desc.type != DT_UNDEFINED && tensor_desc.format == FORMAT_RESERVED)){ | (tensor_desc.type != DT_UNDEFINED && tensor_desc.format == FORMAT_RESERVED)){ | ||||
ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "type", "index"}, | ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "type", "index"}, | ||||
@@ -317,6 +331,12 @@ bool SingleOpParser::Validate(const SingleOpDesc &op_desc) { | |||||
index = 0; | index = 0; | ||||
for (auto &tensor_desc : op_desc.output_desc) { | for (auto &tensor_desc : op_desc.output_desc) { | ||||
if (!tensor_desc.GetValidFlag()) { | |||||
ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "type", "index"}, | |||||
{"output", "datatype", std::to_string(index)}); | |||||
GELOGE(PARAM_INVALID, "Output's dataType is invalid when the index is %d", index); | |||||
return false; | |||||
} | |||||
if (tensor_desc.type == DT_UNDEFINED) { | if (tensor_desc.type == DT_UNDEFINED) { | ||||
ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "type", "index"}, | ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "type", "index"}, | ||||
{"output", "datatype", std::to_string(index)}); | {"output", "datatype", std::to_string(index)}); | ||||
@@ -28,6 +28,10 @@ | |||||
namespace ge { | namespace ge { | ||||
struct SingleOpTensorDesc { | struct SingleOpTensorDesc { | ||||
public: | |||||
bool GetValidFlag() const { return is_valid_; } | |||||
void SetValidFlag(bool is_valid) { is_valid_ = is_valid; } | |||||
public: | |||||
std::string name; | std::string name; | ||||
std::vector<int64_t> dims; | std::vector<int64_t> dims; | ||||
std::vector<int64_t> ori_dims; | std::vector<int64_t> ori_dims; | ||||
@@ -36,6 +40,8 @@ struct SingleOpTensorDesc { | |||||
ge::Format ori_format = ge::FORMAT_RESERVED; | ge::Format ori_format = ge::FORMAT_RESERVED; | ||||
ge::DataType type = ge::DT_UNDEFINED; | ge::DataType type = ge::DT_UNDEFINED; | ||||
std::string dynamic_input_name; | std::string dynamic_input_name; | ||||
private: | |||||
bool is_valid_ = true; | |||||
}; | }; | ||||
struct SingleOpAttr { | struct SingleOpAttr { | ||||