Class FuncGraph

Inheritance Relationships

Derived Type

Class Documentation

class FuncGraph

FuncGraph defines interface for a function graph.

Subclassed by mindspore::FuncGraph

Public Functions

FuncGraph() = default

Constructor of FuncGraph.

virtual ~FuncGraph() = default

Destructor of FuncGraph.

virtual const std::vector<AnfNodePtr> get_inputs() const = 0

Get the input parameters.

Returns

Input parameters of this graph.

virtual const std::vector<AnfNodePtr> &parameters() const = 0

Get all parameters.

Returns

All parameters of this graph.

virtual void add_parameter(const ParameterPtr &p) = 0

Adds a parameter to this graph.

Parameters

p[in] The parameter to be added.

virtual ParameterPtr add_parameter() = 0

Adds a new parameter to this graph.

Returns

The new added parameter.

virtual AnfNodePtr output() const = 0

Get the output node.

Returns

The output node, nullptr if output not set.

virtual CNodePtr get_return() const = 0

Get the return CNode.

Returns

The return CNode, nullptr if no return node.

virtual void set_output(const AnfNodePtr &value, bool force_new_ret = false) = 0

Set the output node.

Parameters
  • value[in] The output node to be set.

  • force_new_ret[in] If true, a new return node is always created.

virtual void set_return(const CNodePtr &cnode) = 0

Set the return node.

Parameters

cnode[in] The return CNode to be set.

virtual CNodePtr NewCNode(const std::vector<AnfNodePtr> &inputs = std::vector<AnfNodePtr>()) = 0

Creates a new CNode in this graph.

Parameters

inputs[in] The input nodes of the new CNode.

Returns

The created CNode.

virtual CNodePtr NewCNode(const PrimitivePtr &primitive, const std::vector<AnfNodePtr> &prim_inputs) = 0

Creates a new primitive CNode in this graph.

Parameters
  • primitive[in] The primitive of the new CNode.

  • prim_inputs[in] The argument inputs of the primitive CNode.

Returns

The created primitive CNode.

virtual const AnfNodeSet &nodes() const = 0

Get all nodes in this graph.

Returns

All nodes in this graph.

virtual bool has_attr(const std::string &key) const = 0

Check whether an attribute is set for this graph.

Parameters

key[in] The attribute key (name).

Returns

True if the attribute with the given key is set, false otherwise.

virtual ValuePtr get_attr(const std::string &key) const = 0

Get an attribute value by its key.

Parameters

key[in] The attribute key (name).

Returns

The attribute value for the given key, nullptr if attribute not found.

virtual void set_attr(const std::string &key, const ValuePtr &value) = 0

Set an attribute value.

Parameters
  • key[in] The attribute key (name).

  • value[in] The attribute value.

virtual FuncGraphManagerPtr get_manager() const = 0

Get the manager for this graph.

Returns

The manager of this graph, nullptr if not set.

Public Static Functions

static std::vector<AnfNodePtr> TopoSort(const AnfNodePtr &node)

Topological sort a graph from the given end node.

Parameters

node[in] The end node of the graph to be sorted.

Returns

The sorted nodes.

static FuncGraphPtr Create()

Creates an empty function graph.

Returns

The created graph.

static AnfNodePtr MakeValueNode(const FuncGraphPtr &func_graph)

Creates a value node that holds the given function graph.

Parameters

func_graph[in] The given function graph.

Returns

The created value node that holds the given function graph.

static FuncGraphPtr GetFuncGraphFromAnfNode(const AnfNodePtr &input)

Get the function graph from the input node.

Parameters

input[in] The input node.

Returns

The function graph if the input is value node that holds the graph, nullptr otherwise.