forked from ARM-software/CMSIS-NN
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement arm_lstm_unidirectional_s8 (ARM-software#102)
- API changes - Optimized for scalar, DSP and MVE - Bit exact to TFLM reference kernel - Less scratch-buffer usage
- Loading branch information
1 parent
ffeca90
commit 601d96c
Showing
133 changed files
with
1,830 additions
and
1,889 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <[email protected]> | ||
* SPDX-FileCopyrightText: Copyright 2020-2024 Arm Limited and/or its affiliates <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
|
@@ -22,8 +22,8 @@ | |
* Description: Public header file to contain the CMSIS-NN structs for the | ||
* TensorFlowLite micro compliant functions | ||
* | ||
* $Date: 9 January 2024 | ||
* $Revision: V.2.6.2 | ||
* $Date: 19 January 2024 | ||
* $Revision: V.3.0.0 | ||
* | ||
* Target : Arm(R) M-Profile Architecture | ||
* -------------------------------------------------------------------- */ | ||
|
@@ -40,7 +40,6 @@ | |
* @{ | ||
*/ | ||
|
||
|
||
/** Enum for specifying activation function types */ | ||
typedef enum | ||
{ | ||
|
@@ -180,102 +179,67 @@ typedef struct | |
const int16_t *one_by_one_lut; | ||
} cmsis_nn_softmax_lut_s16; | ||
|
||
/** LSTM guard parameters */ | ||
typedef struct | ||
{ | ||
int32_t input_variance; | ||
int32_t forget_variance; | ||
int32_t cell_variance; | ||
int32_t output_variance; | ||
} cmsis_nn_lstm_guard_params; | ||
|
||
/** LSTM scratch buffer container */ | ||
typedef struct | ||
{ | ||
int16_t *input_gate; | ||
int16_t *forget_gate; | ||
int16_t *cell_gate; | ||
int16_t *output_gate; | ||
} cmsis_nn_lstm_context; | ||
|
||
/** Quantized clip value for cell and projection of LSTM input. Zero value means no clipping. */ | ||
typedef struct | ||
{ | ||
int16_t cell; | ||
int8_t projection; | ||
} cmsis_nn_lstm_clip_params; | ||
|
||
/** CMSIS-NN object for quantization parameters */ | ||
typedef struct | ||
{ | ||
int32_t multiplier; /**< Multiplier value */ | ||
int32_t shift; /**< Shift value */ | ||
} cmsis_nn_scaling; | ||
|
||
/** CMSIS-NN norm layer coefficients */ | ||
/** CMSIS-NN object for LSTM gate parameters*/ | ||
typedef struct | ||
{ | ||
int16_t *input_weight; | ||
int16_t *forget_weight; | ||
int16_t *cell_weight; | ||
int16_t *output_weight; | ||
} cmsis_nn_layer_norm; | ||
int32_t input_multiplier; | ||
int32_t input_shift; | ||
const int8_t *input_weights; | ||
const int32_t *input_effective_bias; /**< Bias added with precomputed kernel_sum * lhs_offset*/ | ||
|
||
/** Parameters for integer LSTM, as defined in TFLM */ | ||
int32_t hidden_multiplier; | ||
int32_t hidden_shift; | ||
const int8_t *hidden_weights; | ||
const int32_t *hidden_effective_bias; /**< Precomputed kernel_sum * lhs_offset*/ | ||
|
||
const int32_t *bias; | ||
arm_nn_activation_type activation_type; | ||
} cmsis_nn_lstm_gate; | ||
|
||
/** CMSIS-NN object for LSTM parameters*/ | ||
typedef struct | ||
{ | ||
int32_t time_major; /**< Nonzero (true) if first row of data is timestamps for input */ | ||
cmsis_nn_scaling input_to_input_scaling; | ||
cmsis_nn_scaling input_to_forget_scaling; | ||
cmsis_nn_scaling input_to_cell_scaling; | ||
cmsis_nn_scaling input_to_output_scaling; | ||
cmsis_nn_scaling recurrent_to_input_scaling; | ||
cmsis_nn_scaling recurrent_to_forget_scaling; | ||
cmsis_nn_scaling recurrent_to_cell_scaling; | ||
cmsis_nn_scaling recurrent_to_output_scaling; | ||
cmsis_nn_scaling cell_to_input_scaling; | ||
cmsis_nn_scaling cell_to_forget_scaling; | ||
cmsis_nn_scaling cell_to_output_scaling; | ||
cmsis_nn_scaling projection_scaling; | ||
cmsis_nn_scaling hidden_scaling; | ||
cmsis_nn_scaling layer_norm_input_scaling; /**< layer normalization for input layer */ | ||
cmsis_nn_scaling layer_norm_forget_scaling; /**< layer normalization for forget gate */ | ||
cmsis_nn_scaling layer_norm_cell_scaling; /**< layer normalization for cell */ | ||
cmsis_nn_scaling layer_norm_output_scaling; /**< layer normalization for outpus layer */ | ||
|
||
int32_t cell_state_shift; | ||
int32_t hidden_offset; | ||
int32_t output_state_offset; | ||
|
||
cmsis_nn_lstm_clip_params clip; | ||
cmsis_nn_lstm_guard_params guard; | ||
cmsis_nn_layer_norm layer_norm; | ||
|
||
/* Effective bias is precalculated as bias + zero_point * weight. | ||
Only applicable to when input/output are s8 and weights are s16 */ | ||
const int32_t *i2i_effective_bias; /**< input to input effective bias */ | ||
const int32_t *i2f_effective_bias; /**< input to forget gate effective bias */ | ||
const int32_t *i2c_effective_bias; /**< input to cell effective bias */ | ||
const int32_t *i2o_effective_bias; /**< input to output effective bias */ | ||
|
||
const int32_t *r2i_effective_bias; /**< recurrent gate to input effective bias */ | ||
const int32_t *r2f_effective_bias; /**< recurrent gate to forget gate effective bias */ | ||
const int32_t *r2c_effective_bias; /**< recurrent gate to cell effective bias */ | ||
const int32_t *r2o_effective_bias; /**< recurrent gate to output effective bias */ | ||
|
||
const int32_t *projection_effective_bias; | ||
|
||
/* Not precalculated bias */ | ||
const int32_t *input_gate_bias; | ||
const int32_t *forget_gate_bias; | ||
const int32_t *cell_gate_bias; | ||
const int32_t *output_gate_bias; | ||
|
||
/* Activation min and max */ | ||
cmsis_nn_activation activation; | ||
int32_t time_major; /**< 0 if first dimension is batch, else first dimension is time */ | ||
int32_t batch_size; | ||
int32_t time_steps; | ||
int32_t input_size; /**< Size of new data input into the LSTM cell*/ | ||
int32_t | ||
hidden_size; /**< Size of output from the LSTM cell, used as output and recursively into the next time step*/ | ||
|
||
int32_t input_offset; | ||
|
||
int32_t forget_to_cell_multiplier; | ||
int32_t forget_to_cell_shift; | ||
int32_t input_to_cell_multiplier; | ||
int32_t input_to_cell_shift; | ||
int32_t cell_clip; /**< Min/max value of cell output*/ | ||
int32_t cell_scale_power; | ||
|
||
int32_t output_multiplier; | ||
int32_t output_shift; | ||
int32_t output_offset; | ||
|
||
cmsis_nn_lstm_gate forget_gate; | ||
cmsis_nn_lstm_gate input_gate; | ||
cmsis_nn_lstm_gate cell_gate; | ||
cmsis_nn_lstm_gate output_gate; | ||
} cmsis_nn_lstm_params; | ||
|
||
/** CMSIS-NN object for LSTM scratch buffers*/ | ||
typedef struct | ||
{ | ||
void *temp1; | ||
void *temp2; | ||
void *cell_state; | ||
} cmsis_nn_lstm_context; | ||
|
||
/** | ||
* @} // end group genPubTypes | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.