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.

py_pass_manager.h 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_OPTIMIZER_PY_PASS_MANAGER_H_
  17. #define MINDSPORE_CCSRC_OPTIMIZER_PY_PASS_MANAGER_H_
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. #include <unordered_map>
  22. #include "ir/anf.h"
  23. #include "ir/func_graph.h"
  24. #include "ir/primitive.h"
  25. #include "utils/graph_utils.h"
  26. #include "common/utils.h"
  27. #include "pipeline/parse/resolve.h"
  28. #include "optimizer/py_pass.h"
  29. #include "optimizer/pass_group.h"
  30. namespace mindspore {
  31. namespace opt {
  32. namespace python_pass {
  33. class PyPassManager;
  34. using PyPassManagerPtr = std::shared_ptr<PyPassManager>;
  35. enum Phase { RESOLVE, OPT };
  36. class PyPassManager {
  37. protected:
  38. PyPassManager();
  39. static PyPassManagerPtr global_instance;
  40. public:
  41. // Singletons should not be cloneable and assignable
  42. PyPassManager(const PyPassManager &other) = delete;
  43. void operator=(const PyPassManager &) = delete;
  44. // Access the only global instance
  45. static PyPassManagerPtr GetInstance();
  46. virtual ~PyPassManager() = default;
  47. void Registe(const std::string &pass_name, const py::function &pattern, const py::function &target,
  48. Phase phase = Phase::RESOLVE, bool run_only_once = false, bool multigraph = true);
  49. void Unregiste(const std::string &pass_name, Phase phase);
  50. PassGroupPtr GetPassGroup(Phase phase);
  51. void ClearRes();
  52. private:
  53. static std::unordered_map<Phase, PassGroupPtr> phase_to_group_;
  54. };
  55. } // namespace python_pass
  56. } // namespace opt
  57. } // namespace mindspore
  58. #endif // MINDSPORE_CCSRC_OPTIMIZER_PY_PASS_MANAGER_H_