Skip to content

Commit

Permalink
Add non zero filter offset support for FC (#110)
Browse files Browse the repository at this point in the history
Fully connected can handle a non zero filter offset. Added a unit test
as well.

Co-authored-by: Adrian Lundell <adrian.lundell@arm.com>
  • Loading branch information
mansnils and AdrianLundell authored Feb 22, 2024
1 parent 1e0f44c commit 72e1ebf
Show file tree
Hide file tree
Showing 19 changed files with 835 additions and 294 deletions.
9 changes: 6 additions & 3 deletions Include/arm_nnsupportfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* Title: arm_nnsupportfunctions.h
* Description: Public header file of support functions for CMSIS NN Library
*
* $Date: 31 January 2024
* $Revision: V.18.1.0
* $Date: 14 February 2024
* $Revision: V.19.0.0
*
* Target : Arm(R) M-Profile Architecture
* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -529,6 +529,8 @@ arm_cmsis_nn_status arm_nn_vec_mat_mult_t_s4(const int8_t *lhs,
* @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>ARM_CMSIS_NN_SUCCESS</code>
*
Expand All @@ -546,7 +548,8 @@ arm_cmsis_nn_status arm_nn_vec_mat_mult_t_s8(const int8_t *lhs,
const int32_t rhs_rows,
const int32_t activation_min,
const int32_t activation_max,
const int32_t address_offset);
const int32_t address_offset,
const int32_t rhs_offset);

/**
* @brief s16 Vector by Matrix (transposed) multiplication
Expand Down
13 changes: 7 additions & 6 deletions Source/FullyConnectedFunctions/arm_fully_connected_s8.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright 2010-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
* SPDX-FileCopyrightText: Copyright 2010-2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -21,8 +21,8 @@
* Title: arm_fully_connected_s8
* Description: Fully connected function compatible with TF Lite.
*
* $Date: 23 October 2023
* $Revision: V.5.2.0
* $Date: 6 February 2024
* $Revision: V.5.3.0
*
* Target : Arm(R) M-Profile Architecture
*
Expand Down Expand Up @@ -60,7 +60,6 @@ arm_cmsis_nn_status arm_fully_connected_s8(const cmsis_nn_context *ctx,
int8_t *output)
{
(void)bias_dims;
(void)fc_params->filter_offset;

int32_t batch_cnt = input_dims->n;

Expand All @@ -71,10 +70,11 @@ arm_cmsis_nn_status arm_fully_connected_s8(const cmsis_nn_context *ctx,
}
#endif

const int32_t *kernel_sum = (const int32_t *) ctx->buf;
const int32_t *kernel_sum = (const int32_t *)ctx->buf;

while (batch_cnt)
{

arm_nn_vec_mat_mult_t_s8(input,
kernel,
kernel_sum,
Expand All @@ -88,7 +88,8 @@ arm_cmsis_nn_status arm_fully_connected_s8(const cmsis_nn_context *ctx,
output_dims->c, /* row_dim or output_depth */
fc_params->activation.min,
fc_params->activation.max,
1L);
1L,
fc_params->filter_offset);

input += filter_dims->n;
output += output_dims->c;
Expand Down
Loading

0 comments on commit 72e1ebf

Please sign in to comment.