54{
55 assert(context != nullptr);
56
57
61 TensorContext &tensor_context = context->tensor();
62 TensorBags &bags = context->bags();
63 TflBufferContext &buffer_context = context->buffer();
64 const tflite::SubGraph *
graph = context->graph();
67
68
69
70
71
72 bool hasBias = (opinputs.size() == 3);
73 assert(opinputs.size() == 2 || hasBias);
74 assert(opoutputs.size() == 1);
75
76 int ifm_idx = opinputs.at(0);
77 int ker_idx = opinputs.at(1);
78 int ofm_idx = opoutputs.at(0);
79
80 const tensor::Shape &ifm_shape = tensor_context.shape(ifm_idx);
81 const tensor::Shape &ofm_shape = tensor_context.shape(ofm_idx);
82 const tensor::Shape &ker_shape = tensor_context.shape(ker_idx);
83
84
86 auto *ifm_bag = bags.
bag(ifm_idx);
87 ifm_obj->bag(ifm_bag);
89
90
92 auto *ofm_bag = bags.
bag(ofm_idx);
93 ofm_obj->bag(ofm_bag);
95
96
98 auto *ker_bag = bags.
bag(ker_idx);
99 ker_obj->bag(ker_bag);
101
102
104
105
106 auto coco_conv2d =
m->entity()->op()->create<
coco::Conv2D>();
107
108
109 coco_conv2d->
ker(ker_obj);
110
111 auto *conv_params = op->builtin_options_as_Conv2DOptions();
112
113 coco_conv2d->stride()->vertical(conv_params->stride_h());
114 coco_conv2d->stride()->horizontal(conv_params->stride_w());
115
116
118
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());
123
124
125 coco_conv2d->arg(load);
126
127
130 conv2d_obj->bag(conv2d_bag);
132
133
135
136
138
139
141
142 if (hasBias)
143 {
144
145
148 btmp_obj->bag(btmp_bag);
150
151 int bias_idx = opinputs.at(2);
152
153
155 coco::Bag *bias_bag = bags.bag(bias_idx);
156 bias_obj->bag(bias_bag);
158
159
161
162
164
165
167
168
169 last_obj = btmp_obj;
170 }
171
172
175
176
179}
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
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 &)
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
TensorSignatures load(const char *info_path)
Function to create TensorSignatures defined in info file.
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.