blob: 5f5a3e5b37d46126edf26a256ced158dd0b7efeb [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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/NEArithmeticAdditionKernel.h"
25
Anthony Barbiereaefd002018-07-20 17:49:35 +010026#include "arm_compute/core/CPP/Validate.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Error.h"
28#include "arm_compute/core/Helpers.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#include "arm_compute/core/ITensor.h"
Georgios Pinitas5a594532018-12-03 14:30:05 +000030#include "arm_compute/core/NEON/wrapper/wrapper.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include "arm_compute/core/Validate.h"
32
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033#include <map>
34#include <string>
35
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036namespace arm_compute
37{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038namespace
39{
Michalis Spyrou7a7fe652020-05-15 11:28:59 +010040template <typename T>
41void add_same(const ITensor *in1, const ITensor *in2, ITensor *out, const ConvertPolicy policy, const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042{
Georgios Pinitas5a594532018-12-03 14:30:05 +000043 /** NEON vector tag type. */
44 using ExactTagType = typename wrapper::traits::neon_bitvector_tag_t<T, wrapper::traits::BitWidth::W128>;
45
46 // Create input windows
47 Window input1_win = window.broadcast_if_dimension_le_one(in1->info()->tensor_shape());
48 Window input2_win = window.broadcast_if_dimension_le_one(in2->info()->tensor_shape());
49
50 // Clear X Dimension on execution window as we handle manually
51 Window win = window;
52 win.set(Window::DimX, Window::Dimension(0, 1, 1));
53
54 constexpr int window_step_x = 16 / sizeof(T);
55 const auto window_start_x = static_cast<int>(window.x().start());
56 const auto window_end_x = static_cast<int>(window.x().end());
57 const bool is_broadcast_across_x = (input1_win.x().step() == 0) || (input2_win.x().step() == 0);
58
59 if(is_broadcast_across_x)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010060 {
Georgios Pinitas5a594532018-12-03 14:30:05 +000061 const bool is_broadcast_input_2 = input2_win.x().step() == 0;
62 Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win;
63 Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win;
64 const ITensor *broadcast_tensor = is_broadcast_input_2 ? in2 : in1;
65 const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? in2 : in1;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066
Georgios Pinitas5a594532018-12-03 14:30:05 +000067 // Clear X Dimension on execution window as we handle manually
68 non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1));
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069
Georgios Pinitas5a594532018-12-03 14:30:05 +000070 Iterator broadcast_input(broadcast_tensor, broadcast_win);
71 Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win);
72 Iterator output(out, win);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073
Michalis Spyroua4f378d2019-04-26 14:54:54 +010074 execute_window_loop(win, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075 {
Georgios Pinitas5a594532018-12-03 14:30:05 +000076 const auto non_broadcast_input_ptr = reinterpret_cast<const T *>(non_broadcast_input.ptr());
77 const auto output_ptr = reinterpret_cast<T *>(output.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078
Georgios Pinitas5a594532018-12-03 14:30:05 +000079 const T broadcast_value = *reinterpret_cast<const T *>(broadcast_input.ptr());
80 const auto broadcast_value_vec = wrapper::vdup_n(broadcast_value, ExactTagType{});
Anthony Barbier6ff3b192017-09-04 18:44:23 +010081
Georgios Pinitas5a594532018-12-03 14:30:05 +000082 // Compute S elements per iteration
83 int x = window_start_x;
84 for(; x <= (window_end_x - window_step_x); x += window_step_x)
85 {
86 const auto non_broadcast_v = wrapper::vloadq(non_broadcast_input_ptr + x);
Michalis Spyrou7a7fe652020-05-15 11:28:59 +010087 const auto res = (policy == ConvertPolicy::SATURATE) ? wrapper::vqadd(broadcast_value_vec, non_broadcast_v) : wrapper::vadd(broadcast_value_vec, non_broadcast_v);
Georgios Pinitas5a594532018-12-03 14:30:05 +000088 wrapper::vstore(output_ptr + x, res);
89 }
90
91 // Compute left-over elements
92 for(; x < window_end_x; ++x)
93 {
94 const auto non_broadcast_v = *(non_broadcast_input_ptr + x);
Michalis Spyrou7a7fe652020-05-15 11:28:59 +010095 *(output_ptr + x) = (policy == ConvertPolicy::SATURATE) ? wrapper::add_sat(broadcast_value, non_broadcast_v) : broadcast_value + non_broadcast_v;
Georgios Pinitas5a594532018-12-03 14:30:05 +000096 }
97 },
98 broadcast_input, non_broadcast_input, output);
99 }
100 else
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100101 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000102 // Clear X Dimension on execution window as we handle manually
103 input1_win.set(Window::DimX, Window::Dimension(0, 1, 1));
104 input2_win.set(Window::DimX, Window::Dimension(0, 1, 1));
105
106 Iterator input1(in1, input1_win);
107 Iterator input2(in2, input2_win);
108 Iterator output(out, win);
109
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100110 execute_window_loop(win, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100111 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000112 const auto input1_ptr = reinterpret_cast<const T *>(input1.ptr());
113 const auto input2_ptr = reinterpret_cast<const T *>(input2.ptr());
114 const auto output_ptr = reinterpret_cast<T *>(output.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100115
Georgios Pinitas5a594532018-12-03 14:30:05 +0000116 // Compute S elements per iteration
117 int x = window_start_x;
118 for(; x <= (window_end_x - window_step_x); x += window_step_x)
119 {
120 const auto val1 = wrapper::vloadq(input1_ptr + x);
121 const auto val2 = wrapper::vloadq(input2_ptr + x);
Michalis Spyrou7a7fe652020-05-15 11:28:59 +0100122 const auto res = (policy == ConvertPolicy::SATURATE) ? wrapper::vqadd(val1, val2) : wrapper::vadd(val1, val2);
Georgios Pinitas5a594532018-12-03 14:30:05 +0000123 wrapper::vstore(output_ptr + x, res);
124 }
125
126 // Compute left-over elements
127 for(; x < window_end_x; ++x)
128 {
129 const auto val1 = *(input1_ptr + x);
130 const auto val2 = *(input2_ptr + x);
Michalis Spyrou7a7fe652020-05-15 11:28:59 +0100131 *(output_ptr + x) = (policy == ConvertPolicy::SATURATE) ? wrapper::add_sat(val1, val2) : val1 + val2;
Georgios Pinitas5a594532018-12-03 14:30:05 +0000132 }
133 },
134 input1, input2, output);
135 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100136}
137
Georgios Pinitas5a594532018-12-03 14:30:05 +0000138void add_QASYMM8_QASYMM8_QASYMM8(const ITensor *in1, const ITensor *in2, ITensor *out, ConvertPolicy policy, const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100139{
Georgios Pinitas5a594532018-12-03 14:30:05 +0000140 ARM_COMPUTE_UNUSED(policy);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100141
Georgios Pinitas5a594532018-12-03 14:30:05 +0000142 // Create input windows
143 Window input1_win = window.broadcast_if_dimension_le_one(in1->info()->tensor_shape());
144 Window input2_win = window.broadcast_if_dimension_le_one(in2->info()->tensor_shape());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100145
Georgios Pinitas5a594532018-12-03 14:30:05 +0000146 // Clear X Dimension on execution window as we handle manually
147 Window win = window;
148 win.set(Window::DimX, Window::Dimension(0, 1, 1));
Pablo Tellod1b0ecc2017-07-11 11:27:04 +0100149
Georgios Pinitas5a594532018-12-03 14:30:05 +0000150 const int window_step_x = 16;
151 const auto window_start_x = static_cast<int>(window.x().start());
152 const auto window_end_x = static_cast<int>(window.x().end());
153 const bool is_broadcast_across_x = (input1_win.x().step() == 0) || (input2_win.x().step() == 0);
Pablo Tellod1b0ecc2017-07-11 11:27:04 +0100154
Georgios Pinitas4c5469b2019-05-21 13:32:43 +0100155 const UniformQuantizationInfo iq1_info = in1->info()->quantization_info().uniform();
156 const UniformQuantizationInfo iq2_info = in2->info()->quantization_info().uniform();
157 const UniformQuantizationInfo oq_info = out->info()->quantization_info().uniform();
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000158
Georgios Pinitas4c5469b2019-05-21 13:32:43 +0100159 const float32x4_t invvscaleo = vdupq_n_f32(1.f / oq_info.scale);
Georgios Pinitas4c5469b2019-05-21 13:32:43 +0100160 const float32x4_t voffseto = vdupq_n_f32(oq_info.offset);
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000161
Georgios Pinitas5a594532018-12-03 14:30:05 +0000162 if(is_broadcast_across_x)
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000163 {
Georgios Pinitas4c5469b2019-05-21 13:32:43 +0100164 const bool is_broadcast_input_2 = input2_win.x().step() == 0;
165 Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win;
166 Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win;
167 const ITensor *broadcast_tensor = is_broadcast_input_2 ? in2 : in1;
168 const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? in2 : in1;
169 const UniformQuantizationInfo broadcast_qinfo = broadcast_tensor->info()->quantization_info().uniform();
170 const UniformQuantizationInfo non_broadcast_qinfo = non_broadcast_tensor->info()->quantization_info().uniform();
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000171
Michalis Spyrou85b75992020-07-16 11:47:12 +0100172 const float32x4_t vscale1 = is_broadcast_input_2 ? vdupq_n_f32(iq1_info.scale) : vdupq_n_f32(iq2_info.scale);
173 const float32x4_t vscale2 = is_broadcast_input_2 ? vdupq_n_f32(iq2_info.scale) : vdupq_n_f32(iq1_info.scale);
174 const int32x4_t voffset1 = is_broadcast_input_2 ? vdupq_n_s32(iq1_info.offset) : vdupq_n_s32(iq2_info.offset);
175 const int32x4_t voffset2 = is_broadcast_input_2 ? vdupq_n_s32(iq2_info.offset) : vdupq_n_s32(iq1_info.offset);
176
Georgios Pinitas5a594532018-12-03 14:30:05 +0000177 // Clear X Dimension on execution window as we handle manually
178 non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1));
179
180 Iterator broadcast_input(broadcast_tensor, broadcast_win);
181 Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win);
182 Iterator output(out, win);
183
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100184 execute_window_loop(win, [&](const Coordinates &)
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000185 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000186 const auto non_broadcast_input_ptr = reinterpret_cast<const uint8_t *>(non_broadcast_input.ptr());
187 const auto output_ptr = reinterpret_cast<uint8_t *>(output.ptr());
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000188
Georgios Pinitas5a594532018-12-03 14:30:05 +0000189 const uint8_t broadcast_value = *reinterpret_cast<const uint8_t *>(broadcast_input.ptr());
190 const uint8x16_t broadcast_value_vec = vdupq_n_u8(broadcast_value);
191
192 const float32x4x4_t bf =
193 {
194 {
195 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(broadcast_value_vec))))), voffset2)), vscale2),
196 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_low_u8(broadcast_value_vec))))), voffset2)), vscale2),
197 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_high_u8(broadcast_value_vec))))), voffset2)), vscale2),
198 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_high_u8(broadcast_value_vec))))), voffset2)), vscale2),
199 }
200 };
201 const float bfs = static_cast<int32_t>(broadcast_value - broadcast_qinfo.offset) * broadcast_qinfo.scale;
202
203 // Compute S elements per iteration
204 int x = window_start_x;
205 for(; x <= (window_end_x - window_step_x); x += window_step_x)
206 {
207 const uint8x16_t a = vld1q_u8(non_broadcast_input_ptr + x);
208 const float32x4x4_t af =
209 {
210 {
211 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(a))))), voffset1)), vscale1),
212 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_low_u8(a))))), voffset1)), vscale1),
213 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_high_u8(a))))), voffset1)), vscale1),
214 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_high_u8(a))))), voffset1)), vscale1),
215 }
216 };
217
218 const int32x4x4_t rf =
219 {
220 {
Vidhya Sudhan Loganathanf8b65202019-02-01 09:49:50 +0000221#ifdef __aarch64__
222 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
223 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
224 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[2], bf.val[2]), invvscaleo)),
225 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[3], bf.val[3]), invvscaleo)),
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100226#else //__aarch64__
Georgios Pinitas5a594532018-12-03 14:30:05 +0000227 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
228 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
229 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[2], bf.val[2]), invvscaleo)),
230 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[3], bf.val[3]), invvscaleo)),
Vidhya Sudhan Loganathanf8b65202019-02-01 09:49:50 +0000231#endif //__aarch64__
Georgios Pinitas5a594532018-12-03 14:30:05 +0000232 }
233 };
234
235 const uint8x8_t pa = vqmovun_s16(vcombine_s16(vqmovn_s32(rf.val[0]), vqmovn_s32(rf.val[1])));
236 const uint8x8_t pb = vqmovun_s16(vcombine_s16(vqmovn_s32(rf.val[2]), vqmovn_s32(rf.val[3])));
237 vst1q_u8(output_ptr + x, vcombine_u8(pa, pb));
238 }
239
240 // Compute left-over elements
241 for(; x < window_end_x; ++x)
242 {
243 const float afs = static_cast<int32_t>(*(non_broadcast_input_ptr + x) - non_broadcast_qinfo.offset) * non_broadcast_qinfo.scale;
Georgios Pinitas4c5469b2019-05-21 13:32:43 +0100244 *(output_ptr + x) = quantize_qasymm8((afs + bfs), oq_info);
Georgios Pinitas5a594532018-12-03 14:30:05 +0000245 }
246 },
247 broadcast_input, non_broadcast_input, output);
248 }
249 else
250 {
251 // Clear X Dimension on execution window as we handle manually
252 input1_win.set(Window::DimX, Window::Dimension(0, 1, 1));
253 input2_win.set(Window::DimX, Window::Dimension(0, 1, 1));
254
Georgios Pinitas5a594532018-12-03 14:30:05 +0000255 Iterator input1(in1, input1_win);
256 Iterator input2(in2, input2_win);
257 Iterator output(out, win);
258
Michalis Spyrou85b75992020-07-16 11:47:12 +0100259 const float32x4_t vscale1 = vdupq_n_f32(iq1_info.scale);
260 const float32x4_t vscale2 = vdupq_n_f32(iq2_info.scale);
261 const int32x4_t voffset1 = vdupq_n_s32(iq1_info.offset);
262 const int32x4_t voffset2 = vdupq_n_s32(iq2_info.offset);
263
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100264 execute_window_loop(win, [&](const Coordinates &)
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000265 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000266 const auto input1_ptr = reinterpret_cast<const uint8_t *>(input1.ptr());
267 const auto input2_ptr = reinterpret_cast<const uint8_t *>(input2.ptr());
268 const auto output_ptr = reinterpret_cast<uint8_t *>(output.ptr());
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000269
Georgios Pinitas5a594532018-12-03 14:30:05 +0000270 // Compute S elements per iteration
271 int x = window_start_x;
272 for(; x <= (window_end_x - window_step_x); x += window_step_x)
273 {
274 const uint8x16_t a = vld1q_u8(input1_ptr + x);
275 const uint8x16_t b = vld1q_u8(input2_ptr + x);
276
277 const float32x4x4_t af =
278 {
279 {
280 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(a))))), voffset1)), vscale1),
281 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_low_u8(a))))), voffset1)), vscale1),
282 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_high_u8(a))))), voffset1)), vscale1),
283 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_high_u8(a))))), voffset1)), vscale1),
284 }
285 };
286
287 const float32x4x4_t bf =
288 {
289 {
290 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(b))))), voffset2)), vscale2),
291 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_low_u8(b))))), voffset2)), vscale2),
292 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_high_u8(b))))), voffset2)), vscale2),
293 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(vmovl_u8(vget_high_u8(b))))), voffset2)), vscale2),
294 }
295 };
296
297 const int32x4x4_t rf =
298 {
299 {
Vidhya Sudhan Loganathanf8b65202019-02-01 09:49:50 +0000300#ifdef __aarch64__
301 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
302 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
303 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[2], bf.val[2]), invvscaleo)),
304 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[3], bf.val[3]), invvscaleo)),
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100305#else //__aarch64__
Georgios Pinitas5a594532018-12-03 14:30:05 +0000306 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
307 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
308 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[2], bf.val[2]), invvscaleo)),
309 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[3], bf.val[3]), invvscaleo)),
Vidhya Sudhan Loganathanf8b65202019-02-01 09:49:50 +0000310#endif //__aarch64__
Georgios Pinitas5a594532018-12-03 14:30:05 +0000311 }
312 };
313
314 const uint8x8_t pa = vqmovun_s16(vcombine_s16(vqmovn_s32(rf.val[0]), vqmovn_s32(rf.val[1])));
315 const uint8x8_t pb = vqmovun_s16(vcombine_s16(vqmovn_s32(rf.val[2]), vqmovn_s32(rf.val[3])));
316 vst1q_u8(output_ptr + x, vcombine_u8(pa, pb));
317 }
318
319 // Compute left-over elements
320 for(; x < window_end_x; ++x)
321 {
Georgios Pinitas4c5469b2019-05-21 13:32:43 +0100322 const float afs = static_cast<int32_t>((*(input1_ptr + x)) - iq1_info.offset) * iq1_info.scale;
323 const float bfs = static_cast<int32_t>((*(input2_ptr + x)) - iq2_info.offset) * iq2_info.scale;
324 *(output_ptr + x) = quantize_qasymm8((afs + bfs), out->info()->quantization_info());
Georgios Pinitas5a594532018-12-03 14:30:05 +0000325 }
326 },
327 input1, input2, output);
328 }
329}
330
Michalis Spyroubc4d7c22019-12-03 15:11:09 +0000331void add_QASYMM8_SIGNED_QASYMM8_SIGNED_QASYMM8_SIGNED(const ITensor *in1, const ITensor *in2, ITensor *out, ConvertPolicy policy, const Window &window)
332{
333 ARM_COMPUTE_UNUSED(policy);
334
335 // Create input windows
336 Window input1_win = window.broadcast_if_dimension_le_one(in1->info()->tensor_shape());
337 Window input2_win = window.broadcast_if_dimension_le_one(in2->info()->tensor_shape());
338
339 // Clear X Dimension on execution window as we handle manually
340 Window win = window;
341 win.set(Window::DimX, Window::Dimension(0, 1, 1));
342
343 const int window_step_x = 16;
344 const auto window_start_x = static_cast<int>(window.x().start());
345 const auto window_end_x = static_cast<int>(window.x().end());
346 const bool is_broadcast_across_x = (input1_win.x().step() == 0) || (input2_win.x().step() == 0);
347
348 const UniformQuantizationInfo iq1_info = in1->info()->quantization_info().uniform();
349 const UniformQuantizationInfo iq2_info = in2->info()->quantization_info().uniform();
350 const UniformQuantizationInfo oq_info = out->info()->quantization_info().uniform();
351
Michalis Spyroubc4d7c22019-12-03 15:11:09 +0000352 const float32x4_t invvscaleo = vdupq_n_f32(1.f / oq_info.scale);
Michalis Spyroubc4d7c22019-12-03 15:11:09 +0000353 const float32x4_t voffseto = vdupq_n_f32(oq_info.offset);
354
355 if(is_broadcast_across_x)
356 {
357 const bool is_broadcast_input_2 = input2_win.x().step() == 0;
358 Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win;
359 Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win;
360 const ITensor *broadcast_tensor = is_broadcast_input_2 ? in2 : in1;
361 const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? in2 : in1;
362 const UniformQuantizationInfo broadcast_qinfo = broadcast_tensor->info()->quantization_info().uniform();
363 const UniformQuantizationInfo non_broadcast_qinfo = non_broadcast_tensor->info()->quantization_info().uniform();
364
Michalis Spyrou2232a202020-07-13 15:15:33 +0100365 const float32x4_t vscale1 = is_broadcast_input_2 ? vdupq_n_f32(iq1_info.scale) : vdupq_n_f32(iq2_info.scale);
366 const float32x4_t vscale2 = is_broadcast_input_2 ? vdupq_n_f32(iq2_info.scale) : vdupq_n_f32(iq1_info.scale);
367 const int32x4_t voffset1 = is_broadcast_input_2 ? vdupq_n_s32(iq1_info.offset) : vdupq_n_s32(iq2_info.offset);
368 const int32x4_t voffset2 = is_broadcast_input_2 ? vdupq_n_s32(iq2_info.offset) : vdupq_n_s32(iq1_info.offset);
369
Michalis Spyroubc4d7c22019-12-03 15:11:09 +0000370 // Clear X Dimension on execution window as we handle manually
371 non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1));
372
373 Iterator broadcast_input(broadcast_tensor, broadcast_win);
374 Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win);
375 Iterator output(out, win);
376
377 execute_window_loop(win, [&](const Coordinates &)
378 {
379 const auto non_broadcast_input_ptr = reinterpret_cast<const int8_t *>(non_broadcast_input.ptr());
380 const auto output_ptr = reinterpret_cast<int8_t *>(output.ptr());
381
382 const int8_t broadcast_value = *reinterpret_cast<const int8_t *>(broadcast_input.ptr());
383 const int8x16_t broadcast_value_vec = vdupq_n_s8(broadcast_value);
384
385 const float32x4x4_t bf =
386 {
387 {
388 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_low_s8(broadcast_value_vec)))), voffset2)), vscale2),
389 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_high_s16(vmovl_s8(vget_low_s8(broadcast_value_vec)))), voffset2)), vscale2),
390 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_high_s8(broadcast_value_vec)))), voffset2)), vscale2),
391 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_high_s16(vmovl_s8(vget_high_s8(broadcast_value_vec)))), voffset2)), vscale2),
392 }
393 };
394 const float bfs = static_cast<int32_t>(broadcast_value - broadcast_qinfo.offset) * broadcast_qinfo.scale;
395
396 // Compute S elements per iteration
397 int x = window_start_x;
398 for(; x <= (window_end_x - window_step_x); x += window_step_x)
399 {
Georgios Pinitasd7d7e902019-12-18 15:40:54 +0000400 const int8x16_t a = vld1q_s8(non_broadcast_input_ptr + x);
Michalis Spyroubc4d7c22019-12-03 15:11:09 +0000401 const float32x4x4_t af =
402 {
403 {
404 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_low_s8(a)))), voffset1)), vscale1),
405 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_high_s16(vmovl_s8(vget_low_s8(a)))), voffset1)), vscale1),
406 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_high_s8(a)))), voffset1)), vscale1),
407 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_high_s16(vmovl_s8(vget_high_s8(a)))), voffset1)), vscale1),
408 }
409 };
410
411 const int32x4x4_t rf =
412 {
413 {
414#ifdef __aarch64__
415 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
416 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
417 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[2], bf.val[2]), invvscaleo)),
418 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[3], bf.val[3]), invvscaleo)),
419#else //__aarch64__
420 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
421 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
422 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[2], bf.val[2]), invvscaleo)),
423 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[3], bf.val[3]), invvscaleo)),
424#endif //__aarch64__
425 }
426 };
427
428 const int8x8_t pa = vqmovn_s16(vcombine_s16(vqmovn_s32(rf.val[0]), vqmovn_s32(rf.val[1])));
429 const int8x8_t pb = vqmovn_s16(vcombine_s16(vqmovn_s32(rf.val[2]), vqmovn_s32(rf.val[3])));
430 vst1q_s8(output_ptr + x, vcombine_s8(pa, pb));
431 }
432
433 // Compute left-over elements
434 for(; x < window_end_x; ++x)
435 {
436 const float afs = static_cast<int32_t>(*(non_broadcast_input_ptr + x) - non_broadcast_qinfo.offset) * non_broadcast_qinfo.scale;
437 *(output_ptr + x) = quantize_qasymm8_signed((afs + bfs), oq_info);
438 }
439 },
440 broadcast_input, non_broadcast_input, output);
441 }
442 else
443 {
444 // Clear X Dimension on execution window as we handle manually
445 input1_win.set(Window::DimX, Window::Dimension(0, 1, 1));
446 input2_win.set(Window::DimX, Window::Dimension(0, 1, 1));
447
448 Iterator input1(in1, input1_win);
449 Iterator input2(in2, input2_win);
450 Iterator output(out, win);
451
Michalis Spyrou2232a202020-07-13 15:15:33 +0100452 const float32x4_t vscale1 = vdupq_n_f32(iq1_info.scale);
453 const float32x4_t vscale2 = vdupq_n_f32(iq2_info.scale);
454 const int32x4_t voffset1 = vdupq_n_s32(iq1_info.offset);
455 const int32x4_t voffset2 = vdupq_n_s32(iq2_info.offset);
Michalis Spyroubc4d7c22019-12-03 15:11:09 +0000456 execute_window_loop(win, [&](const Coordinates &)
457 {
458 const auto input1_ptr = reinterpret_cast<const int8_t *>(input1.ptr());
459 const auto input2_ptr = reinterpret_cast<const int8_t *>(input2.ptr());
460 const auto output_ptr = reinterpret_cast<int8_t *>(output.ptr());
461
462 // Compute S elements per iteration
463 int x = window_start_x;
464 for(; x <= (window_end_x - window_step_x); x += window_step_x)
465 {
466 const int8x16_t a = vld1q_s8(input1_ptr + x);
467 const int8x16_t b = vld1q_s8(input2_ptr + x);
468
469 const float32x4x4_t af =
470 {
471 {
472 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_low_s8(a)))), voffset1)), vscale1),
473 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_high_s16(vmovl_s8(vget_low_s8(a)))), voffset1)), vscale1),
474 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_high_s8(a)))), voffset1)), vscale1),
475 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_high_s16(vmovl_s8(vget_high_s8(a)))), voffset1)), vscale1),
476 }
477 };
478
479 const float32x4x4_t bf =
480 {
481 {
482 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_low_s8(b)))), voffset2)), vscale2),
483 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_high_s16(vmovl_s8(vget_low_s8(b)))), voffset2)), vscale2),
484 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_high_s8(b)))), voffset2)), vscale2),
485 vmulq_f32(vcvtq_f32_s32(vsubq_s32(vmovl_s16(vget_high_s16(vmovl_s8(vget_high_s8(b)))), voffset2)), vscale2),
486 }
487 };
488
489 const int32x4x4_t rf =
490 {
491 {
492#ifdef __aarch64__
493 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
494 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
495 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[2], bf.val[2]), invvscaleo)),
496 vcvtnq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[3], bf.val[3]), invvscaleo)),
497#else //__aarch64__
498 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
499 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
500 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[2], bf.val[2]), invvscaleo)),
501 vcvtq_s32_f32(vmlaq_f32(voffseto, vaddq_f32(af.val[3], bf.val[3]), invvscaleo)),
502#endif //__aarch64__
503 }
504 };
505
506 const int8x8_t pa = vqmovn_s16(vcombine_s16(vqmovn_s32(rf.val[0]), vqmovn_s32(rf.val[1])));
507 const int8x8_t pb = vqmovn_s16(vcombine_s16(vqmovn_s32(rf.val[2]), vqmovn_s32(rf.val[3])));
508 vst1q_s8(output_ptr + x, vcombine_s8(pa, pb));
509 }
510
511 // Compute left-over elements
512 for(; x < window_end_x; ++x)
513 {
514 const float afs = static_cast<int32_t>((*(input1_ptr + x)) - iq1_info.offset) * iq1_info.scale;
515 const float bfs = static_cast<int32_t>((*(input2_ptr + x)) - iq2_info.offset) * iq2_info.scale;
516 *(output_ptr + x) = quantize_qasymm8_signed((afs + bfs), out->info()->quantization_info());
517 }
518 },
519 input1, input2, output);
520 }
521}
522
Manuel Bottini3689fcd2019-06-14 17:18:12 +0100523void add_QSYMM16_QSYMM16_QSYMM16(const ITensor *in1, const ITensor *in2, ITensor *out, ConvertPolicy policy, const Window &window)
524{
525 ARM_COMPUTE_UNUSED(policy);
526
527 // Create input windows
528 Window input1_win = window.broadcast_if_dimension_le_one(in1->info()->tensor_shape());
529 Window input2_win = window.broadcast_if_dimension_le_one(in2->info()->tensor_shape());
530
531 // Clear X Dimension on execution window as we handle manually
532 Window win = window;
533 win.set(Window::DimX, Window::Dimension(0, 1, 1));
534
535 const int window_step_x = 8;
536 const auto window_start_x = static_cast<int>(window.x().start());
537 const auto window_end_x = static_cast<int>(window.x().end());
538 const bool is_broadcast_across_x = (input1_win.x().step() == 0) || (input2_win.x().step() == 0);
539
540 const UniformQuantizationInfo iq1_info = in1->info()->quantization_info().uniform();
541 const UniformQuantizationInfo iq2_info = in2->info()->quantization_info().uniform();
542 const UniformQuantizationInfo oq_info = out->info()->quantization_info().uniform();
543
544 const float32x4_t vscale1 = vdupq_n_f32(iq1_info.scale);
545 const float32x4_t vscale2 = vdupq_n_f32(iq2_info.scale);
546 const float32x4_t invvscaleo = vdupq_n_f32(1.f / oq_info.scale);
547
548 if(is_broadcast_across_x)
549 {
550 const bool is_broadcast_input_2 = input2_win.x().step() == 0;
551 Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win;
552 Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win;
553 const ITensor *broadcast_tensor = is_broadcast_input_2 ? in2 : in1;
554 const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? in2 : in1;
555 const UniformQuantizationInfo broadcast_qinfo = broadcast_tensor->info()->quantization_info().uniform();
556 const UniformQuantizationInfo non_broadcast_qinfo = non_broadcast_tensor->info()->quantization_info().uniform();
557
558 // Clear X Dimension on execution window as we handle manually
559 non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1));
560
561 Iterator broadcast_input(broadcast_tensor, broadcast_win);
562 Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win);
563 Iterator output(out, win);
564
565 execute_window_loop(win, [&](const Coordinates &)
566 {
567 const auto non_broadcast_input_ptr = reinterpret_cast<const int16_t *>(non_broadcast_input.ptr());
568 const auto output_ptr = reinterpret_cast<int16_t *>(output.ptr());
569
570 const int16_t broadcast_value = *reinterpret_cast<const int16_t *>(broadcast_input.ptr());
571 const int16x8_t broadcast_value_vec = vdupq_n_s16(broadcast_value);
572
573 const float32x4x2_t bf =
574 {
575 {
576 vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_low_s16(broadcast_value_vec))), vscale2),
577 vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_high_s16(broadcast_value_vec))), vscale2),
578 }
579 };
580 const float bfs = static_cast<int32_t>(broadcast_value) * broadcast_qinfo.scale;
581
582 // Compute S elements per iteration
583 int x = window_start_x;
584 for(; x <= (window_end_x - window_step_x); x += window_step_x)
585 {
586 const int16x8_t a = vld1q_s16(non_broadcast_input_ptr + x);
587 const float32x4x2_t af =
588 {
589 {
590 vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_low_s16(a))), vscale1),
591 vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_high_s16(a))), vscale1),
592 }
593 };
594
595 const int32x4x4_t rf =
596 {
597 {
598#ifdef __aarch64__
599 vcvtnq_s32_f32(vmulq_f32(vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
600 vcvtnq_s32_f32(vmulq_f32(vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
601#else //__aarch64__
602 vcvtq_s32_f32(vmulq_f32(vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
603 vcvtq_s32_f32(vmulq_f32(vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
604#endif //__aarch64__
605 }
606 };
607
608 const int16x8_t pa = vcombine_s16(vqmovn_s32(rf.val[0]), vqmovn_s32(rf.val[1]));
609 vst1q_s16(output_ptr + x, pa);
610 }
611
612 // Compute left-over elements
613 for(; x < window_end_x; ++x)
614 {
615 const float afs = static_cast<int32_t>(*(non_broadcast_input_ptr + x)) * non_broadcast_qinfo.scale;
616 *(output_ptr + x) = quantize_qsymm16((afs + bfs), oq_info);
617 }
618 },
619 broadcast_input, non_broadcast_input, output);
620 }
621 else
622 {
623 // Clear X Dimension on execution window as we handle manually
624 input1_win.set(Window::DimX, Window::Dimension(0, 1, 1));
625 input2_win.set(Window::DimX, Window::Dimension(0, 1, 1));
626
627 Iterator input1(in1, input1_win);
628 Iterator input2(in2, input2_win);
629 Iterator output(out, win);
630
631 execute_window_loop(win, [&](const Coordinates &)
632 {
633 const auto input1_ptr = reinterpret_cast<const int16_t *>(input1.ptr());
634 const auto input2_ptr = reinterpret_cast<const int16_t *>(input2.ptr());
635 const auto output_ptr = reinterpret_cast<int16_t *>(output.ptr());
636
637 // Compute S elements per iteration
638 int x = window_start_x;
639 for(; x <= (window_end_x - window_step_x); x += window_step_x)
640 {
641 const int16x8_t a = vld1q_s16(input1_ptr + x);
642 const int16x8_t b = vld1q_s16(input2_ptr + x);
643
644 const float32x4x2_t af =
645 {
646 {
647 vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_low_s16(a))), vscale1),
648 vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_high_s16(a))), vscale1),
649 }
650 };
651
652 const float32x4x2_t bf =
653 {
654 {
655 vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_low_s16(b))), vscale2),
656 vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_high_s16(b))), vscale2),
657 }
658 };
659
660 const int32x4x2_t rf =
661 {
662 {
663#ifdef __aarch64__
664 vcvtnq_s32_f32(vmulq_f32(vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
665 vcvtnq_s32_f32(vmulq_f32(vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
666#else //__aarch64__
667 vcvtq_s32_f32(vmulq_f32(vaddq_f32(af.val[0], bf.val[0]), invvscaleo)),
668 vcvtq_s32_f32(vmulq_f32(vaddq_f32(af.val[1], bf.val[1]), invvscaleo)),
669#endif //__aarch64__
670 }
671 };
672
673 const int16x8_t pa = vcombine_s16(vqmovn_s32(rf.val[0]), vqmovn_s32(rf.val[1]));
674 vst1q_s16(output_ptr + x, pa);
675 }
676
677 // Compute left-over elements
678 for(; x < window_end_x; ++x)
679 {
680 const float afs = static_cast<int32_t>((*(input1_ptr + x))) * iq1_info.scale;
681 const float bfs = static_cast<int32_t>((*(input2_ptr + x))) * iq2_info.scale;
682 *(output_ptr + x) = quantize_qsymm16((afs + bfs), out->info()->quantization_info());
683 }
684 },
685 input1, input2, output);
686 }
687}
688
Georgios Pinitas5a594532018-12-03 14:30:05 +0000689void add_S16_U8_S16(const ITensor *in1, const ITensor *in2, ITensor *out, ConvertPolicy policy, const Window &window)
690{
691 // Create input windows
692 Window win = window;
693 Window input1_win = window.broadcast_if_dimension_le_one(in1->info()->tensor_shape());
694 Window input2_win = window.broadcast_if_dimension_le_one(in2->info()->tensor_shape());
695
696 // Clear X Dimension on execution window as we handle manually
697 win.set(Window::DimX, Window::Dimension(0, 1, 1));
698 input1_win.set(Window::DimX, Window::Dimension(0, 1, 1));
699 input2_win.set(Window::DimX, Window::Dimension(0, 1, 1));
700
701 Iterator input1(in1, input1_win);
702 Iterator input2(in2, input2_win);
703 Iterator output(out, win);
704
705 const int window_step_x = 8;
706 const auto window_start_x = static_cast<int>(window.x().start());
707 const auto window_end_x = static_cast<int>(window.x().end());
708
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100709 execute_window_loop(win, [&](const Coordinates &)
Georgios Pinitas5a594532018-12-03 14:30:05 +0000710 {
711 const auto input1_ptr = reinterpret_cast<const int16_t *>(input1.ptr());
712 const auto input2_ptr = reinterpret_cast<const uint8_t *>(input2.ptr());
713 const auto output_ptr = reinterpret_cast<int16_t *>(output.ptr());
714
715 if(policy == ConvertPolicy::WRAP)
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000716 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000717 // Compute S elements per iteration
718 int x = window_start_x;
719 for(; x <= (window_end_x - window_step_x); x += window_step_x)
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000720 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000721 const auto vin1 = wrapper::vloadq(input1_ptr + x);
722 const auto vin2 = vreinterpretq_s16_u16(wrapper::vmovl(wrapper::vload(input2_ptr + x)));
723 wrapper::vstore(output_ptr + x, wrapper::vadd(vin1, vin2));
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000724 }
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000725
Georgios Pinitas5a594532018-12-03 14:30:05 +0000726 // Compute left-over elements
727 for(; x < window_end_x; ++x)
728 {
729 *(output_ptr + x) = *(input1_ptr + x) + static_cast<int16_t>(*(input2_ptr + x));
730 }
731 }
732 else
733 {
734 // Compute S elements per iteration
735 int x = window_start_x;
736 for(; x <= (window_end_x - window_step_x); x += window_step_x)
737 {
738 const auto vin1 = wrapper::vloadq(input1_ptr + x);
739 const auto vin2 = vreinterpretq_s16_u16(wrapper::vmovl(wrapper::vload(input2_ptr + x)));
740 wrapper::vstore(output_ptr + x, wrapper::vqadd(vin1, vin2));
741 }
742
743 // Compute left-over elements
744 for(; x < window_end_x; ++x)
745 {
746 *(output_ptr + x) = wrapper::add_sat(*(input1_ptr + x), static_cast<int16_t>(*(input2_ptr + x)));
747 }
748 }
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000749 },
750 input1, input2, output);
751}
752
Georgios Pinitas5a594532018-12-03 14:30:05 +0000753inline void add_U8_S16_S16(const ITensor *input1, const ITensor *input2, ITensor *output, ConvertPolicy policy, const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100754{
Georgios Pinitas5a594532018-12-03 14:30:05 +0000755 // Simply swap the two input buffers:
756 add_S16_U8_S16(input2, input1, output, policy, window);
757}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100758
Georgios Pinitas5a594532018-12-03 14:30:05 +0000759void add_U8_U8_S16(const ITensor *in1, const ITensor *in2, ITensor *out, ConvertPolicy policy, const Window &window)
760{
761 // Create input windows
762 Window win = window;
763 Window input1_win = window.broadcast_if_dimension_le_one(in1->info()->tensor_shape());
764 Window input2_win = window.broadcast_if_dimension_le_one(in2->info()->tensor_shape());
765
766 // Clear X Dimension on execution window as we handle manually
767 win.set(Window::DimX, Window::Dimension(0, 1, 1));
768 input1_win.set(Window::DimX, Window::Dimension(0, 1, 1));
769 input2_win.set(Window::DimX, Window::Dimension(0, 1, 1));
770
771 Iterator input1(in1, input1_win);
772 Iterator input2(in2, input2_win);
773 Iterator output(out, win);
774
775 const int window_step_x = 8;
776 const auto window_start_x = static_cast<int>(window.x().start());
777 const auto window_end_x = static_cast<int>(window.x().end());
778
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100779 execute_window_loop(win, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100780 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000781 const auto input1_ptr = reinterpret_cast<const uint8_t *>(input1.ptr());
782 const auto input2_ptr = reinterpret_cast<const uint8_t *>(input2.ptr());
783 const auto output_ptr = reinterpret_cast<int16_t *>(output.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100784
Georgios Pinitas5a594532018-12-03 14:30:05 +0000785 if(policy == ConvertPolicy::WRAP)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100786 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000787 // Compute S elements per iteration
788 int x = window_start_x;
789 for(; x <= (window_end_x - window_step_x); x += window_step_x)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100790 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000791 const auto vin1 = vreinterpretq_s16_u16(wrapper::vmovl(wrapper::vload(input1_ptr + x)));
792 const auto vin2 = vreinterpretq_s16_u16(wrapper::vmovl(wrapper::vload(input2_ptr + x)));
793 wrapper::vstore(output_ptr + x, wrapper::vadd(vin1, vin2));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100794 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100795
Georgios Pinitas5a594532018-12-03 14:30:05 +0000796 // Compute left-over elements
797 for(; x < window_end_x; ++x)
798 {
799 *(output_ptr + x) = static_cast<int16_t>(*(input1_ptr + x)) + static_cast<int16_t>(*(input2_ptr + x));
800 }
801 }
802 else
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100803 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000804 // Compute S elements per iteration
805 int x = window_start_x;
806 for(; x <= (window_end_x - window_step_x); x += window_step_x)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100807 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000808 const auto vin1 = vreinterpretq_s16_u16(wrapper::vmovl(wrapper::vload(input1_ptr + x)));
809 const auto vin2 = vreinterpretq_s16_u16(wrapper::vmovl(wrapper::vload(input2_ptr + x)));
810 wrapper::vstore(output_ptr + x, wrapper::vqadd(vin1, vin2));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100811 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100812
Georgios Pinitas5a594532018-12-03 14:30:05 +0000813 // Compute left-over elements
814 for(; x < window_end_x; ++x)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100815 {
Georgios Pinitas5a594532018-12-03 14:30:05 +0000816 *(output_ptr + x) = wrapper::add_sat(static_cast<int16_t>(*(input1_ptr + x)),
817 static_cast<int16_t>(*(input2_ptr + x)));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100818 }
Georgios Pinitas5a594532018-12-03 14:30:05 +0000819 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100820 },
821 input1, input2, output);
822}
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000823
Michele Di Giorgio19023832020-06-17 16:08:10 +0000824Status validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output, ConvertPolicy policy)
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000825{
826 ARM_COMPUTE_UNUSED(policy);
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000827
Michele Di Giorgio19023832020-06-17 16:08:10 +0000828 ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(&input1);
829 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input1, 1, DataType::U8, DataType::QASYMM8, DataType::QASYMM8_SIGNED,
Michele Di Giorgio11c562c2020-06-10 16:34:50 +0100830 DataType::S16, DataType::QSYMM16, DataType::F16,
831 DataType::S32, DataType::F32);
Michele Di Giorgio19023832020-06-17 16:08:10 +0000832 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input2, 1, DataType::U8, DataType::QASYMM8, DataType::QASYMM8_SIGNED,
Michele Di Giorgio11c562c2020-06-10 16:34:50 +0100833 DataType::S16, DataType::QSYMM16, DataType::F16,
834 DataType::S32, DataType::F32);
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000835
Michele Di Giorgio19023832020-06-17 16:08:10 +0000836 const TensorShape out_shape = TensorShape::broadcast_shape(input1.tensor_shape(), input2.tensor_shape());
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000837
838 ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible");
Michele Di Giorgio19023832020-06-17 16:08:10 +0000839 ARM_COMPUTE_RETURN_ERROR_ON_MSG((input1.tensor_shape().x() != input2.tensor_shape().x()) && ((input1.data_type() != input2.data_type()) || (input1.data_type() != output.data_type())
840 || (input2.data_type() != output.data_type())),
841 "Broadcasting across width is supported on configurations where all tensors have the same data type");
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000842
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000843 // Validate in case of configured output
Michele Di Giorgio19023832020-06-17 16:08:10 +0000844 if(output.total_size() > 0)
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000845 {
846 ARM_COMPUTE_RETURN_ERROR_ON_MSG(
Michele Di Giorgio19023832020-06-17 16:08:10 +0000847 !(input1.data_type() == DataType::U8 && input2.data_type() == DataType::U8 && output.data_type() == DataType::U8)
848 && !(input1.data_type() == DataType::U8 && input2.data_type() == DataType::U8 && output.data_type() == DataType::S16)
849 && !(input1.data_type() == DataType::U8 && input2.data_type() == DataType::S16 && output.data_type() == DataType::S16)
850 && !(input1.data_type() == DataType::S16 && input2.data_type() == DataType::U8 && output.data_type() == DataType::S16)
851 && !(input1.data_type() == DataType::S16 && input2.data_type() == DataType::S16 && output.data_type() == DataType::S16)
852 && !(input1.data_type() == DataType::S32 && input2.data_type() == DataType::S32 && output.data_type() == DataType::S32)
853 && !(input1.data_type() == DataType::F32 && input2.data_type() == DataType::F32 && output.data_type() == DataType::F32)
854 && !(input1.data_type() == DataType::F16 && input2.data_type() == DataType::F16 && output.data_type() == DataType::F16)
855 && !(input1.data_type() == DataType::QASYMM8 && input2.data_type() == DataType::QASYMM8 && output.data_type() == DataType::QASYMM8)
856 && !(input1.data_type() == DataType::QASYMM8_SIGNED && input2.data_type() == DataType::QASYMM8_SIGNED && output.data_type() == DataType::QASYMM8_SIGNED)
857 && !(input1.data_type() == DataType::QSYMM16 && input2.data_type() == DataType::QSYMM16 && output.data_type() == DataType::QSYMM16),
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000858 "You called addition with the wrong image formats");
859
Michele Di Giorgio19023832020-06-17 16:08:10 +0000860 ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, output.tensor_shape(), 0),
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000861 "Wrong shape for output");
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000862 }
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000863
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000864 return Status{};
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000865}
866
Michalis Spyrou173ba9b2020-06-23 17:25:43 +0100867std::pair<Status, Window> validate_and_configure_window(const ITensorInfo &input1, const ITensorInfo &input2, ITensorInfo &output)
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000868{
Michele Di Giorgio19023832020-06-17 16:08:10 +0000869 const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(input1, input2);
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000870 const TensorShape &out_shape = broadcast_pair.first;
871 const ValidRegion &valid_region = broadcast_pair.second;
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000872
Michele Di Giorgio4a616532020-06-04 15:05:38 +0100873 // Auto initialize output if not initialized
Michele Di Giorgio4a616532020-06-04 15:05:38 +0100874 {
Michele Di Giorgio19023832020-06-17 16:08:10 +0000875 set_shape_if_empty(output, out_shape);
Michele Di Giorgio4a616532020-06-04 15:05:38 +0100876
Michele Di Giorgio19023832020-06-17 16:08:10 +0000877 if(input1.data_type() == DataType::S16 || input2.data_type() == DataType::S16)
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000878 {
Michele Di Giorgio19023832020-06-17 16:08:10 +0000879 set_format_if_unknown(output, Format::S16);
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000880 }
Michele Di Giorgio19023832020-06-17 16:08:10 +0000881 if(input1.data_type() == DataType::S32 || input2.data_type() == DataType::S32)
Michele Di Giorgio11c562c2020-06-10 16:34:50 +0100882 {
Michele Di Giorgio19023832020-06-17 16:08:10 +0000883 set_format_if_unknown(output, Format::S32);
Michele Di Giorgio11c562c2020-06-10 16:34:50 +0100884 }
Michele Di Giorgio19023832020-06-17 16:08:10 +0000885 else if(input1.data_type() == DataType::F16 || input2.data_type() == DataType::F16)
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000886 {
Michele Di Giorgio19023832020-06-17 16:08:10 +0000887 set_format_if_unknown(output, Format::F16);
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000888 }
Michele Di Giorgio19023832020-06-17 16:08:10 +0000889 else if(input1.data_type() == DataType::F32 || input2.data_type() == DataType::F32)
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000890 {
Michele Di Giorgio19023832020-06-17 16:08:10 +0000891 set_format_if_unknown(output, Format::F32);
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000892 }
Michele Di Giorgio19023832020-06-17 16:08:10 +0000893 else if(input1.data_type() == DataType::QASYMM8 || input2.data_type() == DataType::QASYMM8)
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000894 {
Michele Di Giorgio19023832020-06-17 16:08:10 +0000895 set_data_type_if_unknown(output, DataType::QASYMM8);
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000896 }
Michele Di Giorgio19023832020-06-17 16:08:10 +0000897 else if(input1.data_type() == DataType::QASYMM8_SIGNED || input2.data_type() == DataType::QASYMM8_SIGNED)
Michalis Spyroubc4d7c22019-12-03 15:11:09 +0000898 {
Michele Di Giorgio19023832020-06-17 16:08:10 +0000899 set_data_type_if_unknown(output, DataType::QASYMM8_SIGNED);
Michalis Spyroubc4d7c22019-12-03 15:11:09 +0000900 }
Michele Di Giorgio19023832020-06-17 16:08:10 +0000901 else if(input1.data_type() == DataType::QSYMM16 || input2.data_type() == DataType::QSYMM16)
Manuel Bottini3689fcd2019-06-14 17:18:12 +0100902 {
Michele Di Giorgio19023832020-06-17 16:08:10 +0000903 set_data_type_if_unknown(output, DataType::QSYMM16);
Manuel Bottini3689fcd2019-06-14 17:18:12 +0100904 }
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000905 }
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000906
Georgios Pinitas5a594532018-12-03 14:30:05 +0000907 Window win = calculate_max_window(valid_region, Steps());
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000908
Georgios Pinitas5a594532018-12-03 14:30:05 +0000909 // NEArithmeticAdditionKernel doesn't need padding so update_window_and_padding() can be skipped
910 Coordinates coord;
Michele Di Giorgio19023832020-06-17 16:08:10 +0000911 coord.set_num_dimensions(output.num_dimensions());
912 output.set_valid_region(valid_region);
Georgios Pinitas5a594532018-12-03 14:30:05 +0000913 return std::make_pair(Status{}, win);
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000914}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100915} // namespace
916
917NEArithmeticAdditionKernel::NEArithmeticAdditionKernel()
Michalis Spyrou173ba9b2020-06-23 17:25:43 +0100918 : _func(nullptr), _policy()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100919{
920}
921
Michalis Spyrou173ba9b2020-06-23 17:25:43 +0100922void NEArithmeticAdditionKernel::configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output, ConvertPolicy policy)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100923{
Michele Di Giorgio19023832020-06-17 16:08:10 +0000924 ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
Michalis Spyrou173ba9b2020-06-23 17:25:43 +0100925 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1, *input2, *output, policy));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100926
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000927 // Configure kernel window
Michalis Spyrou173ba9b2020-06-23 17:25:43 +0100928 auto win_config = validate_and_configure_window(*input1, *input2, *output);
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000929 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100930
931 static std::map<std::string, AddFunction *> map_function =
932 {
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000933 { "add_wrap_QASYMM8_QASYMM8_QASYMM8", &add_QASYMM8_QASYMM8_QASYMM8 },
934 { "add_saturate_QASYMM8_QASYMM8_QASYMM8", &add_QASYMM8_QASYMM8_QASYMM8 },
Michalis Spyroubc4d7c22019-12-03 15:11:09 +0000935 { "add_wrap_QASYMM8_SIGNED_QASYMM8_SIGNED_QASYMM8_SIGNED", &add_QASYMM8_SIGNED_QASYMM8_SIGNED_QASYMM8_SIGNED },
936 { "add_saturate_QASYMM8_SIGNED_QASYMM8_SIGNED_QASYMM8_SIGNED", &add_QASYMM8_SIGNED_QASYMM8_SIGNED_QASYMM8_SIGNED },
Manuel Bottini3689fcd2019-06-14 17:18:12 +0100937 { "add_wrap_QSYMM16_QSYMM16_QSYMM16", &add_QSYMM16_QSYMM16_QSYMM16 },
938 { "add_saturate_QSYMM16_QSYMM16_QSYMM16", &add_QSYMM16_QSYMM16_QSYMM16 },
Michalis Spyrou7a7fe652020-05-15 11:28:59 +0100939 { "add_wrap_U8_U8_U8", &add_same<uint8_t> },
940 { "add_saturate_U8_U8_U8", &add_same<uint8_t> },
Georgios Pinitas5a594532018-12-03 14:30:05 +0000941 { "add_wrap_S16_U8_S16", &add_S16_U8_S16 },
942 { "add_saturate_S16_U8_S16", &add_S16_U8_S16 },
943 { "add_wrap_U8_S16_S16", &add_U8_S16_S16 },
944 { "add_saturate_U8_S16_S16", &add_U8_S16_S16 },
945 { "add_wrap_U8_U8_S16", &add_U8_U8_S16 },
946 { "add_saturate_U8_U8_S16", &add_U8_U8_S16 },
Michalis Spyrou7a7fe652020-05-15 11:28:59 +0100947 { "add_wrap_S16_S16_S16", &add_same<int16_t> },
948 { "add_saturate_S16_S16_S16", &add_same<int16_t> },
Michele Di Giorgio11c562c2020-06-10 16:34:50 +0100949 { "add_wrap_S32_S32_S32", &add_same<int32_t> },
950 { "add_saturate_S32_S32_S32", &add_same<int32_t> },
Michalis Spyrou7a7fe652020-05-15 11:28:59 +0100951 { "add_wrap_F32_F32_F32", &add_same<float> },
952 { "add_saturate_F32_F32_F32", &add_same<float> },
Georgios Pinitas5a594532018-12-03 14:30:05 +0000953#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Michalis Spyrou7a7fe652020-05-15 11:28:59 +0100954 { "add_wrap_F16_F16_F16", &add_same<float16_t> },
955 { "add_saturate_F16_F16_F16", &add_same<float16_t> },
Georgios Pinitas5a594532018-12-03 14:30:05 +0000956#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100957 };
958
Georgios Pinitas5a594532018-12-03 14:30:05 +0000959 _policy = policy;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100960
961 std::string function_to_call("add_");
962 function_to_call += policy == ConvertPolicy::WRAP ? "wrap_" : "saturate_";
Michalis Spyrou173ba9b2020-06-23 17:25:43 +0100963 function_to_call += string_from_data_type(input1->data_type()) + "_";
964 function_to_call += string_from_data_type(input2->data_type()) + "_";
965 function_to_call += string_from_data_type(output->data_type());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100966
967 auto it = map_function.find(function_to_call);
968
969 if(it != map_function.end())
970 {
971 _func = it->second;
972 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100973
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000974 INEKernel::configure(win_config.second);
975}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100976
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000977Status NEArithmeticAdditionKernel::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy)
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000978{
Michele Di Giorgio19023832020-06-17 16:08:10 +0000979 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output);
980
981 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output, policy));
982 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(*input1->clone(), *input2->clone(), *output->clone()).first);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100983
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000984 return Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100985}
986
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100987void NEArithmeticAdditionKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100988{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100989 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100990 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
991 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
Michalis Spyrou173ba9b2020-06-23 17:25:43 +0100992 // Dispatch kernel
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100993 (*_func)(tensors.get_const_tensor(TensorType::ACL_SRC_0),
994 tensors.get_const_tensor(TensorType::ACL_SRC_1),
995 tensors.get_tensor(TensorType::ACL_DST),
996 _policy,
997 window);
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000998}
Michalis Spyrou7a7fe652020-05-15 11:28:59 +0100999} // namespace arm_compute