MMALIB User Guide
Common definitions

Introduction

This module consists of definitions (macros, structures, utility functions) that are commonly applicable to all MMALIB kernels.

Data Structures

struct  MMALIB_bufParams1D_t
 A structure for a 1 dimensional buffer descriptor. More...
 
struct  MMALIB_bufParams2D_t
 A structure for a 2 dimensional buffer descriptor. More...
 
struct  MMALIB_bufParams3D_t
 A structure for a 3 dimensional buffer descriptor. More...
 
struct  MMALIB_bufParamsND_t
 A structure for a N dimensional buffer descriptor. More...
 

Functions

static int32_t MMALIB_sizeof (uint32_t type)
 Inline function returns number of bytes per element given a type of MMALIB_data_type_e. More...
 

Typedefs

typedef double MMALIB_D64
 Double precision floating point. More...
 
typedef float MMALIB_F32
 Single precision floating point. More...
 
typedef MMALIB_STATUS_NAME MMALIB_STATUS
 Return value for MMALIB functions. More...
 
typedef void * MMALIB_kernelHandle
 Handle type for MMALIB operations. More...
 

Enumerations

enum  MMALIB_data_type_e {
  MMALIB_INT8 = 0, MMALIB_INT16 = 1, MMALIB_INT32 = 2, MMALIB_INT64 = 3,
  MMALIB_INT128 = 4, MMALIB_UINT8 = 5, MMALIB_UINT16 = 6, MMALIB_UINT24 = 7,
  MMALIB_UINT32 = 8, MMALIB_UINT64 = 9, MMALIB_UINT128 = 10, MMALIB_FLOAT16 = 11,
  MMALIB_FLOAT32 = 12, MMALIB_FLOAT64 = 13
}
 The enumeration of all data types. More...
 
enum  MMALIB_dimension_e {
  MMALIB_2D = 0, MMALIB_3D = 1, MMALIB_4D = 2, MMALIB_5D = 3,
  MMALIB_6D = 4
}
 The enumeration of multidimensional buffer types. More...
 
enum  MMALIB_STATUS_NAME {
  MMALIB_SUCCESS = 0, MMALIB_ERR_FAILURE = 1, MMALIB_ERR_INVALID_VALUE = 2, MMALIB_ERR_INVALID_TYPE,
  MMALIB_ERR_INVALID_DIMENSION, MMALIB_ERR_NULL_POINTER = 5, MMALIB_ERR_NOT_IMPLEMENTED, MMALIB_ERR_NOT_EQUAL_WIDTH_STRIDE,
  MMALIB_ERR_NOT_ALIGNED_PTRS_STRIDES, MMALIB_ERR_NOT_ALIGNED_WIDTHS, MMALIB_ERR_BUFFER_TOO_SMALL = 10, MMALIB_ERR_INVALID_ACTIVATION = 11,
  MMALIB_ERROR_MAX = 12
}
 The enumeration of all status codes. More...
 
enum  MMALIB_FUNCTION_STYLE { MMALIB_FUNCTION_NATC = 0, MMALIB_FUNCTION_OPTIMIZED, MMALIB_FUNCTION_MAX = 128 }
 Enumeration for the style of function implementation. More...
 
enum  MMALIB_activation_type_e { MMALIB_NONE = 0, MMALIB_RELU, MMALIB_SATURATION, MMALIB_ROUNDING }
 The enumeration of possible activation operations on the computation. More...
 
enum  MMALIB_buffer_mode_e { MMALIB_LINEAR = 0, MMALIB_SE_CIRCULAR, MMALIB_BUF_CIRCULAR }
 Buffer structure for input feature maps and coefficients of MMALIB_CNN_convolve_row_ixX_ixX_oxX. More...
 

Macros

#define MMALIB_ISSIGNED(type)   ((type) < MMALIB_UINT8 || (type) > MMALIB_UINT128)
 
#define MMALIB_SIGNEDNESS(type)   (MMALIB_ISSIGNED((type)) ? "signed" : "unsigned")
 
#define MMALIB_PARAM_SIZE   128
 Parameter structure size in bytes. More...
 
#define MMALIB_BYTE_WIDTH   64
 MMA width in bytes. More...
 
