Compute Library
 22.08
depthwise_u8q.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2022 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 
28 #include "depthwise_depthfirst.hpp"
31 
33 
34 #if defined(__aarch64__)
35 #if defined(ARM_COMPUTE_ENABLE_SVE)
42 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
44 
48 
56 
57 #endif // defined(__aarch64__)
58 
59 #include <cstdint>
60 
62 
63 namespace arm_conv {
64 namespace depthwise {
65 
66 static const DepthwiseImplementation<uint8_t, uint8_t, uint8_t, Requantize32> depthwise_u8q_methods[] = {
67 #if defined(__aarch64__)
68 #if defined(ARM_COMPUTE_ENABLE_SVE)
69  {
70  DepthwiseMethod::DEPTHFIRST,
71  "sve_u8q_nhwc_3x3_s1_output2x2_dot_depthfirst",
72  constraint<Requantize32>(is_supported<sve_u8q_nhwc_3x3_s1_output2x2_dot_depthfirst>,
73  has_no_channel_multiplier,
74  qp_has_no_left_shift,
75  cpu_has_sve2),
76  nullptr,
77  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
78  auto strat = new sve_u8q_nhwc_3x3_s1_output2x2_dot_depthfirst(args.cpu_info);
79  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
80  },
81  },
82  {
83  DepthwiseMethod::DEPTHFIRST,
84  "sve_u8q_nhwc_3x3_s1_output2x2_mla_depthfirst",
85  constraint<Requantize32>(is_supported<sve_u8q_nhwc_3x3_s1_output2x2_mla_depthfirst>,
86  has_no_channel_multiplier,
87  qp_has_no_left_shift,
88  cpu_has_sve2),
89  nullptr,
90  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
91  auto strat = new sve_u8q_nhwc_3x3_s1_output2x2_mla_depthfirst(args.cpu_info);
92  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
93  },
94  },
95  {
96  DepthwiseMethod::DEPTHFIRST,
97  "sve_u8q_nhwc_3x3_s2_output2x2_mla_depthfirst",
98  constraint<Requantize32>(is_supported<sve_u8q_nhwc_3x3_s2_output2x2_mla_depthfirst>,
99  has_no_channel_multiplier,
100  qp_has_no_left_shift,
101  cpu_has_sve2),
102  nullptr,
103  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
104  auto strat = new sve_u8q_nhwc_3x3_s2_output2x2_mla_depthfirst(args.cpu_info);
105  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
106  },
107  },
108  {
109  DepthwiseMethod::DEPTHFIRST,
110  "sve_u8q_nhwc_5x5_s1_output2x2_mla_depthfirst",
111  constraint<Requantize32>(is_supported<sve_u8q_nhwc_5x5_s1_output2x2_mla_depthfirst>,
112  has_no_channel_multiplier,
113  qp_has_no_left_shift,
114  cpu_has_sve2),
115  nullptr,
116  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
117  auto strat = new sve_u8q_nhwc_5x5_s1_output2x2_mla_depthfirst(args.cpu_info);
118  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
119  },
120  },
121  {
122  DepthwiseMethod::DEPTHFIRST,
123  "sve_u8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst",
124  constraint<Requantize32>(is_supported<sve_u8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst>,
125  qp_has_no_left_shift,
126  has_channel_multiplier,
127  cpu_has_sve2),
128  nullptr,
129  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
130  auto strat = new sve_u8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst(args.cpu_info);
131  return new DepthwiseDepthfirstMultiplier<uint8_t, uint8_t, uint8_t, int32_t, false>(strat, args, qp);
132  },
133  },
134  {
135  DepthwiseMethod::DEPTHFIRST,
136  "sve_u8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst",
137  constraint<Requantize32>(is_supported<sve_u8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst>,
138  qp_has_no_left_shift,
139  has_channel_multiplier,
140  cpu_has_sve2),
141  nullptr,
142  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
143  auto strat = new sve_u8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst(args.cpu_info);
144  return new DepthwiseDepthfirstMultiplier<uint8_t, uint8_t, uint8_t, int32_t, false>(strat, args, qp);
145  },
146  },
147 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
148  {
149  DepthwiseMethod::DEPTHFIRST,
150  "a64_u8q_nhwc_3x3_s1_output2x2_dot_depthfirst",
151  constraint<Requantize32>(is_supported<a64_u8q_nhwc_3x3_s1_output2x2_dot_depthfirst>,
152  cpu_has_dot_product,
153  has_no_channel_multiplier,
154  qp_has_no_left_shift),
155  nullptr,
156  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
157  auto strat = new a64_u8q_nhwc_3x3_s1_output2x2_dot_depthfirst(args.cpu_info);
158  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
159  },
160  },
161 
162  {
163  DepthwiseMethod::DEPTHFIRST,
164  "a64_u8qa_nhwc_3x3_s1_output2x2_mla_depthfirst",
165  constraint<Requantize32>(is_supported<a64_u8qa_nhwc_3x3_s1_output2x2_mla_depthfirst>,
166  has_no_channel_multiplier,
167  qp_zero_a_offset,
168  qp_has_no_left_shift),
169  nullptr,
170  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
171  auto strat = new a64_u8qa_nhwc_3x3_s1_output2x2_mla_depthfirst(args.cpu_info);
172  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
173  },
174  },
175  {
176  DepthwiseMethod::DEPTHFIRST,
177  "a64_u8qa_nhwc_3x3_s2_output2x2_mla_depthfirst",
178  constraint<Requantize32>(is_supported<a64_u8qa_nhwc_3x3_s2_output2x2_mla_depthfirst>,
179  has_no_channel_multiplier,
180  qp_zero_a_offset,
181  qp_has_no_left_shift),
182  nullptr,
183  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
184  auto strat = new a64_u8qa_nhwc_3x3_s2_output2x2_mla_depthfirst(args.cpu_info);
185  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
186  },
187  },
188  {
189  DepthwiseMethod::DEPTHFIRST,
190  "a64_u8qa_nhwc_5x5_s1_output2x2_mla_depthfirst",
191  constraint<Requantize32>(is_supported<a64_u8qa_nhwc_5x5_s1_output2x2_mla_depthfirst>,
192  has_no_channel_multiplier,
193  qp_zero_a_offset,
194  qp_has_no_left_shift),
195  nullptr,
196  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
197  auto strat = new a64_u8qa_nhwc_5x5_s1_output2x2_mla_depthfirst(args.cpu_info);
198  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
199  },
200  },
201 
202  {
203  DepthwiseMethod::DEPTHFIRST,
204  "a64_u8q_nhwc_3x3_s1_output2x2_mla_depthfirst",
205  constraint<Requantize32>(is_supported<a64_u8q_nhwc_3x3_s1_output2x2_mla_depthfirst>,
206  has_no_channel_multiplier,
207  qp_has_no_left_shift),
208  nullptr,
209  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
210  auto strat = new a64_u8q_nhwc_3x3_s1_output2x2_mla_depthfirst(args.cpu_info);
211  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
212  },
213  },
214  {
215  DepthwiseMethod::DEPTHFIRST,
216  "a64_u8q_nhwc_3x3_s2_output2x2_mla_depthfirst",
217  constraint<Requantize32>(is_supported<a64_u8q_nhwc_3x3_s2_output2x2_mla_depthfirst>,
218  has_no_channel_multiplier,
219  qp_has_no_left_shift),
220  nullptr,
221  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
222  auto strat = new a64_u8q_nhwc_3x3_s2_output2x2_mla_depthfirst(args.cpu_info);
223  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
224  },
225  },
226  {
227  DepthwiseMethod::DEPTHFIRST,
228  "a64_u8q_nhwc_5x5_s1_output2x2_mla_depthfirst",
229  constraint<Requantize32>(is_supported<a64_u8q_nhwc_5x5_s1_output2x2_mla_depthfirst>,
230  has_no_channel_multiplier,
231  qp_has_no_left_shift),
232  nullptr,
233  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
234  auto strat = new a64_u8q_nhwc_5x5_s1_output2x2_mla_depthfirst(args.cpu_info);
235  return new DepthwiseDepthfirst<uint8_t>(strat, args, qp);
236  },
237  },
238  {
239  DepthwiseMethod::DEPTHFIRST,
240  "a64_u8q_nhwc_generic_output3x3_mla_depthfirst",
241  constraint<Requantize32>(has_no_channel_multiplier),
242  nullptr,
243  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
244  auto kernel = new a64_u8q_nhwc_generic_output9_mla_depthfirst(args.cpu_info);
245  auto strat = new GenericDepthfirstStrategy<uint8_t>(kernel, 3, 3, args);
246  return new DepthwiseDepthfirstGeneric<uint8_t>(strat, args, qp);
247  },
248  },
249  {
250  DepthwiseMethod::DEPTHFIRST,
251  "a64_u8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst",
252  constraint<Requantize32>(is_supported<a64_u8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst>,
253  cpu_has_dot_product,
254  has_channel_multiplier,
255  qp_has_no_left_shift),
256  nullptr,
257  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
258  auto strat = new a64_u8q_packed_to_nhwc_3x3_s2_with_multiplier_output2x4_dot_depthfirst(args.cpu_info);
259  return new DepthwiseDepthfirstMultiplier<uint8_t, uint8_t, uint8_t, int32_t, false>(strat, args, qp);
260  },
261  },
262  {
263  DepthwiseMethod::DEPTHFIRST,
264  "a64_u8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst",
265  constraint<Requantize32>(is_supported<a64_u8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst>,
266  cpu_has_dot_product,
267  has_channel_multiplier,
268  qp_has_no_left_shift),
269  nullptr,
270  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
271  auto strat = new a64_u8q_packed_to_nhwc_5x5_s1_with_multiplier_output4x2_dot_depthfirst(args.cpu_info);
272  return new DepthwiseDepthfirstMultiplier<uint8_t, uint8_t, uint8_t, int32_t, false>(strat, args, qp);
273  },
274  },
275  {
276  DepthwiseMethod::DEPTHFIRST,
277  "a64_u8q_packed_to_nhwc_generic_with_multiplier_output2x8_mla_depthfirst",
278  constraint<Requantize32>(has_channel_multiplier),
279  nullptr,
280  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<uint8_t, uint8_t, uint8_t> * {
281  auto kern = new a64_u8q_packed_to_nhwc_generic_with_multiplier_output2x8_mla_depthfirst(args.cpu_info);
282  auto strat = new GenericDepthfirstMultiplierStrategy<uint8_t>(kern, args);
283  return new DepthwiseDepthfirstMultiplier<uint8_t, uint8_t, uint8_t, int32_t, true>(strat, args, qp);
284  },
285  },
286 
287 #endif // defined(__aarch64__)
288  { DepthwiseMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
289 };
290 
291 template <>
293 {
294  return depthwise_u8q_methods;
295 }
296 
297 template UniqueDepthwiseCommon<uint8_t, uint8_t, uint8_t> depthwise(const DepthwiseArgs &, const Requantize32 &);
298 template std::vector<KernelDescription> get_compatible_kernels<uint8_t, uint8_t, uint8_t, Requantize32>(const DepthwiseArgs &, const Requantize32 &);
299 
300 } // namespace depthwise
301 } // namespace arm_conv
const DepthwiseImplementation< float > * depthwise_implementation_list()
template std::vector< KernelDescription > get_compatible_kernels< uint8_t, uint8_t, uint8_t, Requantize32 >(const DepthwiseArgs &, const Requantize32 &)
template UniqueDepthwiseCommon< float > depthwise(const DepthwiseArgs &, const Nothing &)