ONE - On-device Neural Engine
Loading...
Searching...
No Matches
tflimport::SubGraphBuilder Class Reference

GraphBuilder for Sub operator. More...

#include <Sub.h>

Collaboration diagram for tflimport::SubGraphBuilder:

Public Member Functions

void build (const tflite::Operator *op, GraphBuilderContext *) const override
 
- Public Member Functions inherited from tflimport::GraphBuilder
virtual bool validate (const tflite::Operator *) const
 
virtual ~GraphBuilder ()
 

Detailed Description

GraphBuilder for Sub operator.

Definition at line 30 of file Sub.h.

Member Function Documentation

◆ build()

void tflimport::SubGraphBuilder::build ( const tflite::Operator *  op,
GraphBuilderContext context 
) const
overridevirtual

Implements tflimport::GraphBuilder.

Definition at line 39 of file Sub.cpp.

40{
41 assert(context != nullptr); // check if init(..) is called
42
43 coco::Module *m = context->m();
44 coco::Block *blk = context->block();
45 TensorContext &tensor_context = context->tensor();
46 TensorBags &bags = context->bags();
47
48 IndexVector opinputs = as_index_vector(op->inputs());
49 IndexVector opoutputs = as_index_vector(op->outputs());
50
51 // these are fixed in tflite
52 // input index 0 : left input feature
53 // input index 1 : right input feature
54 // output index 0 : output feature
55 assert(opinputs.size() == 2);
56 assert(opoutputs.size() == 1);
57
58 // Default parameter values are referenced from schema_generated.h
59 auto *params = op->builtin_options_as_SubOptions();
60 tflite::ActivationFunctionType activation = tflite::ActivationFunctionType_NONE;
61
62 if (auto *params = op->builtin_options_as_SubOptions())
63 {
64 activation = params->fused_activation_function();
65 }
66 assert(activation == tflite::ActivationFunctionType_NONE);
67
68 // Construct a vector of input objects
69 std::vector<coco::FeatureObject *> input_objects;
70
71 for (auto &input_index : opinputs)
72 {
73 // Add objects for input feature map
74 const tensor::Shape &input_shape = tensor_context.shape(input_index);
75 coco::FeatureObject *input_obj = m->entity()->object()->create<coco::FeatureObject>();
76 coco::Bag *input_bag = bags.bag(input_index);
77 input_obj->bag(input_bag);
79
80 input_objects.emplace_back(input_obj);
81 }
82
83 // Create an object for an output feature map
84 int const output_index = opoutputs.at(0);
85 const tensor::Shape &output_shape = tensor_context.shape(output_index);
86 coco::FeatureObject *output_obj = m->entity()->object()->create<coco::FeatureObject>();
87 coco::Bag *output_bag = bags.bag(output_index);
88 output_obj->bag(output_bag);
90
91 // Create Load ops
92 auto left_load = op_builder(m).load(input_objects[0]).pop();
93 auto right_load = op_builder(m).load(input_objects[1]).pop();
94
95 // Create a Sub
96 auto coco_sub = m->entity()->op()->create<coco::Sub>();
97
98 coco_sub->left(left_load);
99 coco_sub->right(right_load);
100
101 // Create an Eval instruction
102 auto eval = instr_builder(m).eval(output_obj, coco_sub);
103
104 // Append the instruction to the block
105 blk->instr()->append(eval);
106
107 // TODO activation, e.g., relu
108 assert(params->fused_activation_function() ==
109 tflite::ActivationFunctionType::ActivationFunctionType_NONE);
110}
OpBuilder op_builder(coco::Module *m)
Definition IRBuilder.h:144
InstrBuilder instr_builder(coco::Module *m)
Definition IRBuilder.h:174
coco::Eval * eval(coco::Object *out, coco::Op *op) const
Create "Eval" instruction with a given "Object" and "Op".
Definition IRBuilder.h:162
OpBuilder & load(coco::Object *obj)
Create "Load" op and push it onto the internal stack.
Definition IRBuilder.h:70
coco::Op * pop(void)
Pop op from the internal stack.
Definition IRBuilder.h:116
A collection of (abstracted) elements of the same type.
Definition Bag.h:48
Op * left(void) const
Definition Op.h:232
A unit of (grouped) instructions.
Definition Block.h:40
InstrList * instr(void)
Definition Block.h:65
void append(Child *child)
static std::unique_ptr< BHWC > create(const nncc::core::ADT::feature::Shape &shape)
FeatureMap values (used in CNN)
const FeatureLayout * layout(void) const
Top-level element of coco IR which represents a neural network.
Definition Module.h:34
coco::Bag * bag(void) const
Definition Object.h:74
Element-wise subtraction.
Definition Ops.h:306
const luci_interpreter::RuntimeShape output_shape
nncc::core::ADT::feature::Shape as_feature_shape(const nncc::core::ADT::tensor::Shape &)
Definition tflite.cpp:54
std::vector< int32_t > IndexVector
Definition Convert.h:29
IndexVector as_index_vector(const flatbuffers::Vector< int32_t > *array)
Converts flatbuffers::Vector to IndexVector.
Definition Convert.cpp:28
virtual ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const =0

References coco::DLinkedList< Child, Parent >::Head::append(), morph::tflite::as_feature_shape(), tflimport::as_index_vector(), coco::FeatureLayout::at(), tflimport::TensorBags::bag(), coco::Object::bag(), tflimport::GraphBuilderContext::bags(), tflimport::GraphBuilderContext::block(), coco::FeatureLayouts::BHWC::create(), InstrBuilder::eval(), coco::Block::instr(), instr_builder(), coco::FeatureObject::layout(), coco::BinaryOp::left(), OpBuilder::load(), tflimport::GraphBuilderContext::m(), m, op_builder(), output_shape, OpBuilder::pop(), tflimport::TensorContext::shape(), and tflimport::GraphBuilderContext::tensor().


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