AIfES 2  2.0.0
ailayer_dense.h
Go to the documentation of this file.
1 
52 #ifndef AILAYER_DENSE
53 #define AILAYER_DENSE
54 
55 #include "core/aifes_core.h"
59 
60 #define DENSE_WEIGHTS_SIZE(INPUTS, OUTPUTS) ((INPUTS) * (OUTPUTS))
61 #define DENSE_BIAS_SIZE(OUTPUTS) (OUTPUTS)
62 
63 #define DENSE_WEIGHTS_SHAPE(INPUTS, OUTPUTS) {INPUTS, OUTPUTS}
64 #define DENSE_BIAS_SHAPE(OUTPUTS) {1, OUTPUTS}
65 
66 typedef struct ailayer_dense ailayer_dense_t;
67 
71 struct ailayer_dense {
80  uint32_t neurons;
82 
90  uint16_t weights_shape[2];
91  uint16_t bias_shape[1];
95  void *optimem[2];
97 
102 
115  void (*linear)(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result);
116 
128  void (*mat_mul_at)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
129 
141  void (*mat_mul_bt)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
142 
150  void (*tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
151 
159  void (*sum_channelwise)(const aitensor_t *a, int8_t channel_axis, aitensor_t *result);
160 
162 
163  uint16_t result_shape[2];
164 };
165 
172 
185 
209 
247 
257 
258 uint32_t ailayer_dense_sizeof_bwdmem(const ailayer_t *self);
259 
271 
283 void ailayer_dense_set_paramem(ailayer_t *self, void *memory_ptr);
284 
295 
305 void ailayer_dense_set_trainmem(ailayer_t *self, void *memory_ptr);
306 
307 #ifdef AIDEBUG_PRINT_MODULE_SPECS
313 #endif // AIDEBUG_PRINT_MODULE_SPECS
314 
315 #endif // AILAYER_DENSE
AIfES 2 core interface.
const aicore_layertype_t * ailayer_dense_type
Dense layer type.
void ailayer_dense_print_specs(const ailayer_t *self)
Print the layer specification.
void ailayer_dense_set_paramem(ailayer_t *self, void *memory_ptr)
Distribute provided memory to the parameter pointers.
ailayer_t * ailayer_dense(ailayer_dense_t *layer, ailayer_t *input_layer)
Initialize and connect the given Dense layer.
void ailayer_dense_backward(ailayer_t *self)
Calculate the backward pass for the given Dense layer.
void ailayer_dense_forward(ailayer_t *self)
Calculate the forward pass for given Dense layer.
void ailayer_dense_set_trainmem(ailayer_t *self, void *memory_ptr)
Distribute provided memory to the gradients pointers.
uint32_t ailayer_dense_sizeof_trainmem(const ailayer_t *self)
Calculate and return the memory size needed by this layer for training.
uint32_t ailayer_dense_sizeof_paramem(const ailayer_t *self)
Calculate and return the parameter memory size needed for this layer.
void ailayer_dense_calc_result_shape(ailayer_t *self)
Calculate the shape of the result tensor (ailayer.result)
Math functions for F32 data type, default implementation.
Definition of the Q31 (aiq31) data-type.
Math functions for Q7 data type, default implementation.
Type indicator of the layer.
Definition: aifes_core.h:82
General Dense layer structure.
Definition: ailayer_dense.h:71
uint16_t weights_shape[2]
Weights tensor shape (n x m matrix).
Definition: ailayer_dense.h:90
uint16_t bias_shape[1]
Bias weights tensor shape (n x m matrix).
Definition: ailayer_dense.h:91
aitensor_t * gradients[2]
Gradients structure for the back propagation algorithm.
Definition: ailayer_dense.h:94
void(* mat_mul_bt)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Required math function: Matrix multiplication with transposed b.
Definition: ailayer_dense.h:141
void(* sum_channelwise)(const aitensor_t *a, int8_t channel_axis, aitensor_t *result)
Required math function: Channel-wise sum.
Definition: ailayer_dense.h:159
void * optimem[2]
Memory field used by the trainings optimizer.
Definition: ailayer_dense.h:95
void(* linear)(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)
Required math function: Linear transformation.
Definition: ailayer_dense.h:115
void(* tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Required math function: Element wise tensor addition.
Definition: ailayer_dense.h:150
aitensor_t bias
Tensor containing the layer bias weights.
Definition: ailayer_dense.h:88
void(* mat_mul_at)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Required math function: Matrix multiplication with transposed a.
Definition: ailayer_dense.h:128
uint32_t neurons
Layer neurons count (number of outputs).
Definition: ailayer_dense.h:80
ailayer_t base
Inherited field members from general ailayer struct.
Definition: ailayer_dense.h:72
uint16_t result_shape[2]
Inference result tensor (ailayer.result) shape.
Definition: ailayer_dense.h:163
aitensor_t weights
Tensor containing the layer weights.
Definition: ailayer_dense.h:87
aitensor_t * trainable_params[2]
Pointer to the weights and biases (which are the trainable parameters).
Definition: ailayer_dense.h:93
AIfES layer interface.
Definition: aifes_core.h:252
A tensor in AIfES.
Definition: aifes_math.h:89