AIfES 2  2.0.0
ailayer Struct Reference

AIfES layer interface. More...

#include <aifes_core.h>

Data Fields

const aicore_layertype_tlayer_type
 Type of the layer (for example ailayer_dense_type)
 
void * layer_configuration
 Layer specific configurations (back-link from abstract layer class to implementation)
 
aitensor_t result
 The result of the forward function is stored here.
 
uint8_t(* get_result_bound )(const ailayer_t *self, const uint8_t selector, void *result_bound)
 Result and delta min and max values. More...
 
void(* calc_result_shape )(ailayer_t *self)
 Calculate and write the shape to the result tensor. More...
 
void(* forward )(ailayer_t *self)
 Calculate the forward pass and write the result to the result tensor. More...
 
aitensor_t deltas
 The result of the backward function is stored here.
 
void(* backward )(ailayer_t *self)
 Calculate the backward pass and write the result to the deltas tensor. More...
 
Layer connections

Defines the model graph.

ailayer_tinput_layer
 
ailayer_toutput_layer
 
Inference and training scheduling order (Not in use yet)

The scheduler can execute the layers along this path.

ailayer_tnext_scheduled
 
ailayer_tprev_scheduled
 
Training memory API

Makes the memory of the trainable params, the gradients and optimizer stuff accessible.

This is used, for example, for the optimiser or debugging purposes.

uint8_t trainable_params_count
 Number of trainable parameter tensors.
 
aitensor_t ** trainable_params
 Array of tensor pointers with length trainable_params_count.
 
aitensor_t ** gradients
 Array of tensor pointers with length trainable_params_count.
 
void ** optimem
 Array of memory pointers with length trainable_params_count.
 
Parameter memory

Calculate the size and set the memory for the parameter.

This memory (for example for weights, bias, ...) will last through all the lifetime of the model.
This is only intended for training when no initial weights are available. If the parameters are already known, set the parameter directly to the layer.

uint32_t(* sizeof_paramem )(const ailayer_t *self)
 Size of required memory (in bytes).
 
void(* set_paramem )(ailayer_t *self, void *memory_ptr)
 Set and distribute the memory block internally.
 
Training memory

Calculate the size and set the working memory for the training

This memory (for example for gradients, momentums, ...) is needed during the whole training process. If the training is finished, it can be deleted.

uint32_t(* sizeof_trainmem )(const ailayer_t *self)
 Size of required memory (in bytes).
 
void(* set_trainmem )(ailayer_t *self, void *memory_ptr)
 Set and distribute the memory block internally.
 

Detailed Description

AIfES layer interface.

The interface contains the necessary functions and parameters for inference and training on the model. (Refer to aifes_core.h for a structural overview)

The call order of the functions for inference:

for each layer in the model
endfor
for each layer in the model
endfor
// The result of the inference is now in output_layer.result tensor
void(* forward)(ailayer_t *self)
Calculate the forward pass and write the result to the result tensor.
Definition: aifes_core.h:300
void(* calc_result_shape)(ailayer_t *self)
Calculate and write the shape to the result tensor.
Definition: aifes_core.h:294

The call order of the functions for training:

for each layer in the model
endfor
// If the parameters are not already pretrained, a new parameter memory block can be created
for each layer in the model
allocate memory of size sizeof_paramem()
endfor
init_trainable_parameters_model() // Do some weight initialization
for each layer in the model
allocate memory of size sizeof_trainmem()
endfor
init_trainmem_model() // For example set the optimem to zero
for iterations
for each batch in dataset
zero_gradients_model()
for each sample in the batch
for each layer in the model
endfor
calc_delta()
for each layer in the model (reverse)
endfor
endfor
update_params_model()
endfor
endfor
void(* set_paramem)(ailayer_t *self, void *memory_ptr)
Set and distribute the memory block internally.
Definition: aifes_core.h:337
void(* backward)(ailayer_t *self)
Calculate the backward pass and write the result to the deltas tensor.
Definition: aifes_core.h:326
void(* set_trainmem)(ailayer_t *self, void *memory_ptr)
Set and distribute the memory block internally.
Definition: aifes_core.h:348
uint32_t(* sizeof_paramem)(const ailayer_t *self)
Size of required memory (in bytes).
Definition: aifes_core.h:336
uint32_t(* sizeof_trainmem)(const ailayer_t *self)
Size of required memory (in bytes).
Definition: aifes_core.h:347

Field Documentation

◆ backward

void(* backward) (ailayer_t *self)

Calculate the backward pass and write the result to the deltas tensor.

Parameters
selfThe layer

◆ calc_result_shape

void(* calc_result_shape) (ailayer_t *self)

Calculate and write the shape to the result tensor.

Made for easy creation of the model (layers can be connected to each other without worrying about the shapes).

Parameters
selfThe layer

◆ forward

void(* forward) (ailayer_t *self)

Calculate the forward pass and write the result to the result tensor.

Parameters
selfThe layer

◆ get_result_bound

uint8_t(* get_result_bound) (const ailayer_t *self, const uint8_t selector, void *result_bound)

Result and delta min and max values.

Returns the min/max values if the result can only be in certain value ranges (like sigmoid). This may be used e.g. for quantization algorithms. Set to NULL if not in use.

Parameters
selfThe layer
selectorSelect the requested bound (AILAYER_RESULT_LOWER_BOUND, AILAYER_RESULT_UPPER_BOUND, AILAYER_DELTA_LOWER_BOUND, AILAYER_DELTA_UPPER_BOUND)
result_boundA scalar of aiscalar type in which the bound value can be written
Returns
TRUE if bound available else FALSE

The documentation for this struct was generated from the following file: