You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

pass_manager.h 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Copyright 2019 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_OPTIMIZER_COMMON_PASS_MANAGER_H_
  17. #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_COMMON_PASS_MANAGER_H_
  18. #include <utility>
  19. #include <vector>
  20. #include <string>
  21. #include <memory>
  22. #include "backend/optimizer/common/pass.h"
  23. #include "backend/optimizer/common/node_pass.h"
  24. namespace mindspore {
  25. namespace opt {
  26. // @brief For optimization passes management
  27. class PassManager {
  28. public:
  29. explicit PassManager(const std::string &name = "pm", bool run_only_once = true)
  30. : name_(name), passes_{}, run_only_once_(run_only_once) {}
  31. virtual ~PassManager() = default;
  32. // Get all the passes added by AddPass
  33. const std::vector<PassPtr> &Passes() const;
  34. // Add graph pass, the pass object will be freed when pass manager freed.
  35. void AddPass(const PassPtr &pass);
  36. // Run passes added in pass manager on the input graph
  37. // @param [inout] graph The graph to be optimized
  38. // @return true, graph changed
  39. // @return false, graph not changed
  40. bool Run(const FuncGraphPtr &func_graph) const;
  41. // Run the given graph passes on the input graph
  42. // @param [inout] graph The graph to be optimized
  43. // @param [in] passes The given graph passes
  44. // @return true, graph changed
  45. // @return false, graph not changed
  46. bool Run(const FuncGraphPtr &func_graph, const std::vector<PassPtr> &passes) const;
  47. std::string name() const { return name_; }
  48. private:
  49. const std::string name_;
  50. std::vector<PassPtr> passes_;
  51. bool run_only_once_;
  52. };
  53. using PassManagerPtr = std::shared_ptr<PassManager>;
  54. } // namespace opt
  55. } // namespace mindspore
  56. #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_COMMON_PASS_MANAGER_H_