Skip to content

Commit 5474a6a

Browse files
authored
Merge pull request #91 from tum-ei-eda/fix-integration
Fix integration
2 parents 3454f4e + b0fa666 commit 5474a6a

27 files changed

+2910
-17
lines changed

.github/workflows/integration_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
matrix:
3030
tflm_ref:
3131
- main # latest upstream
32-
- 19aaea85e4679a9a2f265e07ba190ac5ea4d3766 # Last working commit (needs to be updated manually)
32+
- 8eb6b23de4470d6a8da3131650d6a67514dfa130 # Last working commit (needs to be updated manually)
3333
config:
3434
- {vext: "OFF", portable: "OFF", pext: "OFF", mode: "release_with_logs", toolchain: "gcc", arch: "native", vlen: 0, elen: 64, sim: "Native"}
3535
- {vext: "OFF", portable: "OFF", pext: "OFF", mode: "release_with_logs", toolchain: "gcc", arch: "rv32gc", vlen: 0, elen: 64, sim: "Spike"}
@@ -227,7 +227,7 @@ jobs:
227227
matrix:
228228
tflm_ref:
229229
- main # latest upstream
230-
- 19aaea85e4679a9a2f265e07ba190ac5ea4d3766 # Last working commit (needs to be updated manually)
230+
- 8eb6b23de4470d6a8da3131650d6a67514dfa130 # Last working commit (needs to be updated manually)
231231
config:
232232
- {vext_flag: "", portable_flag: "", pext_flag: "", toolchain: "x86", arch: "", vlen: 0, elen: 0, sim: "Native"}
233233
- {vext_flag: "", portable_flag: "", pext_flag: "", toolchain: "GCC", arch: "rv32gc", vlen: 0, elen: 0, sim: "Spike"}

