1 /*
2 * SPDX-FileCopyrightText: Copyright 2010-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_depthwise_conv_wrapper_s8.c
22 * Description: Wrapper API to select appropriate depthwise conv API based
23 * on dimensions.
24 *
25 * $Date: 13 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 * s8 Depthwise conv wrapper function
45 *
46 * Refer header file for details.
47 *
48 */
arm_depthwise_conv_wrapper_s8(const cmsis_nn_context * ctx,const cmsis_nn_dw_conv_params * dw_conv_params,const cmsis_nn_per_channel_quant_params * quant_params,const cmsis_nn_dims * input_dims,const int8_t * input,const cmsis_nn_dims * filter_dims,const int8_t * filter,const cmsis_nn_dims * bias_dims,const int32_t * bias,const cmsis_nn_dims * output_dims,int8_t * output)49 arm_cmsis_nn_status arm_depthwise_conv_wrapper_s8(const cmsis_nn_context *ctx,
50 const cmsis_nn_dw_conv_params *dw_conv_params,
51 const cmsis_nn_per_channel_quant_params *quant_params,
52 const cmsis_nn_dims *input_dims,
53 const int8_t *input,
54 const cmsis_nn_dims *filter_dims,
55 const int8_t *filter,
56 const cmsis_nn_dims *bias_dims,
57 const int32_t *bias,
58 const cmsis_nn_dims *output_dims,
59 int8_t *output)
60 {
61 arm_cmsis_nn_status status = ARM_CMSIS_NN_SUCCESS;
62 if (1 == dw_conv_params->ch_mult && input_dims->n == 1 && dw_conv_params->dilation.w == 1 &&
63 dw_conv_params->dilation.h == 1)
64 {
65 #if !defined(ARM_MATH_MVEI)
66 if (filter_dims->w == 3 && filter_dims->h == 3 && dw_conv_params->padding.h <= 1 &&
67 dw_conv_params->padding.w <= 1)
68 {
69 status = arm_depthwise_conv_3x3_s8(ctx,
70 dw_conv_params,
71 quant_params,
72 input_dims,
73 input,
74 filter_dims,
75 filter,
76 bias_dims,
77 bias,
78 output_dims,
79 output);
80 }
81 else
82 #endif
83 {
84 status = arm_depthwise_conv_s8_opt(ctx,
85 dw_conv_params,
86 quant_params,
87 input_dims,
88 input,
89 filter_dims,
90 filter,
91 bias_dims,
92 bias,
93 output_dims,
94 output);
95 }
96 }
97 else
98 {
99 status = arm_depthwise_conv_s8(ctx,
100 dw_conv_params,
101 quant_params,
102 input_dims,
103 input,
104 filter_dims,
105 filter,
106 bias_dims,
107 bias,
108 output_dims,
109 output);
110 }
111
112 /* Return to application */
113 return status;
114 }
115
116 /**
117 * @} end of NNConv group
118 */
119