LSTM

riscv_nmsis_nn_status riscv_nn_lstm_calculate_gate_s16(const int16_t *data_in, const int16_t *hidden_in, const nmsis_nn_lstm_gate *gate, const nmsis_nn_lstm_params *params, int16_t *output, const int32_t batch_offset)
riscv_nmsis_nn_status riscv_nn_lstm_calculate_gate_s8_s16(const int8_t *data_in, const int8_t *hidden_in, const nmsis_nn_lstm_gate *gate, const nmsis_nn_lstm_params *params, int16_t *output, const int32_t batch_offset)
riscv_nmsis_nn_status riscv_nn_lstm_step_s16(const int16_t *data_in, const int16_t *hidden_in, int16_t *hidden_out, const nmsis_nn_lstm_params *params, nmsis_nn_lstm_context *buffers, const int32_t batch_offset)
riscv_nmsis_nn_status riscv_nn_lstm_step_s8(const int8_t *data_in, const int8_t *hidden_in, int8_t *hidden_out, const nmsis_nn_lstm_params *params, nmsis_nn_lstm_context *buffers, const int32_t batch_offset)
riscv_nmsis_nn_status riscv_nn_vec_mat_mul_result_acc_s8_s16(const int8_t *lhs, const int8_t *rhs, const int32_t *effective_bias, int16_t *dst, const int32_t dst_multiplier, const int32_t dst_shift, const int32_t rhs_cols, const int32_t rhs_rows, const int32_t batches, const int32_t batch_offset)
group supportLSTM

Support functions for LSTM.

Functions

riscv_nmsis_nn_status riscv_nn_lstm_calculate_gate_s16(const int16_t *data_in, const int16_t *hidden_in, const nmsis_nn_lstm_gate *gate, const nmsis_nn_lstm_params *params, int16_t *output, const int32_t batch_offset)

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

Parameters
  • data_in[in] Data input pointer

  • hidden_in[in] Hidden state/ recurrent input pointer

  • gate_data[in] Struct containing all information about the gate caluclation, see riscv_nn_types.

  • params[in] Struct containing all information about the lstm_operation, see riscv_nn_types

  • output[out] Hidden state/ recurrent output pointer

  • batch_offset[in] Number of timesteps between consecutive batches, see riscv_nn_lstm_step_s16.

Returns

The function returns RISCV_NMSIS_NN_SUCCESS

riscv_nmsis_nn_status riscv_nn_lstm_calculate_gate_s8_s16(const int8_t *data_in, const int8_t *hidden_in, const nmsis_nn_lstm_gate *gate, const nmsis_nn_lstm_params *params, int16_t *output, const int32_t batch_offset)

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

Parameters
  • data_in[in] Data input pointer

  • hidden_in[in] Hidden state/ recurrent input pointer

  • gate_data[in] Struct containing all information about the gate caluclation, see riscv_nn_types.

  • params[in] Struct containing all information about the lstm_operation, see riscv_nn_types

  • output[out] Hidden state/ recurrent output pointer

  • batch_offset[in] Number of timesteps between consecutive batches, see riscv_nn_lstm_step_s8.

Returns

The function returns RISCV_NMSIS_NN_SUCCESS

riscv_nmsis_nn_status riscv_nn_lstm_step_s16(const int16_t *data_in, const int16_t *hidden_in, int16_t *hidden_out, const nmsis_nn_lstm_params *params, nmsis_nn_lstm_context *buffers, const int32_t batch_offset)

Update LSTM function for an iteration step using s16 input and output, and s16 internally.

Parameters
  • data_in[in] Data input pointer

  • hidden_in[in] Hidden state/ recurrent input pointer

  • hidden_out[out] Hidden state/ recurrent output pointer

  • params[in] Struct containg all information about the lstm operator, see riscv_nn_types.

  • buffers[in] Struct containg pointers to all temporary scratch buffers needed for the lstm operator, see riscv_nn_types.

  • batch_offset[in] Number of timesteps between consecutive batches. E.g for params->timing_major = true, all batches for t=0 are stored sequentially, so batch offset = 1. For params->time major = false, all time steps are stored continously before the next batch, so batch offset = params->time_steps.

Returns

The function returns RISCV_NMSIS_NN_SUCCESS

riscv_nmsis_nn_status riscv_nn_lstm_step_s8(const int8_t *data_in, const int8_t *hidden_in, int8_t *hidden_out, const nmsis_nn_lstm_params *params, nmsis_nn_lstm_context *buffers, const int32_t batch_offset)

Update LSTM function for an iteration step using s8 input and output, and s16 internally.

Parameters
  • data_in[in] Data input pointer

  • hidden_in[in] Hidden state/ recurrent input pointer

  • hidden_out[out] Hidden state/ recurrent output pointer

  • params[in] Struct containg all information about the lstm operator, see riscv_nn_types.

  • buffers[in] Struct containg pointers to all temporary scratch buffers needed for the lstm operator, see riscv_nn_types.

  • batch_offset[in] Number of timesteps between consecutive batches. E.g for params->timing_major = true, all batches for t=0 are stored sequentially, so batch offset = 1. For params->time major = false, all time steps are stored continously before the next batch, so batch offset = params->time_steps.

Returns

The function returns RISCV_NMSIS_NN_SUCCESS

riscv_nmsis_nn_status riscv_nn_vec_mat_mul_result_acc_s8_s16(const int8_t *lhs, const int8_t *rhs, const int32_t *effective_bias, int16_t *dst, const int32_t dst_multiplier, const int32_t dst_shift, const int32_t rhs_cols, const int32_t rhs_rows, const int32_t batches, const int32_t batch_offset)

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] Batched vector

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

  • effective_bias[in] Bias + lhs_offset * kernel_sum term precalculated into a constant vector.

  • dst[out] Output

  • 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

  • batches[in] Batch size

  • batch_offset[in] Number of timesteps between consecutive batches in input, see riscv_nn_lstm_step_s8. Note that the output is always stored with sequential batches.

Returns

The function returns RISCV_NMSIS_NN_SUCCESS