1 /** 2 * Copyright 2022 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_TOOLS_OPTIMIZER_FUSION_RESHAPE_TRANSPOSE_FUSION_H_ 18 #define MINDSPORE_LITE_TOOLS_OPTIMIZER_FUSION_RESHAPE_TRANSPOSE_FUSION_H_ 19 20 #include <string> 21 #include <memory> 22 #include <unordered_map> 23 #include "include/backend/optimizer/optimizer.h" 24 #include "tools/optimizer/common/multiple_pattern_process_pass.h" 25 #include "utils/check_convert_utils.h" 26 27 namespace mindspore { 28 namespace opt { 29 class ReshapeTransposeFusion : public MultiplePatternProcessPass { 30 public: 31 explicit ReshapeTransposeFusion(const std::string &name = "ReshapeTransposeFusion", bool multigraph = true) MultiplePatternProcessPass(name,multigraph)32 : MultiplePatternProcessPass(name, multigraph) {} 33 ~ReshapeTransposeFusion() override = default; 34 35 private: 36 VectorRef DefineReshapeTransposePattern() const; 37 VectorRef DefineTransposeReshapePattern() const; 38 std::unordered_map<std::string, VectorRef> DefinePatterns() const override; 39 40 AnfNodePtr ReshapeTransFusion(const FuncGraphPtr &func_graph, const CNodePtr &transpose) const; 41 AnfNodePtr TransReshapeFusion(const FuncGraphPtr &func_graph, const CNodePtr &transpose) const; 42 AnfNodePtr TransReshapeTransFusion(const FuncGraphPtr &func_graph, const CNodePtr &transpose) const; 43 AnfNodePtr Process(const std::string &pattern_name, const FuncGraphPtr &, const AnfNodePtr &, 44 const EquivPtr &) const override; 45 }; 46 } // namespace opt 47 } // namespace mindspore 48 #endif // MINDSPORE_LITE_TOOLS_OPTIMIZER_FUSION_RESHAPE_TRANSPOSE_FUSION_H_ 49