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_group.h 2.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Copyright 2020 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_FRONTEND_OPTIMIZER_PASS_GROUP_H_
  17. #define MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_PASS_GROUP_H_
  18. #include <utility>
  19. #include <vector>
  20. #include <string>
  21. #include <memory>
  22. #include "frontend/optimizer/py_pass.h"
  23. namespace mindspore {
  24. namespace opt {
  25. namespace python_pass {
  26. class PassGroup {
  27. public:
  28. explicit PassGroup(const std::string &name = "pass_group", bool run_only_once = false)
  29. : name_(name), passes_{}, run_only_once_(run_only_once) {}
  30. virtual ~PassGroup() = default;
  31. // Add graph pass, the pass object will be freed when pass manager freed.
  32. void AddPass(const PythonPassPtr &pass);
  33. // Delete graph pass before the pass manager is freed.
  34. bool DeletePass(const std::string &pass_name);
  35. // Run passes added in pass manager on the input graph
  36. // @param [inout] graph The graph to be optimized
  37. // @return true, graph changed
  38. // @return false, graph not changed
  39. bool Run(const FuncGraphPtr &func_graph) const;
  40. // Run the given graph passes on the input graph
  41. // @param [inout] func_graph The graph to be optimized
  42. // @param [in] passes The given graph passes
  43. // @param [inout] res MatchResult used to collect all matched patterns and nodes
  44. // @return true, graph changed
  45. // @return false, graph not changed
  46. bool Run(const FuncGraphPtr &func_graph, const std::vector<PythonPassPtr> &passes, const MatchResultPtr &res) const;
  47. std::string name() const { return name_; }
  48. void SetRunOnlyOnce(bool run_only_once) { run_only_once_ = run_only_once; }
  49. size_t size() { return passes_.size(); }
  50. private:
  51. const std::string name_;
  52. std::vector<PythonPassPtr> passes_;
  53. bool run_only_once_;
  54. };
  55. using PassGroupPtr = std::shared_ptr<PassGroup>;
  56. } // namespace python_pass
  57. } // namespace opt
  58. } // namespace mindspore
  59. #endif // MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_PASS_GROUP_H_