#define MMALIB_ALIGN_SHIFT_64BYTES   6
 Number of bits to shift for 64-byte memory alignment. More...
 
#define MMALIB_ALIGN_SHIFT_128BYTES   7
 Number of bits to shift for 128-byte memory alignment. More...
 
#define MMALIB_ALIGN_SHIFT_256BYTES   8
 Number of bits to shift for 256-byte memory alignment. More...
 
#define MMALIB_ALIGN_64BYTES   (1 << MMALIB_ALIGN_SHIFT_64BYTES)
 Align by 64-byte memory alignment. More...
 
#define MMALIB_ALIGN_128BYTES   (1 << MMALIB_ALIGN_SHIFT_128BYTES)
 Align by 128-byte memory alignment. More...
 
#define MMALIB_ALIGN_256BYTES   (1 << MMALIB_ALIGN_SHIFT_256BYTES)
 Align by 256-byte memory alignment. More...
 
#define MMALIB_L2DATA_ALIGN_SHIFT   MMALIB_ALIGN_SHIFT_64BYTES
 Set the default L2 data alignment. More...
 
#define MMALIB_L2DATA_ALIGNMENT   (((uint32_t)1) << ((uint32_t)MMALIB_L2DATA_ALIGN_SHIFT))
 Macro that specifies the alignment of data buffers in L2 memory for optimal performance. More...
 
#define MMALIB_CALC_STRIDE(BYTES, ALIGN_SHIFT)   (((((BYTES)-1) >> (ALIGN_SHIFT)) + 1) << (ALIGN_SHIFT))
 Macro function that computes the minimum stride for the specified number of bytes and alignment. More...
 
#define MMALIB_MMA_SIZE_8_BIT_SHIFT   6
 Macro for MMALIB shift amounts. More...
 
#define MMALIB_MMA_SIZE_16_BIT_SHIFT   5
 Shift for MMA size when data type is 16-bit integers. More...
 
#define MMALIB_MMA_SIZE_32_BIT_SHIFT   4
 Shift for MMA size when data type is 32-bit integers. More...
 
#define MMALIB_MMA_SIZE_8_BIT
 MMA size as a function of precision. More...
 
#define MMALIB_MMA_SIZE_16_BIT
 type is 16-bit integers More...
 
#define MMALIB_MMA_SIZE_32_BIT
 type is 32-bit integers More...
 

Macro Definition Documentation

◆ MMALIB_ISSIGNED

#define MMALIB_ISSIGNED (   type)    ((type) < MMALIB_UINT8 || (type) > MMALIB_UINT128)

Definition at line 70 of file MMALIB_bufParams.h.

◆ MMALIB_SIGNEDNESS

#define MMALIB_SIGNEDNESS (   type)    (MMALIB_ISSIGNED((type)) ? "signed" : "unsigned")

Definition at line 71 of file MMALIB_bufParams.h.

◆ MMALIB_PARAM_SIZE

#define MMALIB_PARAM_SIZE   128

Parameter structure size in bytes.

Definition at line 198 of file MMALIB_types.h.

◆ MMALIB_BYTE_WIDTH

#define MMALIB_BYTE_WIDTH   64

MMA width in bytes.

Definition at line 199 of file MMALIB_types.h.

◆ MMALIB_ALIGN_SHIFT_64BYTES

#define MMALIB_ALIGN_SHIFT_64BYTES   6

Number of bits to shift for 64-byte memory alignment.

Definition at line 207 of file MMALIB_types.h.

◆ MMALIB_ALIGN_SHIFT_128BYTES

#define MMALIB_ALIGN_SHIFT_128BYTES   7

Number of bits to shift for 128-byte memory alignment.

Definition at line 209 of file MMALIB_types.h.

◆ MMALIB_ALIGN_SHIFT_256BYTES

#define MMALIB_ALIGN_SHIFT_256BYTES   8

Number of bits to shift for 256-byte memory alignment.

Definition at line 211 of file MMALIB_types.h.

◆ MMALIB_ALIGN_64BYTES

#define MMALIB_ALIGN_64BYTES   (1 << MMALIB_ALIGN_SHIFT_64BYTES)

Align by 64-byte memory alignment.

Definition at line 214 of file MMALIB_types.h.

◆ MMALIB_ALIGN_128BYTES

