| AIfES 2 2.0.0

Data Fields
ailayer_conv2d Struct Reference

General Conv2D layer structure. More...

`#include <ailayer_conv2d.h>`

## Data Fields
ailayer_t | base
| Inherited field members from general ailayer struct.
uint16_t | result_shape [4]
| The shape of the result.
Layer configuration
Required configuration parameters for the layer These fields have to be configured by the user before calling the initializer function.
uint32_t | filter_count
| Number of filters ( \( C_{out} \)).
uint16_t | kernel_size [2]
| Size of the kernels ( \( [H_{kernel}, W_{kernel}] \)).
uint16_t | stride [2]
| The stride in the direction of height and width ( \( [S_{h}, S_{w}] \)).
uint16_t | dilation [2]
| The dilation in the direction of height and width ( \( [D_{h}, D_{w}] \)).
uint16_t | padding [2]
| The (symmetric) zero padding in the direction of height and width ( \( [P_{h}, P_{w}] \)).
int8_t | channel_axis
| Index of the channel axis (1 for channels first and -1 or 3 for channels last).
Trainable parameters
Data fields for the trainable parameters (weights, bias) of the layer
aitensor_t | weights
| Tensor containing the weights.
aitensor_t | bias
| Tensor containing the bias weights.
uint16_t | weights_shape [4]
| Weights tensor shape.
uint16_t | bias_shape [1]
| Bias weights tensor shape.
aitensor_t * | trainable_params [2]
| Pointer to the weights and bias (which are the trainable parameters).
aitensor_t * | gradients [2]
| Gradients structure for the backpropagation algorithm.
void * | optimem [2]
| Memory field used by the optimizer for training.
Math functions
Required data type specific math functions
void(* | conv2d_fwd )(const aitensor_t *input, const uint16_t stride[2], const uint16_t dilation[2], const uint16_t padding[2], const aitensor_t *weights, const aitensor_t *bias, int8_t channel_axis, void *work_space, aitensor_t *output)
| Required math function: 2D-Convolution. More...
void(* | conv2d_bwd )(const aitensor_t *input, const uint16_t stride[2], const uint16_t dilation[2], const uint16_t padding[2], const aitensor_t *output, int8_t channel_axis, void *work_space, aitensor_t *d_weights)
| Required math function: Gradients of 2D-Convolution with respect to the weights. More...
void(* | conv2d_bwd_full )(const aitensor_t *delta_out, const uint16_t stride[2], const uint16_t dilation[2], const uint16_t padding[2], const aitensor_t *weights, int8_t channel_axis, void *work_space, aitensor_t *delta_in)
| Required math function: Gradients of 2D-Convolution with respect to the input. More...
void(* | tensor_add )(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
| Required math function: Element wise tensor addition. More...
void(* | sum_channelwise )(const aitensor_t *x, int8_t channel_axis, aitensor_t *result)
| Required math function: Channel-wise sum. More...

## Detailed Description

General Conv2D layer structure.

## Field Documentation

## ◆ conv2d_bwd

void(* conv2d_bwd) (const aitensor_t *input, const uint16_t stride[2], const uint16_t dilation[2], const uint16_t padding[2], const aitensor_t *output, int8_t channel_axis, void *work_space, aitensor_t *d_weights)

Required math function: Gradients of 2D-Convolution with respect to the weights.

Requires a math function that calculates the gradients with respect to the weights \( \partial w = \mathrm{d} L / \mathrm{d} w \).

\[ \partial w = x_{in} \ast delta_{out} \]

Parameters

  input | Input data with dimension \( [N,C_{in},H_{in},W_{in}] \) (channels first) or \( [N,H_{in},W_{in},C_{in}] \) (channels last)
  stride | The stride in the direction of height and width
  dilation | The dilation in the direction of height and width
  padding | The (symmetric) zero padding in the direction of height and width
  output | Gradients backpropagated from the following layer with dimension \( [N,C_{out},H_{out},W_{out}] \) (channels first) or \( [N,H_{out},W_{out},C_{out}] \) (channels last)
  channel_axis | Index of the channel axis (1 for channels first and -1 or 3 for channels last).
  work_space | Pointer to a work space buffer for intermediate results.
  d_weights | Output gradients of the weights with dimension \( [C_{out},C_{in},H_{kernel},W_{kernel}] \) (channels first) or \( [C_{out},H_{kernel},W_{kernel},C_{in}] \) (channels last)

## ◆ conv2d_bwd_full

void(* conv2d_bwd_full) (const aitensor_t *delta_out, const uint16_t stride[2], const uint16_t dilation[2], const uint16_t padding[2], const aitensor_t *weights, int8_t channel_axis, void *work_space, aitensor_t *delta_in)

Required math function: Gradients of 2D-Convolution with respect to the input.

Requires a math function that calculates the gradients with respect to the input \( delta_{in} = \mathrm{d} L / \mathrm{d} x_{in} \).

\[ delta_{in} = delta_{out} \ast' w \]

\( \cdot \ast' \cdot \) is a transposed convolution.

Parameters

  delta_out | Gradients backpropagated from the following layer with dimension \( [N,C_{in},H_{in},W_{in}] \) (channels first) or \( [N,H_{in},W_{in},C_{in}] \) (channels last)
  stride | The stride in the direction of height and width
  dilation | The dilation in the direction of height and width
  padding | The (symmetric) zero padding in the direction of height and width
  weights | Convolution kernels with dimension \( [C_{out},C_{in},H_{kernel},W_{kernel}] \) (channels first) or \( [C_{out},H_{kernel},W_{kernel},C_{in}] \) (channels last)
  channel_axis | Index of the channel axis (1 for channels first and -1 or 3 for channels last).
  work_space | Pointer to a work space buffer for intermediate results.
  delta_in | Resulting input gradients for backpropagation to the previous layer with dimension \( [N,C_{in},H_{in},W_{in}] \) (channels first) or \( [N,H_{in},W_{in},C_{in}] \) (channels last)

## ◆ conv2d_fwd

void(* conv2d_fwd) (const aitensor_t *input, const uint16_t stride[2], const uint16_t dilation[2], const uint16_t padding[2], const aitensor_t *weights, const aitensor_t *bias, int8_t channel_axis, void *work_space, aitensor_t *output)

Required math function: 2D-Convolution.

Requires a math function that performs a 2D-convolution and adds a channel-wise bias:

\[ x_{out} = x_{in} \ast w + b \]

Parameters

  input | Input data with dimension \( [N,C_{in},H_{in},W_{in}] \) (channels first) or \( [N,H_{in},W_{in},C_{in}] \) (channels last)
  stride | The stride in the direction of height and width
  dilation | The dilation in the direction of height and width
  padding | The (symmetric) zero padding in the direction of height and width
  weights | Convolution kernels with dimension \( [C_{out},C_{in},H_{kernel},W_{kernel}] \) (channels first) or \( [C_{out},H_{kernel},W_{kernel},C_{in}] \) (channels last)
  bias | Bias with dimension \( C_{out} \)
  channel_axis | Index of the channel axis (1 for channels first and -1 or 3 for channels last).
  work_space | Pointer to a work space buffer for intermediate results.
  output | Output after convolution with dimension \( [N,C_{out},H_{out},W_{out}] \) (channels first) or \( [N,H_{out},W_{out},C_{out}] \) (channels last)

## ◆ sum_channelwise

void(* sum_channelwise) (const aitensor_t *x, int8_t channel_axis, aitensor_t *result)

Required math function: Channel-wise sum.

Requires a math function that calculates the sum of all elements of each channel c. The result tensor is 1D.:

\[ result_c = \sum_i(x_{ci}) \]

## ◆ tensor_add

void(* tensor_add) (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)

Required math function: Element wise tensor addition.

Requires a math function that adds two tensors element wise:

\[ result = a + b \]

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

- ailayer_conv2d.h