HPM SDK
HPMicro Software Development Kit
NN Activation Functions

The activation functions are used to filter out some input data. They include sigmoid, tanh and ReLU (Rectified Linear Unit) functions. More...

Functions

static void hpm_nn_activate_s8 (q7_t *in_out, uint32_t size, uint16_t int_bits, riscv_nn_activation_fun act_fun)
 This function uses the sigmoid or tanh function to perform activation for signed 8-bit integer input vectors. More...
 
static void hpm_nn_activate_s16 (q15_t *in_out, uint32_t size, uint16_t int_bits, riscv_nn_activation_fun act_fun)
 This function uses sigmoid or tanh function to perform activation for signed 16-bit integer input vectors. More...
 
static void hpm_nn_leaky_relu_s8 (q7_t *in_out, uint32_t size, q15_t slope) riscv_nn_leaky_relu_s8(in_out
 This function uses the leaky ReLU function to perform activation for signed 8-bit integer input vectors. More...
 
static void hpm_nn_relu_any_s8 (q7_t *data, uint16_t size, q7_t max_val)
 This function uses the ReLU function to perform activation for signed 8-bit integer input vectors. More...
 
static void hpm_nn_relu_s8 (q7_t *in_out, uint32_t size)
 This function uses the ReLU function to perform activation for signed 8-bit integer input vectors. More...
 
static void hpm_nn_relu_s16 (q15_t *in_out, uint32_t size)
 This function uses the ReLU function to perform activation for signed 16-bit integer input vectors. More...
 

Variables

static void size
 
static void slope
 

Detailed Description

The activation functions are used to filter out some input data. They include sigmoid, tanh and ReLU (Rectified Linear Unit) functions.

Function Documentation

◆ hpm_nn_activate_s16()

static void hpm_nn_activate_s16 ( q15_t *  in_out,
uint32_t  size,
uint16_t  int_bits,
riscv_nn_activation_fun  act_fun 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

This function uses sigmoid or tanh function to perform activation for signed 16-bit integer input vectors.

Parameters
[in,out]in_outpointer of the input/output vector
[in]sizenumber of elements in the input/output vector
[in]int_bitsnumber of the bits in the integer part, which is supposed to be smaller than 4
[in]act_funselection of activation functions. See the Note below for details.
Note
The availbale activation functions for selection include:
  • NN_SIGMOID: Use the sigmoid activation function
  • NN_TANH: Use the tanh activation function

◆ hpm_nn_activate_s8()

static void hpm_nn_activate_s8 ( q7_t *  in_out,
uint32_t  size,
uint16_t  int_bits,
riscv_nn_activation_fun  act_fun 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

This function uses the sigmoid or tanh function to perform activation for signed 8-bit integer input vectors.

Parameters
[in,out]in_outpointer of the input/output vector
[in]sizenumber of elements in the input/output vector
[in]int_bitsnumber of the bits in the integer part, which is supposed to be smaller than 4
[in]act_funselection of activation functions. See the Note below for details.
Note
The available activation functions for selection include:
  • NN_SIGMOID: Use the sigmoid activation function
  • NN_TANH: Use the tanh activation function

Example:

#define SIZE 32
q7_t in_out[SIZE] = {...};
hpm_nn_activate_s8(in_out, SIZE, 0, NN_SIGMOID);
static void hpm_nn_activate_s8(q7_t *in_out, uint32_t size, uint16_t int_bits, riscv_nn_activation_fun act_fun)
This function uses the sigmoid or tanh function to perform activation for signed 8-bit integer input ...
Definition: hpm_math.h:6876

◆ hpm_nn_leaky_relu_s8()

static void hpm_nn_leaky_relu_s8 ( q7_t *  in_out,
uint32_t  size,
q15_t  slope 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

This function uses the leaky ReLU function to perform activation for signed 8-bit integer input vectors.

Parameters
[in,out]in_outpointer of the input/output vector
[in]sizenumber of elements in the input/output vector
[in]slopeslope value to be multiplied with the negative inputs. The result will be right shifted 15 bits to scale back to signed 8-bit integer.

Example:

#define SIZE 1024
q15_t slope = 16384;
q7_t in_out[SIZE] = {...};
hpm_nn_leaky_relu_s8(in_out, SIZE, slope);
static void hpm_nn_leaky_relu_s8(q7_t *in_out, uint32_t size, q15_t slope) riscv_nn_leaky_relu_s8(in_out
This function uses the leaky ReLU function to perform activation for signed 8-bit integer input vecto...
static void slope
Definition: hpm_math.h:6938

◆ hpm_nn_relu_any_s8()

static void hpm_nn_relu_any_s8 ( q7_t *  data,
uint16_t  size,
q7_t  max_val 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

This function uses the ReLU function to perform activation for signed 8-bit integer input vectors.

Parameters
[in,out]datapointer of the input/output vector
[in]sizenumber of elements in the input/output vector
[in]max_valmaximum value to limit the output vector

◆ hpm_nn_relu_s16()

static void hpm_nn_relu_s16 ( q15_t *  in_out,
uint32_t  size 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

This function uses the ReLU function to perform activation for signed 16-bit integer input vectors.

Parameters
[in,out]in_outpointer of the input/output vector
[in]sizenumber of elements in the input/output vector

◆ hpm_nn_relu_s8()

static void hpm_nn_relu_s8 ( q7_t *  in_out,
uint32_t  size 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

This function uses the ReLU function to perform activation for signed 8-bit integer input vectors.

Parameters
[in,out]in_outpointer of the input/output vector
[in]sizenumber of elements in the input/output vector

Example:

#define H 16
#define W 16
#define CH 5
#define NUM (H * W *CH)
q7_t in_out[NUM] = {...};
hpm_nn_relu_s8(in_out, NUM);
static void hpm_nn_relu_s8(q7_t *in_out, uint32_t size)
This function uses the ReLU function to perform activation for signed 8-bit integer input vectors.
Definition: hpm_math.h:6974

Variable Documentation

◆ size

static int32_t size

◆ slope

void slope