21#include "GraphBuilder.h"
31#include <schema_generated.h>
43 auto const options = op->builtin_options_as_Conv2DOptions();
45 if ((options->stride_h() == 0) || (options->stride_w() == 0))
55 assert(context !=
nullptr);
64 const tflite::SubGraph *graph = context->
graph();
72 bool hasBias = (opinputs.size() == 3);
73 assert(opinputs.size() == 2 || hasBias);
74 assert(opoutputs.size() == 1);
76 int ifm_idx = opinputs.at(0);
77 int ker_idx = opinputs.at(1);
78 int ofm_idx = opoutputs.at(0);
86 auto *ifm_bag = bags.
bag(ifm_idx);
87 ifm_obj->bag(ifm_bag);
92 auto *ofm_bag = bags.
bag(ofm_idx);
93 ofm_obj->bag(ofm_bag);
98 auto *ker_bag = bags.
bag(ker_idx);
99 ker_obj->bag(ker_bag);
106 auto coco_conv2d =
m->entity()->op()->create<
coco::Conv2D>();
109 coco_conv2d->
ker(ker_obj);
111 auto *conv_params = op->builtin_options_as_Conv2DOptions();
113 coco_conv2d->stride()->vertical(conv_params->stride_h());
114 coco_conv2d->stride()->horizontal(conv_params->stride_w());
119 coco_conv2d->pad()->top(padding.
top());
120 coco_conv2d->pad()->bottom(padding.
bottom());
121 coco_conv2d->pad()->left(padding.
left());
122 coco_conv2d->pad()->right(padding.
right());
125 coco_conv2d->arg(load);
129 auto *conv2d_bag =
m->entity()->
bag()->create(num_elements(ofm_shape));
130 conv2d_obj->bag(conv2d_bag);
147 auto *btmp_bag =
m->entity()->
bag()->create(num_elements(ofm_shape));
148 btmp_obj->bag(btmp_bag);
151 int bias_idx = opinputs.at(2);
156 bias_obj->bag(bias_bag);
OpBuilder op_builder(coco::Module *m)
InstrBuilder instr_builder(coco::Module *m)
coco::Copy * copy(coco::Object *into, coco::Object *from) const
Create "Copy" instruction with given two "Object".
coco::Eval * eval(coco::Object *out, coco::Op *op) const
Create "Eval" instruction with a given "Object" and "Op".
OpBuilder & load(coco::Object *obj)
Create "Load" op and push it onto the internal stack.
coco::Op * pop(void)
Pop op from the internal stack.
OpBuilder & add(void)
Create "Add" op and push it onto the internal stack.
A collection of (abstracted) elements of the same type.
A unit of (grouped) instructions.
2D Convolution over 3D Feature Map with 4D kernel
KernelObject * ker(void) const
void append(Child *child)
static std::unique_ptr< BC > create(const nncc::core::ADT::feature::Shape &shape)
static std::unique_ptr< BHWC > create(const nncc::core::ADT::feature::Shape &shape)
FeatureMap values (used in CNN)
static std::unique_ptr< NHWC > create(const nncc::core::ADT::kernel::Shape &shape)
Convolution Kernel (in CNN) values.
Top-level element of coco IR which represents a neural network.
coco::Bag * bag(void) const
uint32_t left(void) const
uint32_t right(void) const
uint32_t bottom(void) const
bool validate(const tflite::Operator *op) const override
void build(const tflite::Operator *op, GraphBuilderContext *context) const override
Class to store context to build IR from tflite.
TflBufferContext & buffer()
const tflite::SubGraph * graph()
Pre-creates coco:Bags for each operands(tensors)
coco::Bag * bag(int32_t tensor_id)
Extracts and holds operand(tensor) information such as name, shape, and type.
const tensor::Shape & shape(uint32_t tensor_id)
Class to read and provide buffer information of tflite.
nncc::core::ADT::feature::Shape as_feature_shape(const nncc::core::ADT::tensor::Shape &)
nncc::core::ADT::kernel::Shape as_kernel_shape(const nncc::core::ADT::tensor::Shape &)
std::vector< int32_t > IndexVector
coco::Padding2D conv2D_padding(const tflite::Conv2DOptions *options, const tensor::Shape &ifm_shape, const tensor::Shape &kernel_shape)
coco::FeatureObject * build_activation(tflite::ActivationFunctionType act, coco::Block *block, coco::FeatureObject *ifm)
Add coco::Eval for fused activation. This method creates an ofm object, appends Eval(ofm object,...
IndexVector as_index_vector(const flatbuffers::Vector< int32_t > *array)
Converts flatbuffers::Vector to IndexVector.
Core coco entity for constant weights.