1 /*
2  * SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /* ----------------------------------------------------------------------
20  * Project:      CMSIS NN Library
21  * Title:        arm_convolve_wrapper_s16.c
22  * Description:  s16 convolution layer wrapper function with the main purpose to call the optimal kernel available in
23  * cmsis-nn to perform the convolution.
24  *
25  * $Date:        30 January 2023
26  * $Revision:    V.2.1.0
27  *
28  * Target :  Arm(R) M-Profile Architecture
29  *
30  * -------------------------------------------------------------------- */
31 
32 #include "arm_nnfunctions.h"
33 
34 /**
35  *  @ingroup Public
36  */
37 
38 /**
39  * @addtogroup NNConv
40  * @{
41  */
42 
43 /*
44  * Convolution layer
45  *
46  * Refer header file for details.
47  *
48  */
49 
arm_convolve_wrapper_s16(const cmsis_nn_context * ctx,const cmsis_nn_conv_params * conv_params,const cmsis_nn_per_channel_quant_params * quant_params,const cmsis_nn_dims * input_dims,const int16_t * input_data,const cmsis_nn_dims * filter_dims,const int8_t * filter_data,const cmsis_nn_dims * bias_dims,const int64_t * bias_data,const cmsis_nn_dims * output_dims,int16_t * output_data)50 arm_cmsis_nn_status arm_convolve_wrapper_s16(const cmsis_nn_context *ctx,
51                                              const cmsis_nn_conv_params *conv_params,
52                                              const cmsis_nn_per_channel_quant_params *quant_params,
53                                              const cmsis_nn_dims *input_dims,
54                                              const int16_t *input_data,
55                                              const cmsis_nn_dims *filter_dims,
56                                              const int8_t *filter_data,
57                                              const cmsis_nn_dims *bias_dims,
58                                              const int64_t *bias_data,
59                                              const cmsis_nn_dims *output_dims,
60                                              int16_t *output_data)
61 {
62 #if defined(ARM_MATH_DSP) && !defined(ARM_MATH_MVEI)
63     if (filter_dims->w * filter_dims->h * input_dims->c < 512 &&
64         (conv_params->dilation.w == 1 && conv_params->dilation.h == 1))
65     {
66         return arm_convolve_fast_s16(ctx,
67                                      conv_params,
68                                      quant_params,
69                                      input_dims,
70                                      input_data,
71                                      filter_dims,
72                                      filter_data,
73                                      bias_dims,
74                                      bias_data,
75                                      output_dims,
76                                      output_data);
77     }
78     else
79     {
80         return arm_convolve_s16(ctx,
81                                 conv_params,
82                                 quant_params,
83                                 input_dims,
84                                 input_data,
85                                 filter_dims,
86                                 filter_data,
87                                 bias_dims,
88                                 bias_data,
89                                 output_dims,
90                                 output_data);
91     }
92 #else
93     return arm_convolve_s16(ctx,
94                             conv_params,
95                             quant_params,
96                             input_dims,
97                             input_data,
98                             filter_dims,
99                             filter_data,
100                             bias_dims,
101                             bias_data,
102                             output_dims,
103                             output_data);
104 #endif
105 }
106 
107 /**
108  * @} end of NNConv group
109  */
110