# arm_nnfunctions.h File Reference

CMSIS-NN: arm_nnfunctions.h File Reference

| CMSIS-NN Version 1.1.0 CMSIS NN Software Library

- Main Page
- Usage and Description
- Reference

All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Macros Groups Pages
Macros | Functions
arm_nnfunctions.h File Reference

## Macros

#define | USE_INTRINSIC

## Functions

arm_status | arm_convolve_HWC_q7_basic (const q7_t *Im_in, const uint16_t dim_im_in, const uint16_t ch_im_in, const q7_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel, const uint16_t padding, const uint16_t stride, const q7_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q7_t *Im_out, const uint16_t dim_im_out, q15_t *bufferA, q7_t *bufferB)
| Basic Q7 convolution function. More...

arm_status

arm_convolve_HWC_q7_basic_nonsquare (const q7_t *Im_in, const uint16_t dim_im_in_x, const uint16_t dim_im_in_y, const uint16_t ch_im_in, const q7_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel_x, const uint16_t dim_kernel_y, const uint16_t padding_x, const uint16_t padding_y, const uint16_t stride_x, const uint16_t stride_y, const q7_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q7_t *Im_out, const uint16_t dim_im_out_x, const uint16_t dim_im_out_y, q15_t *bufferA, q7_t *bufferB)

| Basic Q7 convolution function (non-sqaure shape) More...
arm_status | arm_convolve_HWC_q15_basic (const q15_t *Im_in, const uint16_t dim_im_in, const uint16_t ch_im_in, const q15_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel, const uint16_t padding, const uint16_t stride, const q15_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q15_t *Im_out, const uint16_t dim_im_out, q15_t *bufferA, q7_t *bufferB)
| Basic Q15 convolution function. More...
arm_status | arm_convolve_HWC_q7_fast (const q7_t *Im_in, const uint16_t dim_im_in, const uint16_t ch_im_in, const q7_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel, const uint16_t padding, const uint16_t stride, const q7_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q7_t *Im_out, const uint16_t dim_im_out, q15_t *bufferA, q7_t *bufferB)
| Fast Q7 convolution function. More...

arm_status

arm_convolve_HWC_q7_fast_nonsquare (const q7_t *Im_in, const uint16_t dim_im_in_x, const uint16_t dim_im_in_y, const uint16_t ch_im_in, const q7_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel_x, const uint16_t dim_kernel_y, const uint16_t padding_x, const uint16_t padding_y, const uint16_t stride_x, const uint16_t stride_y, const q7_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q7_t *Im_out, const uint16_t dim_im_out_x, const uint16_t dim_im_out_y, q15_t *bufferA, q7_t *bufferB)

| Fast Q7 convolution function (non-sqaure shape) More...

arm_status

arm_convolve_1x1_HWC_q7_fast_nonsquare (const q7_t *Im_in, const uint16_t dim_im_in_x, const uint16_t dim_im_in_y, const uint16_t ch_im_in, const q7_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel_x, const uint16_t dim_kernel_y, const uint16_t padding_x, const uint16_t padding_y, const uint16_t stride_x, const uint16_t stride_y, const q7_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q7_t *Im_out, const uint16_t dim_im_out_x, const uint16_t dim_im_out_y, q15_t *bufferA, q7_t *bufferB)

| Fast Q7 version of 1x1 convolution (non-sqaure shape) More...
arm_status | arm_convolve_HWC_q7_RGB (const q7_t *Im_in, const uint16_t dim_im_in, const uint16_t ch_im_in, const q7_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel, const uint16_t padding, const uint16_t stride, const q7_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q7_t *Im_out, const uint16_t dim_im_out, q15_t *bufferA, q7_t *bufferB)
| Q7 version of convolution for RGB image. More...
arm_status | arm_convolve_HWC_q15_fast (const q15_t *Im_in, const uint16_t dim_im_in, const uint16_t ch_im_in, const q15_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel, const uint16_t padding, const uint16_t stride, const q15_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q15_t *Im_out, const uint16_t dim_im_out, q15_t *bufferA, q7_t *bufferB)
| Fast Q15 convolution function. More...

arm_status

arm_convolve_HWC_q15_fast_nonsquare (const q15_t *Im_in, const uint16_t dim_im_in_x, const uint16_t dim_im_in_y, const uint16_t ch_im_in, const q15_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel_x, const uint16_t dim_kernel_y, const uint16_t padding_x, const uint16_t padding_y, const uint16_t stride_x, const uint16_t stride_y, const q15_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q15_t *Im_out, const uint16_t dim_im_out_x, const uint16_t dim_im_out_y, q15_t *bufferA, q7_t *bufferB)

