• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_LITE_SRC_PASS_REDUNDANT_OP_REMOVE_PASS_H_
18 #define MINDSPORE_LITE_SRC_PASS_REDUNDANT_OP_REMOVE_PASS_H_
19 #include <string>
20 #include <set>
21 #include "backend/optimizer/common/pass.h"
22 #include "tools/converter/converter_flags.h"
23 #include "tools/optimizer/common/gllo_utils.h"
24 #include "tools/anf_exporter/fetch_content.h"
25 
26 using mindspore::converter::FmkType;
27 namespace mindspore::opt {
28 class RemoveRedundantOpPass : public Pass {
29  public:
RemoveRedundantOpPass(bool is_train_model)30   explicit RemoveRedundantOpPass(bool is_train_model)
31       : Pass("remove_redundant_op_pass"), is_train_model_(is_train_model) {}
32   ~RemoveRedundantOpPass() override = default;
33   int ReplaceOp(const AnfNodePtr &anf_node, const FuncGraphManagerPtr &manager);
34   int ReplaceUpdateStateOp(const FuncGraphPtr &func_graph, const AnfNodePtr &anf_node);
35   int ReplaceTupleGetItem(const AnfNodePtr &anf_node, const FuncGraphManagerPtr &manager);
36   int RemoveDropoutOp(const AnfNodePtr &anf_node, const FuncGraphManagerPtr &manager);
37   int RemoveInvalidPadOp(const AnfNodePtr &anf_node, const FuncGraphManagerPtr &manager);
38   int RemoveInvalidTransposeOp(const AnfNodePtr &anf_node, const FuncGraphManagerPtr &manager);
39   bool Run(const FuncGraphPtr &graph) override;
40 
41  private:
42   int GetConstDataFromInputNode(const CNodePtr &cnode, lite::DataInfo *data_info);
43   bool is_train_model_ = false;
44   std::set<AnfNodePtr> remove_cnode_;
45 };
46 }  // namespace mindspore::opt
47 #endif  // MINDSPORE_LITE_SRC_PASS_REDUNDANT_OP_REMOVE_PASS_H_
48