20 #include <initializer_list>
26 #include "ngraph/ngraph_visibility.hpp"
27 #include "ngraph/node.hpp"
28 #include "ngraph/op/parameter.hpp"
29 #include "ngraph/op/result.hpp"
40 const ParameterVector& parameters,
41 const std::string& name =
"");
43 Function(
const OutputVector& results,
44 const ParameterVector& parameters,
45 const std::string& name =
"");
47 Function(
const std::shared_ptr<Node>& result,
48 const ParameterVector& parameters,
49 const std::string& name =
"");
51 Function(
const ResultVector& results,
52 const ParameterVector& parameters,
53 const std::string& name =
"");
91 std::vector<std::shared_ptr<Node>> get_ops()
const;
92 std::vector<std::shared_ptr<Node>> get_ordered_ops()
const;
93 void map_unordered_ops(std::function<
void(
Node*)> f)
const;
95 friend std::ostream& operator<<(std::ostream&,
const Function&);
97 void replace_node(std::shared_ptr<Node> old, std::shared_ptr<Node> repl);
99 void validate_nodes_and_infer_types();
117 const std::shared_ptr<op::Parameter>& parameter);
119 using topological_sort_t = std::function<std::vector<std::shared_ptr<Node>>(
120 const std::vector<std::shared_ptr<Node>>& root_nodes)>;
121 void set_topological_sort(topological_sort_t);
123 virtual bool visit_attributes(AttributeVisitor& visitor);
138 bool evaluate(
const HostTensorVector& output_tensors,
139 const HostTensorVector& input_tensors)
const;
146 static std::atomic<size_t> m_next_instance_id;
148 const std::string m_unique_name;
149 size_t m_placement{0};
150 topological_sort_t m_topological_sorter;
152 ResultVector m_results;
153 ParameterVector m_parameters;
157 class NGRAPH_API AttributeAdapter<std::shared_ptr<Function>> :
public VisitorAdapter
160 AttributeAdapter(std::shared_ptr<Function>& ref);
162 bool visit_attributes(AttributeVisitor& visitor)
override;
164 static constexpr
DiscreteTypeInfo type_info{
"AttributeAdapter<shared_ptr<Function>>", 0};
167 std::shared_ptr<Function>& m_ref;
int64_t get_result_index(const Output< Node > &value) const
Index for value or result referencing it, or -1.
const std::string & get_friendly_name() const
Gets the friendly name for a function. If no friendly name has been set via set_friendly_name then th...
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:46
std::shared_ptr< Node > get_result() const
Check that there is a single result and return it.
std::shared_ptr< Node > get_output_op(size_t i) const
Return the op that generates output i.
const Shape & get_output_shape(size_t i) const
Return the shape of element i.
bool evaluate(const HostTensorVector &output_tensors, const HostTensorVector &input_tensors) const
Evaluate the function on inputs, putting results in outputs.
size_t get_graph_size() const
Returns the sum of the size of all nodes in the graph plus the size of all constant data....
size_t get_output_size() const
Return the number of outputs for this function.
A handle for one of a node's outputs.
Definition: node_output.hpp:41
NGRAPH_API void replace_node(std::shared_ptr< Node > target, std::shared_ptr< Node > replacement, const std::vector< int64_t > &output_order)
Replace the node target with the node replacement, i.e., redirect all users and control dependencies ...
const PartialShape & get_output_partial_shape(size_t i) const
Return the partial shape of element i.
Shape for a tensor.
Definition: shape.hpp:31
const ParameterVector & get_parameters() const
Return the function parameters.
Definition: function.hpp:126
const element::Type & get_output_element_type(size_t i) const
Return the element type of output i.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
int64_t get_parameter_index(const std::shared_ptr< op::Parameter > ¶meter) const
Index for parameter, or -1.
const ResultVector & get_results() const
Return a list of function's outputs.
Definition: function.hpp:128
const DiscreteTypeInfo & get_type_info() const override
type info enables identification of the value accessor, as well as is_type and as_type.
Definition: function.hpp:165
void replace_parameter(size_t parameter_index, const std::shared_ptr< op::Parameter > ¶meter)
Replace the parameter_indexth parameter of the function with parameter.
bool is_dynamic() const
Returns true if any of the op's defined in the function contains partial shape.
void set_friendly_name(const std::string &name)
Sets a friendly name for a function. This does not overwrite the unique name of the function and is r...
A user-defined function.
Definition: function.hpp:35
const std::string & get_name() const
Get the unique name of the function.