HPM SDK
HPMicro Software Development Kit

The basic functions are used to perform element-wise basic arithmetic operations. More...

Functions

static void hpm_nn_add_s8_sym (const q7_t *in_tensor1, const q7_t *in_tensor2, const int16_t *scale1, const int16_t *scale2, const uint32_t size, const uint16_t pre_rshift, const uint16_t out_scale, const uint16_t post_rshift, q7_t *out)
 This function performs element-wise addition for signed 8-bit integer input vectors with two-stage shift. More...
 
static void hpm_nn_add_s8_sym_round (const q7_t *in_tensor1, const q7_t *in_tensor2, const uint32_t scale1, const uint32_t scale2, const uint32_t size, const uint16_t pre_rshift, const uint16_t out_scale, const uint16_t post_rshift, q7_t *out)
 This function performs element-wise addition for signed 8-bit integer input vectors with two-stage shift with rounding. More...
 
static int hpm_nn_ew_add_s8_asym (const int8_t *in_tensor1, const int8_t *in_tensor2, const int32_t in_offset1, const int32_t in_scale1, const int32_t in_rshift1, const int32_t in_offset2, const int32_t in_scale2, const int32_t in_rshift2, const int32_t lshift, int8_t *out, const int32_t out_offset, const int32_t out_scale, const int32_t out_rshift, const int32_t act_min, const int32_t act_max, const uint32_t size)
 This function performs element-wise addition for signed 8-bit integer input vectors. More...
 
static int hpm_nn_ew_mul_s8_asym (const int8_t *in_tensor1, const int8_t *in_tensor2, const int32_t in_offset1, const int32_t in_offset2, int8_t *out, const int32_t out_offset, const int32_t out_scale, const int32_t out_shift, const int32_t act_min, const int32_t act_max, const uint32_t size)
 This function performs element-wise multiplication for signed 8-bit integer input vectors. More...
 

Detailed Description

The basic functions are used to perform element-wise basic arithmetic operations.

Function Documentation

◆ hpm_nn_add_s8_sym()

