|
|
|
@@ -38,6 +38,18 @@ Status DynamicSingleOpResetShapePass::Run(ComputeGraphPtr graph) { |
|
|
|
return ge::GE_CLI_GE_NOT_INITIALIZED; |
|
|
|
} |
|
|
|
|
|
|
|
// pass if graph has not aicpu node. |
|
|
|
bool is_not_aicpu = false; |
|
|
|
if (CheckAllAicpuNodes(graph, is_not_aicpu) != SUCCESS) { |
|
|
|
GELOGE(ge::GE_CLI_GE_NOT_INITIALIZED, "Check if graph has not aicpu node failed."); |
|
|
|
return ge::GE_CLI_GE_NOT_INITIALIZED; |
|
|
|
} |
|
|
|
if (is_not_aicpu) { |
|
|
|
GELOGI("The graph [%s] has not aicpu node, whose aicpu nodes would not be reset dynamic shape", |
|
|
|
graph->GetName().c_str()); |
|
|
|
return SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|
for (const auto &node : graph->GetDirectNode()) { |
|
|
|
GE_CHECK_NOTNULL(node->GetOpDesc()); |
|
|
|
// pass input and output node |
|
|
|
@@ -53,18 +65,8 @@ Status DynamicSingleOpResetShapePass::Run(ComputeGraphPtr graph) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// pass not aicpu node. |
|
|
|
auto op_desc = node->GetOpDesc(); |
|
|
|
string engine_name = op_desc->GetOpEngineName(); |
|
|
|
if (engine_name.empty()) { |
|
|
|
GELOGE(GRAPH_FAILED, "Get engine failed of node[%s].", node->GetName().c_str()); |
|
|
|
return GRAPH_FAILED; |
|
|
|
} |
|
|
|
if (engine_name != kEngineNameAiCpu && engine_name != kEngineNameAiCpuTf) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// reset aicpu shape to unknown shape |
|
|
|
auto op_desc = node->GetOpDesc(); |
|
|
|
if (ResetOpShape(op_desc) != SUCCESS) { |
|
|
|
GELOGE(ge::GE_CLI_GE_NOT_INITIALIZED, "Reset node[%s] dynamic shapr failed.", node->GetName().c_str()); |
|
|
|
return ge::GE_CLI_GE_NOT_INITIALIZED; |
|
|
|
@@ -76,6 +78,37 @@ Status DynamicSingleOpResetShapePass::Run(ComputeGraphPtr graph) { |
|
|
|
return SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|
Status DynamicSingleOpResetShapePass::CheckAllAicpuNodes(const ComputeGraphPtr &graph, bool &is_not_aicpu) { |
|
|
|
is_not_aicpu = false; |
|
|
|
for (const auto &node : graph->GetDirectNode()) { |
|
|
|
GE_CHECK_NOTNULL(node->GetOpDesc()); |
|
|
|
// pass input and output node |
|
|
|
if (node->GetType() == DATA || node->GetType() == CONSTANT || node->GetType() == CONSTANTOP || |
|
|
|
node->GetType() == NETOUTPUT) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// find if there are aicpu nodes. |
|
|
|
auto op_desc = node->GetOpDesc(); |
|
|
|
string engine_name = op_desc->GetOpEngineName(); |
|
|
|
if (engine_name.empty()) { |
|
|
|
GELOGE(GRAPH_FAILED, "Get engine failed of node[%s].", node->GetName().c_str()); |
|
|
|
return GRAPH_FAILED; |
|
|
|
} |
|
|
|
if (engine_name != kEngineNameAiCpu && engine_name != kEngineNameAiCpuTf) { |
|
|
|
is_not_aicpu = true; |
|
|
|
return SUCCESS; |
|
|
|
} |
|
|
|
} |
|
|
|
return SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|
bool DynamicSingleOpResetShapePass::CheckIfConstInput(const GeTensorDescPtr &input_tensor_desc) { |
|
|
|
bool is_const = false; |
|
|
|
(void)AttrUtils::GetBool(input_desc, CONST_ATTR_NAME_INPUT, is_const); |
|
|
|
return is_const; |
|
|
|
} |
|
|
|
|
|
|
|
Status DynamicSingleOpResetShapePass::ResetOpShape(OpDescPtr &op_desc) { |
|
|
|
GE_CHECK_NOTNULL(op_desc); |
|
|
|
std::vector<int64_t> dynamic_shape_dims = {kDynamicShapeDim}; |
|
|
|
@@ -88,6 +121,10 @@ Status DynamicSingleOpResetShapePass::ResetOpShape(OpDescPtr &op_desc) { |
|
|
|
if (dims_ori.size() == 0) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// pass const input |
|
|
|
if (CheckIfConstInput(input_desc)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
input_desc->SetShape(dynamic_shape); |
|
|
|
} |
|
|
|
for (size_t i = 0; i < op_desc->GetAllOutputsDesc().size(); i++) { |
|
|
|
|