Softmax Functions
-
void riscv_softmax_q15(const q15_t *vec_in, const uint16_t dim_vec, q15_t *p_out)
-
void riscv_softmax_q7(const q7_t *vec_in, const uint16_t dim_vec, q7_t *p_out)
-
riscv_nmsis_nn_status riscv_softmax_s16(const int16_t *input, const int32_t num_rows, const int32_t row_size, const int32_t mult, const int32_t shift, const nmsis_nn_softmax_lut_s16 *softmax_params, int16_t *output)
-
void riscv_softmax_s8(const int8_t *input, const int32_t num_rows, const int32_t row_size, const int32_t mult, const int32_t shift, const int32_t diff_min, int8_t *output)
-
void riscv_softmax_s8_s16(const int8_t *input, const int32_t num_rows, const int32_t row_size, const int32_t mult, const int32_t shift, const int32_t diff_min, int16_t *output)
-
void riscv_softmax_u8(const uint8_t *input, const int32_t num_rows, const int32_t row_size, const int32_t mult, const int32_t shift, const int32_t diff_min, uint8_t *output)
-
void riscv_softmax_with_batch_q7(const q7_t *vec_in, const uint16_t nb_batches, const uint16_t dim_vec, q7_t *p_out)
- group Softmax
Functions
-
void riscv_softmax_q15(const q15_t *vec_in, const uint16_t dim_vec, q15_t *p_out)
Q15 softmax function.
Here, instead of typical e based softmax, we use 2-based softmax, i.e.,:
y_i = 2^(x_i) / sum(2^x_j)
The relative output will be different here. But mathematically, the gradient will be the same with a log(2) scaling factor.
- Parameters
vec_in – [in] pointer to input vector
dim_vec – [in] input vector dimention
p_out – [out] pointer to output vector
-
void riscv_softmax_q7(const q7_t *vec_in, const uint16_t dim_vec, q7_t *p_out)
Q7 softmax function.
Here, instead of typical natural logarithm e based softmax, we use 2-based softmax here, i.e.,:
y_i = 2^(x_i) / sum(2^x_j)
The relative output will be different here. But mathematically, the gradient will be the same with a log(2) scaling factor.
- Parameters
vec_in – [in] pointer to input vector
dim_vec – [in] input vector dimention
p_out – [out] pointer to output vector
-
riscv_nmsis_nn_status riscv_softmax_s16(const int16_t *input, const int32_t num_rows, const int32_t row_size, const int32_t mult, const int32_t shift, const nmsis_nn_softmax_lut_s16 *softmax_params, int16_t *output)
S16 softmax function.
Note
Supported framework: TensorFlow Lite micro (bit-accurate)
- Parameters
input – [in] Pointer to the input tensor
num_rows – [in] Number of rows in the input tensor
row_size – [in] Number of elements in each input row
mult – [in] Input quantization multiplier
shift – [in] Input quantization shift within the range [0, 31]
softmax_params – [in] Softmax s16 layer parameters with two pointers to LUTs speficied below. For indexing the high 9 bits are used and 7 remaining for interpolation. That means 512 entries for the 9-bit indexing and 1 extra for interpolation, i.e. 513 values for each LUT.
Lookup table for exp(x), where x uniform distributed between [-10.0 , 0.0]
Lookup table for 1 / (1 + x), where x uniform distributed between [0.0 , 1.0]
output – [out] Pointer to the output tensor
- Returns
The function returns
RISCV_NMSIS_NN_ARG_ERROR
Argument error check failedRISCV_NMSIS_NN_SUCCESS
- Successful operation
-
void riscv_softmax_s8(const int8_t *input, const int32_t num_rows, const int32_t row_size, const int32_t mult, const int32_t shift, const int32_t diff_min, int8_t *output)
S8 softmax function.
Note
Supported framework: TensorFlow Lite micro (bit-accurate)
- Parameters
input – [in] Pointer to the input tensor
num_rows – [in] Number of rows in the input tensor
row_size – [in] Number of elements in each input row
mult – [in] Input quantization multiplier
shift – [in] Input quantization shift within the range [0, 31]
diff_min – [in] Minimum difference with max in row. Used to check if the quantized exponential operation can be performed
output – [out] Pointer to the output tensor
-
void riscv_softmax_s8_s16(const int8_t *input, const int32_t num_rows, const int32_t row_size, const int32_t mult, const int32_t shift, const int32_t diff_min, int16_t *output)
S8 to s16 softmax function.
Note
Supported framework: TensorFlow Lite micro (bit-accurate)
- Parameters
input – [in] Pointer to the input tensor
num_rows – [in] Number of rows in the input tensor
row_size – [in] Number of elements in each input row
mult – [in] Input quantization multiplier
shift – [in] Input quantization shift within the range [0, 31]
diff_min – [in] Minimum difference with max in row. Used to check if the quantized exponential operation can be performed
output – [out] Pointer to the output tensor
-
void riscv_softmax_u8(const uint8_t *input, const int32_t num_rows, const int32_t row_size, const int32_t mult, const int32_t shift, const int32_t diff_min, uint8_t *output)
U8 softmax function.
Note
Supported framework: TensorFlow Lite micro (bit-accurate)
- Parameters
input – [in] Pointer to the input tensor
num_rows – [in] Number of rows in the input tensor
row_size – [in] Number of elements in each input row
mult – [in] Input quantization multiplier
shift – [in] Input quantization shift within the range [0, 31]
diff_min – [in] Minimum difference with max in row. Used to check if the quantized exponential operation can be performed
output – [out] Pointer to the output tensor
-
void riscv_softmax_with_batch_q7(const q7_t *vec_in, const uint16_t nb_batches, const uint16_t dim_vec, q7_t *p_out)
Q7 softmax function with batch parameter.
Here, instead of typical natural logarithm e based softmax, we use 2-based softmax here, i.e.,:
y_i = 2^(x_i) / sum(2^x_j)
The relative output will be different here. But mathematically, the gradient will be the same with a log(2) scaling factor.
- Parameters
vec_in – [in] pointer to input vector
nb_batches – [in] number of batches
dim_vec – [in] input vector dimention
p_out – [out] pointer to output vector
-
void riscv_softmax_q15(const q15_t *vec_in, const uint16_t dim_vec, q15_t *p_out)