static void hpm_nn_add_s8_sym ( const q7_t *  in_tensor1,
const q7_t *  in_tensor2,
const int16_t *  scale1,
const int16_t *  scale2,
const uint32_t  size,
const uint16_t  pre_rshift,
const uint16_t  out_scale,
const uint16_t  post_rshift,
q7_t *  out 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

This function performs element-wise addition for signed 8-bit integer input vectors with two-stage shift.

Parameters
[in]in_tensor1pointer of the first input vector
[in]in_tensor2pointer of the second input vector
[in]scale1pointer of the first scaling vector
[in]scale2pointer of the second scaling vector
[in]sizenumber of elements in the input vectors
[in]pre_rshiftright shift amount for the accumulator before the scaling
[in]out_scalescaling value for the accumulator
[in]post_rshiftright shift amount for the accumulator after the scaling
[out]outpointer of the element-wise addition results

Example:

#define SIZE 1024
uint16_t pre_rshift = 8; // The addition results of both scaled input
// tensors are in the range of 24-bit; thus, the
// pre_rshift should be in the range of [0, 24].
// Here we scale down the results into 16-bit
// range.
uint16_t out_scale = 3; // Scale up the result into 18-bit range.
uint16_t post_rshift = 11; // Scale down the result into 7-bit range.
q7_t in_tensor1[SIZE] = {...};
q7_t in_tensor2[SIZE] = {...};
q15_t scale1[SIZE] = {...};
q15_t scale2[SIZE] = {...};
q7_t out[SIZE];
hpm_nn_add_s8_sym(in_tensor1, in_tensor2, scale1, scale2, SIZE, pre_rshift,
out_scale, post_rshift, out);
static void hpm_nn_add_s8_sym(const q7_t *in_tensor1, const q7_t *in_tensor2, const int16_t *scale1, const int16_t *scale2, const uint32_t size, const uint16_t pre_rshift, const uint16_t out_scale, const uint16_t post_rshift, q7_t *out)
This function performs element-wise addition for signed 8-bit integer input vectors with two-stage sh...
Definition: hpm_math.h:7058

◆ hpm_nn_add_s8_sym_round()

static void hpm_nn_add_s8_sym_round ( const q7_t *  in_tensor1,
const q7_t *  in_tensor2,
const uint32_t  scale1,
const uint32_t  scale2,
const uint32_t  size,
const uint16_t  pre_rshift,
const uint16_t  out_scale,
const uint16_t  post_rshift,
q7_t *  out 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

This function performs element-wise addition for signed 8-bit integer input vectors with two-stage shift with rounding.

Parameters
[in]in_tensor1pointer of the first input vector
[in]in_tensor2pointer of the second input vector
[in]scale1scaling value for the first input vector. It should be in the range of 0 to {2^23}.
[in]scale2scaling value for the second input vector. It should be in the range of 0 to {2^23}.
[in]sizenumber of elements in the input vectors
[in]pre_rshiftright shift amount for the accumulator before the scaling
[in]out_scalescaling value for the accumulator
[in]post_rshiftright shift amount for the accumulator after the scaling
[out]outpointer of element-wise addition results

◆ hpm_nn_ew_add_s8_asym()

static int hpm_nn_ew_add_s8_asym ( const int8_t *  in_tensor1,
const int8_t *  in_tensor2,
const int32_t  in_offset1,
const int32_t  in_scale1,
const int32_t  in_rshift1,
const int32_t  in_offset2,
const int32_t  in_scale2,
const int32_t  in_rshift2,
const int32_t  lshift,
int8_t *  out,
const int32_t  out_offset,
const int32_t  out_scale,
const int32_t  out_rshift,
const int32_t  act_min,
const int32_t  act_max,
const uint32_t  size 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

This function performs element-wise addition for signed 8-bit integer input vectors.

Parameters
[in]in_tensor1pointer of the first input vector
[in]in_tensor2pointer of the second input vector
[in]in_offset1offset value for first input vector. It should be in the range of -127 to 128.
[in]in_scale1scaling value for first input vector
[in]in_rshift1right shift amount for the first input vector
[in]in_offset2offset value for the second input vector. It should be in the range of -127 to 128.
[in]in_scale2scaling value for the second input vector
[in]in_rshift2right shift amount for the second input vector
[in]lshiftleft shift amount for the first and second input vectors
[out]outpointer of the element-wise addition results
[in]out_offsetoffset value for the output
[in]out_scalescaling value for the output
[in]out_rshiftright shift amount for the output
[in]act_minminimum value that the output is limited to
[in]act_maxmaximum value that the output is limited to
[in]sizenumber of elements in the input vectors
Returns
This function returns 0.

Example:

#define SIZE 1024
int32_t in_offset1 = 16; // Offset for in_tensor1
int32_t in_scale1 = (1<<28); // Scale down in_tensor1 by 1/23
int32_t in_rshift1 = 3; // Scale down in_tensor1 by 1/23
int32_t in_offset2 = 17; // Offset for in_tensor2
int32_t in_scale2 = (1<<28); // Scale down in_tensor2 by 1/23
int32_t in_rshift2 = 3; // Scale down in_tensor2 by 1/23
int32_t lshift = 10; // Scale up the input tensor by 210 times
int32_t out_offset = 18; // Offset for the output tensor
int32_t out_scale = (1<<30); // Scale down in_tensor2 by 1/2
int32_t out_rshift = 4; // Scale down in_tensor2 by 1/24
int32_t act_min = 0xffffffa3; // Limit the outputs in the range of
// [0xffffffa3, 0x0000005d]
int32_t act_max = 0x0000005d; // Limit the outputs in the range of
// [0xffffffa3, 0x0000005d]
int8_t in_tensor1[SIZE] = {...};
int8_t in_tensor2[SIZE] = {...};
int8_t out[SIZE];
hpm_nn_ew_add_s8_asym(in_tensor1, in_tensor2, in_offset1, in_scale1,
in_rshift1, in_offset2, in_scale2, in_rshift2, lshift, out, out_offset,
out_scale, out_rshift, act_min, act_max, SIZE);
static int hpm_nn_ew_add_s8_asym(const int8_t *in_tensor1, const int8_t *in_tensor2, const int32_t in_offset1, const int32_t in_scale1, const int32_t in_rshift1, const int32_t in_offset2, const int32_t in_scale2, const int32_t in_rshift2, const int32_t lshift, int8_t *out, const int32_t out_offset, const int32_t out_scale, const int32_t out_rshift, const int32_t act_min, const int32_t act_max, const uint32_t size)
This function performs element-wise addition for signed 8-bit integer input vectors.
Definition: hpm_math.h:7166
static int32_t out_rshift
Definition: hpm_math.h:14079

◆ hpm_nn_ew_mul_s8_asym()

static int hpm_nn_ew_mul_s8_asym ( const int8_t *  in_tensor1,
const int8_t *  in_tensor2,
const int32_t  in_offset1,
const int32_t  in_offset2,
int8_t *  out,
const int32_t  out_offset,
const int32_t  out_scale,
const int32_t  out_shift,
const int32_t  act_min,
const int32_t  act_max,
const uint32_t  size 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

This function performs element-wise multiplication for signed 8-bit integer input vectors.

Parameters
[in]in_tensor1pointer of the first input vector
[in]in_tensor2pointer of the second input vector
[in]in_offset1offset value for the first input vector. It should be in the range of -127 to 128.
[in]in_offset2offset value for the second input vector. It should be in the range of -127 to 128.
[out]outpointer of element-wise multiplication results
[in]out_offsetoffset value for the output
[in]out_scalescaling value for the output
[in]out_shiftshift amount for the output
[in]act_minminimum value that the output is limited to
[in]act_maxmaximum value that the output is limited to
[in]sizenumber of elements in the input vectors
Returns
This function returns 0.

Example:

#define SIZE 1024
int32_t in_offset1 = 16; // Offset for in_tensor1
int32_t in_offset2 = 17; // Offset for in_tensor2
int32_t out_offset = 18; // Offset for the output tensor
int32_t out_scale = (1<<30); // Scale down the output tensor by 1/2
int32_t out_shift = -4; // Scale down the output tensor by 1/24
int32_t act_min = 0xffffffa3; // Limit the outputs in the range of
// [0xffffffa3, 0x0000005d]
int32_t act_max = 0x0000005d; // Limit the outputs in the range of
// [0xffffffa3, 0x0000005d]
in_tensor1[SIZE] = {...};
in_tensor2[SIZE] = {...};
out[SIZE];
hpm_nn_ew_mul_s8_asym(in_tensor1, in_tensor2, in_offset1, in_offset2, out,
out_offset, out_scale, out_shift, act_min, act_max, SIZE);
static int hpm_nn_ew_mul_s8_asym(const int8_t *in_tensor1, const int8_t *in_tensor2, const int32_t in_offset1, const int32_t in_offset2, int8_t *out, const int32_t out_offset, const int32_t out_scale, const int32_t out_shift, const int32_t act_min, const int32_t act_max, const uint32_t size)
This function performs element-wise multiplication for signed 8-bit integer input vectors.
Definition: hpm_math.h:7235