Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +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 | */ |
| 24 | #include "arm_compute/core/NEON/kernels/NEDequantizationLayerKernel.h" |
| 25 | |
Gian Marco Iodice | 06b184a | 2017-08-29 16:05:25 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/AccessWindowStatic.h" |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/CPP/Validate.h" |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Error.h" |
| 29 | #include "arm_compute/core/Helpers.h" |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/NEON/NEAsymm.h" |
Michalis Spyrou | ba27e44 | 2019-05-28 10:04:57 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/NEON/NESymm.h" |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 32 | #include "arm_compute/core/NEON/wrapper/wrapper.h" |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 33 | #include "arm_compute/core/Utils.h" |
| 34 | #include "arm_compute/core/Validate.h" |
| 35 | #include "arm_compute/core/Window.h" |
| 36 | |
| 37 | #include <arm_neon.h> |
| 38 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 39 | namespace arm_compute |
| 40 | { |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 41 | namespace |
| 42 | { |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 43 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output) |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 44 | { |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 45 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); |
Sang-Hoon Park | d817647 | 2019-12-04 09:46:28 +0000 | [diff] [blame] | 46 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::QSYMM8_PER_CHANNEL, DataType::QSYMM8, DataType::QSYMM16); |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 47 | |
| 48 | if(output->tensor_shape().total_size() > 0) |
| 49 | { |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 50 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(output); |
| 51 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::F16, DataType::F32); |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 52 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output); |
| 53 | } |
| 54 | |
| 55 | return Status{}; |
| 56 | } |
| 57 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 58 | std::tuple<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output) |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 59 | { |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 60 | // Configure kernel window |
| 61 | Window win = calculate_max_window(*input, Steps()); |
| 62 | |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 63 | // Output tensor auto initialization if not yet initialized |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 64 | auto_init_if_empty(*output, input->tensor_shape(), 1, DataType::F32); |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 65 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 66 | // NEDequantizationLayerKernel doesn't need padding so update_window_and_padding() can be skipped |
| 67 | Coordinates coord; |
| 68 | coord.set_num_dimensions(output->num_dimensions()); |
| 69 | output->set_valid_region(ValidRegion(coord, output->tensor_shape())); |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 70 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 71 | return std::make_tuple(Status{}, win); |
| 72 | } |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 73 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 74 | template <typename T> |
| 75 | inline void store_result(T *ptr, const float32x4x4_t &v) |
| 76 | { |
| 77 | ARM_COMPUTE_UNUSED(ptr, v); |
| 78 | } |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 79 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 80 | template <> |
| 81 | inline void store_result<float>(float *ptr, const float32x4x4_t &v) |
| 82 | { |
| 83 | wrapper::vstore(ptr, v.val[0]); |
| 84 | wrapper::vstore(ptr + 4, v.val[1]); |
| 85 | wrapper::vstore(ptr + 8, v.val[2]); |
| 86 | wrapper::vstore(ptr + 12, v.val[3]); |
| 87 | } |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 88 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 89 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 90 | template <> |
| 91 | inline void store_result<float16_t>(float16_t *ptr, const float32x4x4_t &v) |
| 92 | { |
| 93 | wrapper::vstore(ptr, vcombine_f16(vcvt_f16_f32(v.val[0]), vcvt_f16_f32(v.val[1]))); |
| 94 | wrapper::vstore(ptr + 8, vcombine_f16(vcvt_f16_f32(v.val[2]), vcvt_f16_f32(v.val[3]))); |
| 95 | } |
| 96 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 97 | |
| 98 | template <typename T> |
Michalis Spyrou | ba27e44 | 2019-05-28 10:04:57 +0100 | [diff] [blame] | 99 | inline void store_result(T *ptr, const float32x4x2_t &v) |
| 100 | { |
| 101 | ARM_COMPUTE_UNUSED(ptr, v); |
| 102 | } |
| 103 | |
| 104 | template <> |
| 105 | inline void store_result<float>(float *ptr, const float32x4x2_t &v) |
| 106 | { |
| 107 | wrapper::vstore(ptr, v.val[0]); |
| 108 | wrapper::vstore(ptr + 4, v.val[1]); |
| 109 | } |
| 110 | |
| 111 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 112 | template <> |
| 113 | inline void store_result<float16_t>(float16_t *ptr, const float32x4x2_t &v) |
| 114 | { |
| 115 | wrapper::vstore(ptr, vcombine_f16(vcvt_f16_f32(v.val[0]), vcvt_f16_f32(v.val[1]))); |
| 116 | } |
| 117 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 118 | |
Sang-Hoon Park | d817647 | 2019-12-04 09:46:28 +0000 | [diff] [blame] | 119 | template <typename TOut, typename TIn> |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 120 | void run_dequantization_qasymm8(const ITensor *input, ITensor *output, const Window &window) |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 121 | { |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 122 | const UniformQuantizationInfo &qinfo = input->info()->quantization_info().uniform(); |
| 123 | const float scale = qinfo.scale; |
| 124 | const int32_t offset = qinfo.offset; |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 125 | |
| 126 | const int window_step_x = 16; |
| 127 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 128 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 129 | |
| 130 | // Collapse window and reset first dimension to handle tail calculations manually |
| 131 | Window win_collapsed = window.collapse_if_possible(window, Window::DimZ); |
| 132 | win_collapsed.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 133 | |
| 134 | // Create iterators |
| 135 | Iterator in(input, win_collapsed); |
| 136 | Iterator out(output, win_collapsed); |
| 137 | |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 138 | execute_window_loop(win_collapsed, [&](const Coordinates &) |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 139 | { |
Sang-Hoon Park | d817647 | 2019-12-04 09:46:28 +0000 | [diff] [blame] | 140 | const auto in_ptr = reinterpret_cast<const TIn *>(in.ptr()); |
| 141 | const auto out_ptr = reinterpret_cast<TOut *>(out.ptr()); |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 142 | |
| 143 | int x = window_start_x; |
| 144 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 145 | { |
| 146 | const auto vin = wrapper::vloadq(in_ptr + x); |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 147 | const auto vdeq = vdequantize(vin, scale, offset); |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 148 | |
Sang-Hoon Park | d817647 | 2019-12-04 09:46:28 +0000 | [diff] [blame] | 149 | store_result(reinterpret_cast<TOut *>(out_ptr + x), vdeq); |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | // Compute left-over elements |
| 153 | for(; x < window_end_x; ++x) |
| 154 | { |
Sang-Hoon Park | d817647 | 2019-12-04 09:46:28 +0000 | [diff] [blame] | 155 | auto val = *(in_ptr + x); |
| 156 | *(out_ptr + x) = static_cast<TOut>(Qasymm8QuantizationHelper<TIn>::dequantize(val, qinfo)); |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 157 | } |
| 158 | }, |
| 159 | in, out); |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 160 | } |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 161 | |
| 162 | template <typename T> |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 163 | void run_dequantization_qsymm8_per_channel_nchw(const ITensor *input, ITensor *output, const Window &window) |
Michalis Spyrou | 29a01c9 | 2019-08-22 11:44:04 +0100 | [diff] [blame] | 164 | { |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 165 | const auto scale = input->info()->quantization_info().scale(); |
Michalis Spyrou | 29a01c9 | 2019-08-22 11:44:04 +0100 | [diff] [blame] | 166 | |
| 167 | const int window_step_x = 16; |
| 168 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 169 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 170 | |
| 171 | // Reset first dimension to handle tail calculations manually |
| 172 | Window win(window); |
| 173 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 174 | |
| 175 | // Create iterators |
| 176 | Iterator in(input, win); |
| 177 | Iterator out(output, win); |
| 178 | |
| 179 | execute_window_loop(win, [&](const Coordinates & id) |
| 180 | { |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 181 | const auto in_ptr = reinterpret_cast<const int8_t *>(in.ptr()); |
Michalis Spyrou | 29a01c9 | 2019-08-22 11:44:04 +0100 | [diff] [blame] | 182 | const auto out_ptr = reinterpret_cast<T *>(out.ptr()); |
| 183 | |
| 184 | int x = window_start_x; |
| 185 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 186 | { |
| 187 | const auto vin = wrapper::vloadq(in_ptr + x); |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 188 | const auto vdeq = vdequantize(vin, scale[id.z()]); |
Michalis Spyrou | 29a01c9 | 2019-08-22 11:44:04 +0100 | [diff] [blame] | 189 | |
| 190 | store_result<T>(reinterpret_cast<T *>(out_ptr + x), vdeq); |
| 191 | } |
| 192 | |
| 193 | // Compute left-over elements |
| 194 | for(; x < window_end_x; ++x) |
| 195 | { |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 196 | int8_t val = *(in_ptr + x); |
| 197 | *(out_ptr + x) = static_cast<T>(dequantize(val, scale[id.z()])); |
Michalis Spyrou | 29a01c9 | 2019-08-22 11:44:04 +0100 | [diff] [blame] | 198 | } |
| 199 | }, |
| 200 | in, out); |
| 201 | } |
| 202 | |
| 203 | template <typename T> |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 204 | void run_dequantization_qsymm8_per_channel_nhwc(const ITensor *input, ITensor *output, const Window &window) |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 205 | { |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 206 | const auto scale = input->info()->quantization_info().scale(); |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 207 | |
| 208 | const int window_step_x = 16; |
| 209 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 210 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 211 | |
| 212 | // Reset first dimension to handle tail calculations manually |
| 213 | Window win(window); |
| 214 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 215 | |
| 216 | // Create iterators |
| 217 | Iterator in(input, win); |
| 218 | Iterator out(output, win); |
| 219 | |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 220 | execute_window_loop(win, [&](const Coordinates &) |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 221 | { |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 222 | const auto in_ptr = reinterpret_cast<const int8_t *>(in.ptr()); |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 223 | const auto out_ptr = reinterpret_cast<T *>(out.ptr()); |
| 224 | |
| 225 | int x = window_start_x; |
| 226 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 227 | { |
| 228 | const float32x4x4_t vscale = |
| 229 | { |
| 230 | { |
| 231 | scale[x + 0], scale[x + 1], scale[x + 2], scale[x + 3], |
| 232 | scale[x + 4], scale[x + 5], scale[x + 6], scale[x + 7], |
| 233 | scale[x + 8], scale[x + 9], scale[x + 10], scale[x + 11], |
| 234 | scale[x + 12], scale[x + 13], scale[x + 14], scale[x + 15] |
| 235 | } |
| 236 | }; |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 237 | const auto vin = wrapper::vloadq(in_ptr + x); |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 238 | const auto vdeq = vdequantize(vin, vscale); |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 239 | |
| 240 | store_result<T>(reinterpret_cast<T *>(out_ptr + x), vdeq); |
| 241 | } |
| 242 | |
| 243 | // Compute left-over elements |
| 244 | for(; x < window_end_x; ++x) |
| 245 | { |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 246 | int8_t val = *(in_ptr + x); |
| 247 | *(out_ptr + x) = static_cast<T>(dequantize(val, scale[x])); |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 248 | } |
| 249 | }, |
| 250 | in, out); |
| 251 | } |
| 252 | |
| 253 | template <typename T> |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 254 | void run_dequantization_qsymm8(const ITensor *input, ITensor *output, const Window &window) |
| 255 | { |
| 256 | const UniformQuantizationInfo &qinfo = input->info()->quantization_info().uniform(); |
| 257 | const float scale = qinfo.scale; |
| 258 | |
| 259 | const int window_step_x = 16; |
| 260 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 261 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 262 | |
| 263 | // Collapse window and reset first dimension to handle tail calculations manually |
| 264 | Window win_collapsed = window.collapse_if_possible(window, Window::DimZ); |
| 265 | win_collapsed.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 266 | |
| 267 | // Create iterators |
| 268 | Iterator in(input, win_collapsed); |
| 269 | Iterator out(output, win_collapsed); |
| 270 | |
| 271 | execute_window_loop(win_collapsed, [&](const Coordinates &) |
| 272 | { |
| 273 | const auto in_ptr = reinterpret_cast<const int8_t *>(in.ptr()); |
| 274 | const auto out_ptr = reinterpret_cast<T *>(out.ptr()); |
| 275 | |
| 276 | int x = window_start_x; |
| 277 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 278 | { |
| 279 | const auto vin = wrapper::vloadq(in_ptr + x); |
| 280 | const auto vdeq = vdequantize(vin, scale); |
| 281 | |
| 282 | store_result<T>(reinterpret_cast<T *>(out_ptr + x), vdeq); |
| 283 | } |
| 284 | |
| 285 | // Compute left-over elements |
| 286 | for(; x < window_end_x; ++x) |
| 287 | { |
Manuel Bottini | 10c53f1 | 2019-07-17 16:11:53 +0100 | [diff] [blame] | 288 | int8_t val = *(in_ptr + x); |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 289 | *(out_ptr + x) = static_cast<T>(dequantize(val, scale)); |
| 290 | } |
| 291 | }, |
| 292 | in, out); |
| 293 | } |
| 294 | |
| 295 | template <typename T> |
Michalis Spyrou | ba27e44 | 2019-05-28 10:04:57 +0100 | [diff] [blame] | 296 | void run_dequantization_qsymm16(const ITensor *input, ITensor *output, const Window &window) |
| 297 | { |
| 298 | const UniformQuantizationInfo &qinfo = input->info()->quantization_info().uniform(); |
| 299 | const float scale = qinfo.scale; |
| 300 | |
| 301 | const int window_step_x = 8; |
| 302 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 303 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 304 | |
| 305 | // Collapse window and reset first dimension to handle tail calculations manually |
| 306 | Window win_collapsed = window.collapse_if_possible(window, Window::DimZ); |
| 307 | win_collapsed.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 308 | |
| 309 | // Create iterators |
| 310 | Iterator in(input, win_collapsed); |
| 311 | Iterator out(output, win_collapsed); |
| 312 | |
| 313 | execute_window_loop(win_collapsed, [&](const Coordinates &) |
| 314 | { |
| 315 | const auto in_ptr = reinterpret_cast<const int16_t *>(in.ptr()); |
| 316 | const auto out_ptr = reinterpret_cast<T *>(out.ptr()); |
| 317 | |
| 318 | int x = window_start_x; |
| 319 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 320 | { |
| 321 | const auto vin = wrapper::vloadq(in_ptr + x); |
| 322 | const auto vdeq = vdequantize_int16(vin, scale); |
| 323 | |
| 324 | store_result<T>(reinterpret_cast<T *>(out_ptr + x), vdeq); |
| 325 | } |
| 326 | |
| 327 | // Compute left-over elements |
| 328 | for(; x < window_end_x; ++x) |
| 329 | { |
| 330 | int16_t val = *(in_ptr + x); |
| 331 | *(out_ptr + x) = static_cast<T>(dequantize_qsymm16(val, scale)); |
| 332 | } |
| 333 | }, |
| 334 | in, out); |
| 335 | } |
| 336 | |
| 337 | template <typename T> |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 338 | void run_dequantization_core(const ITensor *input, ITensor *output, const Window &window) |
| 339 | { |
| 340 | switch(input->info()->data_type()) |
| 341 | { |
| 342 | case DataType::QASYMM8: |
Sang-Hoon Park | d817647 | 2019-12-04 09:46:28 +0000 | [diff] [blame] | 343 | run_dequantization_qasymm8<T, uint8_t>(input, output, window); |
| 344 | break; |
| 345 | case DataType::QASYMM8_SIGNED: |
| 346 | run_dequantization_qasymm8<T, int8_t>(input, output, window); |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 347 | break; |
Georgios Pinitas | 8217c8e | 2019-11-11 18:24:22 +0000 | [diff] [blame] | 348 | case DataType::QSYMM8_PER_CHANNEL: |
| 349 | input->info()->data_layout() == DataLayout::NHWC ? run_dequantization_qsymm8_per_channel_nhwc<T>(input, output, window) : run_dequantization_qsymm8_per_channel_nchw<T>(input, output, window); |
Michalis Spyrou | 29a01c9 | 2019-08-22 11:44:04 +0100 | [diff] [blame] | 350 | break; |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 351 | case DataType::QSYMM8: |
| 352 | run_dequantization_qsymm8<T>(input, output, window); |
| 353 | break; |
Michalis Spyrou | ba27e44 | 2019-05-28 10:04:57 +0100 | [diff] [blame] | 354 | case DataType::QSYMM16: |
| 355 | run_dequantization_qsymm16<T>(input, output, window); |
| 356 | break; |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 357 | default: |
| 358 | ARM_COMPUTE_ERROR("Unsupported data type."); |
| 359 | } |
| 360 | } |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 361 | } // namespace |
| 362 | |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 363 | NEDequantizationLayerKernel::NEDequantizationLayerKernel() |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 364 | : _input(nullptr), _output(nullptr) |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 365 | { |
| 366 | } |
| 367 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 368 | void NEDequantizationLayerKernel::configure(const ITensor *input, ITensor *output) |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 369 | { |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 370 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 371 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info())); |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 372 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 373 | _input = input; |
| 374 | _output = output; |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 375 | |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 376 | // Configure kernel window |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 377 | auto win_config = validate_and_configure_window(input->info(), output->info()); |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 378 | |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 379 | ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config)); |
Gian Marco Iodice | 06b184a | 2017-08-29 16:05:25 +0100 | [diff] [blame] | 380 | |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 381 | INEKernel::configure(std::get<1>(win_config)); |
| 382 | } |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 383 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 384 | Status NEDequantizationLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output) |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 385 | { |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 386 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output)); |
| 387 | ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(input->clone().get(), output->clone().get()))); |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 388 | return Status{}; |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 389 | } |
| 390 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 391 | void NEDequantizationLayerKernel::run(const Window &window, const ThreadInfo &info) |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 392 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 393 | ARM_COMPUTE_UNUSED(info); |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 394 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 395 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 396 | |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 397 | switch(_output->info()->data_type()) |
Michele Di Giorgio | 32982d8 | 2017-07-07 14:44:43 +0100 | [diff] [blame] | 398 | { |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 399 | case DataType::F32: |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 400 | run_dequantization_core<float>(_input, _output, window); |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 401 | break; |
| 402 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 403 | case DataType::F16: |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 404 | run_dequantization_core<float16_t>(_input, _output, window); |
Georgios Pinitas | 574775c | 2019-02-18 20:08:02 +0000 | [diff] [blame] | 405 | break; |
| 406 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 407 | default: |
| 408 | ARM_COMPUTE_ERROR("Unsupported data type."); |
| 409 | } |
| 410 | } |
Michalis Spyrou | ba27e44 | 2019-05-28 10:04:57 +0100 | [diff] [blame] | 411 | } // namespace arm_compute |