giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 1 | /* |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [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/NEElementwiseOperationKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/CPP/Validate.h" |
| 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/Helpers.h" |
| 29 | #include "arm_compute/core/IAccessWindow.h" |
| 30 | #include "arm_compute/core/ITensor.h" |
| 31 | #include "arm_compute/core/NEON/NEAsymm.h" |
| 32 | #include "arm_compute/core/NEON/NEFixedPoint.h" |
| 33 | #include "arm_compute/core/NEON/wrapper/wrapper.h" |
| 34 | #include "arm_compute/core/TensorInfo.h" |
| 35 | #include "arm_compute/core/Validate.h" |
| 36 | |
| 37 | #include <algorithm> |
| 38 | #include <arm_neon.h> |
| 39 | #include <cstdint> |
| 40 | #include <map> |
| 41 | #include <string> |
| 42 | |
| 43 | namespace arm_compute |
| 44 | { |
| 45 | class Coordinates; |
| 46 | |
| 47 | namespace |
| 48 | { |
| 49 | float32x4x4_t load_quantized(const uint8_t *input1_ptr, const int32x4_t &offset, const float32x4_t &scale) |
| 50 | { |
| 51 | qasymm8x16_t x = vld1q_u8(input1_ptr); |
| 52 | const float32x4x4_t out = |
| 53 | { |
| 54 | { |
| 55 | vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(x))))), offset)), scale), |
| 56 | vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_low_u8(x))))), offset)), scale), |
| 57 | vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_high_u8(x))))), offset)), scale), |
| 58 | vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_high_u8(x))))), offset)), scale), |
| 59 | } |
| 60 | }; |
| 61 | return out; |
| 62 | } |
| 63 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 64 | void store_quantized(uint8_t *output_ptr, const uint32x4x4_t &out) |
| 65 | { |
| 66 | const uint8x8_t pa = vqmovn_u16(vcombine_u16(vqmovn_u32(out.val[0]), vqmovn_u32(out.val[1]))); |
| 67 | const uint8x8_t pb = vqmovn_u16(vcombine_u16(vqmovn_u32(out.val[2]), vqmovn_u32(out.val[3]))); |
| 68 | vst1q_u8(output_ptr, vcombine_u8(pa, pb)); |
| 69 | } |
| 70 | |
| 71 | void store_quantized(uint8_t *output_ptr, const int32x4x4_t &out) |
| 72 | { |
| 73 | const uint8x8_t pa = vqmovun_s16(vcombine_s16(vqmovn_s32(out.val[0]), vqmovn_s32(out.val[1]))); |
| 74 | const uint8x8_t pb = vqmovun_s16(vcombine_s16(vqmovn_s32(out.val[2]), vqmovn_s32(out.val[3]))); |
| 75 | vst1q_u8(output_ptr, vcombine_u8(pa, pb)); |
| 76 | } |
| 77 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 78 | void store_quantized(uint8_t *output_ptr, const float32x4x4_t &rf, const float32x4_t &offset, const float32x4_t &invscale) |
| 79 | { |
| 80 | int32x4x4_t out = |
| 81 | { |
Georgios Pinitas | d57891a | 2019-02-19 18:10:03 +0000 | [diff] [blame] | 82 | { |
| 83 | vcvtq_s32_f32(vmlaq_f32(offset, rf.val[0], invscale)), |
| 84 | vcvtq_s32_f32(vmlaq_f32(offset, rf.val[1], invscale)), |
| 85 | vcvtq_s32_f32(vmlaq_f32(offset, rf.val[2], invscale)), |
| 86 | vcvtq_s32_f32(vmlaq_f32(offset, rf.val[3], invscale)), |
| 87 | } |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 88 | }; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 89 | store_quantized(output_ptr, out); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | float32x4x4_t dup_quantized(qasymm8_t broadcast_value, int offset, float scale) |
| 93 | { |
| 94 | const qasymm8x16_t broadcast_value_vec = vdupq_n_u8(broadcast_value); |
| 95 | const int32x4_t voffset = vdupq_n_s32(offset); |
| 96 | const float32x4_t vscale = vdupq_n_f32(scale); |
| 97 | |
| 98 | const float32x4x4_t broadcast_vector = |
| 99 | { |
| 100 | { |
| 101 | vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(broadcast_value_vec))))), voffset)), vscale), |
| 102 | vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_low_u8(broadcast_value_vec))))), voffset)), vscale), |
| 103 | vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_high_u8(broadcast_value_vec))))), voffset)), vscale), |
| 104 | vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_high_u8(broadcast_value_vec))))), voffset)), vscale), |
| 105 | } |
| 106 | }; |
| 107 | return broadcast_vector; |
| 108 | } |
| 109 | |
| 110 | template <ArithmeticOperation op, typename ScalarType> |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 111 | inline ScalarType elementwise_arithm_op_scalar(const ScalarType &a, const ScalarType &b) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 112 | { |
| 113 | auto res = ScalarType(0); |
| 114 | |
| 115 | switch(op) |
| 116 | { |
| 117 | case ArithmeticOperation::MAX: |
| 118 | res = std::max(a, b); |
| 119 | break; |
| 120 | case ArithmeticOperation::MIN: |
| 121 | res = std::min(a, b); |
| 122 | break; |
| 123 | case ArithmeticOperation::SQUARED_DIFF: |
| 124 | { |
| 125 | res = (a - b) * (a - b); |
| 126 | break; |
| 127 | } |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 128 | case ArithmeticOperation::PRELU: |
| 129 | { |
| 130 | res = (a > 0 ? a : a * b); |
| 131 | break; |
| 132 | } |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 133 | case ArithmeticOperation::DIV: |
| 134 | { |
| 135 | res = a / b; |
| 136 | break; |
| 137 | } |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 138 | case ArithmeticOperation::POWER: |
| 139 | { |
| 140 | res = std::pow(a, b); |
| 141 | break; |
| 142 | } |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 143 | default: |
| 144 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 145 | } |
| 146 | return res; |
| 147 | } |
| 148 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 149 | template <ArithmeticOperation op> |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 150 | inline uint8_t elementwise_arithm_op_quantized_scalar(const float &a, const float &b, UniformQuantizationInfo qinfo) |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 151 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 152 | return quantize_qasymm8(elementwise_arithm_op_scalar<op>(a, b), qinfo); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 153 | } |
| 154 | |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 155 | template <ArithmeticOperation op, typename VectorType> |
| 156 | inline typename VectorType::type elementwise_arithm_op(const typename VectorType::type &a, const typename VectorType::type &b) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 157 | { |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 158 | using vec_type = typename VectorType::type; |
| 159 | using scalar_type = typename VectorType::scalar_type; |
| 160 | using tag_type = typename VectorType::tag_type; |
| 161 | |
| 162 | vec_type res = wrapper::vdup_n(static_cast<scalar_type>(0), tag_type{}); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 163 | |
| 164 | switch(op) |
| 165 | { |
| 166 | case ArithmeticOperation::MAX: |
| 167 | res = wrapper::vmax(a, b); |
| 168 | break; |
| 169 | case ArithmeticOperation::MIN: |
| 170 | res = wrapper::vmin(a, b); |
| 171 | break; |
| 172 | case ArithmeticOperation::SQUARED_DIFF: |
| 173 | { |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 174 | const vec_type tmp = wrapper::vsub(a, b); |
| 175 | res = wrapper::vmul(tmp, tmp); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 176 | break; |
| 177 | } |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 178 | case ArithmeticOperation::PRELU: |
| 179 | { |
| 180 | const vec_type zero = wrapper::vdup_n(static_cast<scalar_type>(0), tag_type{}); |
| 181 | const vec_type tmp = wrapper::vmul(a, b); |
| 182 | const auto gt = wrapper::vcgt(a, zero); |
| 183 | |
| 184 | res = wrapper::vbsl(gt, a, tmp); |
| 185 | break; |
| 186 | } |
| 187 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 188 | default: |
| 189 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 190 | } |
| 191 | |
| 192 | return res; |
| 193 | } |
| 194 | |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 195 | template <> |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 196 | inline float32x4_t elementwise_arithm_op<ArithmeticOperation::DIV, typename wrapper::traits::neon_vector<float, 4>>(const float32x4_t &a, const float32x4_t &b) |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 197 | { |
| 198 | return wrapper::vdiv(a, b); |
| 199 | } |
| 200 | |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 201 | template <> |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 202 | inline float32x4_t elementwise_arithm_op<ArithmeticOperation::POWER, typename wrapper::traits::neon_vector<float, 4>>(const float32x4_t &a, const float32x4_t &b) |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 203 | { |
| 204 | return wrapper::vpow(a, b); |
| 205 | } |
| 206 | |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 207 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 208 | template <> |
Michele Di Giorgio | b3a0a60 | 2019-06-13 15:35:00 +0100 | [diff] [blame] | 209 | inline float16x8_t elementwise_arithm_op<ArithmeticOperation::DIV, typename wrapper::traits::neon_vector<float16_t, 8>>(const float16x8_t &a, const float16x8_t &b) |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 210 | { |
| 211 | return wrapper::vdiv(a, b); |
| 212 | } |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 213 | |
| 214 | template <> |
Michele Di Giorgio | b3a0a60 | 2019-06-13 15:35:00 +0100 | [diff] [blame] | 215 | inline float16x8_t elementwise_arithm_op<ArithmeticOperation::POWER, typename wrapper::traits::neon_vector<float16_t, 8>>(const float16x8_t &a, const float16x8_t &b) |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 216 | { |
| 217 | return wrapper::vpow(a, b); |
| 218 | } |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 219 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 220 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 221 | template <ArithmeticOperation op> |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 222 | inline float32x4x4_t elementwise_arithm_op(const float32x4x4_t &a, const float32x4x4_t &b) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 223 | { |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 224 | using neon_vector_float = wrapper::traits::neon_vector<float, 4>; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 225 | float32x4x4_t out = |
| 226 | { |
Georgios Pinitas | d57891a | 2019-02-19 18:10:03 +0000 | [diff] [blame] | 227 | { |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 228 | elementwise_arithm_op<op, neon_vector_float>(a.val[0], b.val[0]), |
| 229 | elementwise_arithm_op<op, neon_vector_float>(a.val[1], b.val[1]), |
| 230 | elementwise_arithm_op<op, neon_vector_float>(a.val[2], b.val[2]), |
| 231 | elementwise_arithm_op<op, neon_vector_float>(a.val[3], b.val[3]), |
Georgios Pinitas | d57891a | 2019-02-19 18:10:03 +0000 | [diff] [blame] | 232 | } |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 233 | }; |
| 234 | return out; |
| 235 | } |
| 236 | |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 237 | template <ArithmeticOperation op, typename ScalarType, typename VectorType> |
| 238 | inline typename VectorType::type elementwise_arithm_op_broadcast(const typename VectorType::type &a, const ScalarType &broadcast_value, const bool reorder) |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 239 | { |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 240 | using tag_type = typename VectorType::tag_type; |
| 241 | using vec_type = typename VectorType::type; |
| 242 | |
| 243 | vec_type broadcast_vector = wrapper::vdup_n(broadcast_value, tag_type{}); |
| 244 | return elementwise_arithm_op<op, VectorType>(reorder ? broadcast_vector : a, reorder ? a : broadcast_vector); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | template <ComparisonOperation op, typename InputScalarType> |
| 248 | inline uint8_t elementwise_comp_op_scalar(const InputScalarType &a, const InputScalarType &b) |
| 249 | { |
| 250 | bool res = false; |
| 251 | |
| 252 | switch(op) |
| 253 | { |
| 254 | case ComparisonOperation::Equal: |
| 255 | res = (a == b); |
| 256 | break; |
| 257 | case ComparisonOperation::NotEqual: |
| 258 | res = (a != b); |
| 259 | break; |
| 260 | case ComparisonOperation::Greater: |
| 261 | res = (a > b); |
| 262 | break; |
| 263 | case ComparisonOperation::GreaterEqual: |
| 264 | res = (a >= b); |
| 265 | break; |
| 266 | case ComparisonOperation::Less: |
| 267 | res = (a < b); |
| 268 | break; |
| 269 | case ComparisonOperation::LessEqual: |
| 270 | res = (a <= b); |
| 271 | break; |
| 272 | default: |
| 273 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 274 | } |
| 275 | return res ? ~static_cast<uint8_t>(0) : static_cast<uint8_t>(0); |
| 276 | } |
| 277 | |
| 278 | template <ComparisonOperation op> |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 279 | inline uint8_t elementwise_comp_op_quantized_scalar(const float &a, const float &b, UniformQuantizationInfo qinfo) |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 280 | { |
| 281 | ARM_COMPUTE_UNUSED(qinfo); |
| 282 | return elementwise_comp_op_scalar<op>(a, b); |
| 283 | } |
| 284 | |
| 285 | template <ComparisonOperation op, typename InputVectorType, typename OutputVectorType> |
| 286 | inline OutputVectorType elementwise_comp_op(const InputVectorType &a, const InputVectorType &b) |
| 287 | { |
| 288 | OutputVectorType res = { 0, 0, 0, 0 }; |
| 289 | |
| 290 | switch(op) |
| 291 | { |
| 292 | case ComparisonOperation::Equal: |
| 293 | res = wrapper::vceq(a, b); |
| 294 | break; |
| 295 | case ComparisonOperation::NotEqual: |
| 296 | res = wrapper::vnot(wrapper::vceq(a, b)); |
| 297 | break; |
| 298 | case ComparisonOperation::Greater: |
| 299 | res = wrapper::vcgt(a, b); |
| 300 | break; |
| 301 | case ComparisonOperation::GreaterEqual: |
| 302 | res = wrapper::vcge(a, b); |
| 303 | break; |
| 304 | case ComparisonOperation::Less: |
| 305 | res = wrapper::vcgt(b, a); |
| 306 | break; |
| 307 | case ComparisonOperation::LessEqual: |
| 308 | res = wrapper::vcge(b, a); |
| 309 | break; |
| 310 | default: |
| 311 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 312 | } |
| 313 | |
| 314 | return res; |
| 315 | } |
| 316 | |
| 317 | template <ComparisonOperation op> |
| 318 | inline uint32x4x4_t elementwise_comp_op(const float32x4x4_t &a, const float32x4x4_t &b) |
| 319 | { |
| 320 | uint32x4x4_t out = |
| 321 | { |
Georgios Pinitas | d57891a | 2019-02-19 18:10:03 +0000 | [diff] [blame] | 322 | { |
| 323 | elementwise_comp_op<op, float32x4_t, uint32x4_t>(a.val[0], b.val[0]), |
| 324 | elementwise_comp_op<op, float32x4_t, uint32x4_t>(a.val[1], b.val[1]), |
| 325 | elementwise_comp_op<op, float32x4_t, uint32x4_t>(a.val[2], b.val[2]), |
| 326 | elementwise_comp_op<op, float32x4_t, uint32x4_t>(a.val[3], b.val[3]) |
| 327 | } |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 328 | }; |
| 329 | return out; |
| 330 | } |
| 331 | |
| 332 | template <ComparisonOperation op, typename InputScalarType, typename InputVectorType, typename OutputVectorType> |
| 333 | inline OutputVectorType elementwise_comp_op_broadcast(const InputVectorType &a, const InputScalarType &broadcast_value, const bool reorder) |
| 334 | { |
| 335 | InputVectorType broadcast_vector = wrapper::vdup_n(broadcast_value, wrapper::traits::vector_128_tag()); |
| 336 | return elementwise_comp_op<op, InputVectorType, OutputVectorType>(reorder ? broadcast_vector : a, reorder ? a : broadcast_vector); |
| 337 | } |
| 338 | |
| 339 | template <ArithmeticOperation op, typename ScalarType, typename VectorType> |
| 340 | inline int elementwise_arithm_op_loop(int window_start_x, int window_end_x, int window_step_x, |
| 341 | const ScalarType *input1_ptr, const ScalarType *input2_ptr, ScalarType *output_ptr) |
| 342 | { |
| 343 | int x = window_start_x; |
| 344 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 345 | { |
| 346 | const auto a = wrapper::vloadq(input1_ptr + x); |
| 347 | const auto b = wrapper::vloadq(input2_ptr + x); |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 348 | wrapper::vstore(output_ptr + x, elementwise_arithm_op<op, VectorType>(a, b)); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 349 | } |
| 350 | return x; |
| 351 | } |
| 352 | |
| 353 | template <ArithmeticOperation op> |
| 354 | inline int elementwise_arithm_op_quantized_loop(int window_start_x, int window_end_x, int window_step_x, |
| 355 | const uint8_t *input1_ptr, const uint8_t *input2_ptr, uint8_t *output_ptr, |
| 356 | int32x4_t voffset1, int32x4_t voffset2, float32x4_t vscale1, float32x4_t vscale2, |
| 357 | float32x4_t voffseto, float32x4_t invvscaleo) |
| 358 | { |
| 359 | int x = window_start_x; |
| 360 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 361 | { |
| 362 | // Get inputs and compute output |
| 363 | const float32x4x4_t af = load_quantized(input1_ptr + x, voffset1, vscale1); |
| 364 | const float32x4x4_t bf = load_quantized(input2_ptr + x, voffset2, vscale2); |
| 365 | const float32x4x4_t rf = elementwise_arithm_op<op>(af, bf); |
| 366 | store_quantized(output_ptr + x, rf, voffseto, invvscaleo); |
| 367 | } |
| 368 | return x; |
| 369 | } |
| 370 | |
| 371 | template <ArithmeticOperation op, typename ScalarType, typename VectorType> |
| 372 | inline int elementwise_arithm_op_broadcast_loop(int window_start_x, int window_end_x, int window_step_x, |
| 373 | const ScalarType *non_broadcast_input_ptr, const ScalarType &broadcast_value, ScalarType *output_ptr, const bool reorder) |
| 374 | { |
| 375 | int x = window_start_x; |
| 376 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 377 | { |
| 378 | const auto a = wrapper::vloadq((non_broadcast_input_ptr + x)); |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 379 | wrapper::vstore(output_ptr + x, elementwise_arithm_op_broadcast<op, ScalarType, VectorType>(a, broadcast_value, reorder)); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 380 | } |
| 381 | return x; |
| 382 | } |
| 383 | |
| 384 | template <ArithmeticOperation op> |
| 385 | inline int elementwise_arithm_op_quantized_broadcast_loop(int window_start_x, int window_end_x, int window_step_x, |
| 386 | const uint8_t *non_broadcast_input_ptr, float32x4x4_t broadcast_vector, uint8_t *output_ptr, |
| 387 | int32x4_t voffset_non_broadcast, float32x4_t vscale_non_broadcast, |
| 388 | float32x4_t voffseto, float32x4_t invvscaleo, bool reorder) |
| 389 | { |
| 390 | int x = window_start_x; |
| 391 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 392 | { |
| 393 | const float32x4x4_t af = load_quantized(non_broadcast_input_ptr + x, voffset_non_broadcast, vscale_non_broadcast); |
| 394 | const float32x4x4_t rf = elementwise_arithm_op<op>(reorder ? broadcast_vector : af, reorder ? af : broadcast_vector); |
| 395 | store_quantized(output_ptr + x, rf, voffseto, invvscaleo); |
| 396 | } |
| 397 | return x; |
| 398 | } |
| 399 | |
| 400 | template <ComparisonOperation op, typename InputScalarType, typename InputVectorType> |
| 401 | inline int elementwise_comp_op_16_loop(int window_start_x, int window_end_x, int window_step_x, |
| 402 | const InputScalarType *input1_ptr, const InputScalarType *input2_ptr, uint8_t *output_ptr) |
| 403 | { |
| 404 | int x = window_start_x; |
| 405 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 406 | { |
| 407 | const auto a = wrapper::vloadq(input1_ptr + x); |
| 408 | const auto b = wrapper::vloadq(input2_ptr + x); |
| 409 | const auto res = elementwise_comp_op<op, InputVectorType, uint16x8_t>(a, b); |
| 410 | wrapper::vstore(output_ptr + x, wrapper::vmovn(res)); |
| 411 | } |
| 412 | return x; |
| 413 | } |
| 414 | |
| 415 | template <ComparisonOperation op, typename InputScalarType, typename InputVectorType> |
| 416 | inline int elementwise_comp_op_32_loop(int window_start_x, int window_end_x, int window_step_x, |
| 417 | const InputScalarType *input1_ptr, const InputScalarType *input2_ptr, uint8_t *output_ptr) |
| 418 | { |
| 419 | int x = window_start_x; |
| 420 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 421 | { |
| 422 | auto a = wrapper::vloadq(input1_ptr + x); |
| 423 | auto b = wrapper::vloadq(input2_ptr + x); |
| 424 | const auto res = elementwise_comp_op<op, InputVectorType, uint32x4_t>(a, b); |
| 425 | a = wrapper::vloadq(input1_ptr + x + 4); |
| 426 | b = wrapper::vloadq(input2_ptr + x + 4); |
| 427 | const auto res2 = elementwise_comp_op<op, InputVectorType, uint32x4_t>(a, b); |
| 428 | wrapper::vstore(output_ptr + x, wrapper::vmovn(wrapper::vcombine(wrapper::vmovn(res), wrapper::vmovn(res2)))); |
| 429 | } |
| 430 | if(x <= window_end_x - 4) |
| 431 | { |
| 432 | const auto a = wrapper::vloadq(input1_ptr + x); |
| 433 | const auto b = wrapper::vloadq(input2_ptr + x); |
| 434 | const auto res = elementwise_comp_op<op, InputVectorType, uint32x4_t>(a, b); |
| 435 | for(int i = 0; i < 4; i++) |
| 436 | { |
| 437 | *(output_ptr + x + i) = wrapper::vgetlane(res, i); |
| 438 | } |
| 439 | x = +4; |
| 440 | } |
| 441 | return x; |
| 442 | } |
| 443 | |
| 444 | template <ComparisonOperation op> |
| 445 | inline int elementwise_comp_op_quantized_loop(int window_start_x, int window_end_x, int window_step_x, |
| 446 | const uint8_t *input1_ptr, const uint8_t *input2_ptr, uint8_t *output_ptr, |
| 447 | int32x4_t voffset1, int32x4_t voffset2, float32x4_t vscale1, float32x4_t vscale2, |
| 448 | float32x4_t voffseto, float32x4_t invvscaleo) |
| 449 | { |
| 450 | ARM_COMPUTE_UNUSED(voffseto, invvscaleo); |
| 451 | int x = window_start_x; |
| 452 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 453 | { |
| 454 | const float32x4x4_t af = load_quantized(input1_ptr + x, voffset1, vscale1); |
| 455 | const float32x4x4_t bf = load_quantized(input2_ptr + x, voffset2, vscale2); |
| 456 | const uint32x4x4_t rf = elementwise_comp_op<op>(af, bf); |
| 457 | store_quantized(output_ptr + x, rf); |
| 458 | } |
| 459 | return x; |
| 460 | } |
| 461 | |
| 462 | template <ComparisonOperation op, typename InputScalarType, typename InputVectorType> |
| 463 | inline int elementwise_comp_op_broadcast_16_loop(int window_start_x, int window_end_x, int window_step_x, |
| 464 | const InputScalarType *non_broadcast_input_ptr, const InputScalarType &broadcast_value, uint8_t *output_ptr, const bool reorder) |
| 465 | { |
| 466 | int x = window_start_x; |
| 467 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 468 | { |
| 469 | const auto a = elementwise_comp_op_broadcast<op, InputScalarType, InputVectorType, uint16x8_t>(wrapper::vloadq((non_broadcast_input_ptr + x)), broadcast_value, reorder); |
| 470 | wrapper::vstore(output_ptr + x, wrapper::vmovn(a)); |
| 471 | } |
| 472 | return x; |
| 473 | } |
| 474 | |
| 475 | template <ComparisonOperation op, typename InputScalarType, typename InputVectorType> |
| 476 | inline int elementwise_comp_op_broadcast_32_loop(int window_start_x, int window_end_x, int window_step_x, |
| 477 | const InputScalarType *non_broadcast_input_ptr, const InputScalarType &broadcast_value, uint8_t *output_ptr, const bool reorder) |
| 478 | { |
| 479 | int x = window_start_x; |
| 480 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 481 | { |
| 482 | const auto a = elementwise_comp_op_broadcast<op, InputScalarType, InputVectorType, uint32x4_t>(wrapper::vloadq(non_broadcast_input_ptr + x), broadcast_value, reorder); |
| 483 | const auto b = elementwise_comp_op_broadcast<op, InputScalarType, InputVectorType, uint32x4_t>(wrapper::vloadq(non_broadcast_input_ptr + x + 4), broadcast_value, reorder); |
| 484 | wrapper::vstore(output_ptr + x, wrapper::vmovn(wrapper::vcombine(wrapper::vmovn(a), wrapper::vmovn(b)))); |
| 485 | } |
| 486 | if(x <= window_end_x - 4) |
| 487 | { |
| 488 | const auto a = elementwise_comp_op_broadcast<op, InputScalarType, InputVectorType, uint32x4_t>(wrapper::vloadq((non_broadcast_input_ptr + x)), broadcast_value, reorder); |
| 489 | for(int i = 0; i < 4; i++) |
| 490 | { |
| 491 | *(output_ptr + x + i) = wrapper::vgetlane(a, i); |
| 492 | } |
| 493 | x = +4; |
| 494 | } |
| 495 | return x; |
| 496 | } |
| 497 | |
| 498 | template <ComparisonOperation op> |
| 499 | inline int elementwise_comp_op_quantized_broadcast_loop(int window_start_x, int window_end_x, int window_step_x, |
| 500 | const uint8_t *non_broadcast_input_ptr, float32x4x4_t broadcast_vector, uint8_t *output_ptr, |
| 501 | int32x4_t voffset_non_broadcast, float32x4_t vscale_non_broadcast, |
| 502 | float32x4_t voffseto, float32x4_t invvscaleo, bool reorder) |
| 503 | { |
| 504 | ARM_COMPUTE_UNUSED(voffseto, invvscaleo); |
| 505 | int x = window_start_x; |
| 506 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 507 | { |
| 508 | const float32x4x4_t af = load_quantized(non_broadcast_input_ptr + x, voffset_non_broadcast, vscale_non_broadcast); |
| 509 | const uint32x4x4_t rf = elementwise_comp_op<op>(reorder ? broadcast_vector : af, reorder ? af : broadcast_vector); |
| 510 | store_quantized(output_ptr + x, rf); |
| 511 | } |
| 512 | return x; |
| 513 | } |
| 514 | |
| 515 | template <typename InputScalarType, typename OutputScalarType, typename InputVectorType> |
| 516 | void elementwise_op(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, |
| 517 | OutputScalarType (*scalar_func)(const InputScalarType &, const InputScalarType &), |
| 518 | int (*broadcast_func)(int, int, int, const InputScalarType *, const InputScalarType &, OutputScalarType *, const bool), |
| 519 | int (*neon_func)(int, int, int, const InputScalarType *, const InputScalarType *, OutputScalarType *)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 520 | { |
| 521 | // Create input windows |
| 522 | Window input1_win = window.broadcast_if_dimension_le_one(in1->info()->tensor_shape()); |
| 523 | Window input2_win = window.broadcast_if_dimension_le_one(in2->info()->tensor_shape()); |
| 524 | |
| 525 | // Clear X Dimension on execution window as we handle manually |
| 526 | Window win = window; |
| 527 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 528 | |
Michalis Spyrou | e8c0c43 | 2019-01-22 11:08:31 +0000 | [diff] [blame] | 529 | const int window_step_x = std::min(16 / static_cast<int>(sizeof(OutputScalarType)), 8); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 530 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 531 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 532 | const bool is_broadcast_across_x = (input1_win.x().step() == 0) || (input2_win.x().step() == 0); |
| 533 | |
| 534 | if(is_broadcast_across_x) |
| 535 | { |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 536 | const bool is_broadcast_input_2 = input2_win.x().step() == 0; |
| 537 | Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win; |
| 538 | Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win; |
| 539 | const ITensor *broadcast_tensor = is_broadcast_input_2 ? in2 : in1; |
| 540 | const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? in2 : in1; |
| 541 | |
| 542 | // Clear X Dimension on execution window as we handle manually |
| 543 | non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 544 | |
| 545 | Iterator broadcast_input(broadcast_tensor, broadcast_win); |
| 546 | Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win); |
| 547 | Iterator output(out, win); |
| 548 | |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 549 | execute_window_loop(win, [&](const Coordinates &) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 550 | { |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 551 | auto output_ptr = reinterpret_cast<OutputScalarType *>(output.ptr()); |
| 552 | const auto non_broadcast_input_ptr = reinterpret_cast<const InputScalarType *>(non_broadcast_input.ptr()); |
| 553 | const InputScalarType broadcast_value = *reinterpret_cast<const InputScalarType *>(broadcast_input.ptr()); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 554 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 555 | int x = (*broadcast_func)(window_start_x, window_end_x, window_step_x, non_broadcast_input_ptr, broadcast_value, output_ptr, !is_broadcast_input_2); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 556 | for(; x < window_end_x; ++x) |
| 557 | { |
| 558 | const auto a = *(non_broadcast_input_ptr + x); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 559 | *(output_ptr + x) = (*scalar_func)(!is_broadcast_input_2 ? broadcast_value : a, !is_broadcast_input_2 ? a : broadcast_value); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 560 | } |
| 561 | }, |
| 562 | broadcast_input, non_broadcast_input, output); |
| 563 | } |
| 564 | else |
| 565 | { |
| 566 | // Clear X Dimension on execution window as we handle manually |
| 567 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 568 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 569 | |
| 570 | Iterator input1(in1, input1_win); |
| 571 | Iterator input2(in2, input2_win); |
| 572 | Iterator output(out, win); |
| 573 | |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 574 | execute_window_loop(win, [&](const Coordinates &) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 575 | { |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 576 | auto output_ptr = reinterpret_cast<OutputScalarType *>(output.ptr()); |
| 577 | const auto input1_ptr = reinterpret_cast<const InputScalarType *>(input1.ptr()); |
| 578 | const auto input2_ptr = reinterpret_cast<const InputScalarType *>(input2.ptr()); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 579 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 580 | int x = (*neon_func)(window_start_x, window_end_x, window_step_x, input1_ptr, input2_ptr, output_ptr); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 581 | for(; x < window_end_x; ++x) |
| 582 | { |
| 583 | const auto a = *(input1_ptr + x); |
| 584 | const auto b = *(input2_ptr + x); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 585 | *(output_ptr + x) = (*scalar_func)(a, b); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 586 | } |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 587 | }, |
| 588 | input1, input2, output); |
| 589 | } |
| 590 | } |
| 591 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 592 | void elementwise_op_quantized(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window, |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 593 | uint8_t (*scalar_func)(const float &, const float &, UniformQuantizationInfo), |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 594 | int (*broadcast_func)(int, int, int, const uint8_t *, float32x4x4_t, uint8_t *, int32x4_t, float32x4_t, |
| 595 | float32x4_t, float32x4_t, const bool), |
| 596 | int (*neon_func)(int, int, int, const uint8_t *, const uint8_t *, uint8_t *, |
| 597 | int32x4_t, int32x4_t, float32x4_t, float32x4_t, |
| 598 | float32x4_t, float32x4_t)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 599 | { |
| 600 | // Create input windows |
| 601 | Window input1_win = window.broadcast_if_dimension_le_one(in1->info()->tensor_shape()); |
| 602 | Window input2_win = window.broadcast_if_dimension_le_one(in2->info()->tensor_shape()); |
| 603 | |
| 604 | // Clear X Dimension on execution window as we handle manually |
| 605 | Window win = window; |
| 606 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 607 | |
| 608 | const int window_step_x = 16; |
| 609 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 610 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 611 | const bool is_broadcast_across_x = (input1_win.x().step() == 0) || (input2_win.x().step() == 0); |
| 612 | |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 613 | const UniformQuantizationInfo output_qinfo = out->info()->quantization_info().uniform(); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 614 | |
| 615 | // Output quantization info (add 0.5 to round toward the nearest integer - 0.5 rounds away from zero) |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 616 | const float32x4_t voffseto = vdupq_n_f32(output_qinfo.offset + 0.5f); |
| 617 | const float32x4_t invvscaleo = vdupq_n_f32(1.f / output_qinfo.scale); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 618 | |
| 619 | if(is_broadcast_across_x) |
| 620 | { |
| 621 | // Select the broadcast input on the X axis |
| 622 | const bool is_broadcast_input_2 = input2_win.x().step() == 0; |
| 623 | Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win; |
| 624 | Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win; |
| 625 | const ITensor *broadcast_tensor = is_broadcast_input_2 ? in2 : in1; |
| 626 | const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? in2 : in1; |
| 627 | |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 628 | const UniformQuantizationInfo broadcast_qinfo = broadcast_tensor->info()->quantization_info().uniform(); |
| 629 | const UniformQuantizationInfo non_broadcast_qinfo = non_broadcast_tensor->info()->quantization_info().uniform(); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 630 | |
| 631 | const int32x4_t voffset_non_broadcast = vdupq_n_s32(non_broadcast_qinfo.offset); |
| 632 | const float32x4_t vscale_non_broadcast = vdupq_n_f32(non_broadcast_qinfo.scale); |
| 633 | |
| 634 | // Clear X Dimension on execution window as we handle manually |
| 635 | non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 636 | |
| 637 | Iterator broadcast_input(broadcast_tensor, broadcast_win); |
| 638 | Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win); |
| 639 | Iterator output(out, win); |
| 640 | |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 641 | execute_window_loop(win, [&](const Coordinates &) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 642 | { |
| 643 | const auto non_broadcast_input_ptr = reinterpret_cast<const uint8_t *>(non_broadcast_input.ptr()); |
| 644 | const auto output_ptr = reinterpret_cast<uint8_t *>(output.ptr()); |
| 645 | |
| 646 | const uint8_t broadcast_value = *reinterpret_cast<const uint8_t *>(broadcast_input.ptr()); |
| 647 | const float32x4x4_t broadcast_vector = dup_quantized(broadcast_value, broadcast_qinfo.offset, broadcast_qinfo.scale); |
| 648 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 649 | int x = (*broadcast_func)(window_start_x, window_end_x, window_step_x, non_broadcast_input_ptr, broadcast_vector, output_ptr, |
| 650 | voffset_non_broadcast, vscale_non_broadcast, voffseto, invvscaleo, !is_broadcast_input_2); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 651 | for(; x < window_end_x; ++x) |
| 652 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 653 | const float afs = dequantize_qasymm8(*(non_broadcast_input_ptr + x), non_broadcast_qinfo); |
| 654 | const float bfs = dequantize_qasymm8(broadcast_value, broadcast_qinfo); |
| 655 | *(output_ptr + x) = (*scalar_func)(!is_broadcast_input_2 ? bfs : afs, !is_broadcast_input_2 ? afs : bfs, output_qinfo); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 656 | } |
| 657 | }, |
| 658 | broadcast_input, non_broadcast_input, output); |
| 659 | } |
| 660 | else |
| 661 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 662 | const UniformQuantizationInfo input1_qinfo = in1->info()->quantization_info().uniform(); |
| 663 | const UniformQuantizationInfo input2_qinfo = in2->info()->quantization_info().uniform(); |
| 664 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 665 | // Input1 quantization info |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 666 | const int32x4_t voffset1 = vdupq_n_s32(input1_qinfo.offset); |
| 667 | const float32x4_t vscale1 = vdupq_n_f32(input1_qinfo.scale); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 668 | |
| 669 | // Input2 quantization info |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 670 | const int32x4_t voffset2 = vdupq_n_s32(input2_qinfo.offset); |
| 671 | const float32x4_t vscale2 = vdupq_n_f32(input2_qinfo.scale); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 672 | |
| 673 | // Clear X Dimension on execution window as we handle manually |
| 674 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 675 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 676 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 677 | Iterator input1(in1, input1_win); |
| 678 | Iterator input2(in2, input2_win); |
| 679 | Iterator output(out, win); |
| 680 | |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 681 | execute_window_loop(win, [&](const Coordinates &) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 682 | { |
| 683 | const auto input1_ptr = reinterpret_cast<const uint8_t *>(input1.ptr()); |
| 684 | const auto input2_ptr = reinterpret_cast<const uint8_t *>(input2.ptr()); |
| 685 | const auto output_ptr = reinterpret_cast<uint8_t *>(output.ptr()); |
| 686 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 687 | int x = (*neon_func)(window_start_x, window_end_x, window_step_x, input1_ptr, input2_ptr, output_ptr, voffset1, voffset2, |
| 688 | vscale1, vscale2, voffseto, invvscaleo); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 689 | for(; x < window_end_x; ++x) |
| 690 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 691 | const float afs = dequantize_qasymm8(*(input1_ptr + x), input1_qinfo); |
| 692 | const float bfs = dequantize_qasymm8(*(input2_ptr + x), input2_qinfo); |
| 693 | *(output_ptr + x) = (*scalar_func)(afs, bfs, output_qinfo); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 694 | } |
| 695 | }, |
| 696 | input1, input2, output); |
| 697 | } |
| 698 | } |
| 699 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 700 | template <ComparisonOperation op, typename InputScalarType, typename InputVectorType> |
| 701 | void elementwise_comp_op_16(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 702 | { |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 703 | elementwise_op<InputScalarType, uint8_t, InputVectorType>(in1, in2, out, window, |
| 704 | &elementwise_comp_op_scalar<op, InputScalarType>, |
| 705 | &elementwise_comp_op_broadcast_16_loop<op, InputScalarType, InputVectorType>, |
| 706 | &elementwise_comp_op_16_loop<op, InputScalarType, InputVectorType>); |
| 707 | } |
| 708 | |
| 709 | template <ComparisonOperation op, typename InputScalarType, typename InputVectorType> |
| 710 | void elementwise_comp_op_32(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 711 | { |
| 712 | elementwise_op<InputScalarType, uint8_t, InputVectorType>(in1, in2, out, window, |
| 713 | &elementwise_comp_op_scalar<op, InputScalarType>, |
| 714 | &elementwise_comp_op_broadcast_32_loop<op, InputScalarType, InputVectorType>, |
| 715 | &elementwise_comp_op_32_loop<op, InputScalarType, InputVectorType>); |
| 716 | } |
| 717 | |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 718 | template <ArithmeticOperation op, typename VectorType> |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 719 | void elementwise_arithm_op(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 720 | { |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 721 | using scalar_type = typename VectorType::scalar_type; |
| 722 | |
| 723 | elementwise_op<scalar_type, scalar_type, VectorType>(in1, in2, out, window, |
| 724 | &elementwise_arithm_op_scalar<op, scalar_type>, |
| 725 | &elementwise_arithm_op_broadcast_loop<op, scalar_type, VectorType>, |
| 726 | &elementwise_arithm_op_loop<op, scalar_type, VectorType>); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | template <ArithmeticOperation op> |
| 730 | void elementwise_arithm_op_quantized(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 731 | { |
| 732 | elementwise_op_quantized(in1, in2, out, window, &elementwise_arithm_op_quantized_scalar<op>, |
| 733 | &elementwise_arithm_op_quantized_broadcast_loop<op>, |
| 734 | &elementwise_arithm_op_quantized_loop<op>); |
| 735 | } |
| 736 | |
| 737 | template <ComparisonOperation op> |
| 738 | void elementwise_comp_op_quantized(const ITensor *in1, const ITensor *in2, ITensor *out, const Window &window) |
| 739 | { |
| 740 | elementwise_op_quantized(in1, in2, out, window, &elementwise_comp_op_quantized_scalar<op>, |
| 741 | &elementwise_comp_op_quantized_broadcast_loop<op>, |
| 742 | &elementwise_comp_op_quantized_loop<op>); |
| 743 | } |
| 744 | |
| 745 | std::function<void(const ITensor *, const ITensor *, ITensor *, const Window &)> |
| 746 | configure_func(const ITensor *input1, const ITensor *input2, ITensor *output, |
| 747 | std::map<std::string, NEElementwiseOperationKernel::ElementwiseFunction *> map_function) |
| 748 | { |
| 749 | std::string function_to_call("op_"); |
| 750 | function_to_call += string_from_data_type(input1->info()->data_type()) + "_"; |
| 751 | function_to_call += string_from_data_type(input2->info()->data_type()) + "_"; |
| 752 | function_to_call += string_from_data_type(output->info()->data_type()); |
| 753 | |
| 754 | auto it = map_function.find(function_to_call); |
| 755 | |
| 756 | if(it != map_function.end()) |
| 757 | { |
| 758 | auto func = it->second; |
| 759 | return [func](const ITensor * input1, const ITensor * input2, ITensor * output, const Window & window) |
| 760 | { |
| 761 | func(input1, input2, output, window); |
| 762 | }; |
| 763 | } |
| 764 | return nullptr; |
| 765 | } |
| 766 | |
| 767 | template <ArithmeticOperation op> |
| 768 | std::function<void(const ITensor *, const ITensor *, ITensor *, const Window &)> |
| 769 | configure_arithm_func(const ITensor *input1, const ITensor *input2, ITensor *output) |
| 770 | { |
| 771 | static std::map<std::string, NEElementwiseOperationKernel::ElementwiseFunction *> map_function = |
| 772 | { |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 773 | { "op_F32_F32_F32", &elementwise_arithm_op<op, typename wrapper::traits::neon_vector<float, 4>> }, |
| 774 | { "op_S16_S16_S16", &elementwise_arithm_op<op, typename wrapper::traits::neon_vector<int16_t, 8>> }, |
| 775 | { "op_S32_S32_S32", &elementwise_arithm_op<op, typename wrapper::traits::neon_vector<int32_t, 4>> }, |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 776 | { "op_QASYMM8_QASYMM8_QASYMM8", &elementwise_arithm_op_quantized<op> } |
| 777 | }; |
| 778 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 779 | map_function["op_F16_F16_F16"] = &elementwise_arithm_op<op, typename wrapper::traits::neon_vector<float16_t, 8>>; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 780 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 781 | |
| 782 | return configure_func(input1, input2, output, map_function); |
| 783 | } |
| 784 | |
| 785 | template <ComparisonOperation op> |
| 786 | std::function<void(const ITensor *input1, const ITensor *input2, ITensor *output, const Window &window)> |
| 787 | configure_comp_func(const ITensor *input1, const ITensor *input2, ITensor *output) |
| 788 | { |
| 789 | static std::map<std::string, NEElementwiseOperationKernel::ElementwiseFunction *> map_function = |
| 790 | { |
| 791 | { "op_F32_F32_U8", &elementwise_comp_op_32<op, float, float32x4_t> }, |
| 792 | { "op_S16_S16_U8", &elementwise_comp_op_16<op, int16_t, int16x8_t> }, |
| 793 | { "op_S32_S32_U8", &elementwise_comp_op_32<op, int32_t, int32x4_t> }, |
| 794 | { "op_QASYMM8_QASYMM8_U8", &elementwise_comp_op_quantized<op> } |
| 795 | }; |
| 796 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 797 | map_function["op_F16_F16_U8"] = &elementwise_comp_op_16<op, float16_t, float16x8_t>; |
| 798 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 799 | |
| 800 | return configure_func(input1, input2, output, map_function); |
| 801 | } |
| 802 | } // namespace |
| 803 | |
| 804 | NEElementwiseOperationKernel::NEElementwiseOperationKernel() |
| 805 | : _function(nullptr), _input1(nullptr), _input2(nullptr), _output(nullptr) |
| 806 | { |
| 807 | } |
| 808 | |
| 809 | Status NEElementwiseOperationKernel::validate_arguments_common(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) |
| 810 | { |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 811 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input1, 1, DataType::QASYMM8, DataType::S16, DataType::F16, DataType::S32, DataType::F32); |
| 812 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input2, 1, DataType::QASYMM8, DataType::S16, DataType::F16, DataType::S32, DataType::F32); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 813 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(&input1); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 814 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(&input1, &input2); |
| 815 | |
| 816 | const TensorShape out_shape = TensorShape::broadcast_shape(input1.tensor_shape(), input2.tensor_shape()); |
| 817 | |
| 818 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible"); |
| 819 | |
| 820 | // Validate in case of configured output |
| 821 | if(output.total_size() > 0) |
| 822 | { |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 823 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, output.tensor_shape(), 0), |
| 824 | "Wrong shape for output"); |
| 825 | } |
| 826 | |
| 827 | return Status{}; |
| 828 | } |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 829 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 830 | void NEElementwiseOperationKernel::configure_common(const ITensor *input1, const ITensor *input2, ITensor *output) |
| 831 | { |
| 832 | ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 833 | |
| 834 | // Configure kernel window |
| 835 | const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(*input1->info(), *input2->info()); |
| 836 | const TensorShape &out_shape = broadcast_pair.first; |
| 837 | const ValidRegion &valid_region = broadcast_pair.second; |
| 838 | |
| 839 | // Auto initialize output if not initialized |
| 840 | auto_init_if_empty(*output->info(), out_shape, 1, input1->info()->data_type()); |
| 841 | |
| 842 | Window win = calculate_max_window(valid_region); |
| 843 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 844 | _input1 = input1; |
| 845 | _input2 = input2; |
| 846 | _output = output; |
| 847 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 848 | INEKernel::configure(win); |
| 849 | } |
| 850 | |
| 851 | void NEElementwiseOperationKernel::run(const Window &window, const ThreadInfo &info) |
| 852 | { |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 853 | ARM_COMPUTE_UNUSED(info, window); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 854 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 855 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 856 | ARM_COMPUTE_ERROR_ON(_function == nullptr); |
| 857 | _function(_input1, _input2, _output, window); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /** Arithmetic operators (min, max, squared_diff) */ |
| 861 | |
| 862 | void NEArithmeticOperationKernel::configure(ArithmeticOperation op, const ITensor *input1, const ITensor *input2, ITensor *output) |
| 863 | { |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 864 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1->info(), *input2->info(), *output->info())); |
| 865 | configure_common(input1, input2, output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 866 | switch(op) |
| 867 | { |
| 868 | case ArithmeticOperation::MAX: |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 869 | _function = configure_arithm_func<ArithmeticOperation::MAX>(input1, input2, output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 870 | break; |
| 871 | case ArithmeticOperation::MIN: |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 872 | _function = configure_arithm_func<ArithmeticOperation::MIN>(input1, input2, output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 873 | break; |
| 874 | case ArithmeticOperation::SQUARED_DIFF: |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 875 | _function = configure_arithm_func<ArithmeticOperation::SQUARED_DIFF>(input1, input2, output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 876 | break; |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 877 | case ArithmeticOperation::PRELU: |
| 878 | _function = configure_arithm_func<ArithmeticOperation::PRELU>(input1, input2, output); |
| 879 | break; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 880 | default: |
| 881 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 882 | } |
| 883 | } |
| 884 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 885 | Status NEArithmeticOperationKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) |
| 886 | { |
| 887 | // Validate in case of configured output |
| 888 | if(output.total_size() > 0) |
| 889 | { |
| 890 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(&input1, &output); |
| 891 | } |
| 892 | return validate_arguments_common(input1, input2, output); |
| 893 | } |
| 894 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 895 | Status NEArithmeticOperationKernel::validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
| 896 | { |
| 897 | ARM_COMPUTE_UNUSED(op); |
| 898 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 899 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output)); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 900 | return Status{}; |
| 901 | } |
| 902 | |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 903 | /** The division operator */ |
| 904 | |
| 905 | void NEDivisionOperationKernel::configure(const ITensor *input1, const ITensor *input2, ITensor *output) |
| 906 | { |
| 907 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1->info(), *input2->info(), *output->info())); |
| 908 | configure_common(input1, input2, output); |
| 909 | _function = configure_arithm_func<ArithmeticOperation::DIV>(input1, input2, output); |
| 910 | } |
| 911 | |
| 912 | Status NEDivisionOperationKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) |
| 913 | { |
| 914 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input1, 1, DataType::F16, DataType::F32); |
| 915 | return NEArithmeticOperationKernel::validate_arguments(input1, input2, output); |
| 916 | } |
| 917 | |
| 918 | Status NEDivisionOperationKernel::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
| 919 | { |
| 920 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); |
| 921 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output)); |
| 922 | return Status{}; |
| 923 | } |
| 924 | |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 925 | /** The power operator */ |
| 926 | void NEPowerOperationKernel::configure(const ITensor *input1, const ITensor *input2, ITensor *output) |
| 927 | { |
| 928 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1->info(), *input2->info(), *output->info())); |
| 929 | configure_common(input1, input2, output); |
| 930 | _function = configure_arithm_func<ArithmeticOperation::POWER>(input1, input2, output); |
| 931 | } |
| 932 | |
| 933 | Status NEPowerOperationKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) |
| 934 | { |
| 935 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input1, 1, DataType::F16, DataType::F32); |
| 936 | return NEArithmeticOperationKernel::validate_arguments(input1, input2, output); |
| 937 | } |
| 938 | |
| 939 | Status NEPowerOperationKernel::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
| 940 | { |
| 941 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); |
| 942 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output)); |
| 943 | return Status{}; |
| 944 | } |
| 945 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 946 | /** Comparison operators (equal, not equal, less than, greater than, less than or equal, greater than or equal) */ |
| 947 | |
| 948 | void NEComparisonOperationKernel::configure(ComparisonOperation op, const ITensor *input1, const ITensor *input2, ITensor *output) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 949 | { |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 950 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1->info(), *input2->info(), *output->info())); |
| 951 | configure_common(input1, input2, output); |
| 952 | switch(op) |
| 953 | { |
| 954 | case ComparisonOperation::Equal: |
| 955 | _function = configure_comp_func<ComparisonOperation::Equal>(input1, input2, output); |
| 956 | break; |
| 957 | case ComparisonOperation::NotEqual: |
| 958 | _function = configure_comp_func<ComparisonOperation::NotEqual>(input1, input2, output); |
| 959 | break; |
| 960 | case ComparisonOperation::Greater: |
| 961 | _function = configure_comp_func<ComparisonOperation::Greater>(input1, input2, output); |
| 962 | break; |
| 963 | case ComparisonOperation::GreaterEqual: |
| 964 | _function = configure_comp_func<ComparisonOperation::GreaterEqual>(input1, input2, output); |
| 965 | break; |
| 966 | case ComparisonOperation::Less: |
| 967 | _function = configure_comp_func<ComparisonOperation::Less>(input1, input2, output); |
| 968 | break; |
| 969 | case ComparisonOperation::LessEqual: |
| 970 | _function = configure_comp_func<ComparisonOperation::LessEqual>(input1, input2, output); |
| 971 | break; |
| 972 | default: |
| 973 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | Status NEComparisonOperationKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) |
| 978 | { |
| 979 | // Validate in case of configured output |
| 980 | if(output.total_size() > 0) |
| 981 | { |
| 982 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&output, 1, DataType::U8); |
| 983 | } |
| 984 | return validate_arguments_common(input1, input2, output); |
| 985 | } |
| 986 | |
| 987 | Status NEComparisonOperationKernel::validate(ComparisonOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
| 988 | { |
| 989 | ARM_COMPUTE_UNUSED(op); |
| 990 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); |
| 991 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output)); |
| 992 | return Status{}; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 993 | } |
| 994 | } // namespace arm_compute |