Include/CMSIS/NN/Include/arm_nn_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ extern "C" {
3232
#define cmsis_nn_bias_data muriscv_nn_bias_data
3333
#define cmsis_nn_per_channel_quant_params muriscv_nn_per_channel_quant_params
3434
#define cmsis_nn_per_tensor_quant_params muriscv_nn_per_tensor_quant_params
35+
#define cmsis_nn_quant_params muriscv_nn_quant_params
3536
#define cmsis_nn_activation muriscv_nn_activation
3637
#define cmsis_nn_conv_params muriscv_nn_conv_params
3738
#define cmsis_nn_dw_conv_params muriscv_nn_dw_conv_params
3839
#define cmsis_nn_pool_params muriscv_nn_pool_params
3940
#define cmsis_nn_fc_params muriscv_nn_fc_params
4041
#define cmsis_nn_svdf_params muriscv_nn_svdf_params
4142
#define cmsis_nn_softmax_lut_s16 muriscv_nn_softmax_lut_s16
43+
#define cmsis_nn_bmm_params muriscv_nn_bmm_params
4244

4345
#define cmsis_nn_lstm_params muriscv_nn_lstm_params
4446
#define cmsis_nn_lstm_context muriscv_nn_lstm_context

Include/CMSIS/NN/Include/arm_nnfunctions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ extern "C" {
9090
#define arm_depthwise_conv_s4_opt_get_buffer_size muriscv_nn_depthwise_conv_s4_opt_get_buffer_size
9191
#define arm_fully_connected_s4 muriscv_nn_fully_connected_s4
9292
#define arm_fully_connected_s8 muriscv_nn_fully_connected_s8
93+
#define arm_fully_connected_per_channel_s8 muriscv_nn_fully_connected_per_channel_s8
94+
#define arm_fully_connected_wrapper_s8 muriscv_nn_fully_connected_wrapper_s8
9395
#define arm_vector_sum_s8 muriscv_nn_vector_sum_s8
9496
#define arm_vector_sum_s8_s64 muriscv_nn_vector_sum_s8_s64
9597
#define arm_fully_connected_s8_get_buffer_size muriscv_nn_fully_connected_s8_get_buffer_size
@@ -122,6 +124,7 @@ extern "C" {
122124
#define arm_softmax_s16 muriscv_nn_softmax_s16
123125
#define arm_softmax_u8 muriscv_nn_softmax_u8
124126
#define arm_reshape_s8 muriscv_nn_reshape_s8
127+
#define arm_transpose_s8 muriscv_nn_transpose_s8
125128
#define arm_concatenation_s8_x muriscv_nn_concatenation_s8_x
126129
#define arm_concatenation_s8_y muriscv_nn_concatenation_s8_y
127130
#define arm_concatenation_s8_z muriscv_nn_concatenation_s8_z
@@ -133,6 +136,11 @@ extern "C" {
133136
#define arm_svdf_s8_get_buffer_size_mve muriscv_nn_svdf_s8_get_buffer_size_mve
134137
#define arm_lstm_unidirectional_s8 muriscv_nn_lstm_unidirectional_s8
135138
#define arm_lstm_unidirectional_s16 muriscv_nn_lstm_unidirectional_s16
139+
#define arm_batch_matmul_s8 muriscv_nn_batch_matmul_s8
140+
#define arm_batch_matmul_s16 muriscv_nn_batch_matmul_s16
141+
#define arm_pad_s8 muriscv_nn_pad_s8
142+
#define arm_minimum_s8 muriscv_nn_minimum_s8
143+
#define arm_maximum_s8 muriscv_nn_maximum_s8
136144
#ifdef __cplusplus
137145
}
138146
#endif

Include/muriscv_nn_functions.h

Lines changed: 286 additions & 5 deletions
Large diffs are not rendered by default.

Include/muriscv_nn_support_functions.h

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
* Title: muriscv_nn_support_functions.h
2323
* Description: Public header file of support functions for MURISCV NN Library
2424
*
25-
* $Date: 27 May 2024
26-
* $Revision: V.22.1.0
25+
* $Date: 08 October 2024
26+
* $Revision: V.22.4.0
2727
*
2828
* Target : Arm(R) M-Profile Architecture
2929
* -------------------------------------------------------------------- */
@@ -849,7 +849,48 @@ muriscv_nn_status muriscv_nn_vec_mat_mult_t_s8(const int8_t *lhs,
849849
const int32_t rhs_offset);
850850

851851
/**
852-
* @brief s16 Vector by Matrix (transposed) multiplication
852+
* @brief s8 Vector by Matrix (transposed) multiplication using per channel quantization for output
853+
*
854+
* @param[in] lhs Input left-hand side vector
855+
* @param[in] rhs Input right-hand side matrix (transposed)
856+
* @param[in] kernel_sum Kernel sums of the kernels (rhs). See muriscv_nn_vector_sum_s8 for more info.
857+
* @param[in] bias Input bias
858+
* @param[out] dst Output vector
859+
* @param[in] lhs_offset Offset to be added to the input values of the left-hand side vector.
860+
* Range: -127 to 128
861+
* @param[in] dst_offset Offset to be added to the output values. Range: -127 to 128
862+
* @param[in] dst_multiplier Output multipliers
863+
* @param[in] dst_shift Output shifts
864+
* @param[in] rhs_cols Number of columns in the right-hand side input matrix
865+
* @param[in] rhs_rows Number of rows in the right-hand side input matrix
866+
* @param[in] activation_min Minimum value to clamp the output to. Range: int8
867+
* @param[in] activation_max Maximum value to clamp the output to. Range: int8
868+
* @param[in] address_offset Memory position offset for dst. First output is stored at 'dst', the
869+
* second at 'dst + address_offset' and so on. Default value is typically 1.
870+
* @param[in] rhs_offset Offset to be added to the input values of the right-hand side vector.
871+
* Range: -127 to 128
872+
*
873+
* @return The function returns <code>MURISCV_NN_SUCCESS</code>
874+
*
875+
*/
876+
muriscv_nn_status muriscv_nn_vec_mat_mult_t_per_ch_s8(const int8_t *lhs,
877+
const int8_t *rhs,
878+
const int32_t *kernel_sum,
879+
const int32_t *bias,
880+
int8_t *dst,
881+
const int32_t lhs_offset,
882+
const int32_t dst_offset,
883+
const int32_t *dst_multiplier,
884+
const int32_t *dst_shift,
885+
const int32_t rhs_cols,
886+
const int32_t rhs_rows,
887+
const int32_t activation_min,
888+
const int32_t activation_max,
889+
const int32_t address_offset,
890+
const int32_t rhs_offset);
891+
892+
/**
893+
* @brief s16 Vector by s8 Matrix (transposed) multiplication
853894
*
854895
* @param[in] lhs Input left-hand side vector
855896
* @param[in] rhs Input right-hand side matrix (transposed)
@@ -876,6 +917,34 @@ muriscv_nn_status muriscv_nn_vec_mat_mult_t_s16(const int16_t *lhs,
876917
const int32_t activation_min,
877918
const int32_t activation_max);
878919

920+
/**
921+
* @brief s16 Vector by s16 Matrix (transposed) multiplication
922+
*
923+
* @param[in] lhs Input left-hand side vector
924+
* @param[in] rhs Input right-hand side matrix (transposed)
925+
* @param[in] bias Input bias
926+
* @param[out] dst Output vector
927+
* @param[in] dst_multiplier Output multiplier
928+
* @param[in] dst_shift Output shift
929+
* @param[in] rhs_cols Number of columns in the right-hand side input matrix
930+
* @param[in] rhs_rows Number of rows in the right-hand side input matrix
931+
* @param[in] activation_min Minimum value to clamp the output to. Range: int16
932+
* @param[in] activation_max Maximum value to clamp the output to. Range: int16
933+
*
934+
* @return The function returns <code>MURISCV_NN_SUCCESS</code>
935+
*
936+
*/
937+
muriscv_nn_status muriscv_nn_vec_mat_mult_t_s16_s16(const int16_t *lhs,
938+
const int16_t *rhs,
939+
const int64_t *bias,
940+
int16_t *dst,
941+
const int32_t dst_multiplier,
942+
const int32_t dst_shift,
943+
const int32_t rhs_cols,
944+
const int32_t rhs_rows,
945+
const int32_t activation_min,
946+
const int32_t activation_max);
947+
879948
/**
880949
* @brief s8 Vector by Matrix (transposed) multiplication with s16 output
881950
*
@@ -2488,6 +2557,26 @@ muriscv_nn_status muriscv_nn_elementwise_mul_acc_s16(const int16_t *input_1_vect
24882557
const int32_t out_activation_max,
24892558
const int32_t block_size);
24902559

2560+
/**
2561+
* @brief Check if a broadcast is required between 2 muriscv_nn_dims.
2562+
* @param[in] shape_1 pointer to input tensor 1
2563+
* @param[in] shape_2 pointer to input tensor 2
2564+
* @return The function returns 1 if a broadcast is required, or 0 if not.
2565+
*
2566+
* @details Compares each dimension and returns 1 if any dimension does not match.
2567+
* This function does not check that broadcast rules are met.
2568+
*/
2569+
__STATIC_FORCEINLINE int32_t muriscv_nn_check_broadcast_required(const muriscv_nn_dims *shape_1, const muriscv_nn_dims *shape_2)
2570+
{
2571+
if ((shape_1->n != shape_2->n) || (shape_1->h != shape_2->h) || (shape_1->w != shape_2->w) ||
2572+
(shape_1->c != shape_2->c))
2573+
{
2574+
return 1;
2575+
}
2576+
2577+
return 0;
2578+
}
2579+
24912580
#ifdef __cplusplus
24922581
}
24932582
#endif

Include/muriscv_nn_types.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ typedef struct
8989
int32_t shift; /**< Shift value */
9090
} muriscv_nn_per_tensor_quant_params;
9191

92+
/** MURISCV-NN object for quantization parameters.
93+
* This struct supports both per-tensor and per-channels requantization
94+
* and is recommended for new operators.
95+
*/
96+
typedef struct
97+
{
98+
int32_t *multiplier; /**< Multiplier values */
99+
int32_t *shift; /**< Shift values */
100+
int32_t is_per_channel; /** Indicating if per channel or per tensor quantization */
101+
} muriscv_nn_quant_params;
102+
92103
/** MURISCV-NN object for the quantized Relu activation */
93104
typedef struct
94105
{
@@ -148,6 +159,21 @@ typedef struct
148159
muriscv_nn_activation activation;
149160
} muriscv_nn_fc_params;
150161

162+
/** MURISCV-NN object for Batch Matmul layer parameters */
163+
typedef struct
164+
{
165+
const bool adj_x;
166+
const bool adj_y;
167+
muriscv_nn_fc_params fc_params;
168+
} muriscv_nn_bmm_params;
169+
170+
/** MURISCV-NN object for Transpose layer parameters */
171+
typedef struct
172+
{
173+
const int32_t num_dims;
174+
const uint32_t *permutations; /**< The dimensions applied to the input dimensions */
175+
} muriscv_nn_transpose_params;
176+
151177
/** MURISCV-NN object for SVDF layer parameters */
152178
typedef struct
153179
{

Integration/tflm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ set(TFLM_SRCS
271271
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/micro/micro_log.cc
272272
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/micro/tflite_bridge/flatbuffer_conversions_bridge.h
273273
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/micro/tflite_bridge/flatbuffer_conversions_bridge.cc
274-
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api/error_reporter.cc
275-
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api/error_reporter.h
274+
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/compiler/mlir/lite/core/api/error_reporter.cc
275+
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/compiler/mlir/lite/core/api/error_reporter.h
276276
# ${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api/op_resolver.cc
277277
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api/flatbuffer_conversions.cc
278278
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api/tensor_utils.h

Integration/tflm/download_tflm.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ set -euo pipefail
2323
# Path to this script
2424
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2525

26+
TFLM_REF=${TFLM_REF:-""}
27+
2628
echo "Download TFLM sources."
2729
if [ ! -d "tflite-micro" ]; then
2830
git clone https://github.com/tensorflow/tflite-micro.git

Source/BasicMathFunctions/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ target_sources(${MURISCVNN_LIB} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_e
2424
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_elementwise_mul_s16.c
2525
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_elementwise_mul_s16_s8.c
2626
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_elementwise_mul_acc_s16.c
27-
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_elementwise_mul_s16_batch_offset.c)
27+
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_elementwise_mul_s16_batch_offset.c
28+
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_maximum_s8.c
29+
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_minimum_s8.c)

0 commit comments

Comments
 (0)