Skip to content

Commit

Permalink
Add transpose (ARM-software#152)
Browse files Browse the repository at this point in the history
Adds scalar and MVE version for transpose.
  • Loading branch information
mansnils authored Oct 28, 2024
1 parent 25eb94f commit 7409979
Show file tree
Hide file tree
Showing 56 changed files with 3,391 additions and 11 deletions.
1 change: 1 addition & 0 deletions ARM.CMSIS-NN.pdsc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<file category="source" name="Source/ActivationFunctions/arm_relu_q7.c"/>
<file category="source" name="Source/ActivationFunctions/arm_nn_activation_s16.c"/>
<file category="source" name="Source/ReshapeFunctions/arm_reshape_s8.c"/>
<file category="source" name="Source/TransposeFunctions/arm_transpose_s8.c"/>
<file category="source" name="Source/NNSupportFunctions/arm_nn_vec_mat_mult_t_s4.c"/>
<file category="source" name="Source/NNSupportFunctions/arm_nn_vec_mat_mult_t_s8.c"/>
<file category="source" name="Source/NNSupportFunctions/arm_nn_vec_mat_mult_t_per_ch_s8.c"/>
Expand Down
11 changes: 9 additions & 2 deletions Include/arm_nn_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* Description: Public header file to contain the CMSIS-NN structs for the
* TensorFlowLite micro compliant functions
*
* $Date: 19 Aug 2024
* $Revision: V.3.4.0
* $Date: 21 Oct 2024
* $Revision: V.3.5.0
*
* Target : Arm(R) M-Profile Architecture
* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -189,6 +189,13 @@ typedef struct
cmsis_nn_fc_params fc_params;
} cmsis_nn_bmm_params;

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

/** CMSIS-NN object for SVDF layer parameters */
typedef struct
{
Expand Down
32 changes: 30 additions & 2 deletions Include/arm_nnfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* Title: arm_nnfunctions.h
* Description: Public header file for CMSIS NN Library
*
* $Date: 17 October 2024
* $Revision: V.17.2.0
* $Date: 23 October 2024
* $Revision: V.17.3.0
*
* Target : Arm(R) M-Profile Architecture
* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -2335,6 +2335,34 @@ void arm_softmax_u8(const uint8_t *input,
*/
void arm_reshape_s8(const int8_t *input, int8_t *output, const uint32_t total_size);

/**
* @defgroup Transpose Transpose Functions
*
*/

/**
* @brief Basic transpose function
*
* @param[in] input_data Input (activation) data pointer. Data type: int8
* @param[out] output_data Output data pointer. Data type: int8
* @param[in] input_dims Input (activation) tensor dimensions. Format: [N, H, W, C_IN]
* @param[in] output_dims Output tensor dimensions. Format may be arbitrary relative to input format.
* The output dimension will depend on the permutation dimensions.
* In other words the out dimensions are the result of applying the permutation
* to the input dimensions.
* @param[in] transpose_params Transpose parameters. Contains permutation dimensions.
*
* @return The function returns either
* <code>ARM_CMSIS_NN_ARG_ERROR</code> if argument constraints fail. or,
* <code>ARM_CMSIS_NN_SUCCESS</code> on successful completion.
*
*/
arm_cmsis_nn_status arm_transpose_s8(const int8_t *input_data,
int8_t *const output_data,
const cmsis_nn_dims *const input_dims,
const cmsis_nn_dims *const output_dims,
const cmsis_nn_transpose_params *const transpose_params);

/**
* @defgroup Concatenation Concatenation Functions
*
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Examples are Cortex-M55 or Cortex-M85 configured with MVE.
| LSTM | Yes | Yes | No | Yes | Yes | No | Yes | Yes | No |
| SVDF | Yes | No | No | Yes | No | No | Yes | No | No |
| Pad | Yes | No | N/A | No | No | N/A | Yes | No | N/A |
| Transpose | Yes | No | N/A | No | No | N/A | Yes | No | N/A |

* int4 weights + int8 activations

Expand Down
5 changes: 5 additions & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ option(RESHAPE "Reshape" ON)
option(SVDF "SVDF" ON)
option(LSTM "LSTM" ON)
option(PAD "Pad" ON)
option(TRANSPOSE "Transpose" ON)

# Always needed if any other module above is on.
option(NNSUPPORT "NN Support" ON)
Expand Down Expand Up @@ -86,6 +87,10 @@ if (PAD)
add_subdirectory(PadFunctions)
endif()

if (TRANSPOSE)
add_subdirectory(TransposeFunctions)
endif()

# Keep NNSUPPORT at the end
if (NNSUPPORT)
add_subdirectory(NNSupportFunctions)
Expand Down
20 changes: 20 additions & 0 deletions Source/TransposeFunctions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# SPDX-FileCopyrightText: Copyright 2019-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.
#

file(GLOB SRC "./*_s8*.c")
target_sources(cmsis-nn PRIVATE ${SRC})
Loading

0 comments on commit 7409979

Please sign in to comment.