32 #include "aifes_config.h"
37 #define AILAYER_SETTINGS_TRAINING_MODE 0
38 #define AILAYER_SETTINGS_TRAINABLE 1
39 #define AILAYER_SETTINGS_BATCH_MODE 2
40 #define AILAYER_SETTINGS_NO_INPUT_GRADIENT 3
41 #define AILAYER_SETTINGS_KEEP_INPUT_BUFFER_FOR_RESULT 4
43 #define AILAYER_SETTINGS_SET(settings, mask, selector, value) (settings = ((settings) & ~(mask << (selector))) | ((value) << (selector)))
44 #define AILAYER_SETTINGS_IS(settings, mask, selector) (((settings) >> (selector)) & mask)
Type indicator of the layer.
Definition: aifes_core.h:82
void(* print_specs)(const ailayer_t *self)
Set a function to print specs of the layer (for example size, constants)
Definition: aifes_core.h:92
const char * name
Name of the layer type (for example "Dense")
Definition: aifes_core.h:83
Type indicator of the loss to check for the loss type.
Definition: aifes_core.h:121
void(* print_specs)(const ailoss_t *self)
Set a function to print specs of the loss.
Definition: aifes_core.h:131
const char * name
Name of the loss type (for example "Mean Squared Error")
Definition: aifes_core.h:122
Type indicator of the optimizer to check for the optimizer type.
Definition: aifes_core.h:160
void(* print_specs)(const aiopti_t *self)
Set a function to print specs of the optimizer.
Definition: aifes_core.h:170
const char * name
Name of the optimizer type (for example "ADAM")
Definition: aifes_core.h:161
AIfES layer interface.
Definition: aifes_core.h:252
void ** optimem
Array of memory pointers with length trainable_params_count.
Definition: aifes_core.h:334
aitensor_t result
The result of the forward function is stored here.
Definition: aifes_core.h:292
void(* set_paramem)(ailayer_t *self, void *memory_ptr)
Set and distribute the memory block internally.
Definition: aifes_core.h:352
void(* backward)(ailayer_t *self)
Calculate the backward pass and write the result to the deltas tensor.
Definition: aifes_core.h:341
const aicore_layertype_t * layer_type
Type of the layer (for example ailayer_dense_type)
Definition: aifes_core.h:253
void * layer_configuration
Layer specific configurations (back-link from abstract layer class to implementation)
Definition: aifes_core.h:254
uint8_t trainable_params_count
Number of trainable parameter tensors.
Definition: aifes_core.h:331
void(* set_trainmem)(ailayer_t *self, void *memory_ptr)
Set and distribute the memory block internally.
Definition: aifes_core.h:373
void * tempmem
Pointer to the memory for the forward pass, backward pass and the optimizer.
Definition: aifes_core.h:362
void(* forward)(ailayer_t *self)
Calculate the forward pass and write the result to the result tensor.
Definition: aifes_core.h:315
void(* calc_result_shape)(ailayer_t *self)
Calculate and write the shape to the result tensor.
Definition: aifes_core.h:300
aitensor_t deltas
The result of the backward function is stored here.
Definition: aifes_core.h:323
aitensor_t ** trainable_params
Array of tensor pointers with length trainable_params_count.
Definition: aifes_core.h:332
uint32_t(* sizeof_bwdmem)(const ailayer_t *self)
Size of required memory for the backward pass (in bytes).
Definition: aifes_core.h:361
void(* calc_result_tensor_params)(ailayer_t *self)
If available, calculate and set the tensor_params of the result tensor.
Definition: aifes_core.h:309
uint32_t(* sizeof_paramem)(const ailayer_t *self)
Size of required memory (in bytes).
Definition: aifes_core.h:351
uint32_t settings
General layer settings like freezing weights or switching between training and evaluation mode.
Definition: aifes_core.h:271
uint32_t(* sizeof_fwdmem)(const ailayer_t *self)
Size of required memory for the forward pass (in bytes).
Definition: aifes_core.h:360
aitensor_t ** gradients
Array of tensor pointers with length trainable_params_count.
Definition: aifes_core.h:333
void(* init_params)(ailayer_t *self)
Initialize the (trainable and not trainable) parameters of the layer with default initializers.
Definition: aifes_core.h:353
uint32_t(* sizeof_trainmem)(const ailayer_t *self)
Size of required memory (in bytes).
Definition: aifes_core.h:372
AIfES loss interface.
Definition: aifes_core.h:385
void * loss_configuration
Loss specific configurations (back-link from abstract loss class to implementation)
Definition: aifes_core.h:387
const aicore_losstype_t * loss_type
Type of the loss (for example ailoss_mse_type)
Definition: aifes_core.h:386
ailayer_t connection_layer
Dummy layer for docking to the layer structure.
Definition: aifes_core.h:389
void(* calc_delta)(ailoss_t *self, const aitensor_t *target_data)
Calculate the error on the target data and write it to the deltas tensor of connection layer.
Definition: aifes_core.h:404
void(* calc_loss)(ailoss_t *self, const aitensor_t *target_data, void *result)
Calculate the loss / cost for the model on the given targets.
Definition: aifes_core.h:397
Indicator for the used datatype.
Definition: aifes_math.h:44
AIfES artificial neural network model.
Definition: aifes_core.h:181
uint16_t trainable_params_count
Total number of trainable parameter tensors.
Definition: aifes_core.h:186
uint16_t layer_count
Total number of layers of the model (usually autogenerated).
Definition: aifes_core.h:185
ailayer_t * input_layer
Input layer of the model that gets the input data.
Definition: aifes_core.h:182
ailayer_t * output_layer
Output layer of the model.
Definition: aifes_core.h:183
ailoss_t * loss
The loss or cost function of the model (only for training).
Definition: aifes_core.h:188
AIfES optimizer interface.
Definition: aifes_core.h:438
void * optimizer_configuration
Optimizer specific configurations (back-link from abstract aiopti class to implementation)
Definition: aifes_core.h:440
void(* init_optimem)(aiopti_t *self, const aitensor_t *params, const aitensor_t *gradients, void *optimem)
Initialize the optimization memory for a trainable parameter tensor.
Definition: aifes_core.h:459
void(* begin_step)(aiopti_t *self)
Called in the beginning of every model optimization step for parameter initialization.
Definition: aifes_core.h:472
const aicore_optitype_t * optimizer_type
Type of the optimizer (for example aiopti_sgd_type)
Definition: aifes_core.h:439
void(* update_params)(aiopti_t *self, aitensor_t *params, const aitensor_t *gradients, void *optimem)
Performs an optimization step on the given tensor.
Definition: aifes_core.h:481
uint32_t(* sizeof_optimem)(aiopti_t *self, const aitensor_t *params)
Calculates the optimization memory size for a trainable parameter tensor.
Definition: aifes_core.h:450
void * learning_rate
The learning rate configures the training speed.
Definition: aifes_core.h:443
const aimath_dtype_t * dtype
The data-type of the parameter that the optimizer can optimize and the learning rate.
Definition: aifes_core.h:441
void(* zero_gradients)(aiopti_t *self, aitensor_t *gradients)
Set the gradient tensor to zero.
Definition: aifes_core.h:466
void(* end_step)(aiopti_t *self)
Called in the end of every model optimization step.
Definition: aifes_core.h:487
A tensor in AIfES.
Definition: aifes_math.h:89