AIfES 2  2.0.0
ailayer_maxpool2d.h File Reference

Base layer implementation of the MaxPool2D layer. More...

Go to the source code of this file.

Data Structures

struct  ailayer_maxpool2d
 General layer structure. More...
 

Typedefs

typedef struct ailayer_maxpool2d ailayer_maxpool2d_t
 

Functions

ailayer_tailayer_maxpool2d (ailayer_maxpool2d_t *layer, ailayer_t *input_layer)
 Initialize and connect the given MaxPool2D layer. More...
 
void ailayer_maxpool2d_forward (ailayer_t *self)
 Calculate the forward pass for given MaxPool2D layer. More...
 
void ailayer_maxpool2d_backward (ailayer_t *self)
 Calculate the backward pass for given MaxPool2D layer. More...
 
void ailayer_maxpool2d_calc_result_shape (ailayer_t *self)
 Calculate the shape of the result tensor (ailayer.result) More...
 
uint32_t ailayer_maxpool2d_sizeof_trainmem (const ailayer_t *self)
 Calculate and return the memory size needed by this layer for training. More...
 
void ailayer_maxpool2d_set_trainmem (ailayer_t *self, void *memory_ptr)
 Distribute provided memory to the gradients pointers. More...
 
void ailayer_maxpool2d_print_specs (const ailayer_t *self)
 Print the layer specification. More...
 

Variables

const aicore_layertype_tailayer_maxpool2d_type
 MaxPool2D layer type. More...
 

Detailed Description

Base layer implementation of the MaxPool2D layer.

Version
2.2.0
Date
20.10.2020

This is an "abstract" data-type independent implementation. To use the layer use one of the provided implementations for a specific hardware and data-type (for example from ailayer_maxpool2d_default.h) or set the required math functions on your own.

The MaxPool2D layer (or 2D Max-Pooling layer) is used to compress the size of activations, by only taking the maximum activation values within a small window (pooling kernel).

When the channel axis equals 1 (channels first), the shapes of input and output are \( [N,C,H_{in},W_{in}] \) and \( [N,C,H_{out},W_{out}] \), respectively.

When the channel axis equals -1 or 3 (channels last), the shapes of input and output are \( [N,H_{in},W_{in},C] \) and \( [N,H_{out},W_{out},C] \), respectively.

N is the batch size.

The results of the forward pass of this layer are written to the result tensor of the base ailayer_t struct.

Function Documentation

◆ ailayer_maxpool2d()

ailayer_t* ailayer_maxpool2d ( ailayer_maxpool2d_t layer,
ailayer_t input_layer 
)

Initialize and connect the given MaxPool2D layer.

This function represents the "constructor" of the abstract MaxPool2D layer. It initializes the layer structure and connects it to the previous layer.
This function is not intended to call it directly. Instead use one of the data type specific implementations (like for example ailayer_maxpool2d_f32_default()).

Parameters
*layerThe layer to initialize.
*input_layerThe previous layer that provides the inputs to the layer.
Returns
Pointer to the (successfully) initialized general layer structure (ailayer_maxpool2d.base)

◆ ailayer_maxpool2d_backward()

void ailayer_maxpool2d_backward ( ailayer_t self)

Calculate the backward pass for given MaxPool2D layer.

Implementation of ailayer.backward.

It uses the deltas tensor of the next layer as input and writes the result of the backward pass to the deltas tensor (ailayer.deltas) of the given layer.

Used math functions:

Parameters
*selfLayer to calculate the backward path for.

◆ ailayer_maxpool2d_calc_result_shape()

void ailayer_maxpool2d_calc_result_shape ( ailayer_t self)

Calculate the shape of the result tensor (ailayer.result)

Implementation of ailayer.calc_result_shape.

Resulting shape is \( [N,C,H_{out},W_{out}] \) (channels first) or \( [N,H_{out},W_{out},C] \) (channels last) with

\[ H_{out} = floor \left( \frac{H_{in} + 2 * P_h - H_{pool}}{S_h} \right) + 1 \]

\[ W_{out} = floor \left( \frac{W_{in} + 2 * P_w - W_{pool}}{S_w} \right) + 1 \]

Parameters
*selfLayer to calculate the resulting shape for.

◆ ailayer_maxpool2d_forward()

void ailayer_maxpool2d_forward ( ailayer_t self)

Calculate the forward pass for given MaxPool2D layer.

Implementation of ailayer.forward.

It uses the result tensor of the previous layer as input and writes the result of the forward pass to the result tensor (ailayer.result) of the given layer.

Used math functions:

Parameters
*selfLayer to calculate the forward path for.

◆ ailayer_maxpool2d_print_specs()

void ailayer_maxpool2d_print_specs ( const ailayer_t self)

Print the layer specification.

Parameters
*selfThe layer to print the specification for

◆ ailayer_maxpool2d_set_trainmem()

void ailayer_maxpool2d_set_trainmem ( ailayer_t self,
void *  memory_ptr 
)

Distribute provided memory to the gradients pointers.

Implementation of ailayer.set_trainmem.

The required memory size can be calculated with ailayer_maxpool2d_sizeof_trainmem().

Parameters
*selfThe layer to set the memory fields for.
*memory_ptrThe memory that can be used for the gradients

◆ ailayer_maxpool2d_sizeof_trainmem()

uint32_t ailayer_maxpool2d_sizeof_trainmem ( const ailayer_t self)

Calculate and return the memory size needed by this layer for training.

Implementation of ailayer.sizeof_trainmem.

The memory size is calculated for storage of the max_locations.

Parameters
*selfThe layer to calculate the gradient memory size for.
Returns
Calculated gradient memory size in bytes.

Variable Documentation

◆ ailayer_maxpool2d_type

const aicore_layertype_t* ailayer_maxpool2d_type
extern

MaxPool2D layer type.

Defines the type of the layer (for example for type checks and debug prints). See aicore_layertype for more information about the layer type.