• 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_H_
18 #define MINDSPORE_CORE_API_IR_FUNC_GRAPH_H_
19 
20 #include <vector>
21 #include <memory>
22 #include <string>
23 
24 #include "utils/visible.h"
25 #include "api/ir/func_graph_manager.h"
26 
27 namespace mindspore::api {
28 
29 class MS_CORE_API FuncGraph {
30  public:
31   FuncGraph() = default;
32   virtual ~FuncGraph() = default;
33 
34   virtual const std::vector<AnfNodePtr> get_inputs() const = 0;
35   virtual const std::vector<AnfNodePtr> &parameters() const = 0;
36   virtual void add_parameter(const ParameterPtr &p) = 0;
37   virtual ParameterPtr add_parameter() = 0;
38 
39   virtual AnfNodePtr output() const = 0;
40   virtual CNodePtr get_return() const = 0;
41   virtual void set_output(const AnfNodePtr &value, bool force_new_ret = false) = 0;
42   virtual void set_return(const CNodePtr &cnode) = 0;
43 
44   virtual CNodePtr NewCNode(const std::vector<AnfNodePtr> &inputs = std::vector<AnfNodePtr>()) = 0;
45   virtual CNodePtr NewCNode(const PrimitivePtr &primitive, const std::vector<AnfNodePtr> &prim_inputs) = 0;
46 
47   virtual const AnfNodeSet &nodes() const = 0;
48 
49   virtual bool has_attr(const std::string &key) const = 0;
50   virtual ValuePtr get_attr(const std::string &key) const = 0;
51   virtual void set_attr(const std::string &key, const ValuePtr &value) = 0;
52 
53   virtual FuncGraphManagerPtr get_manager() const = 0;
54 
55   static std::vector<AnfNodePtr> TopoSort(const AnfNodePtr &node);
56 
57   static FuncGraphPtr Create();
58 
59   static AnfNodePtr MakeValueNode(const FuncGraphPtr &func_graph);
60 
61   static FuncGraphPtr GetFuncGraphFromAnfNode(const AnfNodePtr &input);
62 };
63 }  // namespace mindspore::api
64 #endif  // MINDSPORE_CORE_API_IR_FUNC_GRAPH_H_
65