ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::CircleWhileGraphBuilder Class Reference

#include <CircleWhile.h>

Collaboration diagram for luci::CircleWhileGraphBuilder:

Public Member Functions

bool validate (const ValidateArgs &args) const final
 
CircleNodebuild (const circle::OperatorT &op, GraphBuilderContext *context) const final
 While Node builder.
 
- Public Member Functions inherited from luci::GraphBuilderBase
virtual ~GraphBuilderBase ()=default
 

Detailed Description

Definition at line 25 of file CircleWhile.h.

Member Function Documentation

◆ build()

CircleNode * luci::CircleWhileGraphBuilder::build ( const circle::OperatorT &  op,
GraphBuilderContext context 
) const
finalvirtual

While Node builder.

Note
Current loco does not provide multiple outputs We will create multiple CircleWhileOut nodes to emulate this For two outputs that may look like this

— CircleWhile — Node — - Node —

will be created like this

— CircleWhile — CircleWhileOut — Node — - CircleWhileOut — Node —

Implements luci::GraphBuilderBase.

Definition at line 61 of file CircleWhile.cpp.

63{
64 assert(context != nullptr);
65
66 auto graph = context->graph();
67
68 const std::vector<int32_t> &inputs = op.inputs;
69 const std::vector<int32_t> &outputs = op.outputs;
70 const auto tensors = context->reader()->tensors();
71 const auto opcodes = context->reader()->opcodes();
72
73 std::vector<CircleNode *> input_nodes;
74 for (const int32_t input_tensor_index : inputs)
75 {
76 auto input_node = context->nodefinder()->node(input_tensor_index);
77 assert(input_node != nullptr);
78 input_nodes.push_back(input_node);
79 }
80
81 uint32_t input_count = inputs.size();
82 uint32_t output_count = outputs.size();
83
84 // Create CircleWhile
85 CircleWhile *node = graph->nodes()->create<CircleWhile>(input_count, output_count);
86
87 for (uint32_t idx = 0; idx < input_count; ++idx)
88 {
89 node->input(idx, input_nodes[idx]);
90 }
91
92 const auto *options = op.builtin_options.AsWhileOptions();
93 node->cond_branch(options->cond_subgraph_index);
94 node->body_branch(options->body_subgraph_index);
95
96 assert(outputs.size() > 0);
97 {
98 // Lets use name of output 0 as While name
99 const auto output_tensor = tensors[outputs[0]];
100 assert(output_tensor != nullptr);
101 node->name(tensor_name(output_tensor));
102 assert(opcodes[op.opcode_index] != nullptr);
103 node->op_version(opcodes[op.opcode_index]->version());
104
105 // NOTE We don't set quantization for While itself but to virtual outputs
106 }
107
108 // Create virtual outputs of While
109 for (uint32_t n = 0; n < output_count; ++n)
110 {
111 const auto output_tensor = tensors[outputs[n]];
112 assert(output_tensor != nullptr);
113
114 auto *nodeout = graph->nodes()->create<CircleWhileOut>();
115
116 nodeout->input(node);
117 nodeout->index(n);
118
119 copy_tensor_attributes(output_tensor, nodeout);
120
121 // Note: leave shape_status to UNKNOWN to run shape inference
122
123 context->nodefinder()->enroll(outputs[n], nodeout);
124 }
125
126 return node;
127}
std::vector< Node * > input_nodes(const Graph *)
Definition Graph.cpp:71
const char * tensor_name(const circle::Tensor *tensor)
void copy_tensor_attributes(const circle::Tensor *tensor, CircleNode *node)
Copy common tensor attributes such as name, type, etc. to node.
CircleInput * input_node(loco::Graph *g, const loco::GraphInputIndex &index)
Find a Pull node with a given input index.

References luci::CircleWhile::body_branch(), luci::CircleWhile::cond_branch(), luci::copy_tensor_attributes(), luci::IndexNodeFinder::enroll(), luci::GraphBuilderContext::graph(), luci::CircleWhile::input(), luci::CircleWhileOut::input(), luci::input_node(), luci::CircleNode::name(), luci::IndexNodeFinder::node(), luci::GraphBuilderContext::nodefinder(), luci::CircleNode::op_version(), luci::CircleReader::opcodes(), luci::GraphBuilderContext::reader(), luci::tensor_name(), and luci::CircleReader::tensors().

◆ validate()

bool luci::CircleWhileGraphBuilder::validate ( const ValidateArgs args) const
finalvirtual

Implements luci::GraphBuilderBase.

Definition at line 28 of file CircleWhile.cpp.

29{
30 const auto &inputs = args.op.inputs;
31 const auto *options = args.op.builtin_options.AsWhileOptions();
32
33 if (inputs.size() != args.op.outputs.size())
34 return false;
35
36 auto num_graphs = static_cast<int32_t>(args.reader.num_subgraph());
37 if (options->cond_subgraph_index >= num_graphs)
38 return false;
39 if (options->body_subgraph_index >= num_graphs)
40 return false;
41
42 return true;
43}
args
Definition infer.py:21

The documentation for this class was generated from the following files: