blob: 4ff249a5d5186f693368ea2e3ea633b0ff5373a3 [file] [log] [blame]
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +00001/*
ramelg018a164882022-04-07 02:42:52 +01002 * Copyright (c) 2021-2022 Arm Limited.
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +00003 *
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"
ramelg018a164882022-04-07 02:42:52 +010028#include "depthwise_depthfirst.hpp"
29#include "depthwise_depthfirst_generic.hpp"
30#include "depthwise_depthfirst_multiplier.hpp"
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000031
32#include "depthwise_implementation_constraints.hpp"
33
34#if defined(__aarch64__)
ramelg018a164882022-04-07 02:42:52 +010035#if defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000036#include "kernels/sve_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst.hpp"
37#include "kernels/sve_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst.hpp"
38#include "kernels/sve_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst.hpp"
39#include "kernels/sve_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst.hpp"
40#include "kernels/sve_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst.hpp"
41#include "kernels/sve_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst.hpp"
42#include "kernels/sve_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst.hpp"
ramelg018a164882022-04-07 02:42:52 +010043#endif // defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000044#include "kernels/a64_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst.hpp"
45#include "kernels/a64_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst.hpp"
46#include "kernels/a64_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst.hpp"
47#include "kernels/a64_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst.hpp"
48#include "kernels/a64_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst.hpp"
49#include "kernels/a64_s8q_nhwc_generic_output9_mla_depthfirst.hpp"
50#include "kernels/a64_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst.hpp"
51#include "kernels/a64_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst.hpp"
52#include "kernels/a64_s8q_packed_to_nhwc_generic_with_multiplier_output2x8_mla_depthfirst.hpp"
53#endif // defined(__aarch64__)
54
55#include <cstdint>
56
57using arm_gemm::Requantize32;
58
59namespace arm_conv {
60namespace depthwise {
61
62namespace
63{
Freddie Liardet487d3902021-09-21 12:36:43 +010064#if defined(__aarch64__)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000065bool qp_weights_are_symmetric(const DepthwiseArgs &, const void *_qp)
66{
67 const auto qp = static_cast<const arm_gemm::Requantize32 *>(_qp);
68 return qp->b_offset == 0;
69}
Freddie Liardet487d3902021-09-21 12:36:43 +010070#endif // defined(__aarch64__)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000071}
72
73static const DepthwiseImplementation<int8_t, int8_t, int8_t, Requantize32> depthwise_s8q_methods[] = {
74#if defined(__aarch64__)
ramelg018a164882022-04-07 02:42:52 +010075#if defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000076 {
77 DepthwiseMethod::DEPTHFIRST,
78 "sve_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst",
79 constraint<Requantize32>(is_supported<sve_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst>,
80 has_no_channel_multiplier,
81 qp_has_no_left_shift,
Michalis Spyrou20fca522021-06-07 14:23:57 +010082 qp_weights_are_symmetric,
83 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000084 nullptr,
85 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +010086 auto strat = new sve_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst(args.cpu_info);
87 return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +000088 },
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> * {
ramelg018a164882022-04-07 02:42:52 +010099 auto strat = new sve_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst(args.cpu_info);
100 return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000101 },
102 },
103 {
104 DepthwiseMethod::DEPTHFIRST,
105 "sve_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst",
106 constraint<Requantize32>(is_supported<sve_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst>,
107 has_no_channel_multiplier,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100108 qp_has_no_left_shift,
109 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000110 nullptr,
111 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100112 auto strat = new sve_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst(args.cpu_info);
113 return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000114 },
115 },
116 {
117 DepthwiseMethod::DEPTHFIRST,
118 "sve_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst",
119 constraint<Requantize32>(is_supported<sve_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst>,
120 has_no_channel_multiplier,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100121 qp_has_no_left_shift,
122 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000123 nullptr,
124 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100125 auto strat = new sve_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst(args.cpu_info);
126 return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000127 },
128 },
129 {
130 DepthwiseMethod::DEPTHFIRST,
131 "sve_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst",
132 constraint<Requantize32>(is_supported<sve_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst>,
133 has_no_channel_multiplier,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100134 qp_has_no_left_shift,
135 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000136 nullptr,
137 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100138 auto strat = new sve_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst(args.cpu_info);
139 return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000140 },
141 },
142 {
143 DepthwiseMethod::DEPTHFIRST,
144 "sve_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst",
145 constraint<Requantize32>(is_supported<sve_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst>,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100146 qp_has_no_left_shift,
ramelg018a164882022-04-07 02:42:52 +0100147 has_channel_multiplier,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100148 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000149 nullptr,
150 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100151 auto strat = new sve_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst(args.cpu_info);
152 return new DepthwiseDepthfirstMultiplier<int8_t, int8_t, int8_t, int32_t, false>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000153 },
154 },
155 {
156 DepthwiseMethod::DEPTHFIRST,
157 "sve_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst",
158 constraint<Requantize32>(is_supported<sve_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst>,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100159 qp_has_no_left_shift,
ramelg018a164882022-04-07 02:42:52 +0100160 has_channel_multiplier,
Michalis Spyrou20fca522021-06-07 14:23:57 +0100161 cpu_has_sve2),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000162 nullptr,
163 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100164 auto strat = new sve_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst(args.cpu_info);
165 return new DepthwiseDepthfirstMultiplier<int8_t, int8_t, int8_t, int32_t, false>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000166 },
167 },
ramelg018a164882022-04-07 02:42:52 +0100168#endif // defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000169 {
170 DepthwiseMethod::DEPTHFIRST,
171 "a64_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst",
172 constraint<Requantize32>(is_supported<a64_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst>,
173 has_no_channel_multiplier,
174 qp_weights_are_symmetric,
175 qp_has_no_left_shift,
176 cpu_has_dot_product),
177 nullptr,
178 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100179 auto strat = new a64_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst(args.cpu_info);
180 return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000181 },
182 },
183 {
184 DepthwiseMethod::DEPTHFIRST,
185 "a64_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst",
186 constraint<Requantize32>(is_supported<a64_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst>,
187 has_no_channel_multiplier,
188 qp_has_no_left_shift,
189 cpu_has_dot_product),
190 nullptr,
191 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100192 auto strat = new a64_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst(args.cpu_info);
193 return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000194 },
195 },
196 {
197 DepthwiseMethod::DEPTHFIRST,
198 "a64_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst",
199 constraint<Requantize32>(is_supported<a64_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst>,
200 has_no_channel_multiplier,
201 qp_has_no_left_shift),
202 nullptr,
203 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100204 auto strat = new a64_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst(args.cpu_info);
205 return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000206 },
207 },
208 {
209 DepthwiseMethod::DEPTHFIRST,
210 "a64_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst",
211 constraint<Requantize32>(is_supported<a64_s8q_nhwc_3x3_s2_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> * {
ramelg018a164882022-04-07 02:42:52 +0100216 auto strat = new a64_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst(args.cpu_info);
217 return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000218 },
219 },
220 {
221 DepthwiseMethod::DEPTHFIRST,
222 "a64_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst",
223 constraint<Requantize32>(is_supported<a64_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst>,
224 has_no_channel_multiplier,
225 qp_has_no_left_shift),
226 nullptr,
227 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100228 auto strat = new a64_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst(args.cpu_info);
229 return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000230 },
231 },
232 {
233 DepthwiseMethod::DEPTHFIRST,
234 "a64_s8q_nhwc_generic_output3x3_mla_depthfirst",
235 constraint<Requantize32>(has_no_channel_multiplier),
236 nullptr,
237 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100238 auto kernel = new a64_s8q_nhwc_generic_output9_mla_depthfirst(args.cpu_info);
239 auto strat = new GenericDepthfirstStrategy<int8_t>(kernel, 3, 3, args);
240 return new DepthwiseDepthfirstGeneric<int8_t>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000241 },
242 },
243 {
244 DepthwiseMethod::DEPTHFIRST,
245 "a64_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst",
246 constraint<Requantize32>(is_supported<a64_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst>,
247 qp_has_no_left_shift,
ramelg018a164882022-04-07 02:42:52 +0100248 has_channel_multiplier,
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000249 cpu_has_dot_product),
250 nullptr,
251 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100252 auto strat = new a64_s8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst(args.cpu_info);
253 return new DepthwiseDepthfirstMultiplier<int8_t, int8_t, int8_t, int32_t, false>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000254 },
255 },
256 {
257 DepthwiseMethod::DEPTHFIRST,
258 "a64_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst",
259 constraint<Requantize32>(is_supported<a64_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst>,
260 qp_has_no_left_shift,
ramelg018a164882022-04-07 02:42:52 +0100261 has_channel_multiplier,
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000262 cpu_has_dot_product),
263 nullptr,
264 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100265 auto strat = new a64_s8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst(args.cpu_info);
266 return new DepthwiseDepthfirstMultiplier<int8_t, int8_t, int8_t, int32_t, false>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000267 },
268 },
269 {
270 DepthwiseMethod::DEPTHFIRST,
271 "a64_s8q_packed_to_nhwc_generic_with_multiplier_output2x8_mla_depthfirst",
ramelg018a164882022-04-07 02:42:52 +0100272 constraint<Requantize32>(has_channel_multiplier),
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000273 nullptr,
274 [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
ramelg018a164882022-04-07 02:42:52 +0100275 auto kern = new a64_s8q_packed_to_nhwc_generic_with_multiplier_output2x8_mla_depthfirst(args.cpu_info);
276 auto strat = new GenericDepthfirstMultiplierStrategy<int8_t>(kern, args);
277 return new DepthwiseDepthfirstMultiplier<int8_t, int8_t, int8_t, int32_t, true>(strat, args, qp);
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000278 },
279 },
280#endif // defined(__aarch64__)
281 { DepthwiseMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
282};
283
284template <>
285const DepthwiseImplementation<int8_t, int8_t, int8_t, Requantize32> *depthwise_implementation_list()
286{
287 return depthwise_s8q_methods;
288}
289
290template UniqueDepthwiseCommon<int8_t, int8_t, int8_t> depthwise(const DepthwiseArgs &, const Requantize32 &);
291template std::vector<KernelDescription> get_compatible_kernels<int8_t, int8_t, int8_t, Requantize32>(const DepthwiseArgs &, const Requantize32 &);
292
293} // namespace depthwise
294} // namespace arm_conv