1 /*
2 * SPDX-FileCopyrightText: Copyright 2023-2024 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_s4.c
22 * Description: s4 convolution layer wrapper function with the main purpose to call the optimal kernel available in
23 * cmsis-nn to perform the convolution. See header files for details.
24 *
25 * $Date: 10 April 2024
26 * $Revision: V.1.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_s4(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 int8_t * input_data,const cmsis_nn_dims * filter_dims,const int8_t * filter_data,const cmsis_nn_dims * bias_dims,const int32_t * bias_data,const cmsis_nn_dims * output_dims,int8_t * output_data)50 arm_cmsis_nn_status arm_convolve_wrapper_s4(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 int8_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 int32_t *bias_data,
59 const cmsis_nn_dims *output_dims,
60 int8_t *output_data)
61 {
62 if ((conv_params->padding.w == 0) && (conv_params->padding.h == 0) && (filter_dims->w == 1) &&
63 (filter_dims->h == 1) && (conv_params->dilation.w == 1 && conv_params->dilation.h == 1))
64 {
65 if ((conv_params->stride.w == 1) && (conv_params->stride.h == 1))
66 {
67 return arm_convolve_1x1_s4_fast(ctx,
68 conv_params,
69 quant_params,
70 input_dims,
71 input_data,
72 filter_dims,
73 filter_data,
74 bias_dims,
75 bias_data,
76 output_dims,
77 output_data);
78 }
79 else
80 {
81 return arm_convolve_1x1_s4(ctx,
82 conv_params,
83 quant_params,
84 input_dims,
85 input_data,
86 filter_dims,
87 filter_data,
88 bias_dims,
89 bias_data,
90 output_dims,
91 output_data);
92 }
93 }
94 else if ((input_dims->h == 1) && conv_params->dilation.w == 1 && (filter_dims->h == 1) &&
95 ((conv_params->stride.w * input_dims->c) % 4 == 0) && (input_dims->c == filter_dims->c))
96 {
97 return arm_convolve_1_x_n_s4(ctx,
98 conv_params,
99 quant_params,
100 input_dims,
101 input_data,
102 filter_dims,
103 filter_data,
104 bias_dims,
105 bias_data,
106 output_dims,
107 output_data);
108 }
109 else
110 {
111 return arm_convolve_s4(ctx,
112 conv_params,
113 quant_params,
114 input_dims,
115 input_data,
116 filter_dims,
117 filter_data,
118 bias_dims,
119 bias_data,
120 output_dims,
121 output_data);
122 }
123 }
124 /**
125 * @} end of NNConv group
126 */
127