Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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 | */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 24 | #include "arm_compute/core/NEON/kernels/NEDepthConvertLayerKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 25 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CPP/Validate.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/Helpers.h" |
| 29 | #include "arm_compute/core/ITensor.h" |
| 30 | #include "arm_compute/core/NEON/NEFixedPoint.h" |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 31 | #include "arm_compute/core/NEON/NEMath.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/TensorInfo.h" |
| 33 | #include "arm_compute/core/Validate.h" |
| 34 | |
| 35 | #include <arm_neon.h> |
| 36 | |
| 37 | using namespace arm_compute; |
| 38 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 39 | namespace |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | { |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 41 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, ConvertPolicy policy, uint32_t shift) |
| 42 | { |
| 43 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input); |
| 44 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(output); |
| 45 | ARM_COMPUTE_UNUSED(policy); |
| 46 | ARM_COMPUTE_RETURN_ERROR_ON(input == output); |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 47 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::U8, DataType::S16, DataType::U16, DataType::F16, DataType::F32); |
| 48 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::QASYMM8, DataType::U8, DataType::S16, DataType::U16, DataType::U32, DataType::S32, DataType::F16, DataType::F32); |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 49 | ARM_COMPUTE_RETURN_ERROR_ON(shift >= 8); |
| 50 | |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 51 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QASYMM8 && (output->data_type() != DataType::F16 && output->data_type() != DataType::F32), |
| 52 | "Only data_types supported [in] QASYMM8 -> [out] F16, F32"); |
| 53 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 54 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::U8 && (output->data_type() != DataType::S16 && output->data_type() != DataType::U16 |
| 55 | && output->data_type() != DataType::S32), |
| 56 | "Only data_types supported [in] U8 -> [out] U16, S16, S32"); |
| 57 | |
| 58 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::U16 && (output->data_type() != DataType::U8 && output->data_type() != DataType::U32), |
| 59 | "Only data_types supported [in] U16 -> [out] U8, U32"); |
| 60 | |
| 61 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::S16 && (output->data_type() != DataType::U8 && output->data_type() != DataType::S32), |
| 62 | "Only data_types supported [in] S16 -> [out] U8, S32"); |
| 63 | |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 64 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::F16 && (output->data_type() != DataType::QASYMM8 && output->data_type() != DataType::F32), |
| 65 | "Only data_types supported [in] F16 -> [out] QASYMM8, F32"); |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 66 | |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 67 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::F32 && (output->data_type() != DataType::QASYMM8 && output->data_type() != DataType::F16), |
| 68 | "Only data_types supported [in] F32 -> [out] QASYMM8, F16"); |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 69 | |
| 70 | // Validate in case of configured output |
| 71 | if(output->total_size() > 0) |
| 72 | { |
| 73 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output); |
| 74 | } |
| 75 | |
| 76 | return Status{}; |
| 77 | } |
| 78 | |
| 79 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output) |
| 80 | { |
| 81 | constexpr unsigned int num_elems_processed_per_iteration = 16; |
| 82 | |
| 83 | Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); |
| 84 | |
| 85 | AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration); |
| 86 | AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); |
| 87 | bool window_changed = update_window_and_padding(win, input_access, output_access); |
| 88 | output_access.set_valid_region(win, output->valid_region()); |
| 89 | |
| 90 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 91 | return std::make_pair(err, win); |
| 92 | } |
| 93 | } // namespace |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 94 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 95 | NEDepthConvertLayerKernel::NEDepthConvertLayerKernel() |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 96 | : _input(nullptr), _output(nullptr), _policy(), _shift(0) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 97 | { |
| 98 | } |
| 99 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 100 | void NEDepthConvertLayerKernel::configure(const ITensor *input, ITensor *output, ConvertPolicy policy, uint32_t shift) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 101 | { |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 102 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 103 | |
| 104 | // Auto initialize output shape if not initialized (We can only auto-configure the shape, datatype must be given) |
| 105 | set_shape_if_empty(*output->info(), input->info()->tensor_shape()); |
Georgios Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 106 | |
| 107 | _input = input; |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 108 | _output = output; |
Georgios Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 109 | _policy = policy; |
| 110 | _shift = shift; |
| 111 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 112 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), policy, shift)); |
Georgios Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 113 | |
| 114 | // Configure kernel window |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 115 | auto win_config = validate_and_configure_window(input->info(), output->info()); |
| 116 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 117 | ICPPKernel::configure(win_config.second); |
| 118 | } |
Georgios Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 119 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 120 | Status NEDepthConvertLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output, ConvertPolicy policy, uint32_t shift) |
| 121 | { |
| 122 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, policy, shift)); |
| 123 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first); |
| 124 | |
| 125 | return Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 128 | void NEDepthConvertLayerKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 129 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 130 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 131 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Georgios Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 132 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 133 | ARM_COMPUTE_ERROR_ON_NULLPTR(_input, _output); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 134 | ARM_COMPUTE_ERROR_ON(_input == _output); |
| 135 | |
| 136 | Iterator input(_input, window); |
| 137 | Iterator output(_output, window); |
| 138 | |
| 139 | switch(_input->info()->data_type()) |
| 140 | { |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 141 | case DataType::QASYMM8: |
| 142 | { |
| 143 | switch(_output->info()->data_type()) |
| 144 | { |
| 145 | /* Up-conversion QASYMM8 -> F32 */ |
| 146 | case DataType::F32: |
| 147 | { |
| 148 | const float32x4_t scale = vdupq_n_f32(_input->info()->quantization_info().scale); |
| 149 | const int32x4_t offset = vdupq_n_s32(_input->info()->quantization_info().offset); |
| 150 | |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 151 | execute_window_loop(window, [&](const Coordinates &) |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 152 | { |
| 153 | const uint8x16_t texels_u8 = vld1q_u8(input.ptr()); |
| 154 | const uint16x8x2_t texels_u16 = |
| 155 | { |
| 156 | { |
| 157 | vmovl_u8(vget_low_u8(texels_u8)), |
| 158 | vmovl_u8(vget_high_u8(texels_u8)) |
| 159 | } |
| 160 | }; |
| 161 | |
| 162 | const int32x4x4_t texels_s32 = |
| 163 | { |
| 164 | { |
| 165 | vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(texels_u16.val[0]))), |
| 166 | vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(texels_u16.val[0]))), |
| 167 | vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(texels_u16.val[1]))), |
| 168 | vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(texels_u16.val[1]))) |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | vst1q_f32(reinterpret_cast<float *>(output.ptr()), vmulq_f32(vcvtq_f32_s32(vsubq_s32(texels_s32.val[0], offset)), scale)); |
| 173 | vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 4, vmulq_f32(vcvtq_f32_s32(vsubq_s32(texels_s32.val[1], offset)), scale)); |
| 174 | vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 8, vmulq_f32(vcvtq_f32_s32(vsubq_s32(texels_s32.val[2], offset)), scale)); |
| 175 | vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 12, vmulq_f32(vcvtq_f32_s32(vsubq_s32(texels_s32.val[3], offset)), scale)); |
| 176 | }, |
| 177 | input, output); |
| 178 | break; |
| 179 | } |
| 180 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 181 | /* Up-conversion QASYMM8 -> F16 */ |
| 182 | case DataType::F16: |
| 183 | { |
| 184 | const float16x8_t scale = vdupq_n_f16(static_cast<float16_t>(_input->info()->quantization_info().scale)); |
| 185 | const int16x8_t offset = vdupq_n_s16(static_cast<int16_t>(_input->info()->quantization_info().offset)); |
| 186 | |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 187 | execute_window_loop(window, [&](const Coordinates &) |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 188 | { |
| 189 | const uint8x16_t texels_u8 = vld1q_u8(input.ptr()); |
| 190 | const int16x8x2_t texels_s16 = |
| 191 | { |
| 192 | { |
| 193 | vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(texels_u8))), |
| 194 | vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(texels_u8))) |
| 195 | } |
| 196 | }; |
| 197 | |
| 198 | vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()), vmulq_f16(vcvtq_f16_s16(vsubq_s16(texels_s16.val[0], offset)), scale)); |
| 199 | vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()) + 8, vmulq_f16(vcvtq_f16_s16(vsubq_s16(texels_s16.val[1], offset)), scale)); |
| 200 | }, |
| 201 | input, output); |
| 202 | break; |
| 203 | } |
| 204 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 205 | default: |
| 206 | ARM_COMPUTE_ERROR("Output data type not supported"); |
| 207 | } |
| 208 | break; |
| 209 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 210 | case DataType::U8: |
| 211 | { |
| 212 | const int16x8_t b = vdupq_n_s16(_shift); |
| 213 | |
| 214 | switch(_output->info()->data_type()) |
| 215 | { |
| 216 | case DataType::S16: |
| 217 | { |
| 218 | /* Up-conversion U8 -> S16 */ |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 219 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 220 | { |
| 221 | const uint8x16_t texels_u8 = vld1q_u8(input.ptr()); |
| 222 | |
| 223 | const int16x8x2_t texels = |
| 224 | { |
| 225 | { |
| 226 | vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(texels_u8))), b), |
| 227 | vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(texels_u8))), b) |
| 228 | } |
| 229 | }; |
| 230 | |
| 231 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()), texels.val[0]); |
| 232 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()) + 8, texels.val[1]); |
| 233 | }, |
| 234 | input, output); |
| 235 | break; |
| 236 | } |
| 237 | case DataType::S32: |
| 238 | { |
| 239 | /* Up-conversion U8 -> S32 */ |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 240 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 241 | { |
| 242 | const uint8x16_t texels_u8 = vld1q_u8(input.ptr()); |
| 243 | |
| 244 | const int16x8x2_t texels = |
| 245 | { |
| 246 | { |
| 247 | vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(texels_u8))), b), |
| 248 | vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(texels_u8))), b) |
| 249 | } |
| 250 | }; |
| 251 | |
| 252 | vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()), vmovl_s16(vget_low_s16(texels.val[0]))); |
| 253 | vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 4, vmovl_s16(vget_high_s16(texels.val[0]))); |
| 254 | vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 8, vmovl_s16(vget_low_s16(texels.val[1]))); |
| 255 | vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 12, vmovl_s16(vget_high_s16(texels.val[1]))); |
| 256 | }, |
| 257 | input, output); |
| 258 | break; |
| 259 | } |
| 260 | case DataType::U16: |
| 261 | { |
| 262 | /* Up-conversion U8 -> U16 */ |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 263 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 264 | { |
| 265 | const uint8x16_t texels_u8 = vld1q_u8(input.ptr()); |
| 266 | |
| 267 | const uint16x8x2_t texels = |
| 268 | { |
| 269 | { |
| 270 | vshlq_u16(vmovl_u8(vget_low_u8(texels_u8)), b), |
| 271 | vshlq_u16(vmovl_u8(vget_high_u8(texels_u8)), b) |
| 272 | } |
| 273 | }; |
| 274 | |
| 275 | vst1q_u16(reinterpret_cast<uint16_t *>(output.ptr()), texels.val[0]); |
| 276 | vst1q_u16(reinterpret_cast<uint16_t *>(output.ptr()) + 8, texels.val[1]); |
| 277 | }, |
| 278 | input, output); |
| 279 | break; |
| 280 | } |
| 281 | default: |
| 282 | ARM_COMPUTE_ERROR("Output data type not supported"); |
| 283 | } |
| 284 | break; |
| 285 | } |
| 286 | case DataType::S16: |
| 287 | { |
| 288 | switch(_output->info()->data_type()) |
| 289 | { |
| 290 | case DataType::U8: |
| 291 | { |
| 292 | const int16x8_t b = vdupq_n_s16(-static_cast<int16_t>(_shift)); |
| 293 | |
| 294 | /* Down-conversion S16 -> U8 */ |
| 295 | if(ConvertPolicy::SATURATE == _policy) |
| 296 | { |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 297 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 298 | { |
| 299 | const int16x8x2_t texels = |
| 300 | { |
| 301 | { |
| 302 | vqshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr())), b), |
| 303 | vqshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr()) + 8), b) |
| 304 | } |
| 305 | }; |
| 306 | |
| 307 | vst1q_u8(output.ptr(), vcombine_u8(vqmovun_s16(texels.val[0]), vqmovun_s16(texels.val[1]))); |
| 308 | }, |
| 309 | input, output); |
| 310 | } |
| 311 | else |
| 312 | { |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 313 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 314 | { |
| 315 | const int16x8x2_t texels = |
| 316 | { |
| 317 | { |
| 318 | vshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr())), b), |
| 319 | vshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr()) + 8), b) |
| 320 | } |
| 321 | }; |
| 322 | |
| 323 | vst1q_u8(output.ptr(), vcombine_u8(vmovn_u16(vreinterpretq_u16_s16(texels.val[0])), |
| 324 | vmovn_u16(vreinterpretq_u16_s16(texels.val[1])))); |
| 325 | }, |
| 326 | input, output); |
| 327 | } |
| 328 | break; |
| 329 | } |
| 330 | case DataType::S32: |
| 331 | { |
| 332 | const int32x4_t b = vdupq_n_s32(_shift); |
| 333 | |
| 334 | /* Up-conversion S16 -> S32 */ |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 335 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 336 | { |
| 337 | const int16x8x2_t texels = |
| 338 | { |
| 339 | { |
| 340 | vld1q_s16(reinterpret_cast<int16_t *>(input.ptr())), |
| 341 | vld1q_s16(reinterpret_cast<int16_t *>(input.ptr()) + 8) |
| 342 | } |
| 343 | }; |
| 344 | |
| 345 | const int32x4x4_t texels_s32 = |
| 346 | { |
| 347 | { |
| 348 | vshlq_s32(vmovl_s16(vget_low_s16(texels.val[0])), b), |
| 349 | vshlq_s32(vmovl_s16(vget_high_s16(texels.val[0])), b), |
| 350 | vshlq_s32(vmovl_s16(vget_low_s16(texels.val[1])), b), |
| 351 | vshlq_s32(vmovl_s16(vget_high_s16(texels.val[1])), b) |
| 352 | } |
| 353 | }; |
| 354 | |
| 355 | vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()), texels_s32.val[0]); |
| 356 | vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 4, texels_s32.val[1]); |
| 357 | vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 8, texels_s32.val[2]); |
| 358 | vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 12, texels_s32.val[3]); |
| 359 | }, |
| 360 | input, output); |
| 361 | break; |
| 362 | } |
| 363 | default: |
| 364 | ARM_COMPUTE_ERROR("Output data type not supported"); |
| 365 | } |
| 366 | break; |
| 367 | } |
| 368 | case DataType::U16: |
| 369 | { |
| 370 | switch(_output->info()->data_type()) |
| 371 | { |
| 372 | case DataType::U8: |
| 373 | { |
| 374 | const int16x8_t b = vdupq_n_s16(-static_cast<int16_t>(_shift)); |
| 375 | |
| 376 | /* Down-conversion U16 -> U8 */ |
| 377 | if(ConvertPolicy::SATURATE == _policy) |
| 378 | { |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 379 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 380 | { |
| 381 | const uint16x8x2_t texels = |
| 382 | { |
| 383 | { |
| 384 | vqshlq_u16(vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr())), b), |
| 385 | vqshlq_u16(vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr()) + 8), b) |
| 386 | } |
| 387 | }; |
| 388 | |
| 389 | vst1q_u8(output.ptr(), vcombine_u8(vqmovn_u16(texels.val[0]), vqmovn_u16(texels.val[1]))); |
| 390 | }, |
| 391 | input, output); |
| 392 | } |
| 393 | else |
| 394 | { |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 395 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 396 | { |
| 397 | const uint16x8x2_t texels = |
| 398 | { |
| 399 | { |
| 400 | vshlq_u16(vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr())), b), |
| 401 | vshlq_u16(vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr()) + 8), b) |
| 402 | } |
| 403 | }; |
| 404 | |
| 405 | vst1q_u8(output.ptr(), vcombine_u8(vmovn_u16(texels.val[0]), vmovn_u16(texels.val[1]))); |
| 406 | }, |
| 407 | input, output); |
| 408 | } |
| 409 | break; |
| 410 | } |
| 411 | case DataType::U32: |
| 412 | { |
| 413 | const int32x4_t b = vdupq_n_s32(_shift); |
| 414 | |
| 415 | /* Up-conversion U16 -> U32 */ |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 416 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 417 | { |
| 418 | const uint16x8x2_t texels = |
| 419 | { |
| 420 | { |
| 421 | vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr())), |
| 422 | vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr()) + 8) |
| 423 | } |
| 424 | }; |
| 425 | |
| 426 | vst1q_u32(reinterpret_cast<uint32_t *>(output.ptr()), vshlq_u32(vmovl_u16(vget_low_u16(texels.val[0])), b)); |
| 427 | vst1q_u32(reinterpret_cast<uint32_t *>(output.ptr()) + 4, vshlq_u32(vmovl_u16(vget_high_u16(texels.val[0])), b)); |
| 428 | vst1q_u32(reinterpret_cast<uint32_t *>(output.ptr()) + 8, vshlq_u32(vmovl_u16(vget_low_u16(texels.val[1])), b)); |
| 429 | vst1q_u32(reinterpret_cast<uint32_t *>(output.ptr()) + 12, vshlq_u32(vmovl_u16(vget_high_u16(texels.val[1])), b)); |
| 430 | }, |
| 431 | input, output); |
| 432 | break; |
| 433 | } |
| 434 | default: |
| 435 | ARM_COMPUTE_ERROR("Output data type not supported"); |
| 436 | } |
| 437 | break; |
| 438 | } |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 439 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 440 | case DataType::F16: |
| 441 | switch(_output->info()->data_type()) |
| 442 | { |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 443 | case DataType::QASYMM8: |
| 444 | { |
| 445 | const float16x8_t scale = vinvq_f16(vdupq_n_f16(static_cast<float16_t>(_output->info()->quantization_info().scale))); |
| 446 | const int16x8_t offset = vdupq_n_s16(static_cast<int16_t>(_output->info()->quantization_info().offset)); |
| 447 | const int16x8_t max_val_vec = vdupq_n_s16(255); |
| 448 | const int16x8_t zero_val_vec = vdupq_n_s16(0); |
| 449 | |
| 450 | /* Down-conversion F16 -> QASYMM8 */ |
| 451 | execute_window_loop(window, [&](const Coordinates & id) |
| 452 | { |
| 453 | const float16x8x2_t texels = |
| 454 | { |
| 455 | { |
| 456 | vmulq_f16(vld1q_f16(reinterpret_cast<float16_t *>(input.ptr())), scale), |
| 457 | vmulq_f16(vld1q_f16(reinterpret_cast<float16_t *>(input.ptr()) + 8), scale), |
| 458 | } |
| 459 | }; |
| 460 | |
| 461 | const auto texel_quantized_0 = vmaxq_s16(vminq_s16(vaddq_s16(vcvtq_s16_f16(texels.val[0]), offset), max_val_vec), zero_val_vec); |
| 462 | const auto texel_quantized_1 = vmaxq_s16(vminq_s16(vaddq_s16(vcvtq_s16_f16(texels.val[1]), offset), max_val_vec), zero_val_vec); |
| 463 | vst1q_u8(reinterpret_cast<uint8_t *>(output.ptr()), vcombine_u8(vqmovun_s16(texel_quantized_0), vqmovun_s16(texel_quantized_1))); |
| 464 | }, |
| 465 | input, output); |
| 466 | break; |
| 467 | } |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 468 | case DataType::F32: |
| 469 | { |
| 470 | const float32x4_t scale = vdupq_n_f32(1 << _shift); |
| 471 | |
| 472 | /* Up-conversion F16 -> F32 */ |
| 473 | execute_window_loop(window, [&](const Coordinates & id) |
| 474 | { |
| 475 | const float16x8x2_t texels = |
| 476 | { |
| 477 | { |
| 478 | vld1q_f16(reinterpret_cast<float16_t *>(input.ptr())), |
| 479 | vld1q_f16(reinterpret_cast<float16_t *>(input.ptr()) + 8) |
| 480 | } |
| 481 | }; |
| 482 | |
| 483 | vst1q_f32(reinterpret_cast<float *>(output.ptr()), vmulq_f32(vcvt_f32_f16(vget_low_f16(texels.val[0])), scale)); |
| 484 | vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 4, vmulq_f32(vcvt_f32_f16(vget_high_f16(texels.val[0])), scale)); |
| 485 | vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 8, vmulq_f32(vcvt_f32_f16(vget_low_f16(texels.val[1])), scale)); |
| 486 | vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 12, vmulq_f32(vcvt_f32_f16(vget_high_f16(texels.val[1])), scale)); |
| 487 | }, |
| 488 | input, output); |
| 489 | break; |
| 490 | } |
| 491 | default: |
| 492 | ARM_COMPUTE_ERROR("Output data type not supported"); |
| 493 | } |
| 494 | break; |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 495 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 496 | case DataType::F32: |
| 497 | switch(_output->info()->data_type()) |
| 498 | { |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 499 | case DataType::QASYMM8: |
| 500 | { |
| 501 | const float32x4_t scale = vinvq_f32(vdupq_n_f32(_output->info()->quantization_info().scale)); |
| 502 | const int32x4_t offset = vdupq_n_s32(_output->info()->quantization_info().offset); |
| 503 | const int32x4_t max_val_vec = vdupq_n_s32(255); |
| 504 | const int32x4_t zero_val_vec = vdupq_n_s32(0); |
| 505 | |
| 506 | /* Down-conversion F32 -> QASYMM8 */ |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 507 | execute_window_loop(window, [&](const Coordinates &) |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 508 | { |
| 509 | const float32x4x4_t texels = |
| 510 | { |
| 511 | { |
| 512 | vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr())), scale), |
| 513 | vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 4), scale), |
| 514 | vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 8), scale), |
| 515 | vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 12), scale) |
| 516 | } |
| 517 | }; |
| 518 | |
| 519 | const auto texel_quantized_0 = vmaxq_s32(vminq_s32(vaddq_s32(vcvtq_s32_f32(texels.val[0]), offset), max_val_vec), zero_val_vec); |
| 520 | const auto texel_quantized_1 = vmaxq_s32(vminq_s32(vaddq_s32(vcvtq_s32_f32(texels.val[1]), offset), max_val_vec), zero_val_vec); |
| 521 | const auto texel_quantized_2 = vmaxq_s32(vminq_s32(vaddq_s32(vcvtq_s32_f32(texels.val[2]), offset), max_val_vec), zero_val_vec); |
| 522 | const auto texel_quantized_3 = vmaxq_s32(vminq_s32(vaddq_s32(vcvtq_s32_f32(texels.val[3]), offset), max_val_vec), zero_val_vec); |
| 523 | |
| 524 | const auto converted_0 = vqmovn_u16(vcombine_u16(vqmovun_s32(texel_quantized_0), vqmovun_s32(texel_quantized_1))); |
| 525 | const auto converted_1 = vqmovn_u16(vcombine_u16(vqmovun_s32(texel_quantized_2), vqmovun_s32(texel_quantized_3))); |
| 526 | |
| 527 | vst1q_u8(reinterpret_cast<uint8_t *>(output.ptr()), vcombine_u8(converted_0, converted_1)); |
| 528 | }, |
| 529 | input, output); |
| 530 | break; |
| 531 | } |
| 532 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 533 | case DataType::F16: |
| 534 | { |
| 535 | const float32x4_t scale = vdupq_n_f32(1.f / (1 << _shift)); |
| 536 | |
| 537 | /* Down-conversion F32 -> F16 */ |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 538 | execute_window_loop(window, [&](const Coordinates &) |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 539 | { |
| 540 | const float32x4x4_t texels = |
| 541 | { |
| 542 | { |
| 543 | vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr())), scale), |
| 544 | vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 4), scale), |
| 545 | vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 8), scale), |
| 546 | vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 12), scale) |
| 547 | } |
| 548 | }; |
| 549 | |
| 550 | vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()), vcombine_f16(vcvt_f16_f32(texels.val[0]), vcvt_f16_f32(texels.val[1]))); |
| 551 | vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()) + 8, vcombine_f16(vcvt_f16_f32(texels.val[2]), vcvt_f16_f32(texels.val[3]))); |
| 552 | }, |
| 553 | input, output); |
| 554 | break; |
| 555 | } |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 556 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 557 | default: |
| 558 | ARM_COMPUTE_ERROR("Output data type not supported"); |
| 559 | } |
| 560 | break; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 561 | default: |
| 562 | ARM_COMPUTE_ERROR("Not supported"); |
| 563 | } |
| 564 | } |