#define MMALIB_ALIGN_128BYTES   (1 << MMALIB_ALIGN_SHIFT_128BYTES)

Align by 128-byte memory alignment.

Definition at line 216 of file MMALIB_types.h.

◆ MMALIB_ALIGN_256BYTES

#define MMALIB_ALIGN_256BYTES   (1 << MMALIB_ALIGN_SHIFT_256BYTES)

Align by 256-byte memory alignment.

Definition at line 218 of file MMALIB_types.h.

◆ MMALIB_L2DATA_ALIGN_SHIFT

#define MMALIB_L2DATA_ALIGN_SHIFT   MMALIB_ALIGN_SHIFT_64BYTES

Set the default L2 data alignment.

Definition at line 221 of file MMALIB_types.h.

◆ MMALIB_L2DATA_ALIGNMENT

#define MMALIB_L2DATA_ALIGNMENT   (((uint32_t)1) << ((uint32_t)MMALIB_L2DATA_ALIGN_SHIFT))

Macro that specifies the alignment of data buffers in L2 memory for optimal performance.

Definition at line 226 of file MMALIB_types.h.

◆ MMALIB_CALC_STRIDE

#define MMALIB_CALC_STRIDE (   BYTES,
  ALIGN_SHIFT 
)    (((((BYTES)-1) >> (ALIGN_SHIFT)) + 1) << (ALIGN_SHIFT))

Macro function that computes the minimum stride for the specified number of bytes and alignment.

Definition at line 234 of file MMALIB_types.h.

◆ MMALIB_MMA_SIZE_8_BIT_SHIFT

#define MMALIB_MMA_SIZE_8_BIT_SHIFT   6

Macro for MMALIB shift amounts.

Shift for MMA size when data type is 8-bit integers

Definition at line 238 of file MMALIB_types.h.

◆ MMALIB_MMA_SIZE_16_BIT_SHIFT

#define MMALIB_MMA_SIZE_16_BIT_SHIFT   5

Shift for MMA size when data type is 16-bit integers.

Definition at line 240 of file MMALIB_types.h.

◆ MMALIB_MMA_SIZE_32_BIT_SHIFT

#define MMALIB_MMA_SIZE_32_BIT_SHIFT   4

Shift for MMA size when data type is 32-bit integers.

Definition at line 242 of file MMALIB_types.h.

◆ MMALIB_MMA_SIZE_8_BIT

