| AIfES 2 2.0.0

ailayer_maxpool2d.h
Go to the documentation of this file.
1
38 #ifndef AILAYER_MAXPOOL2D_H
39 #define AILAYER_MAXPOOL2D_H
40
41 #include "core/aifes_core.h"
42
43 #define AIFES_CHANNELS_FIRST 1
44 #define AIFES_CHANNELS_LAST -1
45
46 typedef struct ailayer_maxpool2d ailayer_maxpool2d_t;
47
51 struct ailayer_maxpool2d {
52 ailayer_t base;
60 // Values (configurable)
61 uint16_t pool_size[2];
62 uint16_t stride[2];
63 uint16_t padding[2]; // Must be 0 >= padding < pool_size; -inf padding
64
65 int8_t channel_axis;
67
72 // Values (autogenerated)
73 uint32_t *max_locations;
75 void *optimem[2];
77
82
99 void (*maxpool2d_fwd)(
100 const aitensor_t *input,
101 const uint16_t pool_size[2],
102 const uint16_t stride[2],
103 const uint16_t padding[2],
104 int8_t channel_axis,
105 void *work_space,
106 uint32_t *max_locations,
107 aitensor_t *output
108 );
109
126 void (*maxpool2d_bwd)(
127 const aitensor_t *delta_out,
128 const uint16_t pool_size[2],
129 const uint16_t stride[2],
130 const uint16_t padding[2],
131 int8_t channel_axis,
132 void *work_space,
133 const uint32_t *max_locations,
134 aitensor_t *delta_in
135 );
137
138 uint16_t result_shape[4];
139 };
140
146 extern const aicore_layertype_t *ailayer_maxpool2d_type;
147
159 ailayer_t *ailayer_maxpool2d(ailayer_maxpool2d_t *layer, ailayer_t *input_layer);
160
173 void ailayer_maxpool2d_forward(ailayer_t *self);
174
187 void ailayer_maxpool2d_backward(ailayer_t *self);
188
204 void ailayer_maxpool2d_calc_result_shape(ailayer_t *self);
205
215 uint32_t ailayer_maxpool2d_sizeof_trainmem(const ailayer_t *self);
216
226 void ailayer_maxpool2d_set_trainmem(ailayer_t *self, void *memory_ptr);
227
228 #ifdef AIDEBUG_PRINT_MODULE_SPECS
233 void ailayer_maxpool2d_print_specs(const ailayer_t *self);
234 #endif // AIDEBUG_PRINT_MODULE_SPECS
235
236 #endif // AILAYER_MAXPOOL2D_H
aifes_core.h
AIfES 2 core interface.
ailayer_maxpool2d_set_trainmem
void ailayer_maxpool2d_set_trainmem(ailayer_t *self, void *memory_ptr)
Distribute provided memory to the gradients pointers.
ailayer_maxpool2d
ailayer_t * ailayer_maxpool2d(ailayer_maxpool2d_t *layer, ailayer_t *input_layer)
Initialize and connect the given MaxPool2D layer.
ailayer_maxpool2d_forward
void ailayer_maxpool2d_forward(ailayer_t *self)
Calculate the forward pass for given MaxPool2D layer.
ailayer_maxpool2d_sizeof_trainmem
uint32_t ailayer_maxpool2d_sizeof_trainmem(const ailayer_t *self)
Calculate and return the memory size needed by this layer for training.
ailayer_maxpool2d_type
const aicore_layertype_t * ailayer_maxpool2d_type
MaxPool2D layer type.
ailayer_maxpool2d_backward
void ailayer_maxpool2d_backward(ailayer_t *self)
Calculate the backward pass for given MaxPool2D layer.
ailayer_maxpool2d_calc_result_shape
void ailayer_maxpool2d_calc_result_shape(ailayer_t *self)
Calculate the shape of the result tensor (ailayer.result)
ailayer_maxpool2d_print_specs
void ailayer_maxpool2d_print_specs(const ailayer_t *self)
Print the layer specification.
aicore_layertype
Type indicator of the layer.
Definition: aifes_core.h:82
ailayer_maxpool2d
General layer structure.
Definition: ailayer_maxpool2d.h:51
ailayer_maxpool2d::result_shape
uint16_t result_shape[4]
The shape of the result.
Definition: ailayer_maxpool2d.h:138
ailayer_maxpool2d::max_locations
uint32_t * max_locations
Pointer to memory section where the indices of the maximum values per pooling window are stored.
Definition: ailayer_maxpool2d.h:73
ailayer_maxpool2d::optimem
void * optimem[2]
Memory field used by the optimizer for training.
Definition: ailayer_maxpool2d.h:75
ailayer_maxpool2d::maxpool2d_fwd
void(* maxpool2d_fwd)(const aitensor_t *input, const uint16_t pool_size[2], const uint16_t stride[2], const uint16_t padding[2], int8_t channel_axis, void *work_space, uint32_t *max_locations, aitensor_t *output)
Required math function: 2D Max-Pooling.
Definition: ailayer_maxpool2d.h:99
ailayer_maxpool2d::padding
uint16_t padding[2]
The (symmetric) minus infinity padding in the direction of height and width ( ).
Definition: ailayer_maxpool2d.h:63
ailayer_maxpool2d::maxpool2d_bwd
void(* maxpool2d_bwd)(const aitensor_t *delta_out, const uint16_t pool_size[2], const uint16_t stride[2], const uint16_t padding[2], int8_t channel_axis, void *work_space, const uint32_t *max_locations, aitensor_t *delta_in)
Required math function: Gradients of 2D Max-Pooling with respect to the input.
Definition: ailayer_maxpool2d.h:126
ailayer_maxpool2d::stride
uint16_t stride[2]
The stride in the direction of height and width ( ).
Definition: ailayer_maxpool2d.h:62
ailayer_maxpool2d::base
ailayer_t base
Inherited field members from general ailayer struct.
Definition: ailayer_maxpool2d.h:52
ailayer_maxpool2d::pool_size
uint16_t pool_size[2]
Size of the pooling kernel ( ).
Definition: ailayer_maxpool2d.h:61
ailayer_maxpool2d::channel_axis
int8_t channel_axis
Index of the channel axis (1 for channels first and -1 or 3 for channels last).
Definition: ailayer_maxpool2d.h:65
ailayer
AIfES layer interface.
Definition: aifes_core.h:252
aitensor
A tensor in AIfES.
Definition: aifes_math.h:89