| Fast Q15 convolution function (non-sqaure shape) More...
arm_status | arm_depthwise_separable_conv_HWC_q7 (const q7_t *Im_in, const uint16_t dim_im_in, const uint16_t ch_im_in, const q7_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel, const uint16_t padding, const uint16_t stride, const q7_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q7_t *Im_out, const uint16_t dim_im_out, q15_t *bufferA, q7_t *bufferB)
| Q7 depthwise separable convolution function. More...

arm_status

arm_depthwise_separable_conv_HWC_q7_nonsquare (const q7_t *Im_in, const uint16_t dim_im_in_x, const uint16_t dim_im_in_y, const uint16_t ch_im_in, const q7_t *wt, const uint16_t ch_im_out, const uint16_t dim_kernel_x, const uint16_t dim_kernel_y, const uint16_t padding_x, const uint16_t padding_y, const uint16_t stride_x, const uint16_t stride_y, const q7_t *bias, const uint16_t bias_shift, const uint16_t out_shift, q7_t *Im_out, const uint16_t dim_im_out_x, const uint16_t dim_im_out_y, q15_t *bufferA, q7_t *bufferB)

| Q7 depthwise separable convolution function (non-square shape) More...
arm_status | arm_fully_connected_q7 (const q7_t *pV, const q7_t *pM, const uint16_t dim_vec, const uint16_t num_of_rows, const uint16_t bias_shift, const uint16_t out_shift, const q7_t *bias, q7_t *pOut, q15_t *vec_buffer)
| Q7 basic fully-connected layer function. More...
arm_status | arm_fully_connected_q7_opt (const q7_t *pV, const q7_t *pM, const uint16_t dim_vec, const uint16_t num_of_rows, const uint16_t bias_shift, const uint16_t out_shift, const q7_t *bias, q7_t *pOut, q15_t *vec_buffer)
| Q7 opt fully-connected layer function. More...
arm_status | arm_fully_connected_q15 (const q15_t *pV, const q15_t *pM, const uint16_t dim_vec, const uint16_t num_of_rows, const uint16_t bias_shift, const uint16_t out_shift, const q15_t *bias, q15_t *pOut, q15_t *vec_buffer)
| Q15 basic fully-connected layer function. More...
arm_status | arm_fully_connected_q15_opt (const q15_t *pV, const q15_t *pM, const uint16_t dim_vec, const uint16_t num_of_rows, const uint16_t bias_shift, const uint16_t out_shift, const q15_t *bias, q15_t *pOut, q15_t *vec_buffer)
| Q15 opt fully-connected layer function. More...
arm_status | arm_fully_connected_mat_q7_vec_q15 (const q15_t *pV, const q7_t *pM, const uint16_t dim_vec, const uint16_t num_of_rows, const uint16_t bias_shift, const uint16_t out_shift, const q7_t *bias, q15_t *pOut, q15_t *vec_buffer)
| Mixed Q15-Q7 fully-connected layer function. More...
arm_status | arm_fully_connected_mat_q7_vec_q15_opt (const q15_t *pV, const q7_t *pM, const uint16_t dim_vec, const uint16_t num_of_rows, const uint16_t bias_shift, const uint16_t out_shift, const q7_t *bias, q15_t *pOut, q15_t *vec_buffer)
| Mixed Q15-Q7 opt fully-connected layer function. More...
q7_t * | arm_nn_mat_mult_kernel_q7_q15 (const q7_t *pA, const q15_t *pInBuffer, const uint16_t ch_im_out, const uint16_t numCol_A, const uint16_t bias_shift, const uint16_t out_shift, const q7_t *bias, q7_t *pOut)
| Matrix-Multiplication Kernels for Convolution. More...
q7_t * | arm_nn_mat_mult_kernel_q7_q15_reordered (const q7_t *pA, const q15_t *pInBuffer, const uint16_t ch_im_out, const uint16_t numCol_A, const uint16_t bias_shift, const uint16_t out_shift, const q7_t *bias, q7_t *pOut)
| Matrix-multiplication function for convolution with reordered columns. More...
void | arm_relu_q7 (q7_t *data, uint16_t size)
| Q7 RELU function. More...
void | arm_relu_q15 (q15_t *data, uint16_t size)
| Q15 RELU function. More...
void | arm_nn_activations_direct_q7 (q7_t *data, uint16_t size, uint16_t int_width, arm_nn_activation_type type)
| Q7 neural network activation function using direct table look-up. More...
void | arm_nn_activations_direct_q15 (q15_t *data, uint16_t size, uint16_t int_width, arm_nn_activation_type type)
| Q15 neural network activation function using direct table look-up. More...
void | arm_maxpool_q7_HWC (q7_t *Im_in, const uint16_t dim_im_in, const uint16_t ch_im_in, const uint16_t dim_kernel, const uint16_t padding, const uint16_t stride, const uint16_t dim_im_out, q7_t *bufferA, q7_t *Im_out)
| Q7 max pooling function. More...
void | arm_avepool_q7_HWC (q7_t *Im_in, const uint16_t dim_im_in, const uint16_t ch_im_in, const uint16_t dim_kernel, const uint16_t padding, const uint16_t stride, const uint16_t dim_im_out, q7_t *bufferA, q7_t *Im_out)
| Q7 average pooling function. More...
void | arm_softmax_q7 (const q7_t *vec_in, const uint16_t dim_vec, q7_t *p_out)
| Q7 softmax function. More...
void | arm_softmax_q15 (const q15_t *vec_in, const uint16_t dim_vec, q15_t *p_out)
| Q15 softmax function. More...

