forked from ARM-software/CMSIS-NN
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Int8 and Int16 Batch Matmul support (ARM-software#139)
* Adds new BatchMatmulFunctions folder * Adds new Batch Matmul public functions * Adds new s16 x s16 vector matmult function * Adds new unit tests * Adds new struct for batch matmul params * Remove cmake files from check version script Change-Id: I4709f56b23c2be91c08e26e381a1e956b6a9978b <Co-authored-by: Ryan O'Shea, [email protected]> <Co-authored-by: Adrian Lundell, [email protected]>
- Loading branch information
Showing
98 changed files
with
11,493 additions
and
50 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# | ||
# SPDX-FileCopyrightText: Copyright 2019-2022 Arm Limited and/or its affiliates <[email protected]> | ||
# SPDX-FileCopyrightText: Copyright 2019-2022, 2024 Arm Limited and/or its affiliates <[email protected]> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
@@ -18,7 +18,7 @@ | |
|
||
SET(ROOT ${CMSIS_PATH}) | ||
|
||
# Select which parts of the CMSIS-DSP must be compiled. | ||
# Select which parts of the CMSIS-NN must be compiled. | ||
# There are some dependencies between the parts but they are not tracked | ||
# by this cmake. So, enabling some functions may require to enable some | ||
# other ones. | ||
|
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,105 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <open-source-office.com> | ||
* | ||
* 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_nn_batch_matmul_s16.c | ||
* Description: Batch matrix multiplication. Does not perform transposes, see header file for details. | ||
* | ||
* $Date: 19 June 2024 | ||
* $Revision: V.1.0.0 | ||
* | ||
* Target : Arm(R) M-Profile Architecture | ||
* | ||
* -------------------------------------------------------------------- */ | ||
#include "arm_nnfunctions.h" | ||
#include "arm_nnsupportfunctions.h" | ||
|
||
/** | ||
* @ingroup Public | ||
*/ | ||
|
||
/** | ||
* @addtogroup FC | ||
* @{ | ||
*/ | ||
|
||
/* | ||
* s16 batch matrix multiplication | ||
* Refer to header file for details. | ||
*/ | ||
arm_cmsis_nn_status arm_batch_matmul_s16(const cmsis_nn_context *ctx, | ||
const cmsis_nn_bmm_params *bmm_params, | ||
const cmsis_nn_per_tensor_quant_params *quant_params, | ||
const cmsis_nn_dims *input_lhs_dims, | ||
const int16_t *input_lhs, | ||
const cmsis_nn_dims *input_rhs_dims, | ||
const int16_t *input_rhs, | ||
const cmsis_nn_dims *output_dims, | ||
int16_t *output) | ||
{ | ||
(void)ctx; | ||
const int32_t output_batch = output_dims->n; | ||
const int32_t output_height = output_dims->h; | ||
const int32_t lhs_rows = input_lhs_dims->w; | ||
const int32_t rhs_rows = input_rhs_dims->w; | ||
const int32_t rhs_cols = input_rhs_dims->c; | ||
|
||
const int32_t inner_lhs_diff = input_lhs_dims->h >= input_rhs_dims->h ? 0 : lhs_rows * rhs_cols; | ||
const int32_t inner_rhs_diff = input_rhs_dims->h >= input_lhs_dims->h ? rhs_rows * rhs_cols : 0; | ||
const int32_t outer_lhs_diff = input_lhs_dims->n >= input_rhs_dims->n | ||
? inner_lhs_diff | ||
: -((lhs_rows * rhs_cols) - inner_lhs_diff) * input_lhs_dims->h; | ||
const int32_t outer_rhs_diff = input_rhs_dims->n >= input_lhs_dims->n ? (rhs_rows * rhs_cols) - inner_rhs_diff | ||
: -inner_rhs_diff * input_rhs_dims->h; | ||
|
||
const int32_t reduced_multiplier = REDUCE_MULTIPLIER(quant_params->multiplier); | ||
|
||
for (int i_out_batch = 0; i_out_batch < output_batch; i_out_batch++) | ||
{ | ||
for (int i_out_height = 0; i_out_height < output_height; i_out_height++) | ||
{ | ||
|
||
for (int j = 0; j < lhs_rows; j++) | ||
{ | ||
arm_nn_vec_mat_mult_t_s16_s16(input_lhs, | ||
input_rhs, | ||
NULL, | ||
output, | ||
reduced_multiplier, | ||
quant_params->shift, | ||
rhs_cols, | ||
rhs_rows, | ||
bmm_params->fc_params.activation.min, | ||
bmm_params->fc_params.activation.max); | ||
input_lhs += rhs_cols; | ||
output += rhs_rows; | ||
} | ||
input_lhs -= inner_lhs_diff; | ||
input_rhs += inner_rhs_diff; | ||
} | ||
input_lhs += outer_lhs_diff; | ||
input_rhs += outer_rhs_diff; | ||
} | ||
|
||
return ARM_CMSIS_NN_SUCCESS; | ||
} | ||
|
||
/** | ||
* @} end of Doxygen group | ||
*/ |
Oops, something went wrong.