23 #include "ngraph/node.hpp"
24 #include "ngraph/shape.hpp"
25 #include "ngraph/type/element_type_traits.hpp"
43 using op_handler = std::function<std::vector<V>(
Node* op, std::vector<V>& inputs)>;
57 : m_handlers(handlers)
80 if (it == m_handlers.end())
82 handler = m_default_handler;
93 using InstPtr = std::unique_ptr<Inst>;
94 using InstStack = std::stack<InstPtr>;
107 virtual void handle(
Evaluator& evaluator, InstStack& inst_stack,
Node* node) = 0;
108 Node* get_node() {
return m_node; }
125 , m_index(value.index)
129 void handle(
Evaluator& evaluator, InstStack& inst_stack,
Node* node)
override
132 if (
auto handler = evaluator.get_handler(node))
135 inst_stack.push(InstPtr(
new ExecuteInst(node, handler)));
138 inst_stack.push(InstPtr(
new ValueInst(v)));
144 for (
auto output : node->
outputs())
165 void handle(
Evaluator& evaluator, InstStack& inst_stack,
Node* node)
override
169 std::vector<V> inputs;
174 std::vector<V> outputs = m_handler(node, inputs);
175 for (
size_t i = 0; i < outputs.size(); ++i)
189 InstStack inst_stack;
190 inst_stack.push(InstPtr(
new ValueInst(value)));
191 while (!inst_stack.empty())
194 std::swap(inst_stack.top(), inst);
196 auto node = inst->get_node();
197 if (m_value_map.find(node->
output(0)) != m_value_map.end())
202 inst->handle(*
this, inst_stack, node);
204 return m_value_map.at(value);
All arguments have been handled; execute the node handler.
Definition: evaluator.hpp:157
Intstructions for evaluations state machine.
Definition: evaluator.hpp:98
Ensure value has been analyzed.
Definition: evaluator.hpp:115
Execute handlers on a subgraph to compute values.
Definition: evaluator.hpp:34
value_map & get_value_map()
Retrieves the value_map, which holds all Output<Node> value associations.
Definition: evaluator.hpp:63
V evaluate(const Output< Node > &value)
Determine information about value.
Definition: evaluator.hpp:187
std::map< RawNodeOutput, V > value_map
values we compute for outputs
Definition: evaluator.hpp:37
const op_handler & get_univeral_handler() const
If set, handles all ops.
Definition: evaluator.hpp:66
std::map< Node::type_info_t, op_handler > op_handler_map
Table of ops with handlers.
Definition: evaluator.hpp:46
const op_handler & get_default_handler() const
If set, handles all ops not in the handlers.
Definition: evaluator.hpp:68
void set_univeral_handler(const op_handler &handler)
If set, handles all ops.
Definition: evaluator.hpp:70
void set_default_handler(const op_handler &handler)
If set, handles all ops not in the handlers.
Definition: evaluator.hpp:72
Evaluator(const op_handler_map &handlers, value_map &values)
construct handler using the provided op handlers.
Definition: evaluator.hpp:56
std::function< std::vector< V >(Node *op, std::vector< V > &inputs)> op_handler
Handler for a computation of a value about an op.
Definition: evaluator.hpp:43
virtual const type_info_t & get_type_info() const =0
Output< Node > output(size_t output_index)
std::vector< Output< Node > > outputs()
std::vector< Output< Node > > input_values() const
A handle for one of a node's outputs.
Definition: node_output.hpp:42
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28