1 /*
2 * SPDX-FileCopyrightText: Copyright 2010-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_s8.c
22 * Description: s8 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: 04 January 2024
26 * $Revision: V.2.5.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_s8(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_s8(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 (input_dims->c == filter_dims->c))
65 {
66 if ((conv_params->stride.w == 1) && (conv_params->stride.h == 1))
67 {
68 return arm_convolve_1x1_s8_fast(ctx,
69 conv_params,
70 quant_params,
71 input_dims,
72 input_data,
73 filter_dims,
74 filter_data,
75 bias_dims,
76 bias_data,
77 output_dims,
78 output_data);
79 }
80 else
81 {
82 return arm_convolve_1x1_s8(ctx,
83 conv_params,
84 quant_params,
85 input_dims,
86 input_data,
87 filter_dims,
88 filter_data,
89 bias_dims,
90 bias_data,
91 output_dims,
92 output_data);
93 }
94 }
95 else if ((input_dims->h == 1) && conv_params->dilation.w == 1 && (filter_dims->h == 1) &&
96 ((conv_params->stride.w * input_dims->c) % 4 == 0) && (input_dims->c == filter_dims->c))
97 {
98 return arm_convolve_1_x_n_s8(ctx,
99 conv_params,
100 quant_params,
101 input_dims,
102 input_data,
103 filter_dims,
104 filter_data,
105 bias_dims,
106 bias_data,
107 output_dims,
108 output_data);
109 }
110 else
111 {
112 return arm_convolve_s8(ctx,
113 conv_params,
114 quant_params,
115 input_dims,
116 input_data,
117 filter_dims,
118 filter_data,
119 bias_dims,
120 bias_data,
121 output_dims,
122 output_data);
123 }
124 }
125
126 /**
127 * @} end of NNConv group
128 */
129