ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::GraphBuilderMultiOutput Class Referenceabstract

Base of general multiple outputs graph builder(e.g., CircleIfGraphBuilder) More...

#include <GraphBuilderMultiOutput.h>

Collaboration diagram for luci::GraphBuilderMultiOutput:

Data Structures

struct  BuildNodeArgs
 
struct  BuildOutArgs
 

Public Member Functions

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

Detailed Description

Base of general multiple outputs graph builder(e.g., CircleIfGraphBuilder)

Definition at line 31 of file GraphBuilderMultiOutput.h.

Constructor & Destructor Documentation

◆ ~GraphBuilderMultiOutput()

virtual luci::GraphBuilderMultiOutput::~GraphBuilderMultiOutput ( )
virtualdefault

Member Function Documentation

◆ build()

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

Implements luci::GraphBuilderBase.

Definition at line 24 of file GraphBuilderMultiOutput.cpp.

26{
27 LOGGER(l);
28
29 assert(context != nullptr);
30
31 const std::vector<int32_t> &inputs = op.inputs;
32 const std::vector<int32_t> &outputs = op.outputs;
33 const auto tensors = context->reader()->tensors();
34 const auto opcodes = context->reader()->opcodes();
35 assert(!tensors.null());
36
37 std::vector<CircleNode *> input_nodes;
38 for (const int32_t input_tensor_index : inputs)
39 {
40 if (input_tensor_index >= 0)
41 {
42 auto input = context->nodefinder()->node(input_tensor_index);
43 if (input == nullptr)
44 INFO(l) << "[luci] Warning: input node is null " << input_tensor_index << std::endl;
45 input_nodes.push_back(input);
46 }
47 else
48 {
49 // If there is no tensor, insert CircleOutputExclude.
50 auto *node = context->graph()->nodes()->create<luci::CircleOutputExclude>();
51 input_nodes.push_back(node);
52 }
53 }
54
55 BuildNodeArgs bna(op, context, input_nodes);
56 auto *node = build_node(bna);
57
58 uint32_t output_count = outputs.size();
59 // NOTE CustomOp inherits GraphBuilderMultiOutput and can have 0 output
60 if (output_count > 0)
61 {
62 // Let's use attributes from output 0 for this node
63 const auto output_tensor = tensors[outputs[0]];
64 assert(output_tensor != nullptr);
65 node->name(tensor_name(output_tensor));
66 node->dtype(luci_datatype(output_tensor->type()));
67
68 // mark operator version
69 assert(opcodes[op.opcode_index] != nullptr);
70 node->op_version(opcodes[op.opcode_index]->version());
71
72 // NOTE We don't set quantization for multiple output nodes but to virtual outputs
73 }
74
75 // Create virtual outputs of Virtual Output node(s)
76 for (uint32_t n = 0; n < output_count; ++n)
77 {
78 const auto output_tensor = tensors[outputs[n]];
79 assert(output_tensor != nullptr);
80
81 BuildOutArgs boa(node, n);
82 auto *nodeout = build_out(boa);
83
84 copy_tensor_attributes(output_tensor, nodeout);
85 // NOTE name of CxxxOut nodes may have same name
86 // mark shape_status
87 if (output_tensor->shape() == nullptr)
88 nodeout->shape_status(ShapeStatus::NOSHAPE);
89 else
90 nodeout->shape_status(ShapeStatus::VALID);
91
92 context->nodefinder()->enroll(outputs[n], nodeout);
93 }
94
95 return node;
96}
#define LOGGER(name)
Definition Log.h:65
#define INFO(name)
Definition Log.h:68
CircleOutputExclude is used to specifying not exported nodes.
std::vector< Node * > input_nodes(const Graph *)
Definition Graph.cpp:71
loco::DataType luci_datatype(circle::TensorType type)
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.

References luci::copy_tensor_attributes(), loco::NodePool::create(), luci::IndexNodeFinder::enroll(), luci::GraphBuilderContext::graph(), INFO, LOGGER, luci::luci_datatype(), luci::IndexNodeFinder::node(), luci::GraphBuilderContext::nodefinder(), loco::Graph::nodes(), luci::NOSHAPE, luci::CircleReader::opcodes(), luci::GraphBuilderContext::reader(), luci::tensor_name(), luci::CircleReader::tensors(), and luci::VALID.


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