Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | 6a2b6e8 | 2019-02-25 13:50:11 +0000 | [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 | */ |
| 24 | #include "arm_compute/core/NEON/kernels/NEArithmeticSubtractionKernel.h" |
| 25 | |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +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" |
Manuel Bottini | 6a2b6e8 | 2019-02-25 13:50:11 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/NEON/NEAsymm.h" |
Michele Di Giorgio | 81f0d15 | 2017-07-11 15:00:52 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/NEON/NEFixedPoint.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 <algorithm> |
| 36 | #include <arm_neon.h> |
| 37 | #include <cstdint> |
| 38 | #include <map> |
| 39 | #include <string> |
| 40 | |
| 41 | using namespace arm_compute; |
| 42 | |
| 43 | namespace arm_compute |
| 44 | { |
| 45 | class Coordinates; |
| 46 | } // namespace arm_compute |
| 47 | |
| 48 | namespace |
| 49 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 50 | constexpr unsigned int num_elems_processed_per_iteration = 16; |
| 51 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 52 | void sub_wrap_U8_U8_U8(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 53 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 54 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 55 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 56 | Iterator output(out, window); |
| 57 | |
| 58 | execute_window_loop(window, [&](const Coordinates & id) |
| 59 | { |
| 60 | const uint8x16_t ta1 = vld1q_u8(input1.ptr()); |
| 61 | const uint8x16_t ta2 = vld1q_u8(input2.ptr()); |
| 62 | |
| 63 | vst1q_u8(output.ptr(), vsubq_u8(ta1, ta2)); |
| 64 | }, |
| 65 | input1, input2, output); |
| 66 | } |
| 67 | |
| 68 | void sub_saturate_U8_U8_U8(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 69 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 70 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 71 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 72 | Iterator output(out, window); |
| 73 | |
| 74 | execute_window_loop(window, [&](const Coordinates & id) |
| 75 | { |
| 76 | const uint8x16_t ta1 = vld1q_u8(input1.ptr()); |
| 77 | const uint8x16_t ta2 = vld1q_u8(input2.ptr()); |
| 78 | |
| 79 | vst1q_u8(output.ptr(), vqsubq_u8(ta1, ta2)); |
| 80 | }, |
| 81 | input1, input2, output); |
| 82 | } |
| 83 | |
Manuel Bottini | 6a2b6e8 | 2019-02-25 13:50:11 +0000 | [diff] [blame] | 84 | void sub_saturate_QAYSMM8_QAYSMM8_QAYSMM8(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 85 | { |
| 86 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 87 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
| 88 | Iterator output(out, window); |
| 89 | |
| 90 | execute_window_loop(window, [&](const Coordinates & id) |
| 91 | { |
| 92 | const float32x4x4_t ta1 = vdequantize(vld1q_u8(reinterpret_cast<const qasymm8_t *>(input1.ptr())), in1->info()->quantization_info()); |
| 93 | const float32x4x4_t ta2 = vdequantize(vld1q_u8(reinterpret_cast<const qasymm8_t *>(input2.ptr())), in2->info()->quantization_info()); |
| 94 | |
| 95 | const float32x4x4_t ta3 = |
| 96 | { |
| 97 | { |
| 98 | vsubq_f32(ta1.val[0], ta2.val[0]), |
| 99 | vsubq_f32(ta1.val[1], ta2.val[1]), |
| 100 | vsubq_f32(ta1.val[2], ta2.val[2]), |
| 101 | vsubq_f32(ta1.val[3], ta2.val[3]), |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | const uint8x16_t result = vquantize(ta3, out->info()->quantization_info()); |
| 106 | |
| 107 | vst1q_u8(reinterpret_cast<qasymm8_t *>(output.ptr()), result); |
| 108 | }, |
| 109 | input1, input2, output); |
| 110 | } |
| 111 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 112 | void sub_wrap_S16_S16_S16(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 113 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 114 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 115 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 116 | Iterator output(out, window); |
| 117 | |
| 118 | execute_window_loop(window, [&](const Coordinates & id) |
| 119 | { |
| 120 | const int16x8x2_t ta1 = vld2q_s16(reinterpret_cast<const int16_t *>(input1.ptr())); |
| 121 | const int16x8x2_t ta2 = vld2q_s16(reinterpret_cast<const int16_t *>(input2.ptr())); |
| 122 | |
| 123 | const int16x8x2_t ta3 = |
| 124 | { |
| 125 | { |
| 126 | vsubq_s16(ta1.val[0], ta2.val[0]), |
| 127 | vsubq_s16(ta1.val[1], ta2.val[1]) |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | vst2q_s16(reinterpret_cast<int16_t *>(output.ptr()), ta3); |
| 132 | }, |
| 133 | input1, input2, output); |
| 134 | } |
| 135 | |
| 136 | void sub_saturate_S16_S16_S16(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 137 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 138 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 139 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 140 | Iterator output(out, window); |
| 141 | |
| 142 | execute_window_loop(window, [&](const Coordinates & id) |
| 143 | { |
| 144 | const int16x8x2_t ta1 = vld2q_s16(reinterpret_cast<const int16_t *>(input1.ptr())); |
| 145 | const int16x8x2_t ta2 = vld2q_s16(reinterpret_cast<const int16_t *>(input2.ptr())); |
| 146 | |
| 147 | const int16x8x2_t ta3 = |
| 148 | { |
| 149 | { |
| 150 | vqsubq_s16(ta1.val[0], ta2.val[0]), |
| 151 | vqsubq_s16(ta1.val[1], ta2.val[1]) |
| 152 | } |
| 153 | }; |
| 154 | |
| 155 | vst2q_s16(reinterpret_cast<int16_t *>(output.ptr()), ta3); |
| 156 | }, |
| 157 | input1, input2, output); |
| 158 | } |
| 159 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 160 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Pablo Tello | d7a5d22 | 2017-07-11 13:54:43 +0100 | [diff] [blame] | 161 | inline float16x8x2_t vsub2q_f16(const float16x8x2_t &a, const float16x8x2_t &b) |
| 162 | { |
| 163 | const float16x8x2_t res = |
| 164 | { |
| 165 | { |
| 166 | vsubq_f16(a.val[0], b.val[0]), |
| 167 | vsubq_f16(a.val[1], b.val[1]) |
| 168 | } |
| 169 | }; |
| 170 | |
| 171 | return res; |
| 172 | } |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 173 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Pablo Tello | d7a5d22 | 2017-07-11 13:54:43 +0100 | [diff] [blame] | 174 | |
| 175 | void sub_F16_F16_F16(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 176 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 177 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 178 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 179 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Pablo Tello | d7a5d22 | 2017-07-11 13:54:43 +0100 | [diff] [blame] | 180 | Iterator output(out, window); |
| 181 | |
| 182 | execute_window_loop(window, [&](const Coordinates & id) |
| 183 | { |
| 184 | const float16x8x2_t a = vld2q_f16(reinterpret_cast<const float16_t *>(input1.ptr())); |
| 185 | const float16x8x2_t b = vld2q_f16(reinterpret_cast<const float16_t *>(input2.ptr())); |
| 186 | |
| 187 | vst2q_f16(reinterpret_cast<float16_t *>(output.ptr()), vsub2q_f16(a, b)); |
| 188 | }, |
| 189 | input1, input2, output); |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 190 | #else /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Pablo Tello | d7a5d22 | 2017-07-11 13:54:43 +0100 | [diff] [blame] | 191 | ARM_COMPUTE_UNUSED(in1); |
| 192 | ARM_COMPUTE_UNUSED(in2); |
| 193 | ARM_COMPUTE_UNUSED(out); |
| 194 | ARM_COMPUTE_UNUSED(window); |
| 195 | ARM_COMPUTE_ERROR("Not supported, recompile the library with arch=arm64-v8.2-a"); |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 196 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Pablo Tello | d7a5d22 | 2017-07-11 13:54:43 +0100 | [diff] [blame] | 197 | } |
| 198 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 199 | void sub_F32_F32_F32(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 200 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 201 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 202 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 203 | Iterator output(out, window); |
| 204 | |
| 205 | execute_window_loop(window, [&](const Coordinates & id) |
| 206 | { |
| 207 | const float32x4x4_t ta1 = vld4q_f32(reinterpret_cast<const float *>(input1.ptr())); |
| 208 | const float32x4x4_t ta2 = vld4q_f32(reinterpret_cast<const float *>(input2.ptr())); |
| 209 | |
| 210 | const float32x4x4_t ta3 = |
| 211 | { |
| 212 | { |
| 213 | vsubq_f32(ta1.val[0], ta2.val[0]), |
| 214 | vsubq_f32(ta1.val[1], ta2.val[1]), |
| 215 | vsubq_f32(ta1.val[2], ta2.val[2]), |
| 216 | vsubq_f32(ta1.val[3], ta2.val[3]), |
| 217 | } |
| 218 | }; |
| 219 | |
| 220 | vst4q_f32(reinterpret_cast<float *>(output.ptr()), ta3); |
| 221 | }, |
| 222 | input1, input2, output); |
| 223 | } |
| 224 | void sub_wrap_S16_U8_S16(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 225 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 226 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 227 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 228 | Iterator output(out, window); |
| 229 | |
| 230 | execute_window_loop(window, [&](const Coordinates & id) |
| 231 | { |
| 232 | const uint8x16_t bv_0 = vld1q_u8(input2.ptr()); |
| 233 | int16x8_t a1_0 = vld1q_s16(reinterpret_cast<const int16_t *>(input1.ptr())); |
| 234 | int16x8_t a2_0 = vld1q_s16(reinterpret_cast<const int16_t *>(input1.ptr()) + 8); |
| 235 | |
| 236 | a1_0 = vsubq_s16(a1_0, vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(bv_0)))); |
| 237 | a2_0 = vsubq_s16(a2_0, vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(bv_0)))); |
| 238 | |
| 239 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()), a1_0); |
| 240 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()) + 8, a2_0); |
| 241 | }, |
| 242 | input1, input2, output); |
| 243 | } |
| 244 | |
| 245 | void sub_saturate_S16_U8_S16(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 246 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 247 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 248 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 249 | Iterator output(out, window); |
| 250 | |
| 251 | execute_window_loop(window, [&](const Coordinates & id) |
| 252 | { |
| 253 | const uint8x16_t bv_0 = vld1q_u8(input2.ptr()); |
| 254 | int16x8_t a1_0 = vld1q_s16(reinterpret_cast<const int16_t *>(input1.ptr())); |
| 255 | int16x8_t a2_0 = vld1q_s16(reinterpret_cast<const int16_t *>(input1.ptr()) + 8); |
| 256 | |
| 257 | a1_0 = vqsubq_s16(a1_0, vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(bv_0)))); |
| 258 | a2_0 = vqsubq_s16(a2_0, vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(bv_0)))); |
| 259 | |
| 260 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()), a1_0); |
| 261 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()) + 8, a2_0); |
| 262 | }, |
| 263 | input1, input2, output); |
| 264 | } |
| 265 | |
| 266 | void sub_wrap_U8_S16_S16(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 267 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 268 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 269 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 270 | Iterator output(out, window); |
| 271 | |
| 272 | execute_window_loop(window, [&](const Coordinates & id) |
| 273 | { |
| 274 | const uint8x16_t bv_0 = vld1q_u8(input1.ptr()); |
| 275 | int16x8_t a1_0 = vld1q_s16(reinterpret_cast<const int16_t *>(input2.ptr())); |
| 276 | int16x8_t a2_0 = vld1q_s16(reinterpret_cast<const int16_t *>(input2.ptr()) + 8); |
| 277 | |
| 278 | a1_0 = vsubq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(bv_0))), a1_0); |
| 279 | a2_0 = vsubq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(bv_0))), a2_0); |
| 280 | |
| 281 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()), a1_0); |
| 282 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()) + 8, a2_0); |
| 283 | }, |
| 284 | input1, input2, output); |
| 285 | } |
| 286 | |
| 287 | void sub_saturate_U8_S16_S16(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 288 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 289 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 290 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 291 | Iterator output(out, window); |
| 292 | |
| 293 | execute_window_loop(window, [&](const Coordinates & id) |
| 294 | { |
| 295 | const uint8x16_t bv_0 = vld1q_u8(input1.ptr()); |
| 296 | int16x8_t a1_0 = vld1q_s16(reinterpret_cast<const int16_t *>(input2.ptr())); |
| 297 | int16x8_t a2_0 = vld1q_s16(reinterpret_cast<const int16_t *>(input2.ptr()) + 8); |
| 298 | |
| 299 | a1_0 = vqsubq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(bv_0))), a1_0); |
| 300 | a2_0 = vqsubq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(bv_0))), a2_0); |
| 301 | |
| 302 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()), a1_0); |
| 303 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()) + 8, a2_0); |
| 304 | }, |
| 305 | input1, input2, output); |
| 306 | } |
| 307 | |
| 308 | void sub_wrap_U8_U8_S16(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 309 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 310 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 311 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 312 | Iterator output(out, window); |
| 313 | |
| 314 | execute_window_loop(window, [&](const Coordinates & id) |
| 315 | { |
| 316 | const uint8x16_t av_0 = vld1q_u8(input1.ptr()); |
| 317 | const uint8x16_t bv_0 = vld1q_u8(input2.ptr()); |
| 318 | |
| 319 | const int16x8_t a1_0 = vsubq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(av_0))), |
| 320 | vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(bv_0)))); |
| 321 | const int16x8_t a2_0 = vsubq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(av_0))), |
| 322 | vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(bv_0)))); |
| 323 | |
| 324 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()), a1_0); |
| 325 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()) + 8, a2_0); |
| 326 | }, |
| 327 | input1, input2, output); |
| 328 | } |
| 329 | |
| 330 | void sub_saturate_U8_U8_S16(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 331 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 332 | Iterator input1(in1, window.broadcast_if_dimension_le_one(in1->info()->tensor_shape())); |
| 333 | Iterator input2(in2, window.broadcast_if_dimension_le_one(in2->info()->tensor_shape())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 334 | Iterator output(out, window); |
| 335 | |
| 336 | execute_window_loop(window, [&](const Coordinates & id) |
| 337 | { |
| 338 | const uint8x16_t av_0 = vld1q_u8(input1.ptr()); |
| 339 | const uint8x16_t bv_0 = vld1q_u8(input2.ptr()); |
| 340 | |
| 341 | const int16x8_t a1_0 = vqsubq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(av_0))), |
| 342 | vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(bv_0)))); |
| 343 | const int16x8_t a2_0 = vqsubq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(av_0))), |
| 344 | vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(bv_0)))); |
| 345 | |
| 346 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()), a1_0); |
| 347 | vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()) + 8, a2_0); |
| 348 | }, |
| 349 | input1, input2, output); |
| 350 | } |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 351 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 352 | inline Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output, ConvertPolicy policy) |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 353 | { |
| 354 | ARM_COMPUTE_UNUSED(policy); |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 355 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(&input1); |
Manuel Bottini | 6a2b6e8 | 2019-02-25 13:50:11 +0000 | [diff] [blame] | 356 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input1, 1, DataType::U8, DataType::QASYMM8, DataType::S16, DataType::F16, DataType::F32); |
| 357 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input2, 1, DataType::U8, DataType::QASYMM8, DataType::S16, DataType::F16, DataType::F32); |
| 358 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&output, 1, DataType::U8, DataType::QASYMM8, DataType::S16, DataType::F16, DataType::F32); |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 359 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 360 | const TensorShape out_shape = TensorShape::broadcast_shape(input1.tensor_shape(), input2.tensor_shape()); |
| 361 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible"); |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 362 | |
Manuel Bottini | 6a2b6e8 | 2019-02-25 13:50:11 +0000 | [diff] [blame] | 363 | ARM_COMPUTE_RETURN_ERROR_ON_MSG( |
| 364 | !(input1.data_type() == DataType::U8 && input2.data_type() == DataType::U8) |
| 365 | && !(input1.data_type() == DataType::QASYMM8 && input2.data_type() == DataType::QASYMM8) |
| 366 | && !(input1.data_type() == DataType::U8 && input2.data_type() == DataType::U8) |
| 367 | && !(input1.data_type() == DataType::U8 && input2.data_type() == DataType::S16) |
| 368 | && !(input1.data_type() == DataType::S16 && input2.data_type() == DataType::U8) |
| 369 | && !(input1.data_type() == DataType::S16 && input2.data_type() == DataType::S16) |
| 370 | && !(input1.data_type() == DataType::F32 && input2.data_type() == DataType::F32) |
| 371 | && !(input1.data_type() == DataType::F16 && input2.data_type() == DataType::F16), |
| 372 | "You called subtract with the wrong image formats"); |
| 373 | |
| 374 | ARM_COMPUTE_RETURN_ERROR_ON_MSG( |
| 375 | input1.data_type() == DataType::QASYMM8 && input2.data_type() == DataType::QASYMM8 && policy == ConvertPolicy::WRAP, |
| 376 | "Convert policy cannot be WRAP if datatype is QASYMM8"); |
| 377 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 378 | // Validate in case of configured output |
| 379 | if(output.total_size() > 0) |
| 380 | { |
| 381 | ARM_COMPUTE_RETURN_ERROR_ON_MSG( |
| 382 | !(input1.data_type() == DataType::U8 && input2.data_type() == DataType::U8 && output.data_type() == DataType::U8) |
Manuel Bottini | 6a2b6e8 | 2019-02-25 13:50:11 +0000 | [diff] [blame] | 383 | && !(input1.data_type() == DataType::QASYMM8 && input2.data_type() == DataType::QASYMM8 && output.data_type() == DataType::QASYMM8) |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 384 | && !(input1.data_type() == DataType::U8 && input2.data_type() == DataType::U8 && output.data_type() == DataType::S16) |
| 385 | && !(input1.data_type() == DataType::U8 && input2.data_type() == DataType::S16 && output.data_type() == DataType::S16) |
| 386 | && !(input1.data_type() == DataType::S16 && input2.data_type() == DataType::U8 && output.data_type() == DataType::S16) |
| 387 | && !(input1.data_type() == DataType::S16 && input2.data_type() == DataType::S16 && output.data_type() == DataType::S16) |
| 388 | && !(input1.data_type() == DataType::F32 && input2.data_type() == DataType::F32 && output.data_type() == DataType::F32) |
| 389 | && !(input1.data_type() == DataType::F16 && input2.data_type() == DataType::F16 && output.data_type() == DataType::F16), |
| 390 | "You called subtract with the wrong image formats"); |
| 391 | |
| 392 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, output.tensor_shape(), 0), |
| 393 | "Wrong shape for output"); |
| 394 | } |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 395 | return Status{}; |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 398 | inline std::pair<Status, Window> validate_and_configure_window(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output) |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 399 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 400 | const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(input1, input2); |
| 401 | const TensorShape &out_shape = broadcast_pair.first; |
| 402 | const ValidRegion &valid_region = broadcast_pair.second; |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 403 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 404 | // Auto initialize output if not initialized |
| 405 | { |
| 406 | set_shape_if_empty(output, out_shape); |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 407 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 408 | if(input1.data_type() == DataType::S16 || input2.data_type() == DataType::S16) |
| 409 | { |
| 410 | set_format_if_unknown(output, Format::S16); |
| 411 | } |
| 412 | else if(input1.data_type() == DataType::F16 && input2.data_type() == DataType::F16) |
| 413 | { |
| 414 | set_format_if_unknown(output, Format::F16); |
| 415 | } |
| 416 | else if(input1.data_type() == DataType::F32 || input2.data_type() == DataType::F32) |
| 417 | { |
| 418 | set_format_if_unknown(output, Format::F32); |
| 419 | } |
| 420 | } |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 421 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 422 | Window win = calculate_max_window(valid_region, Steps(num_elems_processed_per_iteration)); |
| 423 | Window win_input1 = win.broadcast_if_dimension_le_one(input1); |
| 424 | Window win_input2 = win.broadcast_if_dimension_le_one(input2); |
| 425 | |
| 426 | AccessWindowHorizontal input1_access(&input1, 0, num_elems_processed_per_iteration); |
| 427 | AccessWindowHorizontal input2_access(&input2, 0, num_elems_processed_per_iteration); |
| 428 | AccessWindowHorizontal output_access(&output, 0, num_elems_processed_per_iteration); |
| 429 | |
| 430 | bool window_changed = update_window_and_padding(win_input1, input1_access) |
| 431 | || update_window_and_padding(win_input2, input2_access) |
| 432 | || update_window_and_padding(win, output_access); |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 433 | |
| 434 | output_access.set_valid_region(win, valid_region); |
| 435 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 436 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 437 | return std::make_pair(err, win); |
| 438 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 439 | } // namespace |
| 440 | |
| 441 | NEArithmeticSubtractionKernel::NEArithmeticSubtractionKernel() |
| 442 | : _func(nullptr), _input1(nullptr), _input2(nullptr), _output(nullptr) |
| 443 | { |
| 444 | } |
| 445 | |
| 446 | void NEArithmeticSubtractionKernel::configure(const ITensor *input1, const ITensor *input2, ITensor *output, ConvertPolicy policy) |
| 447 | { |
| 448 | ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output); |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 449 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1->info(), *input2->info(), *output->info(), policy)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 450 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 451 | // Configure kernel window |
| 452 | auto win_config = validate_and_configure_window(*input1->info(), *input2->info(), *output->info()); |
| 453 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 454 | |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 455 | static std::map<std::string, NEArithmeticSubtractionKernel::SubFunction *> map_function = |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 456 | { |
| 457 | { "sub_wrap_U8_U8_U8", &sub_wrap_U8_U8_U8 }, |
| 458 | { "sub_wrap_U8_U8_S16", &sub_wrap_U8_U8_S16 }, |
| 459 | { "sub_saturate_U8_U8_U8", &sub_saturate_U8_U8_U8 }, |
| 460 | { "sub_saturate_U8_U8_S16", &sub_saturate_U8_U8_S16 }, |
Manuel Bottini | 6a2b6e8 | 2019-02-25 13:50:11 +0000 | [diff] [blame] | 461 | { "sub_saturate_QASYMM8_QASYMM8_QASYMM8", &sub_saturate_QAYSMM8_QAYSMM8_QAYSMM8 }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 462 | { "sub_wrap_U8_S16_S16", &sub_wrap_U8_S16_S16 }, |
| 463 | { "sub_wrap_S16_U8_S16", &sub_wrap_S16_U8_S16 }, |
| 464 | { "sub_saturate_U8_S16_S16", &sub_saturate_U8_S16_S16 }, |
| 465 | { "sub_saturate_S16_U8_S16", &sub_saturate_S16_U8_S16 }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 466 | { "sub_wrap_S16_S16_S16", &sub_wrap_S16_S16_S16 }, |
| 467 | { "sub_saturate_S16_S16_S16", &sub_saturate_S16_S16_S16 }, |
| 468 | { "sub_wrap_F32_F32_F32", &sub_F32_F32_F32 }, |
| 469 | { "sub_saturate_F32_F32_F32", &sub_F32_F32_F32 }, |
Pablo Tello | d7a5d22 | 2017-07-11 13:54:43 +0100 | [diff] [blame] | 470 | { "sub_wrap_F16_F16_F16", &sub_F16_F16_F16 }, |
| 471 | { "sub_saturate_F16_F16_F16", &sub_F16_F16_F16 }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 472 | }; |
| 473 | |
| 474 | _input1 = input1; |
| 475 | _input2 = input2; |
| 476 | _output = output; |
| 477 | |
| 478 | std::string function_to_call("sub_"); |
| 479 | function_to_call += policy == ConvertPolicy::WRAP ? "wrap_" : "saturate_"; |
| 480 | function_to_call += string_from_data_type(input1->info()->data_type()) + "_"; |
| 481 | function_to_call += string_from_data_type(input2->info()->data_type()) + "_"; |
| 482 | function_to_call += string_from_data_type(output->info()->data_type()); |
| 483 | |
| 484 | auto it = map_function.find(function_to_call); |
| 485 | |
| 486 | if(it != map_function.end()) |
| 487 | { |
| 488 | _func = it->second; |
| 489 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 490 | |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 491 | INEKernel::configure(win_config.second); |
| 492 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 493 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 494 | Status NEArithmeticSubtractionKernel::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy) |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 495 | { |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 496 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); |
| 497 | |
| 498 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output, policy)); |
| 499 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(*input1->clone(), *input2->clone(), *output->clone()).first); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 500 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 501 | return Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 502 | } |
| 503 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 504 | void NEArithmeticSubtractionKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 505 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 506 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 507 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 508 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 509 | ARM_COMPUTE_ERROR_ON(_func == nullptr); |
| 510 | |
| 511 | (*_func)(_input1, _input2, _output, window); |
| 512 | } |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 513 | |
| 514 | BorderSize NEArithmeticSubtractionKernel::border_size() const |
| 515 | { |
| 516 | const unsigned int replicateSize = _output->info()->dimension(0) - std::min(_input1->info()->dimension(0), _input2->info()->dimension(0)); |
| 517 | const unsigned int border = std::min<unsigned int>(num_elems_processed_per_iteration - 1U, replicateSize); |
| 518 | return BorderSize(0, border, 0, 0); |
| 519 | } |