Skip to content

Commit

Permalink
Merge pull request #91 from tum-ei-eda/fix-integration
Browse files Browse the repository at this point in the history
Fix integration
  • Loading branch information
PhilippvK authored Nov 2, 2024
2 parents 3454f4e + b0fa666 commit 5474a6a
Show file tree
Hide file tree
Showing 27 changed files with 2,910 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
matrix:
tflm_ref:
- main # latest upstream
- 19aaea85e4679a9a2f265e07ba190ac5ea4d3766 # Last working commit (needs to be updated manually)
- 8eb6b23de4470d6a8da3131650d6a67514dfa130 # Last working commit (needs to be updated manually)
config:
- {vext: "OFF", portable: "OFF", pext: "OFF", mode: "release_with_logs", toolchain: "gcc", arch: "native", vlen: 0, elen: 64, sim: "Native"}
- {vext: "OFF", portable: "OFF", pext: "OFF", mode: "release_with_logs", toolchain: "gcc", arch: "rv32gc", vlen: 0, elen: 64, sim: "Spike"}
Expand Down Expand Up @@ -227,7 +227,7 @@ jobs:
matrix:
tflm_ref:
- main # latest upstream
- 19aaea85e4679a9a2f265e07ba190ac5ea4d3766 # Last working commit (needs to be updated manually)
- 8eb6b23de4470d6a8da3131650d6a67514dfa130 # Last working commit (needs to be updated manually)
config:
- {vext_flag: "", portable_flag: "", pext_flag: "", toolchain: "x86", arch: "", vlen: 0, elen: 0, sim: "Native"}
- {vext_flag: "", portable_flag: "", pext_flag: "", toolchain: "GCC", arch: "rv32gc", vlen: 0, elen: 0, sim: "Spike"}
Expand Down
2 changes: 2 additions & 0 deletions Include/CMSIS/NN/Include/arm_nn_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ extern "C" {
#define cmsis_nn_bias_data muriscv_nn_bias_data
#define cmsis_nn_per_channel_quant_params muriscv_nn_per_channel_quant_params
#define cmsis_nn_per_tensor_quant_params muriscv_nn_per_tensor_quant_params
#define cmsis_nn_quant_params muriscv_nn_quant_params
#define cmsis_nn_activation muriscv_nn_activation
#define cmsis_nn_conv_params muriscv_nn_conv_params
#define cmsis_nn_dw_conv_params muriscv_nn_dw_conv_params
#define cmsis_nn_pool_params muriscv_nn_pool_params
#define cmsis_nn_fc_params muriscv_nn_fc_params
#define cmsis_nn_svdf_params muriscv_nn_svdf_params
#define cmsis_nn_softmax_lut_s16 muriscv_nn_softmax_lut_s16
#define cmsis_nn_bmm_params muriscv_nn_bmm_params

#define cmsis_nn_lstm_params muriscv_nn_lstm_params
#define cmsis_nn_lstm_context muriscv_nn_lstm_context
Expand Down
8 changes: 8 additions & 0 deletions Include/CMSIS/NN/Include/arm_nnfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ extern "C" {
#define arm_depthwise_conv_s4_opt_get_buffer_size muriscv_nn_depthwise_conv_s4_opt_get_buffer_size
#define arm_fully_connected_s4 muriscv_nn_fully_connected_s4
#define arm_fully_connected_s8 muriscv_nn_fully_connected_s8
#define arm_fully_connected_per_channel_s8 muriscv_nn_fully_connected_per_channel_s8
#define arm_fully_connected_wrapper_s8 muriscv_nn_fully_connected_wrapper_s8
#define arm_vector_sum_s8 muriscv_nn_vector_sum_s8
#define arm_vector_sum_s8_s64 muriscv_nn_vector_sum_s8_s64
#define arm_fully_connected_s8_get_buffer_size muriscv_nn_fully_connected_s8_get_buffer_size
Expand Down Expand Up @@ -122,6 +124,7 @@ extern "C" {
#define arm_softmax_s16 muriscv_nn_softmax_s16
#define arm_softmax_u8 muriscv_nn_softmax_u8
#define arm_reshape_s8 muriscv_nn_reshape_s8
#define arm_transpose_s8 muriscv_nn_transpose_s8
#define arm_concatenation_s8_x muriscv_nn_concatenation_s8_x
#define arm_concatenation_s8_y muriscv_nn_concatenation_s8_y
#define arm_concatenation_s8_z muriscv_nn_concatenation_s8_z
Expand All @@ -133,6 +136,11 @@ extern "C" {
#define arm_svdf_s8_get_buffer_size_mve muriscv_nn_svdf_s8_get_buffer_size_mve
#define arm_lstm_unidirectional_s8 muriscv_nn_lstm_unidirectional_s8
#define arm_lstm_unidirectional_s16 muriscv_nn_lstm_unidirectional_s16
#define arm_batch_matmul_s8 muriscv_nn_batch_matmul_s8
#define arm_batch_matmul_s16 muriscv_nn_batch_matmul_s16
#define arm_pad_s8 muriscv_nn_pad_s8
#define arm_minimum_s8 muriscv_nn_minimum_s8
#define arm_maximum_s8 muriscv_nn_maximum_s8
#ifdef __cplusplus
}
#endif
Expand Down
291 changes: 286 additions & 5 deletions Include/muriscv_nn_functions.h

Large diffs are not rendered by default.

95 changes: 92 additions & 3 deletions Include/muriscv_nn_support_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* Title: muriscv_nn_support_functions.h
* Description: Public header file of support functions for MURISCV NN Library
*
* $Date: 27 May 2024
* $Revision: V.22.1.0
* $Date: 08 October 2024
* $Revision: V.22.4.0
*
* Target : Arm(R) M-Profile Architecture
* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -849,7 +849,48 @@ muriscv_nn_status muriscv_nn_vec_mat_mult_t_s8(const int8_t *lhs,
const int32_t rhs_offset);

/**
* @brief s16 Vector by Matrix (transposed) multiplication
* @brief s8 Vector by Matrix (transposed) multiplication using per channel quantization for output
*
* @param[in] lhs Input left-hand side vector
* @param[in] rhs Input right-hand side matrix (transposed)
* @param[in] kernel_sum Kernel sums of the kernels (rhs). See muriscv_nn_vector_sum_s8 for more info.
* @param[in] bias Input bias
* @param[out] dst Output vector
* @param[in] lhs_offset Offset to be added to the input values of the left-hand side vector.
* Range: -127 to 128
* @param[in] dst_offset Offset to be added to the output values. Range: -127 to 128
* @param[in] dst_multiplier Output multipliers
* @param[in] dst_shift Output shifts
* @param[in] rhs_cols Number of columns in the right-hand side input matrix
* @param[in] rhs_rows Number of rows in the right-hand side input matrix
* @param[in] activation_min Minimum value to clamp the output to. Range: int8
* @param[in] activation_max Maximum value to clamp the output to. Range: int8
* @param[in] address_offset Memory position offset for dst. First output is stored at 'dst', the
* second at 'dst + address_offset' and so on. Default value is typically 1.
* @param[in] rhs_offset Offset to be added to the input values of the right-hand side vector.
* Range: -127 to 128
*
* @return The function returns <code>MURISCV_NN_SUCCESS</code>
*
*/
muriscv_nn_status muriscv_nn_vec_mat_mult_t_per_ch_s8(const int8_t *lhs,
const int8_t *rhs,
const int32_t *kernel_sum,
const int32_t *bias,
int8_t *dst,
const int32_t lhs_offset,
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 activation_min,
const int32_t activation_max,
const int32_t address_offset,
const int32_t rhs_offset);

/**
* @brief s16 Vector by s8 Matrix (transposed) multiplication
*
* @param[in] lhs Input left-hand side vector
* @param[in] rhs Input right-hand side matrix (transposed)
Expand All @@ -876,6 +917,34 @@ muriscv_nn_status muriscv_nn_vec_mat_mult_t_s16(const int16_t *lhs,
const int32_t activation_min,
const int32_t activation_max);

/**
* @brief s16 Vector by s16 Matrix (transposed) multiplication
*
* @param[in] lhs Input left-hand side vector
* @param[in] rhs Input right-hand side matrix (transposed)
* @param[in] bias Input bias
* @param[out] dst Output vector
* @param[in] dst_multiplier Output multiplier
* @param[in] dst_shift Output shift
* @param[in] rhs_cols Number of columns in the right-hand side input matrix
* @param[in] rhs_rows Number of rows in the right-hand side input matrix
* @param[in] activation_min Minimum value to clamp the output to. Range: int16
* @param[in] activation_max Maximum value to clamp the output to. Range: int16
*
* @return The function returns <code>MURISCV_NN_SUCCESS</code>
*
*/
muriscv_nn_status muriscv_nn_vec_mat_mult_t_s16_s16(const int16_t *lhs,
const int16_t *rhs,
const int64_t *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 activation_min,
const int32_t activation_max);

/**
* @brief s8 Vector by Matrix (transposed) multiplication with s16 output
*
Expand Down Expand Up @@ -2488,6 +2557,26 @@ muriscv_nn_status muriscv_nn_elementwise_mul_acc_s16(const int16_t *input_1_vect
const int32_t out_activation_max,
const int32_t block_size);

/**
* @brief Check if a broadcast is required between 2 muriscv_nn_dims.
* @param[in] shape_1 pointer to input tensor 1
* @param[in] shape_2 pointer to input tensor 2
* @return The function returns 1 if a broadcast is required, or 0 if not.
*
* @details Compares each dimension and returns 1 if any dimension does not match.
* This function does not check that broadcast rules are met.
*/
__STATIC_FORCEINLINE int32_t muriscv_nn_check_broadcast_required(const muriscv_nn_dims *shape_1, const muriscv_nn_dims *shape_2)
{
if ((shape_1->n != shape_2->n) || (shape_1->h != shape_2->h) || (shape_1->w != shape_2->w) ||
(shape_1->c != shape_2->c))
{
return 1;
}

return 0;
}

#ifdef __cplusplus
}
#endif
Expand Down
26 changes: 26 additions & 0 deletions Include/muriscv_nn_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ typedef struct
int32_t shift; /**< Shift value */
} muriscv_nn_per_tensor_quant_params;

/** MURISCV-NN object for quantization parameters.
* This struct supports both per-tensor and per-channels requantization
* and is recommended for new operators.
*/
typedef struct
{
int32_t *multiplier; /**< Multiplier values */
int32_t *shift; /**< Shift values */
int32_t is_per_channel; /** Indicating if per channel or per tensor quantization */
} muriscv_nn_quant_params;

/** MURISCV-NN object for the quantized Relu activation */
typedef struct
{
Expand Down Expand Up @@ -148,6 +159,21 @@ typedef struct
muriscv_nn_activation activation;
} muriscv_nn_fc_params;

/** MURISCV-NN object for Batch Matmul layer parameters */
typedef struct
{
const bool adj_x;
const bool adj_y;
muriscv_nn_fc_params fc_params;
} muriscv_nn_bmm_params;

/** MURISCV-NN object for Transpose layer parameters */
typedef struct
{
const int32_t num_dims;
const uint32_t *permutations; /**< The dimensions applied to the input dimensions */
} muriscv_nn_transpose_params;

/** MURISCV-NN object for SVDF layer parameters */
typedef struct
{
Expand Down
4 changes: 2 additions & 2 deletions Integration/tflm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ set(TFLM_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/micro/micro_log.cc
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/micro/tflite_bridge/flatbuffer_conversions_bridge.h
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/micro/tflite_bridge/flatbuffer_conversions_bridge.cc
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api/error_reporter.cc
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api/error_reporter.h
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/compiler/mlir/lite/core/api/error_reporter.cc
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/compiler/mlir/lite/core/api/error_reporter.h
# ${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api/op_resolver.cc
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api/flatbuffer_conversions.cc
${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api/tensor_utils.h
Expand Down
2 changes: 2 additions & 0 deletions Integration/tflm/download_tflm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ set -euo pipefail
# Path to this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

TFLM_REF=${TFLM_REF:-""}

echo "Download TFLM sources."
if [ ! -d "tflite-micro" ]; then
git clone https://github.com/tensorflow/tflite-micro.git
Expand Down
4 changes: 3 additions & 1 deletion Source/BasicMathFunctions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ target_sources(${MURISCVNN_LIB} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_e
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_elementwise_mul_s16.c
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_elementwise_mul_s16_s8.c
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_elementwise_mul_acc_s16.c
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_elementwise_mul_s16_batch_offset.c)
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_elementwise_mul_s16_batch_offset.c
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_maximum_s8.c
${CMAKE_CURRENT_SOURCE_DIR}/muriscv_nn_minimum_s8.c)
Loading

0 comments on commit 5474a6a

Please sign in to comment.