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