MMALIB User Guide
MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights

Introduction

MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX requires that the weights be preprocessed into a specific arrangement. The functions in this module perform that preprocessing and other associated tasks.

This preprocessing can be done offline (more efficient) or at runtime. The input weights are assumed to be stored as illustrated in this Python pseudocode:

print('{')
for g in range(0, numGroupsPerKernel):
for no in range(0, No):
for ni in range(0, Ni):
for row in range(0, Fr):
for col in range(0, Fc):
print("{:>3}, ".format(pWeights[no + g*No, ni, row, col]), end='')
for b in range(0,numBiasVals):
print('{:>5}'.format(pBias[no + g*No, b])), end=',')
print('')
print('')
print('};')

Data Structures

struct  MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_Args
 This structure holds all the input parameters for reordering CNN filter weights for column-based convolution kernel. More...
 

Functions

int32_t MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_getMemorySize (const MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_Args *pArgs)
 This function returns the amount of memory that needs to be allocated for reordered kernel coefficients needed to support MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX. More...
 
MMALIB_STATUS MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_fillBufParams (const MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_Args *pArgs, MMALIB_bufParams2D_t *pReorderedWeights_addr)
 This function populates a structure of dimensional information about the reordered coefficients buffer from a MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_Args structure. More...
 
MMALIB_STATUS MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_exec (uint32_t operation, const MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_Args *pArgs, const MMALIB_bufParams2D_t *pWeights_addr, const void *restrict pWeights, const MMALIB_bufParams2D_t *pBias_addr, const void *restrict pBias, const MMALIB_bufParams2D_t *pReorderedWeights_addr, void *restrict pReorderedWeights)
 This function takes a set of weights and biases (optional) and reorders the coefficients for improved efficiency when computing column flow convolution. More...
 

Enumerations

enum  MMALIB_reorder_weights_operation_e { REORDER_WEIGHTS_AND_BIAS , REORDER_WEIGHTS , REORDER_BIAS }
 Enumeration for different operations for the reorderWeights function. More...
 

Enumeration Type Documentation

◆ MMALIB_reorder_weights_operation_e

Enumeration for different operations for the reorderWeights function.

Enumerator
REORDER_WEIGHTS_AND_BIAS 
REORDER_WEIGHTS 
REORDER_BIAS 

Definition at line 69 of file MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights.h.

Function Documentation

◆ MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_getMemorySize()

int32_t MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_getMemorySize ( const MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_Args pArgs)

This function returns the amount of memory that needs to be allocated for reordered kernel coefficients needed to support MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX.

Parameters
[in]pArgs: Pointer to the structure containing the required dimensional information
Returns
Number of bytes required to store the reordered kernel coefficients
Remarks
Application is expected allocate this amount of memory for reordered coefficients

◆ MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_fillBufParams()

MMALIB_STATUS MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_fillBufParams ( const MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_Args pArgs,
MMALIB_bufParams2D_t pReorderedWeights_addr 
)

This function populates a structure of dimensional information about the reordered coefficients buffer from a MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_Args structure.

Parameters
[in]pArgs: Pointer to the structure containing the required dimensional information
[out]pReorderedWeights_addr: Pointer to structure containing dimensional information of the reordered weights buffer.
Returns
Status of success or error with error codes, refer to MMALIB_STATUS.
Remarks
Application is expected to provide a valid handle

◆ MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_exec()

MMALIB_STATUS MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_exec ( uint32_t  operation,
const MMALIB_CNN_convolve_col_smallNo_ixX_ixX_oxX_reorderWeights_Args pArgs,
const MMALIB_bufParams2D_t pWeights_addr,
const void *restrict  pWeights,
const MMALIB_bufParams2D_t pBias_addr,
const void *restrict  pBias,
const MMALIB_bufParams2D_t pReorderedWeights_addr,
void *restrict  pReorderedWeights 
)

This function takes a set of weights and biases (optional) and reorders the coefficients for improved efficiency when computing column flow convolution.

The function can receive the bias values either embedded in the kernel weights a priori, or as a separate vector. If the weights are already embedded in pWeights, then the function must be called with pBias == NULL.

Parameters
[in]operation: Desired reordering configuration, arguments are of type MMALIB_reorder_weights_operation_e REORDER_WEIGHTS_AND_BIAS = reorder weights and bias values simultaneously REORDER_WEIGHTS = reorder weights, leaving space for bias values to be added later REORDER_BIAS = assume weights are already present, add-in bias values
[in]pArgs: Pointer to argument structure containing necessary parameters for reordering weights
[in]pWeights_addr: Pointer to structure containing dimensional information of the naturally ordered weights buffer.
[in]pWeights[]: Pointer to buffer holding naturally ordered convolution weights
[in]pBias_addr: Pointer to structure containing dimensional information of the bias values buffer.
[in]pBias[]: Pointer to buffer holding bias values
[in]pReorderedWeights_addr: Pointer to structure containing dimensional information of the reordered weights buffer.
[out]pReorderedWeights[]: Pointer to buffer holding the reordered weights
Returns
Status of success or error with error codes, refer to MMALIB_STATUS.
Assumptions:
  • pBias == NULL if the bias values are already stored with weights in pWeights in REORDER_WEIGHTS_AND_BIAS mode
Performance Considerations:
  • This function may either be called during the processing flow, or offline whenever the weights are known.