LSTM

void riscv_nn_lstm_calculate_gate_s8_s16(const int8_t *input, const int8_t *input_to_gate_weights, const int32_t *input_to_gate_bias, const nmsis_nn_scaling input_to_gate_scaling, const int8_t *output_state, const int8_t *recurrent_to_gate_weights, const int32_t *recurrent_to_gate_bias, const nmsis_nn_scaling recurrent_to_gate, const int32_t n_batch, const int32_t n_input, const int32_t n_output, const int32_t n_cell, const riscv_nn_activation_type activation_type, int16_t *gate)
riscv_nmsis_nn_status riscv_nn_lstm_step_s8_s16(const int8_t *input, const int8_t *input_to_input_weight, const int8_t *input_to_forget_weight, const int8_t *input_to_cell_weight, const int8_t *input_to_output_weight, const int8_t *recurrent_to_input_weight, const int8_t *recurrent_to_forget_weight, const int8_t *recurrent_to_cell_weight, const int8_t *recurrent_to_output_weight, const nmsis_nn_lstm_params *lstm, const int n_batch, const int n_cell, const int n_input, const int n_output, int8_t *output_state, int16_t *cell_state, int8_t *output, nmsis_nn_lstm_context *scratch_buffers)
void riscv_nn_lstm_update_cell_state_s16(const int32_t n_block, const int32_t cell_state_scale, int16_t *cell_state, const int16_t *input_gate, const int16_t *forget_gate, const int16_t *cell_gate)
void riscv_nn_lstm_update_output_s8_s16(const int n_batch, const int n_cell, int16_t *cell_state, const int32_t cell_state_scale, const int16_t *output_gate, const nmsis_nn_scaling hidden_scaling, const int32_t hidden_offset, int8_t *output_state, int16_t *cell_gate_scratch)
void riscv_nn_vec_mat_mul_result_acc_s8(const int8_t *lhs_in, const int8_t *rhs_in, const int32_t *bias, int16_t *dst, const int32_t dst_offset, const int32_t dst_multiplier, const int32_t dst_shift, const int32_t rhs_cols, const int32_t rhs_rows, const int32_t batch)
group supportLSTM

Support functions for LSTM.

Functions

void riscv_nn_lstm_calculate_gate_s8_s16(const int8_t *input, const int8_t *input_to_gate_weights, const int32_t *input_to_gate_bias, const nmsis_nn_scaling input_to_gate_scaling, const int8_t *output_state, const int8_t *recurrent_to_gate_weights, const int32_t *recurrent_to_gate_bias, const nmsis_nn_scaling recurrent_to_gate, const int32_t n_batch, const int32_t n_input, const int32_t n_output, const int32_t n_cell, const riscv_nn_activation_type activation_type, int16_t *gate)

Updates a LSTM gate for an iteration step of LSTM function, int8x8_16 version.

param[in] input Input data param[in] input_to_gate_weights Input to gate weights param[in] input_to_gate_bias Input to gate weights param[in] input_to_gate_scaling Input to gate scaling param[in] activation Actival min and max values param[in] output_state Output state param[in] recurrent_to_gate_weights Recurrent to gate weights param[in] recurrent_to_gate_bias Recurrent to gate bias param[in] recurrent_to_gate_scaling Recurrent to gate scaling param[in] n_batch Batch size param[in] n_input Input size param[out] n_output Output size param[in] activation_type Activation type (sigmoid or tanh) param[out] n_cell Cell size

riscv_nmsis_nn_status riscv_nn_lstm_step_s8_s16(const int8_t *input, const int8_t *input_to_input_weight, const int8_t *input_to_forget_weight, const int8_t *input_to_cell_weight, const int8_t *input_to_output_weight, const int8_t *recurrent_to_input_weight, const int8_t *recurrent_to_forget_weight, const int8_t *recurrent_to_cell_weight, const int8_t *recurrent_to_output_weight, const nmsis_nn_lstm_params *lstm, const int n_batch, const int n_cell, const int n_input, const int n_output, int8_t *output_state, int16_t *cell_state, int8_t *output, nmsis_nn_lstm_context *scratch_buffers)

Update LSTM function for an iteration step.

param[in] input Input data param[in] input_to_input_weight Input to input gate weights param[in] input_to_forget_weight Input to forget gate weights param[in] input_to_cell_weight Input to cell gate weights param[in] input_to_output_weight Input to output weights param[in] recurrent_to_input_weight Recurrent signal to input weights param[in] recurrent_to_forget_weight Recurrent signal to forget gate weights param[in] recurrent_to_cell_weight Recurrent signal to cell gate weighst param[in] recurrent_to_output_weight Recurrent signal to output weights param[in] lstm LSTM parameters param[in] n_batch Batch size param[in] n_cell Cell size param[in] n_input Input size param[in] n_output Output size param[out] output_state Output state param[out] cell_state Internal state param[out] output Output signal param[in] *scratch_buffers Struct containing scratch buffers

void riscv_nn_lstm_update_cell_state_s16(const int32_t n_block, const int32_t cell_state_scale, int16_t *cell_state, const int16_t *input_gate, const int16_t *forget_gate, const int16_t *cell_gate)

Update cell state for a single LSTM iteration step, int8x8_16 version.

Parameters
  • n_block[in] total number of cells for all batches

  • cell_state_scale[in] Scaling factor of cell state

  • cell_state[in] Input/output vector, size n_batch*n_cell

  • input_gate[in] Input vector of size n_block

  • forget_gate[in] Input/scratch vector of size n_block, always modified

  • cell_gate[in] Input vector of size, n_block

void riscv_nn_lstm_update_output_s8_s16(const int n_batch, const int n_cell, int16_t *cell_state, const int32_t cell_state_scale, const int16_t *output_gate, const nmsis_nn_scaling hidden_scaling, const int32_t hidden_offset, int8_t *output_state, int16_t *cell_gate_scratch)

Calculate the output state tensor of an LSTM step, s8 input/output and s16 weight version.

Parameters
  • n_batch[in] The number of distinct vectors in each array

  • n_cell[in] Number of cells

  • cell_state[inout] Cell state, size n_batch*n_cell

  • cell_state_scale[in] Scaling of cell_state

  • output_gate[in] Output gate

  • hidden_scale[in] Effective scaling of cell_state .* output_gate

  • hidden_offset[in] Zero point for cell_state .* output_gate

  • output_state[out] Output state

  • cell_gate_scratch[in] Scratch buffer

void riscv_nn_vec_mat_mul_result_acc_s8(const int8_t *lhs_in, const int8_t *rhs_in, const int32_t *bias, int16_t *dst, const int32_t dst_offset, const int32_t dst_multiplier, const int32_t dst_shift, const int32_t rhs_cols, const int32_t rhs_rows, const int32_t batch)

The result of the multiplication is accumulated to the passed result buffer. Multiplies a matrix by a “batched” vector (i.e. a matrix with a batch dimension composed by input vectors independent from each other).

Parameters
  • lhs_in[in] Batched vector

  • rhs_in[in] Weights - input matrix (H(Rows)xW(Columns))

  • bias[in] Bias vector

  • dst[out] Output

  • dst_offset[in] Output offset

  • dst_multiplier[in] Multiplier for quantization

  • dst_shift[in] Shift for quantization

  • rhs_cols[in] Vector/matarix column length

  • rhs_rows[in] Row count of matrix

  • batch[in] Batch size