Compute Library
 22.08
depthwise_s8q.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)
43 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
53 #endif // defined(__aarch64__)
54 
55 #include <cstdint>
56 
58 
59 namespace arm_conv {
60 namespace depthwise {
61 
62 namespace
63 {
64 #if defined(__aarch64__)
65 bool 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 }
70 #endif // defined(__aarch64__)
71 }
72 
73 static const DepthwiseImplementation<int8_t, int8_t, int8_t, Requantize32> depthwise_s8q_methods[] = {
74 #if defined(__aarch64__)
75 #if defined(ARM_COMPUTE_ENABLE_SVE)
76  {
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,
82  qp_weights_are_symmetric,
83  cpu_has_sve2),
84  nullptr,
85  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
86  auto strat = new sve_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst(args.cpu_info);
87  return new DepthwiseDepthfirst<int8_t>(strat, 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,
95  qp_has_no_left_shift,
96  cpu_has_sve2),
97  nullptr,
98  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
99  auto strat = new sve_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst(args.cpu_info);
100  return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
101  },
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,
108  qp_has_no_left_shift,
109  cpu_has_sve2),
110  nullptr,
111  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
112  auto strat = new sve_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst(args.cpu_info);
113  return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
114  },
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,
121  qp_has_no_left_shift,
122  cpu_has_sve2),
123  nullptr,
124  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
125  auto strat = new sve_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst(args.cpu_info);
126  return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
127  },
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,
134  qp_has_no_left_shift,
135  cpu_has_sve2),
136  nullptr,
137  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
138  auto strat = new sve_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst(args.cpu_info);
139  return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
140  },
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>,
146  qp_has_no_left_shift,
147  has_channel_multiplier,
148  cpu_has_sve2),
149  nullptr,
150  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
151  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);
153  },
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>,
159  qp_has_no_left_shift,
160  has_channel_multiplier,
161  cpu_has_sve2),
162  nullptr,
163  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
164  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);
166  },
167  },
168 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
169  {
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> * {
179  auto strat = new a64_s8qs_nhwc_3x3_s1_output2x2_dot_depthfirst(args.cpu_info);
180  return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
181  },
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> * {
192  auto strat = new a64_s8q_nhwc_3x3_s1_output2x2_dot_depthfirst(args.cpu_info);
193  return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
194  },
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> * {
204  auto strat = new a64_s8q_nhwc_3x3_s1_output2x2_mla_depthfirst(args.cpu_info);
205  return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
206  },
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> * {
216  auto strat = new a64_s8q_nhwc_3x3_s2_output2x2_mla_depthfirst(args.cpu_info);
217  return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
218  },
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> * {
228  auto strat = new a64_s8q_nhwc_5x5_s1_output2x2_mla_depthfirst(args.cpu_info);
229  return new DepthwiseDepthfirst<int8_t>(strat, args, qp);
230  },
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> * {
238  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);
241  },
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,
248  has_channel_multiplier,
249  cpu_has_dot_product),
250  nullptr,
251  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
252  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);
254  },
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,
261  has_channel_multiplier,
262  cpu_has_dot_product),
263  nullptr,
264  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
265  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);
267  },
268  },
269  {
270  DepthwiseMethod::DEPTHFIRST,
271  "a64_s8q_packed_to_nhwc_generic_with_multiplier_output2x8_mla_depthfirst",
272  constraint<Requantize32>(has_channel_multiplier),
273  nullptr,
274  [] (const DepthwiseArgs &args, const Requantize32 &qp) -> DepthwiseCommon<int8_t, int8_t, int8_t> * {
275  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);
278  },
279  },
280 #endif // defined(__aarch64__)
281  { DepthwiseMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
282 };
283 
284 template <>
286 {
287  return depthwise_s8q_methods;
288 }
289 
290 template UniqueDepthwiseCommon<int8_t, int8_t, int8_t> depthwise(const DepthwiseArgs &, const Requantize32 &);
291 template 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
const DepthwiseImplementation< float > * depthwise_implementation_list()
template std::vector< KernelDescription > get_compatible_kernels< int8_t, int8_t, int8_t, Requantize32 >(const DepthwiseArgs &, const Requantize32 &)
template UniqueDepthwiseCommon< float > depthwise(const DepthwiseArgs &, const Nothing &)
template UniqueDepthwiseCommon< int8_t, int8_t, int8_t > depthwise(const DepthwiseArgs &, const Requantize32 &)