From 08b220cf8d33246f7a39d19c95f0e6ad10b4d38a Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Wed, 9 Dec 2020 17:04:21 +0800 Subject: [PATCH] modified: ge/graph/passes/folding_pass.cc modified: ge/graph/passes/unused_const_pass.cc --- ge/graph/passes/folding_pass.cc | 8 ++++++++ ge/graph/passes/unused_const_pass.cc | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/ge/graph/passes/folding_pass.cc b/ge/graph/passes/folding_pass.cc index 227a0f61..ec2029d1 100755 --- a/ge/graph/passes/folding_pass.cc +++ b/ge/graph/passes/folding_pass.cc @@ -238,6 +238,14 @@ Status FoldingPass::AddConstNode(NodePtr &node, IndexsToAnchors indexes_to_ancho node->GetName().c_str(), index); return INTERNAL_ERROR; } + + vector curr_origin_op_names; + (void)AttrUtils::GetListStr(node->GetOpDesc(), ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, curr_origin_op_names); + if (curr_origin_op_names.empty()) { + (void)AttrUtils::SetListStr(const_desc, ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, {node->GetName()}); + } else { + (void)AttrUtils::SetListStr(const_desc, ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, curr_origin_op_names); + } GELOGI("add const_node:%s, replace node %s, type %s, index %zu.", const_node->GetName().c_str(), node->GetName().c_str(), node->GetType().c_str(), index); // add new const to re-pass node diff --git a/ge/graph/passes/unused_const_pass.cc b/ge/graph/passes/unused_const_pass.cc index 7c57c53e..f9358a74 100644 --- a/ge/graph/passes/unused_const_pass.cc +++ b/ge/graph/passes/unused_const_pass.cc @@ -40,6 +40,11 @@ Status UnusedConstPass::Run(NodePtr &node) { GELOGD("op type is unused const."); return IsolateAndDeleteNode(node, {-1}); } + // remove those const which only has control-in and control-out + if ((op_type == CONSTANT || op_type == CONSTANTOP) && (node->GetOutDataNodesSize() == 0)) { + GELOGD("Remove unused const %s.", node->GetName().c_str()); + return IsolateAndDeleteNode(node, {-1}); + } return SUCCESS; } } // namespace ge