| AIfES 2 2.0.0

ailayer_conv2d.h
Go to the documentation of this file.
1
41 #ifndef CONV2D_LAYER
42 #define CONV2D_LAYER
43
44 #include "core/aifes_core.h"
45
46 #define AIFES_CHANNELS_FIRST 1
47 #define AIFES_CHANNELS_LAST -1
48
49 #define AIFES_PADDING_SAME 0xFFFF // Not fully implemented yet
50 #define AIFES_PADDING_VALID 0
51
52 typedef struct ailayer_conv2d ailayer_conv2d_t;
53
57 struct ailayer_conv2d {
58 ailayer_t base;
66 // Values (configurable)
67 uint32_t filter_count;
68 uint16_t kernel_size[2];
70 uint16_t stride[2];
71 uint16_t dilation[2];
72 uint16_t padding[2]; // AIFES_PADDING_SAME = 0xFFFF
73
74 int8_t channel_axis;
76
81 aitensor_t weights;
82 aitensor_t bias;
84 uint16_t weights_shape[4];
85 uint16_t bias_shape[1];
87 aitensor_t *trainable_params[2];
88 aitensor_t *gradients[2];
89 void *optimem[2];
91
92 uint16_t result_shape[4];
98
117 void (*conv2d_fwd)(
118 const aitensor_t *input,
119 const uint16_t stride[2], // [s_h, s_w]
120 const uint16_t dilation[2], // [d_h, d_w]
121 const uint16_t padding[2], // AIFES_PADDING_SAME not allowed
122 const aitensor_t *weights,
123 const aitensor_t *bias,
124 int8_t channel_axis,
125 void *work_space,
126 aitensor_t *output
127 );
128
146 void (*conv2d_bwd)(
147 const aitensor_t *input,
148 const uint16_t stride[2], // [s_h, s_w]
149 const uint16_t dilation[2], // [d_h, d_w]
150 const uint16_t padding[2],
151 const aitensor_t *output,
152 int8_t channel_axis,
153 void *work_space,
154 aitensor_t *d_weights
155 );
156
176 void (*conv2d_bwd_full)(
177 const aitensor_t *delta_out,
178 const uint16_t stride[2], // [s_h, s_w]
179 const uint16_t dilation[2], // [d_h, d_w]
180 const uint16_t padding[2],
181 const aitensor_t *weights,
182 int8_t channel_axis,
183 void *work_space,
184 aitensor_t *delta_in
185 );
186
194 void (*tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
195
203 void (*sum_channelwise)(const aitensor_t *x, int8_t channel_axis, aitensor_t *result);
204 };
205
211 extern const aicore_layertype_t *ailayer_conv2d_type;
212
224 ailayer_t *ailayer_conv2d(ailayer_conv2d_t *layer, ailayer_t *input_layer);
225
249 void ailayer_conv2d_forward(ailayer_t *self);
250
284 void ailayer_conv2d_backward(ailayer_t *self);
285
301 void ailayer_conv2d_calc_result_shape(ailayer_t *self);
302
312 uint32_t ailayer_conv2d_sizeof_bwdmem(const ailayer_t *self);
313
324 uint32_t ailayer_conv2d_sizeof_paramem(const ailayer_t *self);
325
337 void ailayer_conv2d_set_paramem(ailayer_t *self, void *memory_ptr);
338
348 uint32_t ailayer_conv2d_sizeof_trainmem(const ailayer_t *self);
349
359 void ailayer_conv2d_set_trainmem(ailayer_t *self, void *memory_ptr);
360
361 #ifdef AIDEBUG_PRINT_MODULE_SPECS
366 void ailayer_conv2d_print_specs(const ailayer_t *self);
367 #endif // AIDEBUG_PRINT_MODULE_SPECS
368
369 #endif // CONV2D_LAYER
aifes_core.h
AIfES 2 core interface.
ailayer_conv2d_calc_result_shape
void ailayer_conv2d_calc_result_shape(ailayer_t *self)
Calculate the shape of the result tensor (ailayer.result)
ailayer_conv2d_sizeof_bwdmem
uint32_t ailayer_conv2d_sizeof_bwdmem(const ailayer_t *self)
Calculate and return the memory size needed for temporary results of the backward pass.
ailayer_conv2d_sizeof_trainmem
uint32_t ailayer_conv2d_sizeof_trainmem(const ailayer_t *self)
Calculate and return the memory size needed by this layer for training.
ailayer_conv2d_type
const aicore_layertype_t * ailayer_conv2d_type
Conv2D layer type.
ailayer_conv2d_print_specs
void ailayer_conv2d_print_specs(const ailayer_t *self)
Print the layer specification.
ailayer_conv2d_backward
void ailayer_conv2d_backward(ailayer_t *self)
Calculate the backward pass for given Conv2D layer.
ailayer_conv2d_set_paramem
void ailayer_conv2d_set_paramem(ailayer_t *self, void *memory_ptr)
Distribute provided memory to the parameter pointers.
ailayer_conv2d_set_trainmem
void ailayer_conv2d_set_trainmem(ailayer_t *self, void *memory_ptr)
Distribute provided memory to the gradients pointers.
ailayer_conv2d_sizeof_paramem
uint32_t ailayer_conv2d_sizeof_paramem(const ailayer_t *self)
Calculate and return the parameter memory size needed for this layer.
ailayer_conv2d
ailayer_t * ailayer_conv2d(ailayer_conv2d_t *layer, ailayer_t *input_layer)
Initialize and connect the given Conv2D layer.
ailayer_conv2d_forward
void ailayer_conv2d_forward(ailayer_t *self)
Calculate the forward pass for given Conv2D layer.
aicore_layertype
Type indicator of the layer.
Definition: aifes_core.h:82
ailayer_conv2d
General Conv2D layer structure.
Definition: ailayer_conv2d.h:57
ailayer_conv2d::result_shape
uint16_t result_shape[4]
The shape of the result.
Definition: ailayer_conv2d.h:92
ailayer_conv2d::conv2d_bwd
void(* conv2d_bwd)(const aitensor_t *input, const uint16_t stride[2], const uint16_t dilation[2], const uint16_t padding[2], const aitensor_t *output, int8_t channel_axis, void *work_space, aitensor_t *d_weights)
Required math function: Gradients of 2D-Convolution with respect to the weights.
Definition: ailayer_conv2d.h:146
ailayer_conv2d::bias_shape
uint16_t bias_shape[1]
Bias weights tensor shape.
Definition: ailayer_conv2d.h:85
ailayer_conv2d::gradients
aitensor_t * gradients[2]
Gradients structure for the backpropagation algorithm.
Definition: ailayer_conv2d.h:88
ailayer_conv2d::conv2d_bwd_full
void(* conv2d_bwd_full)(const aitensor_t *delta_out, const uint16_t stride[2], const uint16_t dilation[2], const uint16_t padding[2], const aitensor_t *weights, int8_t channel_axis, void *work_space, aitensor_t *delta_in)
Required math function: Gradients of 2D-Convolution with respect to the input.
Definition: ailayer_conv2d.h:176
ailayer_conv2d::optimem
void * optimem[2]
Memory field used by the optimizer for training.
Definition: ailayer_conv2d.h:89
ailayer_conv2d::filter_count
uint32_t filter_count
Number of filters ( ).
Definition: ailayer_conv2d.h:67
ailayer_conv2d::conv2d_fwd
void(* conv2d_fwd)(const aitensor_t *input, const uint16_t stride[2], const uint16_t dilation[2], const uint16_t padding[2], const aitensor_t *weights, const aitensor_t *bias, int8_t channel_axis, void *work_space, aitensor_t *output)
Required math function: 2D-Convolution.
Definition: ailayer_conv2d.h:117
ailayer_conv2d::tensor_add
void(* tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Required math function: Element wise tensor addition.
Definition: ailayer_conv2d.h:194
ailayer_conv2d::bias
aitensor_t bias
Tensor containing the bias weights.
Definition: ailayer_conv2d.h:82
ailayer_conv2d::padding
uint16_t padding[2]
The (symmetric) zero padding in the direction of height and width ( ).
Definition: ailayer_conv2d.h:72
ailayer_conv2d::stride
uint16_t stride[2]
The stride in the direction of height and width ( ).
Definition: ailayer_conv2d.h:70
ailayer_conv2d::base
ailayer_t base
Inherited field members from general ailayer struct.
Definition: ailayer_conv2d.h:58
ailayer_conv2d::sum_channelwise
void(* sum_channelwise)(const aitensor_t *x, int8_t channel_axis, aitensor_t *result)
Required math function: Channel-wise sum.
Definition: ailayer_conv2d.h:203
ailayer_conv2d::weights
aitensor_t weights
Tensor containing the weights.
Definition: ailayer_conv2d.h:81
ailayer_conv2d::weights_shape
uint16_t weights_shape[4]
Weights tensor shape.
Definition: ailayer_conv2d.h:84
ailayer_conv2d::kernel_size
uint16_t kernel_size[2]
Size of the kernels ( ).
Definition: ailayer_conv2d.h:68
ailayer_conv2d::dilation
uint16_t dilation[2]
The dilation in the direction of height and width ( ).
Definition: ailayer_conv2d.h:71
ailayer_conv2d::trainable_params
aitensor_t * trainable_params[2]
Pointer to the weights and bias (which are the trainable parameters).
Definition: ailayer_conv2d.h:87
ailayer_conv2d::channel_axis
int8_t channel_axis
Index of the channel axis (1 for channels first and -1 or 3 for channels last).
Definition: ailayer_conv2d.h:74
ailayer
AIfES layer interface.
Definition: aifes_core.h:252
aitensor
A tensor in AIfES.
Definition: aifes_math.h:89