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

GraphBuilder for ReLU6 operator. More...

#include <ReLU6.h>

Collaboration diagram for tflimport::ReLU6GraphBuilder:

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 ReLU6 operator.

Definition at line 30 of file ReLU6.h.

Member Function Documentation

◆ build()

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

Implements tflimport::GraphBuilder.

Definition at line 37 of file ReLU6.cpp.

38{
39 assert(context != nullptr); // check if init(..) is called
40
41 coco::Module *m = context->m();
42 coco::Block *blk = context->block();
43 TensorContext &tensor_context = context->tensor();
44 TensorBags &bags = context->bags();
45
46 IndexVector opinputs = as_index_vector(op->inputs());
47 IndexVector opoutputs = as_index_vector(op->outputs());
48
49 // these are fixed in tflite
50 // input index 0 : input feature
51 // output index 0 : output feature
52 assert(opinputs.size() == 1);
53 assert(opoutputs.size() == 1);
54
55 int ifm_idx = opinputs.at(0);
56 int ofm_idx = opoutputs.at(0);
57
58 const tensor::Shape &ifm_shape = tensor_context.shape(ifm_idx);
59 const tensor::Shape &ofm_shape = tensor_context.shape(ofm_idx);
60
61 // Create an object for an input feature map
62 coco::FeatureObject *ifm_obj = m->entity()->object()->create<coco::FeatureObject>();
63 coco::Bag *ifm_bag = bags.bag(ifm_idx);
64 ifm_obj->bag(ifm_bag);
66
67 // Create an object for an output feature map
68 coco::FeatureObject *ofm_obj = m->entity()->object()->create<coco::FeatureObject>();
69 coco::Bag *ofm_bag = bags.bag(ofm_idx);
70 ofm_obj->bag(ofm_bag);
72
73 // Create a Load op
74 auto coco_load = op_builder(m).load(ifm_obj).pop();
75
76 // Create a ReLU6
77 auto coco_relu6 = m->entity()->op()->create<coco::ReLU6>();
78
79 // Link ops
80 coco_relu6->arg(coco_load);
81
82 // Create an Eval instruction
83 auto eval_ins = instr_builder(m).eval(ofm_obj, coco_relu6);
84
85 // Append the instruction to the block
86 blk->instr()->append(eval_ins);
87}
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
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
Apply ReLU6 over elements.
Definition Ops.h:268
Op * arg(uint32_t n) const final
Return N-th argument.
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

References coco::DLinkedList< Child, Parent >::Head::append(), coco::UnaryOp::arg(), morph::tflite::as_feature_shape(), tflimport::as_index_vector(), 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(), OpBuilder::load(), tflimport::GraphBuilderContext::m(), m, op_builder(), OpBuilder::pop(), tflimport::TensorContext::shape(), and tflimport::GraphBuilderContext::tensor().


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