blob: 46a31185d723c5578847dc4389ff95023eefa2f7 [file] [log] [blame]
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +00001/*
2 * Copyright (c) 2021 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#include "arm_gemm_local.hpp"
26
27#include "depthwise_implementation.hpp"
28#include "depthwise_depthfirst_quantized.hpp"
29#include "depthwise_depthfirst_generic_quantized.hpp"
30#include "depthwise_depthfirst_multiplier_quantized.hpp"
31#include "depthwise_depthfirst_generic_multiplier_quantized.hpp"
32
33#include "depthwise_implementation_constraints.hpp"
34
35#if defined(__aarch64__)
Michalis Spyrou20fca522021-06-07 14:23:57 +010036#if defined(ARM_COMPUTE_ENABLE_SVE) && defined(ARM_COMPUTE_ENABLE_SVE2)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000037#include "kernels/sve_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst.hpp"
38#include "kernels/sve_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst.hpp"
39#include "kernels/sve_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst.hpp"
40#include "kernels/sve_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst.hpp"
41#include "kernels/sve_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst.hpp"
42#include "kernels/sve_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst.hpp"
43#include "kernels/sve_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst.hpp"
Michalis Spyrou20fca522021-06-07 14:23:57 +010044#endif // defined(ARM_COMPUTE_ENABLE_SVE) && defined(ARM_COMPUTE_ENABLE_SVE2)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000045#include "kernels/a64_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst.hpp"
46#include "kernels/a64_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst.hpp"
47#include "kernels/a64_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst.hpp"
48#include "kernels/a64_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst.hpp"
49#include "kernels/a64_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst.hpp"
50#include "kernels/a64_s8q_nhwc_generic_output9_mla_depthfirst.hpp"
51#include "kernels/a64_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst.hpp"
52#include "kernels/a64_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst.hpp"
53#include "kernels/a64_s8q_packed_to_nhwc_generic_with_multiplier_output2x8_mla_depthfirst.hpp"
54#endif // defined(__aarch64__)
55
56#include <cstdint>
57
58using arm_gemm::Requantize32;
59
60namespace arm_conv {
61namespace depthwise {
62
63namespace
64{
Freddie Liardet487d3902021-09-21 12:36:43 +010065#if defined(__aarch64__)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000066bool qp_weights_are_symmetric(const DepthwiseArgs &, const void *_qp)
67{
68 const auto qp = static_cast<const arm_gemm::Requantize32 *>(_qp);
69 return qp->b_offset == 0;
70}
Freddie Liardet487d3902021-09-21 12:36:43 +010071#endif // defined(__aarch64__)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000072}
73
74static const DepthwiseImplementation<int8_t, int8_t, int8_t, Requantize32> depthwise_s8q_methods[] = {
75#if defined(__aarch64__)
Michalis Spyrou20fca522021-06-07 14:23:57 +010076#if defined(ARM_COMPUTE_ENABLE_SVE) && defined(ARM_COMPUTE_ENABLE_SVE2)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000077 {
78 DepthwiseMethod::DEPTHFIRST,
79 "sve_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst",
80 constraint<Requantize32>(is_supported<sve_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst>,
81 has_no_channel_multiplier,
82 qp_has_no_left_shift,
Michalis Spyrou20fca522021-06-07 14:23:57 +010083 qp_weights_are_symmetric,
84 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000085 nullptr,
86 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
87 return new DepthwiseDepthfirstQuantized<sve_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst>(args, qp);
88 },
89 },
90 {
91 DepthwiseMethod::DEPTHFIRST,
92 "sve_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst",
93 constraint<Requantize32>(is_supported<sve_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst>,
94 has_no_channel_multiplier,
Michalis Spyrou20fca522021-06-07 14:23:57 +010095 qp_has_no_left_shift,
96 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000097 nullptr,
98 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
99 return new DepthwiseDepthfirstQuantized<sve_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst>(args, qp);
100 },
101 },
102 {
103 DepthwiseMethod::DEPTHFIRST,
104 "sve_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst",
105 constraint<Requantize32>(is_supported<sve_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst>,
106 has_no_channel_multiplier,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100107 qp_has_no_left_shift,
108 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000109 nullptr,
110 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
111 return new DepthwiseDepthfirstQuantized<sve_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst>(args, qp);
112 },
113 },
114 {
115 DepthwiseMethod::DEPTHFIRST,
116 "sve_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst",
117 constraint<Requantize32>(is_supported<sve_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst>,
118 has_no_channel_multiplier,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100119 qp_has_no_left_shift,
120 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000121 nullptr,
122 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
123 return new DepthwiseDepthfirstQuantized<sve_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst>(args, qp);
124 },
125 },
126 {
127 DepthwiseMethod::DEPTHFIRST,
128 "sve_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst",
129 constraint<Requantize32>(is_supported<sve_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst>,
130 has_no_channel_multiplier,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100131 qp_has_no_left_shift,
132 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000133 nullptr,
134 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
135 return new DepthwiseDepthfirstQuantized<sve_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst>(args, qp);
136 },
137 },
138 {
139 DepthwiseMethod::DEPTHFIRST,
140 "sve_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst",
141 constraint<Requantize32>(is_supported<sve_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst>,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100142 qp_has_no_left_shift,
143 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000144 nullptr,
145 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
146 return new DepthwiseDepthfirstWithMultiplierQuantized<sve_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst>(args, qp);
147 },
148 },
149 {
150 DepthwiseMethod::DEPTHFIRST,
151 "sve_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst",
152 constraint<Requantize32>(is_supported<sve_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst>,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100153 qp_has_no_left_shift,
154 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000155 nullptr,
156 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
157 return new DepthwiseDepthfirstWithMultiplierQuantized<sve_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst>(args, qp);
158 },
159 },
Michalis Spyrou20fca522021-06-07 14:23:57 +0100160#endif // defined(ARM_COMPUTE_ENABLE_SVE) && defined(ARM_COMPUTE_ENABLE_SVE2)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000161 {
162 DepthwiseMethod::DEPTHFIRST,
163 "a64_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst",
164 constraint<Requantize32>(is_supported<a64_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst>,
165 has_no_channel_multiplier,
166 qp_weights_are_symmetric,
167 qp_has_no_left_shift,
168 cpu_has_dot_product),
169 nullptr,
170 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
171 return new DepthwiseDepthfirstQuantized<a64_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst>(args, qp);
172 },
173 },
174 {
175 DepthwiseMethod::DEPTHFIRST,
176 "a64_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst",
177 constraint<Requantize32>(is_supported<a64_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst>,
178 has_no_channel_multiplier,
179 qp_has_no_left_shift,
180 cpu_has_dot_product),
181 nullptr,
182 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
183 return new DepthwiseDepthfirstQuantized<a64_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst>(args, qp);
184 },
185 },
186 {
187 DepthwiseMethod::DEPTHFIRST,
188 "a64_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst",
189 constraint<Requantize32>(is_supported<a64_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst>,
190 has_no_channel_multiplier,
191 qp_has_no_left_shift),
192 nullptr,
193 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
194 return new DepthwiseDepthfirstQuantized<a64_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst>(args, qp);
195 },
196 },
197 {
198 DepthwiseMethod::DEPTHFIRST,
199 "a64_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst",
200 constraint<Requantize32>(is_supported<a64_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst>,
201 has_no_channel_multiplier,
202 qp_has_no_left_shift),
203 nullptr,
204 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
205 return new DepthwiseDepthfirstQuantized<a64_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst>(args, qp);
206 },
207 },
208 {
209 DepthwiseMethod::DEPTHFIRST,
210 "a64_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst",
211 constraint<Requantize32>(is_supported<a64_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst>,
212 has_no_channel_multiplier,
213 qp_has_no_left_shift),
214 nullptr,
215 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
216 return new DepthwiseDepthfirstQuantized<a64_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst>(args, qp);
217 },
218 },
219 {
220 DepthwiseMethod::DEPTHFIRST,
221 "a64_s8q_nhwc_generic_output3x3_mla_depthfirst",
222 constraint<Requantize32>(has_no_channel_multiplier),
223 nullptr,
224 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
225 return new DepthwiseDepthfirstGenericQuantized<a64_s8q_nhwc_generic_output9_mla_depthfirst, 3, 3>(args, qp);
226 },
227 },
228 {
229 DepthwiseMethod::DEPTHFIRST,
230 "a64_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst",
231 constraint<Requantize32>(is_supported<a64_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst>,
232 qp_has_no_left_shift,
233 cpu_has_dot_product),
234 nullptr,
235 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
236 return new DepthwiseDepthfirstWithMultiplierQuantized<a64_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst>(args, qp);
237 },
238 },
239 {
240 DepthwiseMethod::DEPTHFIRST,
241 "a64_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst",
242 constraint<Requantize32>(is_supported<a64_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst>,
243 qp_has_no_left_shift,
244 cpu_has_dot_product),
245 nullptr,
246 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
247 return new DepthwiseDepthfirstWithMultiplierQuantized<a64_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst>(args, qp);
248 },
249 },
250 {
251 DepthwiseMethod::DEPTHFIRST,
252 "a64_s8q_packed_to_nhwc_generic_with_multiplier_output2x8_mla_depthfirst",
253 nullptr,
254 nullptr,
255 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
256 return new DepthwiseDepthfirstGenericWithMultiplierQuantized<a64_s8q_packed_to_nhwc_generic_with_multiplier_output2x8_mla_depthfirst>(args, qp);
257 },
258 },
259#endif // defined(__aarch64__)
260 { DepthwiseMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
261};
262
263template <>
264const DepthwiseImplementation<int8_t, int8_t, int8_t, Requantize32> *depthwise_implementation_list()
265{
266 return depthwise_s8q_methods;
267}
268
269template UniqueDepthwiseCommon<int8_t, int8_t, int8_t> depthwise(const DepthwiseArgs &, const Requantize32 &);
270template std::vector<KernelDescription> get_compatible_kernels<int8_t, int8_t, int8_t, Requantize32>(const DepthwiseArgs &, const Requantize32 &);
271
272} // namespace depthwise
273} // namespace arm_conv