@@ -142,6 +142,7 @@ set(TRAIN_SRC_LIST | |||||
"graph/passes/atomic_addr_clean_pass.cc" | "graph/passes/atomic_addr_clean_pass.cc" | ||||
"graph/passes/mark_same_addr_pass.cc" | "graph/passes/mark_same_addr_pass.cc" | ||||
"graph/passes/mark_graph_unknown_status_pass.cc" | "graph/passes/mark_graph_unknown_status_pass.cc" | ||||
"graph/passes/dynamic_single_op_reset_shape_pass.cc" | |||||
"graph/passes/mark_agnostic_pass.cc" | "graph/passes/mark_agnostic_pass.cc" | ||||
"graph/partition/dynamic_shape_partition.cc" | "graph/partition/dynamic_shape_partition.cc" | ||||
"graph/partition/stage_partition.cc" | "graph/partition/stage_partition.cc" | ||||
@@ -433,6 +434,7 @@ set(INFER_SRC_LIST | |||||
"graph/passes/atomic_addr_clean_pass.cc" | "graph/passes/atomic_addr_clean_pass.cc" | ||||
"graph/passes/mark_same_addr_pass.cc" | "graph/passes/mark_same_addr_pass.cc" | ||||
"graph/passes/mark_graph_unknown_status_pass.cc" | "graph/passes/mark_graph_unknown_status_pass.cc" | ||||
"graph/passes/dynamic_single_op_reset_shape_pass.cc" | |||||
"graph/passes/mark_agnostic_pass.cc" | "graph/passes/mark_agnostic_pass.cc" | ||||
"graph/common/omg_util.cc" | "graph/common/omg_util.cc" | ||||
"graph/common/bcast.cc" | "graph/common/bcast.cc" | ||||
@@ -109,6 +109,7 @@ OMG_HOST_SRC_FILES := \ | |||||
graph/passes/atomic_addr_clean_pass.cc \ | graph/passes/atomic_addr_clean_pass.cc \ | ||||
graph/passes/mark_same_addr_pass.cc \ | graph/passes/mark_same_addr_pass.cc \ | ||||
graph/passes/mark_graph_unknown_status_pass.cc \ | graph/passes/mark_graph_unknown_status_pass.cc \ | ||||
graph/passes/dynamic_single_op_reset_shape_pass.cc \ | |||||
graph/passes/mark_agnostic_pass.cc \ | graph/passes/mark_agnostic_pass.cc \ | ||||
graph/common/omg_util.cc \ | graph/common/omg_util.cc \ | ||||
graph/common/bcast.cc \ | graph/common/bcast.cc \ | ||||
@@ -111,6 +111,7 @@ LIBGE_LOCAL_SRC_FILES := \ | |||||
graph/passes/atomic_addr_clean_pass.cc \ | graph/passes/atomic_addr_clean_pass.cc \ | ||||
graph/passes/mark_same_addr_pass.cc \ | graph/passes/mark_same_addr_pass.cc \ | ||||
graph/passes/mark_graph_unknown_status_pass.cc \ | graph/passes/mark_graph_unknown_status_pass.cc \ | ||||
graph/passes/dynamic_single_op_reset_shape_pass.cc \ | |||||
graph/passes/mark_agnostic_pass.cc \ | graph/passes/mark_agnostic_pass.cc \ | ||||
graph/partition/dynamic_shape_partition.cc \ | graph/partition/dynamic_shape_partition.cc \ | ||||
graph/partition/stage_partition.cc \ | graph/partition/stage_partition.cc \ | ||||
@@ -47,6 +47,8 @@ const char *const kEngineNameDefault = "default"; | |||||
const char *const kVectorEngine = "VectorEngine"; | const char *const kVectorEngine = "VectorEngine"; | ||||
const char *const kAIcoreEngine = "AIcoreEngine"; | const char *const kAIcoreEngine = "AIcoreEngine"; | ||||
const char *const kFileNameSuffix = "online"; | const char *const kFileNameSuffix = "online"; | ||||
const int kDynamicDimSize = 1; | |||||
const int64_t kDynamicDimValue = -2; | |||||
std::map<ge::OpEngineType, std::string> engine_type_map{ | std::map<ge::OpEngineType, std::string> engine_type_map{ | ||||
{ge::ENGINE_SYS, kEngineNameDefault}, {ge::ENGINE_AICORE, kAIcoreEngine}, {ge::ENGINE_VECTOR, kVectorEngine}}; | {ge::ENGINE_SYS, kEngineNameDefault}, {ge::ENGINE_AICORE, kAIcoreEngine}, {ge::ENGINE_VECTOR, kVectorEngine}}; | ||||
@@ -231,6 +233,42 @@ static void GetOpsProtoPath(string &opsproto_path) { | |||||
opsproto_path = (path_base + "ops/op_proto/custom/" + ":") + (path_base + "ops/op_proto/built-in/"); | opsproto_path = (path_base + "ops/op_proto/custom/" + ":") + (path_base + "ops/op_proto/built-in/"); | ||||
} | } | ||||
static Status CheckShapeReset(const OpDescPtr &op_desc, bool &change_shape_flag) { | |||||
GE_CHECK_NOTNULL_EXEC(op_desc, return PARAM_INVALID); | |||||
change_shape_flag = false; | |||||
for (size_t i = 0; i < op_desc->GetAllInputsDesc().size(); i++) { | |||||
auto input_desc = op_desc->MutableInputDesc(static_cast<uint32_t>(i)); | |||||
GE_CHECK_NOTNULL(input_desc); | |||||
// pass scalar input desc | |||||
auto dims = input_desc->GetShape().GetDims(); | |||||
if (dims.size() == kDynamicDimSize && dims[0] == kDynamicDimValue) { | |||||
change_shape_flag = true; | |||||
} | |||||
} | |||||
return SUCCESS; | |||||
} | |||||
static void ResetTensorVecShape(const vector<GeTensor> &inputs, vector<GeTensor> &inputs_dynamic) { | |||||
for (auto input : inputs) { | |||||
auto input_desc = input.GetTensorDesc(); | |||||
GeShape shape_ori = input_desc.GetShape(); | |||||
Format format_ori = input_desc.GetFormat(); | |||||
DataType type_ori = input_desc.GetDataType(); | |||||
std::vector<int64_t> dynamic_shape_dims = {kDynamicDimValue}; | |||||
GeShape dynamic_shape(dynamic_shape_dims); | |||||
ge::GeTensor inputTensor; | |||||
ge::GeTensorDesc desc(shape_ori, format_ori, type_ori); | |||||
if (shape_ori.GetDims().size() > 0) { | |||||
desc.SetShape(dynamic_shape); | |||||
} | |||||
inputTensor.SetTensorDesc(desc); | |||||
inputs_dynamic.push_back(inputTensor); | |||||
} | |||||
} | |||||
class GeGenerator::Impl { | class GeGenerator::Impl { | ||||
public: | public: | ||||
Impl(OmgContext &omg_context) : omg_context_(omg_context) {} | Impl(OmgContext &omg_context) : omg_context_(omg_context) {} | ||||
@@ -557,7 +595,9 @@ Status GeGenerator::CheckForSingleOp(OpDescPtr &op_desc, const vector<GeTensor> | |||||
Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs, | Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs, | ||||
const string &model_file_name, OpEngineType engine_type, ModelBufferData &model_buff, | const string &model_file_name, OpEngineType engine_type, ModelBufferData &model_buff, | ||||
bool is_offline) { | bool is_offline) { | ||||
if (!is_offline) { | |||||
(void)AttrUtils::SetBool(op_desc, ATTR_DYNAMIC_SHAPE_SINGLE_AICPU, true); | |||||
} | |||||
if (CheckForSingleOp(op_desc, inputs, outputs) != SUCCESS) { | if (CheckForSingleOp(op_desc, inputs, outputs) != SUCCESS) { | ||||
GELOGE(PARAM_INVALID, "input param is invalid when build single op!"); | GELOGE(PARAM_INVALID, "input param is invalid when build single op!"); | ||||
return PARAM_INVALID; | return PARAM_INVALID; | ||||
@@ -634,7 +674,18 @@ Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &in | |||||
} | } | ||||
GeModelPtr &ge_model = name_to_ge_model.begin()->second; | GeModelPtr &ge_model = name_to_ge_model.begin()->second; | ||||
GELOGD("The opType in op_desc_tmp is [%s]", op_desc_tmp->GetType().c_str()); | GELOGD("The opType in op_desc_tmp is [%s]", op_desc_tmp->GetType().c_str()); | ||||
GE_CHK_STATUS_RET_NOLOG(impl_->SaveParams(ge_model, op_desc_tmp->GetType(), op_attrs, inputs, outputs)); | |||||
bool dynamic_flag = false; | |||||
if (CheckShapeReset(op_desc, dynamic_flag) == SUCCESS && dynamic_flag) { | |||||
vector<GeTensor> inputs_dynamic; | |||||
vector<GeTensor> outputs_dynamic; | |||||
ResetTensorVecShape(inputs, inputs_dynamic); | |||||
ResetTensorVecShape(outputs, outputs_dynamic); | |||||
GE_CHK_STATUS_RET_NOLOG( | |||||
impl_->SaveParams(ge_model, op_desc_tmp->GetType(), op_attrs, inputs_dynamic, outputs_dynamic)); | |||||
} else { | |||||
GE_CHK_STATUS_RET_NOLOG(impl_->SaveParams(ge_model, op_desc_tmp->GetType(), op_attrs, inputs, outputs)); | |||||
} | |||||
GE_CHK_STATUS_RET_NOLOG(impl_->SaveModel(model_file_name, ge_model, model_buff)); | GE_CHK_STATUS_RET_NOLOG(impl_->SaveModel(model_file_name, ge_model, model_buff)); | ||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
@@ -68,6 +68,7 @@ | |||||
#include "graph/passes/iterator_op_pass.h" | #include "graph/passes/iterator_op_pass.h" | ||||
#include "graph/passes/link_gen_mask_nodes_pass.h" | #include "graph/passes/link_gen_mask_nodes_pass.h" | ||||
#include "graph/passes/mark_graph_unknown_status_pass.h" | #include "graph/passes/mark_graph_unknown_status_pass.h" | ||||
#include "graph/passes/dynamic_single_op_reset_shape_pass.h" | |||||
#include "graph/passes/merge_pass.h" | #include "graph/passes/merge_pass.h" | ||||
#include "graph/passes/merge_input_memcpy_pass.h" | #include "graph/passes/merge_input_memcpy_pass.h" | ||||
#include "graph/passes/merge_to_stream_merge_pass.h" | #include "graph/passes/merge_to_stream_merge_pass.h" | ||||
@@ -655,6 +656,17 @@ Status GraphManager::ReplaceSubgraphWithOriGraph(const ComputeGraphPtr &compute_ | |||||
Status GraphManager::SetSubgraph(uint64_t session_id, ComputeGraphPtr compute_graph, GraphPartitioner &partitioner) { | Status GraphManager::SetSubgraph(uint64_t session_id, ComputeGraphPtr compute_graph, GraphPartitioner &partitioner) { | ||||
GE_CHECK_NOTNULL(compute_graph); | GE_CHECK_NOTNULL(compute_graph); | ||||
PassManager pass_for_dynamic_shape_reset_optimize; | |||||
GE_CHK_STATUS_RET(pass_for_dynamic_shape_reset_optimize.AddPass( | |||||
"SetSubgraph::AfterSetSubgraph::DynamicSingleOpResetShapePass", new (std::nothrow) DynamicSingleOpResetShapePass)) | |||||
GE_TIMESTAMP_START(pass_for_dynamic_shape_reset_optimize); | |||||
ret = pass_for_dynamic_shape_reset_optimize.Run(compute_graph); | |||||
GE_TIMESTAMP_END(pass_for_dynamic_shape_reset_optimize, "SetSubgraph::AfterSetSubgraph"); | |||||
if (ret != SUCCESS && ret != NOT_CHANGED) { | |||||
GELOGE(ret, "Run passes when optimize subgraph failed"); | |||||
return ret; | |||||
} | |||||
auto sub_graph_map = partitioner.GetSubGraphMap(); | auto sub_graph_map = partitioner.GetSubGraphMap(); | ||||
GELOGD("Directly optimize subgraph with build mode:%s, and step:%s.", | GELOGD("Directly optimize subgraph with build mode:%s, and step:%s.", | ||||
options_.build_mode.c_str(), | options_.build_mode.c_str(), | ||||
@@ -1 +1 @@ | |||||
Subproject commit bd2cfdfa85a3d9dcbd7dc825f5759c7f8b3ffa9a | |||||
Subproject commit a83f6219922830574b9faad591d9a96ef23cc0f8 |
@@ -182,6 +182,7 @@ set(COMMON_SRC_FILES | |||||
"${GE_CODE_DIR}/ge/graph/passes/atomic_addr_clean_pass.cc" | "${GE_CODE_DIR}/ge/graph/passes/atomic_addr_clean_pass.cc" | ||||
"${GE_CODE_DIR}/ge/graph/passes/mark_same_addr_pass.cc" | "${GE_CODE_DIR}/ge/graph/passes/mark_same_addr_pass.cc" | ||||
"${GE_CODE_DIR}/ge/graph/passes/mark_graph_unknown_status_pass.cc" | "${GE_CODE_DIR}/ge/graph/passes/mark_graph_unknown_status_pass.cc" | ||||
"${GE_CODE_DIR}/ge/graph/passes/dynamic_single_op_reset_shape_pass.cc" | |||||
"${GE_CODE_DIR}/ge/graph/passes/mark_agnostic_pass.cc" | "${GE_CODE_DIR}/ge/graph/passes/mark_agnostic_pass.cc" | ||||
"${GE_CODE_DIR}/ge/graph/passes/dimension_compute_pass.cc" | "${GE_CODE_DIR}/ge/graph/passes/dimension_compute_pass.cc" | ||||
"${GE_CODE_DIR}/ge/graph/passes/dimension_adjust_pass.cc" | "${GE_CODE_DIR}/ge/graph/passes/dimension_adjust_pass.cc" | ||||