subgraph_const_migration_pass.cctags/v1.2.0
| @@ -204,7 +204,6 @@ set(TRAIN_SRC_LIST | |||
| "graph/passes/constant_fuse_same_pass.cc" | |||
| "graph/passes/fuse_data_nodes_with_common_input_pass.cc" | |||
| "graph/passes/remove_same_const_pass.cc" | |||
| "graph/passes/no_data_out_const_elimination_pass.cc" | |||
| "graph/passes/useless_control_out_remove_pass.cc" | |||
| "graph/passes/control_trigger_pass.cc" | |||
| "graph/passes/dimension_adjust_pass.cc" | |||
| @@ -583,7 +582,6 @@ set(INFER_SRC_LIST | |||
| "graph/passes/addn_pass.cc" | |||
| "graph/passes/common_subexpression_elimination_pass.cc" | |||
| "graph/passes/remove_same_const_pass.cc" | |||
| "graph/passes/no_data_out_const_elimination_pass.cc" | |||
| "graph/passes/useless_control_out_remove_pass.cc" | |||
| "graph/passes/transop_symmetry_elimination_pass.cc" | |||
| "graph/passes/save_pass.cc" | |||
| @@ -194,7 +194,6 @@ OMG_HOST_SRC_FILES := \ | |||
| graph/passes/cond_pass.cc \ | |||
| graph/passes/cond_remove_pass.cc \ | |||
| graph/passes/remove_same_const_pass.cc \ | |||
| graph/passes/no_data_out_const_elimination_pass.cc \ | |||
| graph/passes/useless_control_out_remove_pass.cc \ | |||
| graph/passes/for_pass.cc \ | |||
| graph/passes/enter_pass.cc \ | |||
| @@ -129,7 +129,6 @@ LIBGE_LOCAL_SRC_FILES := \ | |||
| graph/passes/constant_fuse_same_pass.cc \ | |||
| graph/passes/fuse_data_nodes_with_common_input_pass.cc \ | |||
| graph/passes/remove_same_const_pass.cc \ | |||
| graph/passes/no_data_out_const_elimination_pass.cc \ | |||
| graph/passes/useless_control_out_remove_pass.cc \ | |||
| graph/passes/control_trigger_pass.cc \ | |||
| graph/passes/dimension_adjust_pass.cc \ | |||
| @@ -71,7 +71,6 @@ | |||
| #include "graph/passes/remove_same_const_pass.h" | |||
| #include "graph/passes/reshape_recovery_pass.h" | |||
| #include "graph/passes/reshape_remove_pass.h" | |||
| #include "graph/passes/no_data_out_const_elimination_pass.h" | |||
| #include "graph/passes/same_transdata_breadth_fusion_pass.h" | |||
| #include "graph/passes/subgraph_pass.h" | |||
| #include "graph/passes/switch_data_edges_bypass.h" | |||
| @@ -2249,9 +2248,7 @@ Status GraphManager::OptimizeStage1(ge::ComputeGraphPtr &compute_graph) { | |||
| NamesToPass node_pass; | |||
| GE_TIMESTAMP_START(node_pass); | |||
| IdentityPass identity_force_pass(false); // after SwitchToStreamSwitchPass | |||
| NoDataOutConstEliminationPass no_data_out_const_elimination_pass; | |||
| node_pass.emplace_back("IdentityPass", &identity_force_pass); | |||
| node_pass.emplace_back("NoDataOutConstEliminationPass", &no_data_out_const_elimination_pass); | |||
| ret = GEPass(compute_graph).Run(node_pass); | |||
| GE_TIMESTAMP_END(node_pass, "GraphPrepare::node_pass"); | |||
| if (ret != SUCCESS) { | |||
| @@ -1,36 +0,0 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "graph/passes/no_data_out_const_elimination_pass.h" | |||
| namespace ge { | |||
| Status NoDataOutConstEliminationPass::Run(NodePtr &node) { | |||
| GE_CHECK_NOTNULL(node); | |||
| GELOGD("RemoveConstWithoutDataPass running of %s.", node->GetName().c_str()); | |||
| if (node->GetType() == CONSTANT || node->GetType() == CONSTANTOP) { | |||
| GE_CHECK_NOTNULL(node->GetOpDesc()); | |||
| // delete const which has no input and no output of data | |||
| if (node->GetOpDesc()->GetInputsSize() == 0 && node->GetOutDataNodes().size() == 0) { | |||
| GELOGI("Remove const %s.", node->GetName().c_str()); | |||
| if (IsolateAndDeleteNode(node, {}) != SUCCESS) { | |||
| GELOGE(FAILED, "IsolateAndDeleteNode %s failed.", node->GetName().c_str()); | |||
| return FAILED; | |||
| } | |||
| } | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| } // namespace ge | |||
| @@ -1,31 +0,0 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GE_GRAPH_PASSES_REMOVE_CONST_WITHOUT_DATA_PASS_H_ | |||
| #define GE_GRAPH_PASSES_REMOVE_CONST_WITHOUT_DATA_PASS_H_ | |||
| #include "graph/passes/base_pass.h" | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "framework/common/util.h" | |||
| namespace ge { | |||
| class NoDataOutConstEliminationPass : public BaseNodePass { | |||
| public: | |||
| Status Run(ge::NodePtr &node) override; | |||
| }; | |||
| } // namespace ge | |||
| #endif // GE_GRAPH_PASSES_REMOVE_CONST_WITHOUT_DATA_PASS_H_ | |||
| @@ -179,7 +179,6 @@ set(COMMON_SRC_FILES | |||
| "${GE_CODE_DIR}/ge/graph/passes/replace_transshape_pass.cc" | |||
| "${GE_CODE_DIR}/ge/graph/passes/constant_fuse_same_pass.cc" | |||
| "${GE_CODE_DIR}/ge/graph/passes/fuse_data_nodes_with_common_input_pass.cc" | |||
| "${GE_CODE_DIR}/ge/graph/passes/no_data_out_const_elimination_pass.cc" | |||
| "${GE_CODE_DIR}/ge/graph/passes/print_op_pass.cc" | |||
| "${GE_CODE_DIR}/ge/graph/passes/no_use_reshape_remove_pass.cc" | |||
| "${GE_CODE_DIR}/ge/graph/passes/iterator_op_pass.cc" | |||
| @@ -619,7 +618,6 @@ set(PASS_TEST_FILES | |||
| "graph/passes/transop_nearby_allreduce_fusion_pass_unittest.cc" | |||
| "graph/passes/constant_folding_pass_unittest.cc" | |||
| "graph/passes/fuse_data_nodes_with_common_input_pass_unittest.cc" | |||
| "graph/passes/no_data_out_const_elimination_pass_unittest.cc" | |||
| "graph/passes/stop_gradient_pass_unittest.cc" | |||
| "graph/passes/prevent_gradient_pass_unittest.cc" | |||
| "graph/passes/identity_pass_unittest.cc" | |||
| @@ -1,82 +0,0 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "graph/passes/no_data_out_const_elimination_pass.h" | |||
| #include <gtest/gtest.h> | |||
| #include <string> | |||
| #include <vector> | |||
| #include <map> | |||
| #include "common/ge_inner_error_codes.h" | |||
| #include "graph/utils/graph_utils.h" | |||
| namespace ge { | |||
| class UtestNoDataOutConstEliminationPass : public testing::Test { | |||
| protected: | |||
| void SetUp() {} | |||
| void TearDown() {} | |||
| public: | |||
| NodePtr MakeNode(const ComputeGraphPtr &graph, uint32_t in_num, uint32_t out_num, string name, string type) { | |||
| GeTensorDesc test_desc(GeShape(), FORMAT_NCHW, DT_FLOAT); | |||
| auto op_desc = std::make_shared<OpDesc>(name, type); | |||
| for (auto i = 0; i < in_num; ++i) { | |||
| op_desc->AddInputDesc(test_desc); | |||
| } | |||
| for (auto i = 0; i < out_num; ++i) { | |||
| op_desc->AddOutputDesc(test_desc); | |||
| } | |||
| return graph->AddNode(op_desc); | |||
| } | |||
| }; | |||
| /// graph with subgraph | |||
| /// const1 | |||
| /// |(control) | |||
| /// const2 | |||
| /// | | |||
| /// output | |||
| TEST_F(UtestNoDataOutConstEliminationPass, succ_graph1) { | |||
| ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test"); | |||
| auto const_node1 = MakeNode(graph, 0, 1, "const_node1", "Const"); | |||
| auto const_node2 = MakeNode(graph, 1, 1, "const_node2", "Const"); | |||
| auto output_node = MakeNode(graph, 1, 0, "output_node", "NetOutput"); | |||
| GeTensorDesc tensor_desc(GeShape({1,3,224,224}), FORMAT_NCHW, DT_FLOAT); | |||
| const_node1->GetOpDesc()->UpdateOutputDesc(0, tensor_desc); | |||
| const_node2->GetOpDesc()->UpdateInputDesc(0, tensor_desc); | |||
| const_node2->GetOpDesc()->UpdateOutputDesc(0, tensor_desc); | |||
| output_node->GetOpDesc()->UpdateInputDesc(0, tensor_desc); | |||
| GraphUtils::AddEdge(const_node1->GetOutControlAnchor(), const_node2->GetInControlAnchor()); | |||
| GraphUtils::AddEdge(const_node2->GetOutDataAnchor(0), output_node->GetInDataAnchor(0)); | |||
| GEPass pass(graph); | |||
| NamesToPass node_pass; | |||
| NoDataOutConstEliminationPass no_data_out_const_elimination_pass; | |||
| node_pass.emplace_back("NoDataOutConstEliminationPass", &no_data_out_const_elimination_pass); | |||
| auto const1 = graph->FindNode("const_node1"); | |||
| EXPECT_NE(const1, nullptr); | |||
| EXPECT_TRUE(const1->GetInDataNodes().empty()); | |||
| EXPECT_TRUE(const1->GetOutDataNodes().empty()); | |||
| EXPECT_EQ(pass.Run(node_pass), SUCCESS); | |||
| // after pass, const1 will be delete | |||
| const1 = graph->FindNode("const_node1"); | |||
| EXPECT_EQ(const1, nullptr); | |||
| } | |||
| } // namespace ge | |||