## Macro Definition Documentation

#define USE_INTRINSIC

## Function Documentation

q7_t* arm_nn_mat_mult_kernel_q7_q15 | ( | const q7_t * | pA,
|  | const q15_t * | pInBuffer,
|  | const uint16_t | ch_im_out,
|  | const uint16_t | numCol_A,
|  | const uint16_t | bias_shift,
|  | const uint16_t | out_shift,
|  | const q7_t * | bias,
|  | q7_t * | pOut
| ) |  |

These functions are used within convolution layer functions for matrix multiplication.

The implementation is similar to CMSIS-DSP arm_mat_mult functions with one Q7 and one Q15 operands. The Q15 operand is the im2col output which is always with 2 columns. Matrix-multiplication function for convolution

Parameters

  [in] | pA | pointer to operand A
  [in] | pInBuffer | pointer to operand B, always conssists of 2 vectors
  [in] | ch_im_out | numRow of A
  [in] | numCol_A | numCol of A
  [in] | bias_shift | amount of left-shift for bias
  [in] | out_shift | amount of right-shift for output
  [in] | bias | the bias
  [in,out] | pOut | pointer to output

Returns
  The function returns the incremented output pointer

Matrix-Multiplication Kernels for Convolution.

Parameters

  [in] | pA | pointer to operand A
  [in] | pInBuffer | pointer to operand B, always conssists of 2 vectors
  [in] | ch_im_out | numRow of A
  [in] | numCol_A | numCol of A
  [in] | bias_shift | amount of left-shift for bias
  [in] | out_shift | amount of right-shift for output
  [in] | bias | the bias
  [in,out] | pOut | pointer to output

Returns
  The function returns the incremented output pointer

This function does the matrix multiplication with weight matrix and 2 columns from im2col.

References NN_ROUND.

Referenced by arm_convolve_HWC_q7_basic(), arm_convolve_HWC_q7_basic_nonsquare(), and arm_convolve_HWC_q7_RGB().

q7_t* arm_nn_mat_mult_kernel_q7_q15_reordered | ( | const q7_t * | pA,
|  | const q15_t * | pInBuffer,
|  | const uint16_t | ch_im_out,
|  | const uint16_t | numCol_A,
|  | const uint16_t | bias_shift,
|  | const uint16_t | out_shift,
|  | const q7_t * | bias,
|  | q7_t * | pOut
| ) |  |

Parameters

  [in] | pA | pointer to operand A
  [in] | pInBuffer | pointer to operand B, always conssists of 2 vectors
  [in] | ch_im_out | numRow of A
  [in] | numCol_A | numCol of A
  [in] | bias_shift | amount of left-shift for bias
  [in] | out_shift | amount of right-shift for output
  [in] | bias | the bias
  [in,out] | pOut | pointer to output

Returns
  The function returns the incremented output pointer

Parameters

  [in] | pA | pointer to operand A
  [in] | pInBuffer | pointer to operand B, always conssists of 2 vectors
  [in] | ch_im_out | numRow of A
  [in] | numCol_A | numCol of A
  [in] | bias_shift | amount of left-shift for bias
  [in] | out_shift | amount of right-shift for output
  [in] | bias | the bias
  [in,out] | pOut | pointer to output

Returns
  The function returns the incremented output pointer

This function assumes that data in pInBuffer are reordered

References NN_ROUND.

Referenced by arm_convolve_1x1_HWC_q7_fast_nonsquare(), arm_convolve_HWC_q7_fast(), and arm_convolve_HWC_q7_fast_nonsquare().