Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | 8c837ca | 2020-01-07 15:06:41 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2020 ARM Limited. |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 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 | */ |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 24 | #include "arm_compute/core/NEON/kernels/NEDepthwiseConvolutionLayerNativeKernel.h" |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/AccessWindowStatic.h" |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CPP/Validate.h" |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/NEON/wrapper/traits.h" |
| 29 | #include "arm_compute/core/NEON/wrapper/wrapper.h" |
| 30 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
| 32 | #include "src/core/NEON/kernels/convolution/depthwise/impl_qa8_qa8.hpp" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 33 | #include "support/ToolchainSupport.h" |
Georgios Pinitas | 1c29ffc | 2019-08-01 15:03:00 +0100 | [diff] [blame] | 34 | |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace |
| 38 | { |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 39 | void pad_vectors(std::vector<int> &mult, std::vector<int> &shift, int vec_size) |
| 40 | { |
| 41 | ARM_COMPUTE_ERROR_ON(mult.size() != shift.size()); |
| 42 | while(mult.size() % vec_size != 0) |
| 43 | { |
| 44 | mult.push_back(0); |
| 45 | shift.push_back(0); |
| 46 | } |
| 47 | } |
| 48 | |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 49 | template <typename T, int S> |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 50 | void depthwise_loop_multiplier1_fp(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 51 | const Size2D &dilation, const Window &window, bool has_biases) |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 52 | { |
| 53 | using VectorType = typename wrapper::traits::neon_vector<T, S>::type; |
| 54 | using TagType = typename wrapper::traits::neon_vector<T, S>::tag_type; |
| 55 | |
| 56 | const size_t input_stride_y = input->info()->strides_in_bytes().y(); |
| 57 | const size_t input_stride_z = input->info()->strides_in_bytes().z(); |
| 58 | const size_t input_max_offset = input->info()->strides_in_bytes().z() * input->info()->dimension(2) - (input->info()->padding().bottom + input->info()->padding().top) * |
| 59 | input->info()->strides_in_bytes().y(); |
| 60 | const size_t weights_width = weights->info()->dimension(1); |
| 61 | const size_t weights_height = weights->info()->dimension(2); |
| 62 | const size_t weights_stride_y = weights->info()->strides_in_bytes().y(); |
| 63 | const size_t weights_stride_z = weights->info()->strides_in_bytes().z(); |
| 64 | const size_t conv_stride_x = conv_info.stride().first; |
| 65 | const size_t conv_stride_y = conv_info.stride().second; |
| 66 | const size_t conv_pad_left = conv_info.pad_left(); |
| 67 | const size_t conv_pad_top = conv_info.pad_top(); |
| 68 | |
| 69 | Window win_input = window; |
| 70 | win_input.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 71 | win_input.set(Window::DimZ, Window::Dimension(0, 0, 0)); |
| 72 | |
| 73 | Window win_weights = win_input; |
| 74 | win_weights.set(3, Window::Dimension(0, 0, 0)); |
| 75 | |
| 76 | Iterator input_it(input, win_input); |
| 77 | Iterator weights_it(weights, win_weights); |
| 78 | Iterator output_it(output, window); |
| 79 | Iterator biases_it{}; |
| 80 | |
| 81 | if(has_biases) |
| 82 | { |
| 83 | biases_it = Iterator(biases, win_weights); |
| 84 | } |
| 85 | |
| 86 | execute_window_loop(window, [&](const Coordinates & id) |
| 87 | { |
| 88 | VectorType acc = wrapper::vdup_n(static_cast<T>(0), TagType{}); |
| 89 | |
| 90 | const int input_y = id.y() * conv_stride_x - conv_pad_left; |
| 91 | const int input_z = id.z() * conv_stride_y - conv_pad_top; |
| 92 | int input_offset = input_y * input_stride_y + input_z * input_stride_z; |
| 93 | |
| 94 | auto weights_ptr = weights_it.ptr(); |
| 95 | for(size_t h = 0; h < weights_height; ++h) |
| 96 | { |
| 97 | int offs = input_offset; |
| 98 | for(size_t w = 0; w < weights_width; ++w) |
| 99 | { |
| 100 | const auto input_vals = wrapper::vload(reinterpret_cast<T *>(input_it.ptr() + std::min(static_cast<size_t>(offs), input_max_offset))); |
| 101 | const auto weights_vals = wrapper::vload(reinterpret_cast<T *>(weights_ptr + w * weights_stride_y)); |
| 102 | |
| 103 | acc = wrapper::vmla(acc, weights_vals, input_vals); |
| 104 | offs += dilation.x() * input_stride_y; |
| 105 | } |
| 106 | |
| 107 | weights_ptr += weights_stride_z; |
| 108 | input_offset += dilation.y() * input_stride_z; |
| 109 | } |
| 110 | |
| 111 | if(has_biases) |
| 112 | { |
| 113 | const auto biases_vals = wrapper::vload(reinterpret_cast<T *>(biases_it.ptr())); |
| 114 | acc = wrapper::vadd(acc, biases_vals); |
| 115 | } |
| 116 | |
| 117 | wrapper::vstore(reinterpret_cast<T *>(output_it.ptr()), acc); |
| 118 | }, |
| 119 | input_it, weights_it, biases_it, output_it); |
| 120 | } |
| 121 | |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 122 | template <typename T> |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 123 | void depthwise_loop_generic_fp(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 124 | const Size2D &dilation, unsigned int depth_multiplier, const Window &window, bool has_biases) |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 125 | { |
| 126 | const size_t input_stride_y = input->info()->strides_in_bytes().y(); |
| 127 | const size_t input_stride_z = input->info()->strides_in_bytes().z(); |
| 128 | const size_t input_max_offset = input->info()->strides_in_bytes().z() * input->info()->dimension(2) - (input->info()->padding().bottom + input->info()->padding().top) * |
| 129 | input->info()->strides_in_bytes().y(); |
| 130 | const size_t weights_width = weights->info()->dimension(1); |
| 131 | const size_t weights_height = weights->info()->dimension(2); |
| 132 | const size_t weights_stride_y = weights->info()->strides_in_bytes().y(); |
| 133 | const size_t weights_stride_z = weights->info()->strides_in_bytes().z(); |
| 134 | const size_t conv_stride_x = conv_info.stride().first; |
| 135 | const size_t conv_stride_y = conv_info.stride().second; |
| 136 | const size_t conv_pad_left = conv_info.pad_left(); |
| 137 | const size_t conv_pad_top = conv_info.pad_top(); |
| 138 | |
| 139 | Window win_input = window; |
| 140 | win_input.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 141 | win_input.set(Window::DimZ, Window::Dimension(0, 0, 0)); |
| 142 | |
| 143 | Window win_weights = win_input; |
| 144 | win_weights.set(3, Window::Dimension(0, 0, 0)); |
| 145 | |
| 146 | win_input.set_dimension_step(Window::DimX, 1); |
| 147 | |
| 148 | Iterator input_it(input, win_input); |
| 149 | Iterator weights_it(weights, win_weights); |
| 150 | Iterator output_it(output, window); |
| 151 | Iterator biases_it{}; |
| 152 | |
| 153 | if(has_biases) |
| 154 | { |
| 155 | biases_it = Iterator(biases, win_weights); |
| 156 | } |
| 157 | |
| 158 | execute_window_loop(window, [&](const Coordinates & id) |
| 159 | { |
| 160 | std::vector<T> acc(depth_multiplier, static_cast<T>(0)); |
| 161 | |
| 162 | const int input_y = id.y() * conv_stride_x - conv_pad_left; |
| 163 | const int input_z = id.z() * conv_stride_y - conv_pad_top; |
| 164 | int input_offset = input_y * input_stride_y + input_z * input_stride_z; |
| 165 | |
| 166 | auto weights_ptr = weights_it.ptr(); |
| 167 | for(size_t h = 0; h < weights_height; ++h) |
| 168 | { |
| 169 | int offs = input_offset; |
| 170 | for(size_t w = 0; w < weights_width; ++w) |
| 171 | { |
| 172 | const auto input_val = *(reinterpret_cast<T *>(input_it.ptr() + std::min(static_cast<size_t>(offs), input_max_offset))); |
| 173 | |
| 174 | for(size_t m = 0; m < depth_multiplier; ++m) |
| 175 | { |
| 176 | const auto weights_val = *(reinterpret_cast<T *>(weights_ptr + m * sizeof(T) + w * weights_stride_y)); |
Georgios Pinitas | 1c29ffc | 2019-08-01 15:03:00 +0100 | [diff] [blame] | 177 | acc.at(m) = support::cpp11::fma(weights_val, input_val, acc.at(m)); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | offs += dilation.x() * input_stride_y; |
| 181 | } |
| 182 | |
| 183 | weights_ptr += weights_stride_z; |
| 184 | input_offset += dilation.y() * input_stride_z; |
| 185 | } |
| 186 | |
| 187 | if(has_biases) |
| 188 | { |
| 189 | for(size_t m = 0; m < depth_multiplier; ++m) |
| 190 | { |
| 191 | const auto biases_val = *(reinterpret_cast<T *>(biases_it.ptr() + m * sizeof(T))); |
| 192 | *(reinterpret_cast<T *>(output_it.ptr() + m * sizeof(T))) = acc.at(m) + biases_val; |
| 193 | } |
| 194 | } |
| 195 | else |
| 196 | { |
| 197 | for(size_t m = 0; m < depth_multiplier; ++m) |
| 198 | { |
| 199 | *(reinterpret_cast<T *>(output_it.ptr() + m * sizeof(T))) = acc.at(m); |
| 200 | } |
| 201 | } |
| 202 | }, |
| 203 | input_it, weights_it, biases_it, output_it); |
| 204 | } |
| 205 | |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 206 | template <typename T, typename TW, int S> |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 207 | void depthwise_loop_multiplier1_quantized(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 208 | const Size2D &dilation, std::vector<int> output_multiplier, std::vector<int> output_shift, const Window &window, bool has_biases) |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 209 | { |
| 210 | using VectorType = typename wrapper::traits::neon_vector<T, S>::type; |
| 211 | using TagType = typename wrapper::traits::neon_vector<T, S>::tag_type; |
| 212 | |
| 213 | const size_t input_stride_y = input->info()->strides_in_bytes().y(); |
| 214 | const size_t input_stride_z = input->info()->strides_in_bytes().z(); |
| 215 | const size_t input_max_offset = input->info()->strides_in_bytes().z() * input->info()->dimension(2) - (input->info()->padding().bottom + input->info()->padding().top) * |
| 216 | input->info()->strides_in_bytes().y(); |
| 217 | const size_t weights_width = weights->info()->dimension(1); |
| 218 | const size_t weights_height = weights->info()->dimension(2); |
| 219 | const size_t weights_stride_y = weights->info()->strides_in_bytes().y(); |
| 220 | const size_t weights_stride_z = weights->info()->strides_in_bytes().z(); |
| 221 | const size_t conv_stride_x = conv_info.stride().first; |
| 222 | const size_t conv_stride_y = conv_info.stride().second; |
| 223 | const size_t conv_pad_left = conv_info.pad_left(); |
| 224 | const size_t conv_pad_top = conv_info.pad_top(); |
| 225 | |
| 226 | const int32_t input_qoffset = input->info()->quantization_info().uniform().offset; |
| 227 | const int32_t weights_qoffset = weights->info()->quantization_info().uniform().offset; |
| 228 | const int32_t output_qoffset = output->info()->quantization_info().uniform().offset; |
| 229 | const int32_t k_offset = weights_width * weights_height * input_qoffset * weights_qoffset; |
| 230 | |
| 231 | Window win_input = window; |
| 232 | win_input.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 233 | win_input.set(Window::DimZ, Window::Dimension(0, 0, 0)); |
| 234 | |
| 235 | Window win_weights = win_input; |
| 236 | win_weights.set(3, Window::Dimension(0, 0, 0)); |
| 237 | |
| 238 | Iterator input_it(input, win_input); |
| 239 | Iterator weights_it(weights, win_weights); |
| 240 | Iterator output_it(output, window); |
| 241 | Iterator biases_it{}; |
| 242 | |
| 243 | if(has_biases) |
| 244 | { |
| 245 | biases_it = Iterator(biases, win_weights); |
| 246 | } |
| 247 | |
| 248 | execute_window_loop(window, [&](const Coordinates & id) |
| 249 | { |
| 250 | std::vector<int32_t> acc(S, 0); |
| 251 | std::vector<int32_t> in_sum(S, 0); |
| 252 | std::vector<int32_t> we_sum(S, 0); |
| 253 | |
| 254 | const int input_y = id.y() * conv_stride_x - conv_pad_left; |
| 255 | const int input_z = id.z() * conv_stride_y - conv_pad_top; |
| 256 | int input_offset = input_y * input_stride_y + input_z * input_stride_z; |
| 257 | |
| 258 | auto weights_ptr = weights_it.ptr(); |
| 259 | for(size_t h = 0; h < weights_height; ++h) |
| 260 | { |
| 261 | int offs = input_offset; |
| 262 | for(size_t w = 0; w < weights_width; ++w) |
| 263 | { |
| 264 | const auto input_vals = wrapper::vload(reinterpret_cast<T *>(input_it.ptr() + std::min(static_cast<size_t>(offs), input_max_offset))); |
| 265 | const auto weights_vals = wrapper::vload(reinterpret_cast<TW *>(weights_ptr + w * weights_stride_y)); |
| 266 | |
| 267 | for(int i = 0; i < S; ++i) |
| 268 | { |
| 269 | acc.at(i) += input_vals[i] * weights_vals[i]; |
| 270 | in_sum.at(i) += input_vals[i]; |
| 271 | we_sum.at(i) += weights_vals[i]; |
| 272 | } |
| 273 | |
| 274 | offs += dilation.x() * input_stride_y; |
| 275 | } |
| 276 | |
| 277 | weights_ptr += weights_stride_z; |
| 278 | input_offset += dilation.y() * input_stride_z; |
| 279 | } |
| 280 | |
| 281 | VectorType out_vals = wrapper::vdup_n(static_cast<T>(0), TagType{}); |
| 282 | for(int i = 0; i < S; ++i) |
| 283 | { |
| 284 | acc.at(i) -= in_sum.at(i) * weights_qoffset; |
| 285 | acc.at(i) -= we_sum.at(i) * input_qoffset; |
| 286 | acc.at(i) += k_offset; |
| 287 | |
| 288 | if(has_biases) |
| 289 | { |
| 290 | acc.at(i) += *reinterpret_cast<int32_t *>(biases_it.ptr() + i * sizeof(int32_t)); |
| 291 | } |
| 292 | |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 293 | const int out_mul = output_multiplier.at(id.x() + i); |
| 294 | const int out_shift = output_shift.at(id.x() + i); |
| 295 | if(out_shift < 0) |
| 296 | { |
| 297 | acc.at(i) = saturating_doubling_high_mul(acc.at(i) * (1 << (-out_shift)), out_mul) + output_qoffset; |
| 298 | } |
| 299 | else |
| 300 | { |
| 301 | acc.at(i) = rounding_divide_by_exp2(saturating_doubling_high_mul(acc.at(i), out_mul), out_shift) + output_qoffset; |
| 302 | } |
Michele Di Giorgio | 8c837ca | 2020-01-07 15:06:41 +0000 | [diff] [blame] | 303 | out_vals[i] = static_cast<T>(utility::clamp<int32_t, T>(acc.at(i))); |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | wrapper::vstore(reinterpret_cast<T *>(output_it.ptr()), out_vals); |
| 307 | }, |
| 308 | input_it, weights_it, biases_it, output_it); |
| 309 | } |
| 310 | |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 311 | template <typename T, typename TW> |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 312 | void depthwise_loop_generic_quantized(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 313 | const Size2D &dilation, unsigned int depth_multiplier, std::vector<int> output_multiplier, std::vector<int> output_shift, const Window &window, bool has_biases) |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 314 | { |
| 315 | const size_t input_stride_y = input->info()->strides_in_bytes().y(); |
| 316 | const size_t input_stride_z = input->info()->strides_in_bytes().z(); |
| 317 | const size_t input_max_offset = input->info()->strides_in_bytes().z() * input->info()->dimension(2) - (input->info()->padding().bottom + input->info()->padding().top) * |
| 318 | input->info()->strides_in_bytes().y(); |
| 319 | const size_t weights_width = weights->info()->dimension(1); |
| 320 | const size_t weights_height = weights->info()->dimension(2); |
| 321 | const size_t weights_stride_y = weights->info()->strides_in_bytes().y(); |
| 322 | const size_t weights_stride_z = weights->info()->strides_in_bytes().z(); |
| 323 | const size_t conv_stride_x = conv_info.stride().first; |
| 324 | const size_t conv_stride_y = conv_info.stride().second; |
| 325 | const size_t conv_pad_left = conv_info.pad_left(); |
| 326 | const size_t conv_pad_top = conv_info.pad_top(); |
| 327 | |
| 328 | const int32_t input_qoffset = input->info()->quantization_info().uniform().offset; |
| 329 | const int32_t weights_qoffset = weights->info()->quantization_info().uniform().offset; |
| 330 | const int32_t output_qoffset = output->info()->quantization_info().uniform().offset; |
| 331 | const int32_t k_offset = weights_width * weights_height * input_qoffset * weights_qoffset; |
| 332 | |
| 333 | Window win_input = window; |
| 334 | win_input.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 335 | win_input.set(Window::DimZ, Window::Dimension(0, 0, 0)); |
| 336 | |
| 337 | Window win_weights = win_input; |
| 338 | win_weights.set(3, Window::Dimension(0, 0, 0)); |
| 339 | |
| 340 | win_input.set_dimension_step(Window::DimX, 1); |
| 341 | |
| 342 | Iterator input_it(input, win_input); |
| 343 | Iterator weights_it(weights, win_weights); |
| 344 | Iterator output_it(output, window); |
| 345 | Iterator biases_it{}; |
| 346 | |
| 347 | if(has_biases) |
| 348 | { |
| 349 | biases_it = Iterator(biases, win_weights); |
| 350 | } |
| 351 | |
| 352 | execute_window_loop(window, [&](const Coordinates & id) |
| 353 | { |
| 354 | std::vector<int32_t> acc(depth_multiplier, 0); |
| 355 | std::vector<int32_t> we_sum(depth_multiplier, 0); |
| 356 | int32_t in_sum = 0; |
| 357 | |
| 358 | const int input_y = id.y() * conv_stride_x - conv_pad_left; |
| 359 | const int input_z = id.z() * conv_stride_y - conv_pad_top; |
| 360 | int input_offset = input_y * input_stride_y + input_z * input_stride_z; |
| 361 | |
| 362 | auto weights_ptr = weights_it.ptr(); |
| 363 | for(size_t h = 0; h < weights_height; ++h) |
| 364 | { |
| 365 | int offs = input_offset; |
| 366 | for(size_t w = 0; w < weights_width; ++w) |
| 367 | { |
| 368 | const auto input_val = *(reinterpret_cast<T *>(input_it.ptr() + std::min(static_cast<size_t>(offs), input_max_offset))); |
| 369 | |
| 370 | for(size_t m = 0; m < depth_multiplier; ++m) |
| 371 | { |
| 372 | const auto weights_val = *(reinterpret_cast<TW *>(weights_ptr + m * sizeof(T) + w * weights_stride_y)); |
| 373 | acc.at(m) += input_val * weights_val; |
| 374 | |
| 375 | we_sum.at(m) += weights_val; |
| 376 | } |
| 377 | |
| 378 | offs += dilation.x() * input_stride_y; |
| 379 | in_sum += input_val; |
| 380 | } |
| 381 | |
| 382 | weights_ptr += weights_stride_z; |
| 383 | input_offset += dilation.y() * input_stride_z; |
| 384 | } |
| 385 | |
| 386 | for(size_t m = 0; m < depth_multiplier; ++m) |
| 387 | { |
| 388 | acc.at(m) -= in_sum * weights_qoffset; |
| 389 | acc.at(m) -= we_sum.at(m) * input_qoffset; |
| 390 | acc.at(m) += k_offset; |
| 391 | |
| 392 | if(has_biases) |
| 393 | { |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 394 | acc.at(m) += *(reinterpret_cast<int32_t *>(biases_it.ptr() + m * sizeof(int32_t))); |
| 395 | } |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 396 | |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 397 | const int out_mul = output_multiplier.at(id.x() + m); |
| 398 | const int out_shift = output_shift.at(id.x() + m); |
| 399 | if(out_shift < 0) |
| 400 | { |
| 401 | acc.at(m) = saturating_doubling_high_mul(acc.at(m) * (1 << (-out_shift)), out_mul) + output_qoffset; |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 402 | } |
| 403 | else |
| 404 | { |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 405 | acc.at(m) = rounding_divide_by_exp2(saturating_doubling_high_mul(acc.at(m), out_mul), out_shift) + output_qoffset; |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 406 | } |
Michele Di Giorgio | 8c837ca | 2020-01-07 15:06:41 +0000 | [diff] [blame] | 407 | *(reinterpret_cast<T *>(output_it.ptr() + m * sizeof(T))) = static_cast<T>(utility::clamp<int32_t, T>(acc.at(m))); |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 408 | } |
| 409 | }, |
| 410 | input_it, weights_it, biases_it, output_it); |
| 411 | } |
| 412 | |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 413 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, |
| 414 | const Size2D &dilation) |
| 415 | { |
| 416 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output); |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 417 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input); |
| 418 | ARM_COMPUTE_RETURN_ERROR_ON(input->data_layout() == DataLayout::UNKNOWN); |
Michele Di Giorgio | 8c837ca | 2020-01-07 15:06:41 +0000 | [diff] [blame] | 419 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::F16, DataType::F32); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 420 | ARM_COMPUTE_RETURN_ERROR_ON(depth_multiplier == 0); |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 421 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(1) + (weights->dimension(1) - 1) * (dilation.x() - 1) > input->dimension(1) + conv_info.pad_left() + conv_info.pad_right()); |
| 422 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(2) + (weights->dimension(2) - 1) * (dilation.y() - 1) > input->dimension(2) + conv_info.pad_top() + conv_info.pad_bottom()); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 423 | ARM_COMPUTE_RETURN_ERROR_ON((input->dimension(0) * depth_multiplier) != weights->dimension(0)); |
| 424 | ARM_COMPUTE_RETURN_ERROR_ON((dilation.x() < 1) || (dilation.y() < 1)); |
| 425 | ARM_COMPUTE_RETURN_ERROR_ON((conv_info.stride().first < 1) || (conv_info.stride().second < 1)); |
| 426 | |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 427 | if(is_data_type_quantized_per_channel(weights->data_type())) |
| 428 | { |
| 429 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(weights, 1, DataType::QSYMM8_PER_CHANNEL); |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 430 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(0) != weights->quantization_info().scale().size()); |
| 431 | } |
| 432 | else |
| 433 | { |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 434 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 435 | } |
| 436 | |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 437 | if(biases != nullptr) |
| 438 | { |
| 439 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
| 440 | ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != weights->dimension(0)); |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 441 | |
| 442 | if(is_data_type_quantized_asymmetric(input->data_type())) |
| 443 | { |
| 444 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32); |
| 445 | } |
| 446 | else |
| 447 | { |
| 448 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(weights, biases); |
| 449 | } |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | if(output->total_size() != 0) |
| 453 | { |
| 454 | const TensorShape output_shape = misc::shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier, dilation); |
| 455 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 456 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | return Status{}; |
| 460 | } |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 461 | |
| 462 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, |
| 463 | ITensorInfo *output, const PadStrideInfo &conv_info, |
| 464 | unsigned int depth_multiplier, const Size2D &dilation) |
| 465 | { |
| 466 | // Get convolved dimensions |
| 467 | const TensorShape output_shape = misc::shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier, dilation); |
| 468 | |
| 469 | // Output auto inizialitation if not yet initialized |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 470 | auto_init_if_empty(*output, input->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(output_shape).set_quantization_info(output->quantization_info())); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 471 | |
| 472 | // Configure kernel window (generic) |
| 473 | const unsigned int num_elems_read_per_iteration = (depth_multiplier == 1) ? 8 / element_size_from_data_type(input->data_type()) : 1; |
| 474 | const unsigned int num_elems_written_per_iteration = num_elems_read_per_iteration * depth_multiplier; |
| 475 | |
| 476 | // Configure kernel window |
| 477 | Window win = calculate_max_window(*output, Steps(num_elems_written_per_iteration)); |
| 478 | |
| 479 | AccessWindowStatic input_access(input, 0, -conv_info.pad_left(), ceil_to_multiple(num_elems_read_per_iteration, input->dimension(0)), |
| 480 | input->dimension(1) + std::max(std::max(conv_info.pad_right(), conv_info.pad_bottom()), conv_info.pad_top())); |
| 481 | AccessWindowHorizontal weights_access(weights, 0, num_elems_written_per_iteration); |
| 482 | AccessWindowHorizontal output_access(output, 0, num_elems_written_per_iteration); |
| 483 | |
| 484 | bool window_changed = update_window_and_padding(win, input_access, weights_access, output_access); |
| 485 | |
| 486 | if(biases != nullptr) |
| 487 | { |
| 488 | AccessWindowHorizontal biases_access(biases, 0, num_elems_written_per_iteration); |
| 489 | window_changed |= update_window_and_padding(win, biases_access); |
| 490 | } |
| 491 | |
| 492 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 493 | |
| 494 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 495 | return std::make_pair(err, win); |
| 496 | } |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 497 | } // namespace |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 498 | |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 499 | NEDepthwiseConvolutionLayerNativeKernel::NEDepthwiseConvolutionLayerNativeKernel() |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 500 | : _func(), _border_size(0), _input(), _weights(), _biases(), _output(), _conv_info(), _depth_multiplier(1), _dilation(), _output_multiplier(), _output_shift(), _has_biases() |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 501 | { |
| 502 | } |
| 503 | |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 504 | BorderSize NEDepthwiseConvolutionLayerNativeKernel::border_size() const |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 505 | { |
| 506 | return _border_size; |
| 507 | } |
| 508 | |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 509 | void NEDepthwiseConvolutionLayerNativeKernel::configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, |
| 510 | const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation) |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 511 | { |
| 512 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
| 513 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(), conv_info, depth_multiplier, dilation)); |
| 514 | |
| 515 | _input = input; |
| 516 | _weights = weights; |
| 517 | _biases = biases; |
| 518 | _output = output; |
| 519 | _conv_info = conv_info; |
| 520 | _depth_multiplier = depth_multiplier; |
| 521 | _border_size = BorderSize(_conv_info.pad_left(), 0, std::max(std::max(conv_info.pad_right(), conv_info.pad_bottom()), conv_info.pad_top()), 0); |
| 522 | _dilation = dilation; |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 523 | _has_biases = (biases != nullptr); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 524 | |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 525 | if(is_data_type_quantized(_input->info()->data_type())) |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 526 | { |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 527 | const auto input_scale = input->info()->quantization_info().uniform().scale; |
| 528 | const auto output_scale = output->info()->quantization_info().uniform().scale; |
| 529 | |
| 530 | auto weights_scale = weights->info()->quantization_info().scale(); |
| 531 | if(!is_data_type_quantized_per_channel(_weights->info()->data_type())) |
| 532 | { |
| 533 | for(size_t i = 1; i < _weights->info()->dimension(0); ++i) |
| 534 | { |
| 535 | weights_scale.push_back(weights_scale.front()); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | for(size_t i = 0; i < weights_scale.size(); ++i) |
| 540 | { |
Michalis Spyrou | e7be8a0 | 2019-12-12 16:16:09 +0000 | [diff] [blame] | 541 | int32_t out_mult = 0; |
| 542 | int32_t out_shift = 0; |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 543 | const float multiplier = input_scale * weights_scale.at(i) / output_scale; |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 544 | arm_compute::quantization::calculate_quantized_multiplier(multiplier, &out_mult, &out_shift); |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 545 | |
| 546 | _output_multiplier.push_back(out_mult); |
| 547 | _output_shift.push_back(out_shift); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | switch(_weights->info()->data_type()) |
| 552 | { |
| 553 | case DataType::QASYMM8: |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 554 | _func = &NEDepthwiseConvolutionLayerNativeKernel::run_depthwise<uint8_t, uint8_t, 8>; |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 555 | pad_vectors(_output_multiplier, _output_shift, 8); |
| 556 | break; |
Michele Di Giorgio | 8c837ca | 2020-01-07 15:06:41 +0000 | [diff] [blame] | 557 | case DataType::QASYMM8_SIGNED: |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 558 | _func = &NEDepthwiseConvolutionLayerNativeKernel::run_depthwise<int8_t, int8_t, 8>; |
Michele Di Giorgio | 8c837ca | 2020-01-07 15:06:41 +0000 | [diff] [blame] | 559 | pad_vectors(_output_multiplier, _output_shift, 8); |
| 560 | break; |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 561 | case DataType::QSYMM8_PER_CHANNEL: |
Michele Di Giorgio | 8c837ca | 2020-01-07 15:06:41 +0000 | [diff] [blame] | 562 | if(_input->info()->data_type() == DataType::QASYMM8) |
| 563 | { |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 564 | _func = &NEDepthwiseConvolutionLayerNativeKernel::run_depthwise<uint8_t, int8_t, 8>; |
Michele Di Giorgio | 8c837ca | 2020-01-07 15:06:41 +0000 | [diff] [blame] | 565 | } |
| 566 | else |
| 567 | { |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 568 | _func = &NEDepthwiseConvolutionLayerNativeKernel::run_depthwise<int8_t, int8_t, 8>; |
Michele Di Giorgio | 8c837ca | 2020-01-07 15:06:41 +0000 | [diff] [blame] | 569 | } |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 570 | pad_vectors(_output_multiplier, _output_shift, 8); |
| 571 | break; |
| 572 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 573 | case DataType::F16: |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 574 | _func = &NEDepthwiseConvolutionLayerNativeKernel::run_depthwise<float16_t, float16_t, 4>; |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 575 | pad_vectors(_output_multiplier, _output_shift, 4); |
| 576 | break; |
| 577 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 578 | case DataType::F32: |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 579 | _func = &NEDepthwiseConvolutionLayerNativeKernel::run_depthwise<float, float, 2>; |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 580 | pad_vectors(_output_multiplier, _output_shift, 2); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 581 | break; |
| 582 | default: |
| 583 | ARM_COMPUTE_ERROR("Data type not supported"); |
| 584 | break; |
| 585 | } |
| 586 | |
| 587 | auto win_config = validate_and_configure_window(_input->info(), _weights->info(), (biases != nullptr) ? biases->info() : nullptr, _output->info(), _conv_info, _depth_multiplier, dilation); |
| 588 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 589 | INEKernel::configure(win_config.second); |
| 590 | } |
| 591 | |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 592 | Status NEDepthwiseConvolutionLayerNativeKernel::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 593 | unsigned int depth_multiplier, |
| 594 | const Size2D &dilation) |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 595 | { |
| 596 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, conv_info, depth_multiplier, dilation)); |
| 597 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), weights->clone().get(), (biases != nullptr) ? biases->clone().get() : nullptr, output->clone().get(), conv_info, |
| 598 | depth_multiplier, dilation) |
| 599 | .first); |
| 600 | return Status{}; |
| 601 | } |
| 602 | |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 603 | void NEDepthwiseConvolutionLayerNativeKernel::run(const Window &window, const ThreadInfo &info) |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 604 | { |
| 605 | ARM_COMPUTE_UNUSED(info); |
| 606 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 607 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 608 | |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 609 | (this->*_func)(window, _has_biases); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 610 | } |
| 611 | |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 612 | template < typename T, typename TW, int S, typename std::enable_if < std::is_same<T, float>::value |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 613 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 614 | || std::is_same<T, float16_t>::value |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 615 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 616 | , |
| 617 | int >::type > |
| 618 | void NEDepthwiseConvolutionLayerNativeKernel::run_depthwise(const Window &window, bool has_biases) |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 619 | { |
| 620 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 621 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 622 | |
| 623 | if(_depth_multiplier == 1) |
| 624 | { |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 625 | depthwise_loop_multiplier1_fp<T, S>(_input, _weights, _biases, _output, _conv_info, _dilation, window, has_biases); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 626 | } |
| 627 | else |
| 628 | { |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 629 | depthwise_loop_generic_fp<T>(_input, _weights, _biases, _output, _conv_info, _dilation, _depth_multiplier, window, has_biases); |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 633 | template <typename T, typename TW, int S, typename> |
| 634 | void NEDepthwiseConvolutionLayerNativeKernel::run_depthwise(const Window &window, bool has_biases) |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 635 | { |
| 636 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 637 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 638 | |
| 639 | if(_depth_multiplier == 1) |
| 640 | { |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 641 | depthwise_loop_multiplier1_quantized<T, TW, S>(_input, _weights, _biases, _output, _conv_info, _dilation, _output_multiplier, _output_shift, window, has_biases); |
Giorgio Arena | d93e263 | 2019-10-15 11:09:33 +0100 | [diff] [blame] | 642 | } |
| 643 | else |
| 644 | { |
Michalis Spyrou | f401c74 | 2020-05-12 16:18:33 +0100 | [diff] [blame] | 645 | depthwise_loop_generic_quantized<T, TW>(_input, _weights, _biases, _output, _conv_info, _dilation, _depth_multiplier, _output_multiplier, _output_shift, window, has_biases); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | } // namespace arm_compute |