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 16 #ifndef MINDSPORE_CCSRC_TRANSFORM_GRAPH_IR_DF_GRAPH_MANAGER_H_ 17 #define MINDSPORE_CCSRC_TRANSFORM_GRAPH_IR_DF_GRAPH_MANAGER_H_ 18 19 #include <set> 20 #include <string> 21 #include <memory> 22 #include <vector> 23 #include <mutex> 24 #include <map> 25 #include "include/transform/graph_ir/types.h" 26 #include "ir/anf.h" 27 #include "include/backend/visible.h" 28 29 namespace mindspore { 30 namespace transform { 31 class GraphRunner; 32 33 class BACKEND_EXPORT DfGraphManager { 34 public: 35 ~DfGraphManager(); 36 void ClearGraph() noexcept; 37 38 static DfGraphManager &GetInstance(); 39 Status AddGraph(const std::string &name, const DfGraphPtr &graph, const OptionMap &options = {}, 40 const bool &is_cloud = false); 41 std::vector<DfGraphWrapperPtr> GetAllGraphs(); 42 std::set<string> GetSavedGraphs(); 43 void AddSavedGraphs(const std::string &id); 44 DfGraphWrapperPtr GetGraphByName(const std::string &name); 45 DfGraphManager(const DfGraphManager &) = delete; 46 DfGraphManager &operator=(const DfGraphManager &) = delete; 47 void SetAnfGraph(const std::string &name, const AnfGraphPtr &anf_graph_ptr); 48 AnfGraphPtr GetAnfGraph(uint32_t graph_id); 49 std::shared_ptr<transform::GraphRunner> GetGraphRunner(); 50 void SetGraphRunner(const std::shared_ptr<transform::GraphRunner> &graph_runner_ptr) noexcept; 51 void DeleteGraphRunner() noexcept; 52 void SetGeSession(const std::shared_ptr<::ge::Session> &sess_ptr); 53 std::shared_ptr<::ge::Session> GetGeSession(); 54 void DeleteGeSession() noexcept; 55 void AoeGeGraph(); 56 57 private: 58 DfGraphManager(); 59 int GenerateId(); 60 61 std::mutex lock_; 62 std::map<std::string, DfGraphWrapperPtr> graphs_; 63 std::set<string> saved_graphs_; 64 int graph_id_ = 0; 65 std::map<uint32_t, AnfGraphPtr> anf_graphs_; 66 std::shared_ptr<transform::GraphRunner> graph_runner_ptr_ = nullptr; 67 std::shared_ptr<::ge::Session> sess_ptr_; 68 }; 69 } // namespace transform 70 } // namespace mindspore 71 72 #endif // MINDSPORE_CCSRC_TRANSFORM_GRAPH_IR_DF_GRAPH_MANAGER_H_ 73