AIfES 2 2.0.0
ailayer_dense.h
Go to the documentation of this file.
1
55#ifndef AILAYER_DENSE
56#define AILAYER_DENSE
57
58#include "core/aifes_core.h"
62
63#define DENSE_WEIGHTS_SIZE(INPUTS, OUTPUTS) ((INPUTS) * (OUTPUTS))
64#define DENSE_BIAS_SIZE(OUTPUTS) (OUTPUTS)
65
66#define DENSE_WEIGHTS_SHAPE(INPUTS, OUTPUTS) {INPUTS, OUTPUTS}
67#define DENSE_BIAS_SHAPE(OUTPUTS) {1, OUTPUTS}
68
69typedef struct ailayer_dense ailayer_dense_t;
70
84 uint32_t neurons;
86
97 uint16_t weights_shape[2];
98 uint16_t bias_shape[2];
102 void *optimem[2];
104
109
122 void (*linear)(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result);
123
135 void (*mat_mul)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
136
144 void (*tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
145
147
148 uint16_t result_shape[2];
149};
150
157
170
194
230
240
241
253
265void ailayer_dense_set_paramem(ailayer_t *self, void *memory_ptr);
266
277
287void ailayer_dense_set_trainmem(ailayer_t *self, void *memory_ptr);
288
289#ifdef AIDEBUG_PRINT_MODULE_SPECS
296#endif // AIDEBUG_PRINT_MODULE_SPECS
297
298#endif // AILAYER_DENSE
AIfES 2 core interface.
const aicore_layertype_t * ailayer_dense_type
Dense layer type.
ailayer_t * ailayer_dense(ailayer_dense_t *layer, ailayer_t *input_layer)
Initialize and connect the given Dense layer.
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.
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:74
uint16_t weights_shape[2]
Weights tensor shape (n x m matrix).
Definition: ailayer_dense.h:97
const aimath_dtype_t * bias_dtype
Data type of the bias weights.
Definition: ailayer_dense.h:95
aitensor_t * gradients[2]
Gradients structure for the back propagation algorithm.
Definition: ailayer_dense.h:101
void * optimem[2]
Memory field used by the trainings optimizer.
Definition: ailayer_dense.h:102
const aimath_dtype_t * result_dtype
Data type of the inference result values.
Definition: ailayer_dense.h:76
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:122
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:144
aitensor_t bias
Tensor containing the layer bias weights.
Definition: ailayer_dense.h:92
uint32_t neurons
Layer neurons count (number of outputs).
Definition: ailayer_dense.h:84
ailayer_t base
Inherited field members from general ailayer struct.
Definition: ailayer_dense.h:75
uint16_t result_shape[2]
Inference result tensor (ailayer.result) shape.
Definition: ailayer_dense.h:148
uint16_t bias_shape[2]
Bias weights tensor shape (n x m matrix).
Definition: ailayer_dense.h:98
aitensor_t weights
Tensor containing the layer weights.
Definition: ailayer_dense.h:91
const aimath_dtype_t * weights_dtype
Data type of the weights.
Definition: ailayer_dense.h:94
void(* mat_mul)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Required math function: Matrix multiplication.
Definition: ailayer_dense.h:135
aitensor_t * trainable_params[2]
Pointer to the weights and biases (which are the trainable parameters).
Definition: ailayer_dense.h:100
AIfES layer interface.
Definition: aifes_core.h:252
Indicator for the used datatype.
Definition: aifes_math.h:47
A tensor in AIfES.
Definition: aifes_math.h:92