diff --git a/ge/generator/ge_generator.cc b/ge/generator/ge_generator.cc index 90b7f776..e9c2e6ab 100644 --- a/ge/generator/ge_generator.cc +++ b/ge/generator/ge_generator.cc @@ -48,6 +48,7 @@ const char *const kVectorEngine = "VectorEngine"; const char *const kAIcoreEngine = "AIcoreEngine"; const char *const kFileNameSuffix = "online"; const char *const kAicpuAllshape = "_AllShape"; +constexpr char const *kAttrSupportDynamicShape = "support_dynamicshape"; const int64_t kDynamicDimValue = -2; std::map engine_type_map{ @@ -620,6 +621,32 @@ namespace { } return is_need; } + + Status CheckDynamicSupport(GeModelPtr &ge_model, const ComputeGraphPtr &graph) { + bool support_dynamic = true; + bool is_dynamic = false; + for (const auto &node : graph->GetDirectNode()) { + GE_CHECK_NOTNULL(node); + if (node->GetType() == DATA || node->GetType() == CONSTANT || node->GetType() == CONSTANTOP || + node->GetType() == NETOUTPUT) { + continue; + } + auto op_desc = node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + if (AttrUtils::HasAttr(op_desc, kAttrSupportDynamicShape)) { + is_dynamic = true; + (void) AttrUtils::GetBool(op_desc, kAttrSupportDynamicShape, support_dynamic); + if (!support_dynamic) { + GELOGW("Node[%s] doesn't support dynamic shape.", node->GetName().c_str()); + break; + } + } + } + if (is_dynamic) { + (void) AttrUtils::SetBool(ge_model, kAttrSupportDynamicShape, support_dynamic); + } + return SUCCESS; + } } Status GeGenerator::CheckForSingleOp(OpDescPtr &op_desc, const vector &inputs, @@ -694,7 +721,9 @@ Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector &in GELOGE(PARAM_INVALID, "GetSubgraphInstanceNameToModel is empty."); return PARAM_INVALID; } + const ComputeGraphPtr root_graph = ge_root_model->GetRootGraph(); GeModelPtr &ge_model = name_to_ge_model.begin()->second; + GE_CHK_STATUS_RET_NOLOG(CheckDynamicSupport(ge_model, root_graph)); GELOGD("The opType in op_desc_tmp is [%s]", op_desc_tmp->GetType().c_str()); bool all_shape = false;