-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for per channel quantized FC (#142)
* Adds new FC top level functions as well as support function for per channels quantization. * Adds a new FC wrapper. * Remove gcc unroll pragma for MVE in current FC support function.
- Loading branch information
Showing
57 changed files
with
2,132 additions
and
120 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
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
102 changes: 102 additions & 0 deletions
102
Source/FullyConnectedFunctions/arm_fully_connected_per_channel_s8.c
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright 2010-2024 Arm Limited and/or its affiliates <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the License); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* ---------------------------------------------------------------------- | ||
* Project: CMSIS NN Library | ||
* Title: arm_fully_connected_per_channel_s8 | ||
* Description: Fully connected function compatible with TF Lite. | ||
* | ||
* $Date: 15 Aug 2024 | ||
* $Revision: V.1.0.0 | ||
* | ||
* Target : Arm(R) M-Profile Architecture | ||
* | ||
* -------------------------------------------------------------------- */ | ||
|
||
#include "arm_nnfunctions.h" | ||
#include "arm_nnsupportfunctions.h" | ||
|
||
/** | ||
* @ingroup Public | ||
*/ | ||
|
||
/** | ||
* @addtogroup FC | ||
* @{ | ||
*/ | ||
|
||
/* | ||
* S8 basic fully-connected and matrix multiplication layer function using per-channel quantization for TensorFlow Lite | ||
* | ||
* Refer header file for details. | ||
* | ||
*/ | ||
arm_cmsis_nn_status arm_fully_connected_per_channel_s8(const cmsis_nn_context *ctx, | ||
const cmsis_nn_fc_params *fc_params, | ||
const cmsis_nn_per_channel_quant_params *quant_params, | ||
const cmsis_nn_dims *input_dims, | ||
const int8_t *input_data, | ||
const cmsis_nn_dims *filter_dims, | ||
const int8_t *kernel, | ||
const cmsis_nn_dims *bias_dims, | ||
const int32_t *bias_data, | ||
const cmsis_nn_dims *output_dims, | ||
int8_t *output_data) | ||
{ | ||
(void)bias_dims; | ||
|
||
int32_t batch_cnt = input_dims->n; | ||
|
||
#if defined(ARM_MATH_MVEI) | ||
if (ctx->buf == NULL) | ||
{ | ||
return (ARM_CMSIS_NN_ARG_ERROR); | ||
} | ||
#endif | ||
|
||
const int32_t *kernel_sum = (const int32_t *)ctx->buf; | ||
|
||
while (batch_cnt) | ||
{ | ||
|
||
arm_nn_vec_mat_mult_t_per_ch_s8(input_data, | ||
kernel, | ||
kernel_sum, | ||
bias_data, | ||
output_data, | ||
fc_params->input_offset, | ||
fc_params->output_offset, | ||
quant_params->multiplier, | ||
quant_params->shift, | ||
filter_dims->n, /* col_dim or accum_depth */ | ||
output_dims->c, /* row_dim or output_depth */ | ||
fc_params->activation.min, | ||
fc_params->activation.max, | ||
1L, | ||
fc_params->filter_offset); | ||
|
||
input_data += filter_dims->n; | ||
output_data += output_dims->c; | ||
batch_cnt--; | ||
} | ||
return (ARM_CMSIS_NN_SUCCESS); | ||
} | ||
|
||
/** | ||
* @} end of FC group | ||
*/ |
Oops, something went wrong.