Skip to content

Commit

Permalink
Update CMSIS-NN vector_sum_s8 calls to new API (#2685)
Browse files Browse the repository at this point in the history
BUG=Add rhs_offset argument
  • Loading branch information
AdrianLundell authored Sep 17, 2024
1 parent 89f99a9 commit 6147f20
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions tensorflow/lite/micro/kernels/cmsis_nn/fully_connected.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
data->kernel_sums = static_cast<int32_t*>(
context->AllocatePersistentBuffer(context, buf_size));

int32_t input_offset = -data->reference_op_data.input_zero_point;
int32_t filter_offset = -data->reference_op_data.filter_zero_point;
arm_vector_sum_s8(data->kernel_sums, filter_dims.n, data->output_depth,
filter_data, 1, nullptr);
filter_data, input_offset, filter_offset,
tflite::GetTensorData<int32_t>(bias));

// Do not request a scratch buffer since using persistent memory
buf_size = 0;
Expand Down Expand Up @@ -321,7 +324,8 @@ TfLiteStatus EvalQuantizedInt8(TfLiteContext* context, TfLiteNode* node,
// If behaving like batch matmul we calculate kernel sums in eval.
arm_vector_sum_s8(
static_cast<int32_t*>(ctx.buf), filter_dims.n, data.output_depth,
tflite::micro::GetTensorData<int8_t>(filter), 1, nullptr);
tflite::micro::GetTensorData<int8_t>(filter), fc_params.input_offset,
fc_params.filter_offset, bias_data);
}

TF_LITE_ENSURE_EQ(
Expand Down
4 changes: 3 additions & 1 deletion tensorflow/lite/micro/kernels/cmsis_nn/svdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ TfLiteStatus CmsisNnPrepareSvdf(TfLiteContext* context, TfLiteNode* node) {
context->AllocatePersistentBuffer(context, buf_size));

arm_vector_sum_s8(data->kernel_sums, input_size, num_filters,
GetTensorData<int8_t>(weights_feature), 1, nullptr);
GetTensorData<int8_t>(weights_feature),
-data->input_zero_point,
-data->activation_state_zero_point, nullptr);
}

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ LSTMBuffers<int16_t> CMSIS_NN_CreateLSTMBuffers(TfLiteContext* context,
void CMSIS_NN_VectorSum(int32_t* kernel_sum, const int32_t size1,
const int32_t size2, const int8_t* weights,
const int32_t offset, const int32_t* biases) {
arm_vector_sum_s8(kernel_sum, size1, size2, weights, offset, biases);
arm_vector_sum_s8(kernel_sum, size1, size2, weights, offset, 0, biases);
}

void CMSIS_NN_VectorSum(int64_t* kernel_sum, const int32_t size1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ source ${TENSORFLOW_ROOT}tensorflow/lite/micro/tools/make/bash_helpers.sh
DOWNLOADS_DIR=${1}
DOWNLOADED_CMSIS_NN_PATH=${DOWNLOADS_DIR}/cmsis_nn

ZIP_PREFIX_NN="95f293df19c9a38806868fe12a64a4f9b457f9c1"
ZIP_PREFIX_NN="f2cb41ca1450a4eb4307b2779dd5aae9028285a5"
CMSIS_NN_URL="http://github.com/ARM-software/CMSIS-NN/archive/${ZIP_PREFIX_NN}.zip"
CMSIS_NN_MD5="5e0c4cd60a5f074c4d26d1be236caefd"
CMSIS_NN_MD5="4d0e623432d6f8d3b201cbcd89218adf"

should_download=$(check_should_download ${DOWNLOADS_DIR})

Expand Down

0 comments on commit 6147f20

Please sign in to comment.