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 
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 
84  uint16_t weights_shape[4];
85  uint16_t bias_shape[1];
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 
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 
212 
225 
250 
285 
302 
313 
325 
337 void ailayer_conv2d_set_paramem(ailayer_t *self, void *memory_ptr);
338 
349 
359 void ailayer_conv2d_set_trainmem(ailayer_t *self, void *memory_ptr);
360 
361 #ifdef AIDEBUG_PRINT_MODULE_SPECS
367 #endif // AIDEBUG_PRINT_MODULE_SPECS
368 
369 #endif // CONV2D_LAYER
AIfES 2 core interface.
void ailayer_conv2d_calc_result_shape(ailayer_t *self)
Calculate the shape of the result tensor (ailayer.result)
uint32_t ailayer_conv2d_sizeof_bwdmem(const ailayer_t *self)
Calculate and return the memory size needed for temporary results of the backward pass.
uint32_t ailayer_conv2d_sizeof_trainmem(const ailayer_t *self)
Calculate and return the memory size needed by this layer for training.
const aicore_layertype_t * ailayer_conv2d_type
Conv2D layer type.
void ailayer_conv2d_print_specs(const ailayer_t *self)
Print the layer specification.
void ailayer_conv2d_backward(ailayer_t *self)
Calculate the backward pass for given Conv2D layer.
void ailayer_conv2d_set_paramem(ailayer_t *self, void *memory_ptr)
Distribute provided memory to the parameter pointers.
void ailayer_conv2d_set_trainmem(ailayer_t *self, void *memory_ptr)
Distribute provided memory to the gradients pointers.
uint32_t ailayer_conv2d_sizeof_paramem(const ailayer_t *self)
Calculate and return the parameter memory size needed for this layer.
ailayer_t * ailayer_conv2d(ailayer_conv2d_t *layer, ailayer_t *input_layer)
Initialize and connect the given Conv2D layer.
void ailayer_conv2d_forward(ailayer_t *self)
Calculate the forward pass for given Conv2D layer.
Type indicator of the layer.
Definition: aifes_core.h:82
General Conv2D layer structure.
Definition: ailayer_conv2d.h:57
uint16_t result_shape[4]
The shape of the result.
Definition: ailayer_conv2d.h:92
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
uint16_t bias_shape[1]
Bias weights tensor shape.
Definition: ailayer_conv2d.h:85
aitensor_t * gradients[2]
Gradients structure for the backpropagation algorithm.
Definition: ailayer_conv2d.h:88
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
void * optimem[2]
Memory field used by the optimizer for training.
Definition: ailayer_conv2d.h:89
uint32_t filter_count
Number of filters ( ).
Definition: ailayer_conv2d.h:67
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
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
aitensor_t bias
Tensor containing the bias weights.
Definition: ailayer_conv2d.h:82
uint16_t padding[2]
The (symmetric) zero padding in the direction of height and width ( ).
Definition: ailayer_conv2d.h:72
uint16_t stride[2]
The stride in the direction of height and width ( ).
Definition: ailayer_conv2d.h:70
ailayer_t base
Inherited field members from general ailayer struct.
Definition: ailayer_conv2d.h:58
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
aitensor_t weights
Tensor containing the weights.
Definition: ailayer_conv2d.h:81
uint16_t weights_shape[4]
Weights tensor shape.
Definition: ailayer_conv2d.h:84
uint16_t kernel_size[2]
Size of the kernels ( ).
Definition: ailayer_conv2d.h:68
uint16_t dilation[2]
The dilation in the direction of height and width ( ).
Definition: ailayer_conv2d.h:71
aitensor_t * trainable_params[2]
Pointer to the weights and bias (which are the trainable parameters).
Definition: ailayer_conv2d.h:87
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
AIfES layer interface.
Definition: aifes_core.h:252
A tensor in AIfES.
Definition: aifes_math.h:89