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.

df_graph_manager.h 2.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef TRANSFORM_DF_GRAPH_MANAGER_H_
  16. #define TRANSFORM_DF_GRAPH_MANAGER_H_
  17. #include <set>
  18. #include <string>
  19. #include <memory>
  20. #include <vector>
  21. #include <mutex>
  22. #include <map>
  23. #include <utility>
  24. #include "transform/types.h"
  25. #include "ir/anf.h"
  26. namespace mindspore {
  27. const char BROADCAST_GRAPH_NAME[] = "broadcast_subgraph";
  28. namespace transform {
  29. class GraphRunner;
  30. using OptionMap = std::map<std::string, std::string>;
  31. struct DfGraphWrapper {
  32. public:
  33. DfGraphWrapper(const std::string &name, const int &id, const DfGraphPtr &graph_ptr, const OptionMap &options);
  34. ~DfGraphWrapper() {}
  35. std::string name_;
  36. int id_;
  37. DfGraphPtr graph_ptr_;
  38. OptionMap options_ = {};
  39. };
  40. using DfGraphWrapperPtr = std::shared_ptr<DfGraphWrapper>;
  41. class DfGraphManager {
  42. public:
  43. ~DfGraphManager();
  44. void ClearGraph() noexcept;
  45. static DfGraphManager &GetInstance();
  46. Status AddGraph(const std::string &name, const DfGraphPtr &graph, const OptionMap &options = {});
  47. std::vector<DfGraphWrapperPtr> GetAllGraphs();
  48. std::set<string> GetSavedGraphs();
  49. void AddSavedGraphs(const std::string &id);
  50. DfGraphWrapperPtr GetGraphByName(const std::string &name);
  51. DfGraphManager(const DfGraphManager &) = delete;
  52. void SetAnfGraph(const std::string &name, const AnfGraphPtr &anf_graph_ptr);
  53. AnfGraphPtr GetAnfGraph(uint32_t graph_id);
  54. std::shared_ptr<transform::GraphRunner> GetGraphRunner();
  55. void SetGraphRunner(const std::shared_ptr<transform::GraphRunner> &graph_runner_ptr) noexcept;
  56. void DeleteGraphRunner() noexcept;
  57. void SetGeSession(const std::shared_ptr<ge::Session> &sess_ptr);
  58. std::shared_ptr<ge::Session> GetGeSession();
  59. void DeleteGeSession() noexcept;
  60. void EraseAnfGraph();
  61. private:
  62. DfGraphManager();
  63. int GenerateId();
  64. std::mutex lock_;
  65. std::map<std::string, DfGraphWrapperPtr> graphs_;
  66. std::set<string> saved_graphs_;
  67. int graph_id_;
  68. std::map<uint32_t, AnfGraphPtr> anf_graphs_;
  69. std::shared_ptr<transform::GraphRunner> graph_runner_ptr_;
  70. std::shared_ptr<ge::Session> sess_ptr_;
  71. };
  72. } // namespace transform
  73. } // namespace mindspore
  74. #endif // TRANSFORM_DF_GRAPH_MANAGER_H_