• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 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 
17 #ifndef MINDSPORE_CORE_API_IR_FUNC_GRAPH_MANAGER_H_
18 #define MINDSPORE_CORE_API_IR_FUNC_GRAPH_MANAGER_H_
19 
20 #include <memory>
21 #include <utility>
22 #include <unordered_map>
23 
24 #include "utils/visible.h"
25 #include "utils/compact_set.h"
26 #include "utils/hashing.h"
27 #include "ir/anf.h"
28 
29 namespace mindspore::api {
30 
31 class FuncGraph;
32 using FuncGraphPtr = std::shared_ptr<FuncGraph>;
33 
34 class FuncGraphManager;
35 using FuncGraphManagerPtr = std::shared_ptr<FuncGraphManager>;
36 
37 using AnfNodeIndexSet = CompactSet<std::pair<AnfNodePtr, int>>;
38 using NodeUsersMap = std::unordered_map<AnfNodePtr, AnfNodeIndexSet, PointerHash<AnfNodePtr>>;
39 
40 class MS_CORE_API FuncGraphManager {
41  public:
42   FuncGraphManager() = default;
43   virtual ~FuncGraphManager() = default;
44 
45   virtual bool Replace(const AnfNodePtr &old_node, const AnfNodePtr &new_node) = 0;
46   virtual void SetEdge(const AnfNodePtr &node, int index, const AnfNodePtr &value) = 0;
47   virtual void AddEdge(const AnfNodePtr &node, const AnfNodePtr &value) = 0;
48   virtual const NodeUsersMap &node_users() const = 0;
49 
50   static FuncGraphManagerPtr Manage(const FuncGraphPtr &func_graph, bool manage = true);
51 };
52 
53 }  // namespace mindspore::api
54 
55 #endif  // MINDSPORE_CORE_API_IR_FUNC_GRAPH_MANAGER_H_
56