8 #include <initializer_list>
14 #include "ngraph/ngraph_visibility.hpp"
15 #include "ngraph/node.hpp"
16 #include "ngraph/op/assign.hpp"
17 #include "ngraph/op/parameter.hpp"
18 #include "ngraph/op/read_value.hpp"
19 #include "ngraph/op/result.hpp"
20 #include "ngraph/op/sink.hpp"
21 #include "ngraph/op/util/variable.hpp"
32 const ParameterVector& parameters,
33 const std::string& name =
"");
35 Function(
const OutputVector& results,
36 const ParameterVector& parameters,
37 const std::string& name =
"");
39 Function(
const std::shared_ptr<Node>& result,
40 const ParameterVector& parameters,
41 const std::string& name =
"");
43 Function(
const ResultVector& results,
44 const ParameterVector& parameters,
45 const std::string& name =
"");
47 Function(
const ResultVector& results,
48 const SinkVector& sinks,
49 const ParameterVector& parameters,
50 const std::string& name =
"");
52 Function(
const OutputVector& results,
53 const SinkVector& sinks,
54 const ParameterVector& parameters,
55 const std::string& name =
"");
57 Function(
const ResultVector& results,
58 const SinkVector& sinks,
59 const ParameterVector& parameters,
60 const VariableVector& variables,
61 const std::string& name =
"");
63 Function(
const OutputVector& results,
64 const SinkVector& sinks,
65 const ParameterVector& parameters,
66 const VariableVector& variables,
67 const std::string& name =
"");
69 Function(
const ResultVector& results,
70 const ParameterVector& parameters,
71 const VariableVector& variables,
72 const std::string& name =
"");
74 Function(
const OutputVector& results,
75 const ParameterVector& parameters,
76 const VariableVector& variables,
77 const std::string& name =
"");
81 explicit Function(
const OutputVector& results,
const std::string& name =
"");
86 const SinkVector& sinks,
87 const std::string& name =
"");
125 std::vector<std::shared_ptr<Node>> get_ops()
const;
126 std::vector<std::shared_ptr<Node>> get_ordered_ops()
const;
127 void map_unordered_ops(std::function<
void(
Node*)> f)
const;
129 friend std::ostream& operator<<(std::ostream&,
const Function&);
131 void replace_node(std::shared_ptr<Node> old, std::shared_ptr<Node> repl);
133 void validate_nodes_and_infer_types()
const;
151 const std::shared_ptr<op::Parameter>& parameter);
153 using topological_sort_t = std::function<std::vector<std::shared_ptr<Node>>(
154 const std::vector<std::shared_ptr<Node>>& root_nodes)>;
155 void set_topological_sort(topological_sort_t);
174 bool evaluate(
const HostTensorVector& output_tensors,
175 const HostTensorVector& input_tensors,
254 void prerequirements(
bool detect_variables,
bool detect_parameters);
256 static std::atomic<size_t> m_next_instance_id;
258 const std::string m_unique_name;
259 size_t m_placement{0};
260 topological_sort_t m_topological_sorter;
262 ResultVector m_results;
266 ParameterVector m_parameters;
267 VariableVector m_variables;
280 static constexpr
DiscreteTypeInfo type_info{
"AttributeAdapter<std::shared_ptr<Function>>",
282 const DiscreteTypeInfo& get_type_info()
const override {
return type_info; }
An AttributeAdapter "captures" an attribute as an AT& and makes it available as a ValueAccessor<VAT>.
Definition: attribute_adapter.hpp:161
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
Definition: attribute_adapter.hpp:67
A user-defined function.
Definition: function.hpp:27
void remove_sink(const std::shared_ptr< op::Sink > &sink)
Delete sink node from the list of sinks. Method doesn't delete node from graph.
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...
const SinkVector & get_sinks() const
Return a list of function's sinks.
Definition: function.hpp:179
void add_variables(const VariableVector &variables)
Add new variables to the list. Method doesn't validate graph, it should be done manually after all ch...
bool is_dynamic() const
Returns true if any of the op's defined in the function contains partial shape.
Function(const OutputVector &results, const SinkVector &sinks, const std::string &name="")
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....
void add_sinks(const SinkVector &sinks)
Add new sink nodes to the list. Method doesn't validate graph, it should be done manually after all c...
VariablePtr get_variable_by_id(const std::string &variable_id) const
Return a variable by specified variable_id.
size_t get_output_size() const
Return the number of outputs for this function.
const std::string & get_name() const
Get the unique name of the function.
void add_results(const ResultVector &results)
Add new Result nodes to the list. Method doesn't validate graph, it should be done manually after all...
void remove_variable(const VariablePtr &variable)
Delete variable from the list of variables. Method doesn't delete nodes that used this variable from ...
const VariableVector & get_variables() const
Return a list of function's variables.
Definition: function.hpp:237
const ParameterVector & get_parameters() const
Return the function parameters.
Definition: function.hpp:160
int64_t get_parameter_index(const std::shared_ptr< op::Parameter > ¶meter) const
Index for parameter, or -1.
std::shared_ptr< Node > get_output_op(size_t i) const
Return the op that generates output i.
const element::Type & get_output_element_type(size_t i) const
Return the element type of output i.
std::shared_ptr< Node > get_result() const
Check that there is a single result and return it.
void add_parameters(const ParameterVector ¶ms)
Add new Parameter nodes to the list.
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...
const PartialShape & get_output_partial_shape(size_t i) const
Return the partial shape of element 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, EvaluationContext evaluation_context=EvaluationContext()) const
Evaluate the function on inputs, putting results in outputs.
int64_t get_result_index(const Output< Node > &value) const
Index for value or result referencing it, or -1.
void remove_parameter(const std::shared_ptr< op::Parameter > ¶m)
Delete Parameter node from the list of parameters. Method will not delete node from graph....
void replace_parameter(size_t parameter_index, const std::shared_ptr< op::Parameter > ¶meter)
Replace the parameter_indexth parameter of the function with parameter.
Function(const OutputVector &results, const std::string &name="")
void remove_result(const std::shared_ptr< op::Result > &result)
Delete Result node from the list of results. Method will not delete node from graph.
const ResultVector & get_results() const
Return a list of function's outputs.
Definition: function.hpp:162
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:34
Shape for a tensor.
Definition: shape.hpp:19
Definition: element_type.hpp:51
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
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 ...
std::map< std::string, std::shared_ptr< Variant > > EvaluationContext
Definition: node.hpp:63