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 #ifndef MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_H_ 17 #define MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_H_ 18 19 #include <string> 20 #include <vector> 21 #include "include/backend/optimizer/pass_manager.h" 22 #include "include/backend/visible.h" 23 24 namespace mindspore { 25 namespace opt { 26 class BACKEND_EXPORT GraphOptimizer { 27 public: name_(name)28 explicit GraphOptimizer(const std::string &name = "graph_optimizer") : name_(name) {} 29 virtual ~GraphOptimizer() = default; 30 31 void AddPassManager(const PassManagerPtr &pass_manager); 32 FuncGraphPtr Optimize(const FuncGraphPtr &func_graph, bool run_only_once = true); 33 34 private: 35 const std::string name_ = "graph_optimizer"; 36 std::vector<PassManagerPtr> pass_managers_{}; 37 bool run_only_once_ = true; 38 }; 39 } // namespace opt 40 } // namespace mindspore 41 42 #endif // MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_H_ 43