| AIfES 2 2.0.0

ailayer_template.h
Go to the documentation of this file.
1
25 #ifndef TEMPLATE_LAYER
26 #define TEMPLATE_LAYER
27
28 #include "core/aifes_core.h"
29
30 typedef struct ailayer_template ailayer_template_t;
31
35 struct ailayer_template {
36 ailayer_t base; // The base or super "class" of the layer.
37
38 // Configurations of the layer, that can be configured by the user when creating the layer
39 uint32_t example_configuration;
40
41 // Tensor pointer for trainable parameters [DEPRECATED]
42 aitensor_t *params;
43 aitensor_t *d_params; // Gradients
44
45 // If the shape of the result differs from the input shape, this array can be used for the result.
46 // If not, the result shape array of the input tensor can be used for the result tensor too.
47 uint16_t result_shape[2];
49 aitensor_t *trainable_params[2];
50 aitensor_t *gradients[2];
51 void *optimem[2];
53 // Make the math functions accessable for expert developers
54 void (*copy_tensor)(const aitensor_t *from, aitensor_t *to);
55 void (*tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
56 };
57
58 extern const aicore_layertype_t *ailayer_template_type;
68 ailayer_t *ailayer_template(ailayer_template_t *layer, ailayer_t *input_layer);
69
74 void ailayer_template_forward(ailayer_t *self);
75
80 void ailayer_template_backward(ailayer_t *self);
81
86 void ailayer_template_calc_result_shape(ailayer_t *self);
87
94 uint32_t ailayer_template_sizeof_paramem(const ailayer_t *self);
95
101 void ailayer_template_set_paramem(ailayer_t *self, void *memory_ptr);
102
109 uint32_t ailayer_template_sizeof_trainmem(const ailayer_t *self);
110
116 void ailayer_template_set_trainmem(ailayer_t *self, void *memory_ptr);
117
118 #ifdef AIDEBUG_PRINT_MODULE_SPECS
123 void ailayer_template_print_specs(const ailayer_t *self);
124 #endif
125
126 #endif // TEMPLATE_LAYER
aifes_core.h
AIfES 2 core interface.
ailayer_template_print_specs
void ailayer_template_print_specs(const ailayer_t *self)
Print the layer specification.
ailayer_template_calc_result_shape
void ailayer_template_calc_result_shape(ailayer_t *self)
Calculate the shape of the result tensor.
ailayer_template_set_trainmem
void ailayer_template_set_trainmem(ailayer_t *self, void *memory_ptr)
Distribute provided memory to the training gradients pointers - mandatory for hidden layers
ailayer_template_sizeof_paramem
uint32_t ailayer_template_sizeof_paramem(const ailayer_t *self)
Calculate and return the parameter memory size needed for this layer - mandatory for hidden layers
ailayer_template_set_paramem
void ailayer_template_set_paramem(ailayer_t *self, void *memory_ptr)
Distribute provided memory to the parameter pointers - mandatory for hidden layers
ailayer_template
ailayer_t * ailayer_template(ailayer_template_t *layer, ailayer_t *input_layer)
Initialize the given layer struct - mandatory
ailayer_template_forward
void ailayer_template_forward(ailayer_t *self)
Calculate the forward path for given layer - mandatory
ailayer_template_backward
void ailayer_template_backward(ailayer_t *self)
Calculate the backward (training) path for the given layer - depends on usability in training
ailayer_template_sizeof_trainmem
uint32_t ailayer_template_sizeof_trainmem(const ailayer_t *self)
Calculate and return the necessary memory size needed by this layer for training - mandatory for hidd...
aicore_layertype
Type indicator of the layer.
Definition: aifes_core.h:82
ailayer_template
Template for general AIfES layers.
Definition: ailayer_template.h:35
ailayer_template::gradients
aitensor_t * gradients[2]
Gradients structure for the back propagation algorithm.
Definition: ailayer_template.h:50
ailayer_template::optimem
void * optimem[2]
Memory field used by the trainings optimizer.
Definition: ailayer_template.h:51
ailayer_template::tensor_add
void(* tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Function pointer to the used tensor addition.
Definition: ailayer_template.h:55
ailayer_template::copy_tensor
void(* copy_tensor)(const aitensor_t *from, aitensor_t *to)
Function pointer to the used tensor copy function.
Definition: ailayer_template.h:54
ailayer_template::base
ailayer_t base
Inherited field members from general ailayer struct.
Definition: ailayer_template.h:36
ailayer_template::result_shape
uint16_t result_shape[2]
Inference result tensor shape (n x m matrix).
Definition: ailayer_template.h:47
ailayer_template::trainable_params
aitensor_t * trainable_params[2]
Pointer to the weights and biases (which are the trainable parameters).
Definition: ailayer_template.h:49
ailayer
AIfES layer interface.
Definition: aifes_core.h:252
aitensor
A tensor in AIfES.
Definition: aifes_math.h:89