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

Base of general single output graph builder(e.g., Conv2DGraphBuilder) More...

#include <GraphBuilder.h>

Collaboration diagram for luci::GraphBuilder:

Public Member Functions

virtual ~GraphBuilder ()=default
 
bool validate (const ValidateArgs &args, size_t input_cnt) const
 
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 single output graph builder(e.g., Conv2DGraphBuilder)

Definition at line 31 of file GraphBuilder.h.

Constructor & Destructor Documentation

◆ ~GraphBuilder()

virtual luci::GraphBuilder::~GraphBuilder ( )
virtualdefault

Member Function Documentation

◆ build()

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

Implements luci::GraphBuilderBase.

Definition at line 24 of file GraphBuilder.cpp.

25{
26 LOGGER(l);
27
28 assert(context != nullptr);
29
30 const std::vector<int32_t> &inputs = op.inputs;
31 const std::vector<int32_t> &outputs = op.outputs;
32 const auto tensors = context->reader()->tensors();
33 const auto opcodes = context->reader()->opcodes();
34 assert(!tensors.null());
35
36 std::vector<CircleNode *> input_nodes;
37 for (const int32_t input_tensor_index : inputs)
38 {
39 if (input_tensor_index >= 0)
40 {
41 auto input = context->nodefinder()->node(input_tensor_index);
42 if (input == nullptr)
43 INFO(l) << "[luci] Warning: input node is null " << input_tensor_index << std::endl;
44 input_nodes.push_back(input);
45 }
46 else
47 {
48 // If there is no tensor, insert CircleOutputExclude.
49 auto *node = context->graph()->nodes()->create<luci::CircleOutputExclude>();
50 input_nodes.push_back(node);
51 }
52 }
53
54 CircleNode *node = build_node(op, input_nodes, context->graph());
55
56 // Set up node parameters.
57 assert(outputs.size() == 1);
58 {
59 const auto output_tensor = tensors[outputs[0]];
60 assert(output_tensor != nullptr);
61 copy_tensor_attributes(output_tensor, node);
62 // mark shape_status
63 if (output_tensor->shape() == nullptr)
64 node->shape_status(ShapeStatus::NOSHAPE);
65 else
66 node->shape_status(ShapeStatus::VALID);
67
68 // mark operator version
69 assert(opcodes[op.opcode_index] != nullptr);
70 node->op_version(opcodes[op.opcode_index]->version());
71 }
72
73 // Register node's only output.
74 assert(outputs.size() == 1);
75 {
76 context->nodefinder()->enroll(outputs[0], node);
77 }
78
79 return node;
80}
#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
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::IndexNodeFinder::node(), luci::GraphBuilderContext::nodefinder(), loco::Graph::nodes(), luci::NOSHAPE, luci::CircleNode::op_version(), luci::CircleReader::opcodes(), luci::GraphBuilderContext::reader(), luci::CircleNode::shape_status(), luci::CircleReader::tensors(), and luci::VALID.

◆ validate()

bool luci::GraphBuilder::validate ( const ValidateArgs args,
size_t  input_cnt 
) const
inline

Definition at line 37 of file GraphBuilder.h.

38 {
39 return (args.op.inputs.size() == input_cnt && args.op.outputs.size() == 1);
40 }
args
Definition infer.py:21

Referenced by luci::CircleAbsGraphBuilder::validate(), luci::CircleAddGraphBuilder::validate(), luci::CircleArgMaxGraphBuilder::validate(), luci::CircleArgMinGraphBuilder::validate(), luci::CircleAveragePool2DGraphBuilder::validate(), luci::CircleBatchMatMulGraphBuilder::validate(), luci::CircleBCQFullyConnectedGraphBuilder::validate(), luci::CircleBCQGatherGraphBuilder::validate(), luci::CircleBroadcastToGraphBuilder::validate(), luci::CircleCastGraphBuilder::validate(), luci::CircleCeilGraphBuilder::validate(), luci::CircleConv2DGraphBuilder::validate(), luci::CircleCosGraphBuilder::validate(), luci::CircleCumSumGraphBuilder::validate(), luci::CircleDensifyGraphBuilder::validate(), luci::CircleDepthToSpaceGraphBuilder::validate(), luci::CircleDequantizeGraphBuilder::validate(), luci::CircleEluGraphBuilder::validate(), luci::CircleEqualGraphBuilder::validate(), luci::CircleExpGraphBuilder::validate(), luci::CircleExpandDimsGraphBuilder::validate(), luci::CircleFakeQuantGraphBuilder::validate(), luci::CircleFillGraphBuilder::validate(), luci::CircleFloorGraphBuilder::validate(), luci::CircleFloorDivGraphBuilder::validate(), luci::CircleFloorModGraphBuilder::validate(), luci::CircleFullyConnectedGraphBuilder::validate(), luci::CircleGatherGraphBuilder::validate(), luci::CircleGatherNdGraphBuilder::validate(), luci::CircleGeluGraphBuilder::validate(), luci::CircleGreaterGraphBuilder::validate(), luci::CircleGreaterEqualGraphBuilder::validate(), luci::CircleGRUGraphBuilder::validate(), luci::CircleHardSwishGraphBuilder::validate(), luci::CircleInstanceNormGraphBuilder::validate(), luci::CircleL2NormalizeGraphBuilder::validate(), luci::CircleL2Pool2DGraphBuilder::validate(), luci::CircleLeakyReluGraphBuilder::validate(), luci::CircleLessGraphBuilder::validate(), luci::CircleLessEqualGraphBuilder::validate(), luci::CircleLocalResponseNormalizationGraphBuilder::validate(), luci::CircleLogGraphBuilder::validate(), luci::CircleLogicalAndGraphBuilder::validate(), luci::CircleLogicalNotGraphBuilder::validate(), luci::CircleLogicalOrGraphBuilder::validate(), luci::CircleLogisticGraphBuilder::validate(), luci::CircleLogSoftmaxGraphBuilder::validate(), luci::CircleMatrixDiagGraphBuilder::validate(), luci::CircleMatrixSetDiagGraphBuilder::validate(), luci::CircleMaxPool2DGraphBuilder::validate(), luci::CircleMeanGraphBuilder::validate(), luci::CircleMirrorPadGraphBuilder::validate(), luci::CircleMulGraphBuilder::validate(), luci::CircleNegGraphBuilder::validate(), luci::CircleNotEqualGraphBuilder::validate(), luci::CircleOneHotGraphBuilder::validate(), luci::CirclePadGraphBuilder::validate(), luci::CirclePadV2GraphBuilder::validate(), luci::CirclePowGraphBuilder::validate(), luci::CirclePReluGraphBuilder::validate(), luci::CircleQuantizeGraphBuilder::validate(), luci::CircleRangeGraphBuilder::validate(), luci::CircleRankGraphBuilder::validate(), luci::CircleReduceAnyGraphBuilder::validate(), luci::CircleReduceProdGraphBuilder::validate(), luci::CircleReluGraphBuilder::validate(), luci::CircleRelu0To1GraphBuilder::validate(), luci::CircleRelu6GraphBuilder::validate(), luci::CircleReluN1To1GraphBuilder::validate(), luci::CircleResizeBilinearGraphBuilder::validate(), luci::CircleResizeNearestNeighborGraphBuilder::validate(), luci::CircleReverseSequenceGraphBuilder::validate(), luci::CircleReverseV2GraphBuilder::validate(), luci::CircleRmsNormGraphBuilder::validate(), luci::CircleRoPEGraphBuilder::validate(), luci::CircleRoundGraphBuilder::validate(), luci::CircleRsqrtGraphBuilder::validate(), luci::CircleScatterNdGraphBuilder::validate(), luci::CircleSegmentSumGraphBuilder::validate(), luci::CircleSelectGraphBuilder::validate(), luci::CircleSelectV2GraphBuilder::validate(), luci::CircleShapeGraphBuilder::validate(), luci::CircleSinGraphBuilder::validate(), luci::CircleSliceGraphBuilder::validate(), luci::CircleSoftmaxGraphBuilder::validate(), luci::CircleSpaceToDepthGraphBuilder::validate(), luci::CircleSparseToDenseGraphBuilder::validate(), luci::CircleSqrtGraphBuilder::validate(), luci::CircleSquareGraphBuilder::validate(), luci::CircleSquaredDifferenceGraphBuilder::validate(), luci::CircleSqueezeGraphBuilder::validate(), luci::CircleStridedSliceGraphBuilder::validate(), luci::CircleSubGraphBuilder::validate(), luci::CircleSumGraphBuilder::validate(), luci::CircleTanhGraphBuilder::validate(), luci::CircleTileGraphBuilder::validate(), luci::CircleTransposeGraphBuilder::validate(), luci::CircleUnidirectionalSequenceLSTMGraphBuilder::validate(), luci::CircleWhereGraphBuilder::validate(), and luci::CircleZerosLikeGraphBuilder::validate().


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