11 #include "ngraph/node.hpp"
12 #include "ngraph/shape.hpp"
13 #include "ngraph/type/element_type_traits.hpp"
31 using op_handler = std::function<std::vector<V>(
Node* op, std::vector<V>& inputs)>;
45 : m_handlers(handlers)
69 if (it == m_handlers.end())
71 handler = m_default_handler;
82 using InstPtr = std::unique_ptr<Inst>;
83 using InstStack = std::stack<InstPtr>;
96 virtual void handle(
Evaluator& evaluator, InstStack& inst_stack,
Node* node) = 0;
97 Node* get_node() {
return m_node; }
115 , m_index(value.index)
119 void handle(
Evaluator& evaluator, InstStack& inst_stack,
Node* node)
override
122 if (
auto handler = evaluator.get_handler(node))
125 inst_stack.push(InstPtr(
new ExecuteInst(node, handler)));
128 inst_stack.push(InstPtr(
new ValueInst(v)));
134 for (
auto output : node->
outputs())
155 void handle(
Evaluator& evaluator, InstStack& inst_stack,
Node* node)
override
159 std::vector<V> inputs;
164 std::vector<V> outputs = m_handler(node, inputs);
165 for (
size_t i = 0; i < outputs.size(); ++i)
179 InstStack inst_stack;
180 inst_stack.push(InstPtr(
new ValueInst(value)));
181 while (!inst_stack.empty())
184 std::swap(inst_stack.top(), inst);
186 auto node = inst->get_node();
187 if (m_value_map.find(node->
output(0)) != m_value_map.end())
192 inst->handle(*
this, inst_stack, node);
194 return m_value_map.at(value);
All arguments have been handled; execute the node handler.
Definition: evaluator.hpp:147
Intstructions for evaluations state machine.
Definition: evaluator.hpp:87
Ensure value has been analyzed.
Definition: evaluator.hpp:105
Execute handlers on a subgraph to compute values.
Definition: evaluator.hpp:22
value_map & get_value_map()
Retrieves the value_map, which holds all Output<Node> value associations.
Definition: evaluator.hpp:51
V evaluate(const Output< Node > &value)
Determine information about value.
Definition: evaluator.hpp:177
std::map< RawNodeOutput, V > value_map
values we compute for outputs
Definition: evaluator.hpp:25
const op_handler & get_univeral_handler() const
If set, handles all ops.
Definition: evaluator.hpp:54
std::map< Node::type_info_t, op_handler > op_handler_map
Table of ops with handlers.
Definition: evaluator.hpp:34
const op_handler & get_default_handler() const
If set, handles all ops not in the handlers.
Definition: evaluator.hpp:56
void set_univeral_handler(const op_handler &handler)
If set, handles all ops.
Definition: evaluator.hpp:58
void set_default_handler(const op_handler &handler)
If set, handles all ops not in the handlers.
Definition: evaluator.hpp:60
Evaluator(const op_handler_map &handlers, value_map &values)
construct handler using the provided op handlers.
Definition: evaluator.hpp:44
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:31
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:33
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16