#define MMALIB_MMA_SIZE_8_BIT
Value:
((uint32_t)(((uint32_t)1) \
#define MMALIB_MMA_SIZE_8_BIT_SHIFT
Macro for MMALIB shift amounts.
Definition: MMALIB_types.h:238

MMA size as a function of precision.

Shift for MMA size when data type is 8-bit integers

Definition at line 247 of file MMALIB_types.h.

◆ MMALIB_MMA_SIZE_16_BIT

#define MMALIB_MMA_SIZE_16_BIT
Value:
((uint32_t)(((uint32_t)1) \
#define MMALIB_MMA_SIZE_16_BIT_SHIFT
Shift for MMA size when data type is 16-bit integers.
Definition: MMALIB_types.h:240

type is 16-bit integers

Shift for MMA size when data

Definition at line 251 of file MMALIB_types.h.

◆ MMALIB_MMA_SIZE_32_BIT

#define MMALIB_MMA_SIZE_32_BIT
Value:
((int32_t)(((uint32_t)1) \
#define MMALIB_MMA_SIZE_32_BIT_SHIFT
Shift for MMA size when data type is 32-bit integers.
Definition: MMALIB_types.h:242

type is 32-bit integers

Shift for MMA size when data

Definition at line 255 of file MMALIB_types.h.

Typedef Documentation

◆ MMALIB_D64

typedef double MMALIB_D64

Double precision floating point.

Definition at line 136 of file MMALIB_types.h.

◆ MMALIB_F32

typedef float MMALIB_F32

Single precision floating point.

Definition at line 137 of file MMALIB_types.h.

◆ MMALIB_STATUS

Return value for MMALIB functions.

Definition at line 162 of file MMALIB_types.h.

◆ MMALIB_kernelHandle

typedef void* MMALIB_kernelHandle

Handle type for MMALIB operations.

Definition at line 164 of file MMALIB_types.h.

Enumeration Type Documentation

◆ MMALIB_data_type_e

The enumeration of all data types.

Enumerator
MMALIB_INT8 

Signed 8-bit integer

MMALIB_INT16 

Signed 16-bit integer

MMALIB_INT32 

Signed 32-bit integer

MMALIB_INT64 

Signed 64-bit integer

MMALIB_INT128 

Signed 128-bit integer

MMALIB_UINT8 

Unsigned 8-bit integer

MMALIB_UINT16 

Unsigned 16-bit integer

MMALIB_UINT24 

Unsigned 24-bit integer

MMALIB_UINT32 

Unsigned 32-bit integer

MMALIB_UINT64 

Unsigned 64-bit integer

MMALIB_UINT128 

Unsigned 128-bit integer

MMALIB_FLOAT16 

16-bit floating point number

MMALIB_FLOAT32 

32-bit floating point number

MMALIB_FLOAT64 

64-bit floating point number

Definition at line 41 of file MMALIB_bufParams.h.

◆ MMALIB_dimension_e

The enumeration of multidimensional buffer types.

Enumerator
MMALIB_2D 

Two dimensional buffer

MMALIB_3D 

Three dimensional buffer

MMALIB_4D 

Four dimensional buffer

MMALIB_5D 

Five dimensional buffer

MMALIB_6D 

Six dimensional buffer

Definition at line 74 of file MMALIB_bufParams.h.

◆ MMALIB_STATUS_NAME

The enumeration of all status codes.

Enumerator
MMALIB_SUCCESS 

No error

MMALIB_ERR_FAILURE 

Unspecified error

MMALIB_ERR_INVALID_VALUE 

Invalid parameter value

MMALIB_ERR_INVALID_TYPE 

Invalid parameter type (MMALIB_data_type_e data_type)

MMALIB_ERR_INVALID_DIMENSION 

Dimension parameter (width/height) is too big/small

MMALIB_ERR_NULL_POINTER 

Unsupported null pointer condition

MMALIB_ERR_NOT_IMPLEMENTED 

Parameter configuration is not supported/implemented

MMALIB_ERR_NOT_EQUAL_WIDTH_STRIDE 

Stride should be equal to width * element size

MMALIB_ERR_NOT_ALIGNED_PTRS_STRIDES 

Pointers and stride values are not aligned to documented value

MMALIB_ERR_NOT_ALIGNED_WIDTHS 

Width values are not aligned to documented value

MMALIB_ERR_BUFFER_TOO_SMALL 

Buffer size not large enough

MMALIB_ERR_INVALID_ACTIVATION 

Activation selection incompatible with data type

MMALIB_ERROR_MAX 

Definition at line 140 of file MMALIB_types.h.

◆ MMALIB_FUNCTION_STYLE

Enumeration for the style of function implementation.

Enumerator
MMALIB_FUNCTION_NATC 

Natural C implementation of the function

MMALIB_FUNCTION_OPTIMIZED 

Optimized C implementation of the function for the MMA + C7x architecture

MMALIB_FUNCTION_MAX 

Definition at line 167 of file MMALIB_types.h.

◆ MMALIB_activation_type_e

The enumeration of possible activation operations on the computation.

Enumerator
MMALIB_NONE 

Return result as-is (allow wrapping)

MMALIB_RELU 

Return result after applying ReLU operation.

MMALIB_SATURATION 

Return result after saturating.

MMALIB_ROUNDING 

Return result after rounding.

Definition at line 176 of file MMALIB_types.h.

◆ MMALIB_buffer_mode_e

Buffer structure for input feature maps and coefficients of MMALIB_CNN_convolve_row_ixX_ixX_oxX.

Enumerator
MMALIB_LINEAR 

Linear buffer.

MMALIB_SE_CIRCULAR 

Circular buffer for input feature map managed by streaming engine

MMALIB_BUF_CIRCULAR 

Circular buffer for coefficients.

Definition at line 185 of file MMALIB_types.h.

Function Documentation

◆ MMALIB_sizeof()

static int32_t MMALIB_sizeof ( uint32_t  type)
inlinestatic

Inline function returns number of bytes per element given a type of MMALIB_data_type_e.

Definition at line 140 of file MMALIB_bufParams.h.