blob: 6634d4b13cd6e575b1651cbccfa5245854d4bcd1 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
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/NEScaleKernel.h"
25
26#include "arm_compute/core/AccessWindowStatic.h"
27#include "arm_compute/core/Coordinates.h"
28#include "arm_compute/core/Error.h"
29#include "arm_compute/core/Helpers.h"
30#include "arm_compute/core/ITensor.h"
31#include "arm_compute/core/TensorInfo.h"
32#include "arm_compute/core/Validate.h"
33#include "arm_compute/core/Window.h"
34
35#include <arm_neon.h>
36#include <cstddef>
37#include <cstdint>
38
39using namespace arm_compute;
40
41NEScaleKernel::NEScaleKernel()
42 : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr)
43{
44}
45
46BorderSize NEScaleKernel::border_size() const
47{
48 return BorderSize(1);
49}
50
51void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output, InterpolationPolicy policy, bool border_undefined)
52{
Georgios Pinitas583137c2017-08-31 18:12:42 +010053 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S16, DataType::F32);
54 ARM_COMPUTE_ERROR_ON_NULLPTR(output);
55 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
56 ARM_COMPUTE_ERROR_ON(output == input);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010057
58 if(policy == InterpolationPolicy::NEAREST_NEIGHBOR)
59 {
60 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32);
61 }
62
63 if(policy == InterpolationPolicy::BILINEAR)
64 {
65 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32);
66 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dx, 1, DataType::F32);
67 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dy, 1, DataType::F32);
68 }
69
70 ARM_COMPUTE_ERROR_ON(output->info()->dimension(0) == 0);
71 ARM_COMPUTE_ERROR_ON(output->info()->dimension(1) == 0);
72
73 for(size_t i = 2; i < Coordinates::num_max_dimensions; ++i)
74 {
75 ARM_COMPUTE_ERROR_ON(input->info()->dimension(i) != output->info()->dimension(i));
76 }
77
78 _input = input;
79 _output = output;
80 _offsets = offsets;
81 _dx = dx;
82 _dy = dy;
83
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010084 /* Compute the ratio between source width/height and destination width/height */
85 const auto wr = static_cast<float>(input->info()->dimension(0)) / static_cast<float>(output->info()->dimension(0));
86 const auto hr = static_cast<float>(input->info()->dimension(1)) / static_cast<float>(output->info()->dimension(1));
87
88 /* Area interpolation behaves as Nearest Neighbour in case of up-sampling */
89 if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
90 {
91 policy = InterpolationPolicy::NEAREST_NEIGHBOR;
92 }
93
Anthony Barbier6ff3b192017-09-04 18:44:23 +010094 switch(policy)
95 {
96 case InterpolationPolicy::NEAREST_NEIGHBOR:
97 {
98 _func = &NEScaleKernel::scale_nearest;
99 break;
100 }
101 case InterpolationPolicy::BILINEAR:
102 {
103 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_dx, 1, DataType::F32);
104 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_dy, 1, DataType::F32);
105
106 _func = &NEScaleKernel::scale_bilinear;
107 break;
108 }
109 case InterpolationPolicy::AREA:
110 {
111 _func = &NEScaleKernel::scale_area;
112 break;
113 }
114 default:
115 ARM_COMPUTE_ERROR("Unsupported interpolation mode");
116 }
117
118 constexpr unsigned int num_elems_processed_per_iteration = 16;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100119
120 // Configure kernel window
121 Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
122
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100123 const ValidRegion &input_valid_region = input->info()->valid_region();
124
125 // Reads can occur within the valid region of the input
126 AccessWindowStatic input_access(input->info(),
127 input_valid_region.anchor[0] - border_size().left, input_valid_region.anchor[1] - border_size().top,
128 input_valid_region.anchor[0] + input_valid_region.shape[0] + border_size().right,
129 input_valid_region.anchor[1] + input_valid_region.shape[1] + border_size().bottom);
130 AccessWindowHorizontal offsets_access(offsets == nullptr ? nullptr : offsets->info(), 0, num_elems_processed_per_iteration);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131 AccessWindowHorizontal dx_access(dx == nullptr ? nullptr : dx->info(), 0, num_elems_processed_per_iteration);
132 AccessWindowHorizontal dy_access(dy == nullptr ? nullptr : dy->info(), 0, num_elems_processed_per_iteration);
133 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
134
135 update_window_and_padding(win,
136 input_access,
137 offsets_access,
138 dx_access,
139 dy_access,
140 output_access);
141
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100142 output_access.set_valid_region(win, calculate_valid_region_scale(*(input->info()), output->info()->tensor_shape(), policy, border_size(), border_undefined));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100143 INEKernel::configure(win);
144}
145
146void NEScaleKernel::scale_nearest(const Window &window)
147{
148 const size_t input_stride = _input->info()->strides_in_bytes()[1];
149
150 // Compute the ratio between source height and destination height
151 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
152
153 // Don't increment in X and Y direction for the input tensor
154 // A pointer to the start of this plane is needed as base for the precomputed offsets
155 Window win_in(window);
156 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
157 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
158
159 Window win_off;
160 win_off.set(Window::DimX, window[Window::DimX]);
161 win_off.set(Window::DimY, window[Window::DimY]);
162
163 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
164 {
165 win_off.set(d, Window::Dimension(0, 0, 0));
166 }
167
168 Iterator in(_input, win_in);
169 Iterator out(_output, window);
170 Iterator offsets(_offsets, win_off);
171
172 switch(_input->info()->data_type())
173 {
174 case DataType::U8:
175 {
176 uint8x16_t tmp = vdupq_n_u8(0);
177
178 execute_window_loop(window, [&](const Coordinates & id)
179 {
180 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
181 const uint8_t *const in_ptr = in.ptr();
182
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100183 const int in_yi = std::floor((id.y() + 0.5f) * hr);
184 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100185
186 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
187 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
188 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
189 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
190 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
191 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
192 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
193 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
194 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
195 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
196 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
197 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
198 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
199 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
200 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
201 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
202
203 vst1q_u8(out.ptr(), tmp);
204 },
205 in, offsets, out);
206 break;
207 }
208 case DataType::S16:
209 {
210 int16x8x2_t tmp =
211 {
212 {
213 vdupq_n_s16(0),
214 vdupq_n_s16(0)
215 }
216 };
217
218 execute_window_loop(window, [&](const Coordinates & id)
219 {
220 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
221
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100222 const int in_yi = (id.y() + 0.5f) * hr;
223 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100224
225 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
226 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
227 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
228 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
229 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
230 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
231 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
232 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
233
234 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
235 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
236 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
237 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
238 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
239 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
240 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
241 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
242
243 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
244 },
245 in, offsets, out);
246 break;
247 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100248 case DataType::F32:
249 {
250 float32x4x4_t tmp =
251 {
252 {
253 vdupq_n_f32(0),
254 vdupq_n_f32(0),
255 vdupq_n_f32(0),
256 vdupq_n_f32(0)
257 }
258 };
259
260 execute_window_loop(window, [&](const Coordinates & id)
261 {
262 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
263
264 const int in_yi = (id.y() + 0.5f) * hr;
265 const int offset_row = in_yi * input_stride;
266
267 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
268 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1);
269 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2);
270 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3);
271
272 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
273 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1);
274 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2);
275 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3);
276
277 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0);
278 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1);
279 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2);
280 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3);
281
282 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0);
283 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1);
284 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2);
285 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3);
286
287 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
288 },
289 in, offsets, out);
290 break;
291 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100292 default:
293 ARM_COMPUTE_ERROR("Not supported");
294 break;
295 }
296}
297
298void NEScaleKernel::scale_bilinear(const Window &window)
299{
Georgios Pinitas583137c2017-08-31 18:12:42 +0100300 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8, DataType::S16, DataType::F32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100301
302 // Compute the ratio between source height and destination height
303 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
304
305 // Don't increment in X and Y direction for the input tensor
306 // A pointer to the start of this plane is needed as base for the precomputed offsets
307 Window win_in(window);
308 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
309 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
310
311 Window win_off;
312 win_off.set(Window::DimX, window.x());
313 win_off.set(Window::DimY, window.y());
314
315 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
316 {
317 win_off.set(d, Window::Dimension(0, 0, 0));
318 }
319
320 Iterator in(_input, win_in);
321 Iterator out(_output, window);
322 Iterator offsets(_offsets, win_off);
323 Iterator dx(_dx, win_off);
324 Iterator dy(_dy, win_off);
325
326 /* Input image stride */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100327 const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1];
328 const size_t in_stride = in_stide_in_bytes / _input->info()->element_size();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100329
Georgios Pinitas583137c2017-08-31 18:12:42 +0100330 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100331 {
Georgios Pinitas583137c2017-08-31 18:12:42 +0100332 case DataType::U8:
333 {
334 execute_window_loop(window, [&](const Coordinates & id)
335 {
336 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
337 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
338 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
339 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100340
Georgios Pinitas583137c2017-08-31 18:12:42 +0100341 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
342 const int offset_row = in_yi * in_stide_in_bytes;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100343
Georgios Pinitas583137c2017-08-31 18:12:42 +0100344 uint8x8_t tmp0 = vdup_n_u8(0);
345 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0);
346 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1);
347 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2);
348 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3);
349 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4);
350 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5);
351 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6);
352 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100353
Georgios Pinitas583137c2017-08-31 18:12:42 +0100354 uint8x8_t tmp1 = vdup_n_u8(0);
355 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0);
356 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1);
357 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2);
358 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3);
359 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4);
360 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5);
361 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6);
362 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100363
Georgios Pinitas583137c2017-08-31 18:12:42 +0100364 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
365 },
366 in, offsets, dx, dy, out);
367 break;
368 }
369 case DataType::S16:
370 {
371 execute_window_loop(window, [&](const Coordinates & id)
372 {
373 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
374 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
375 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
376
377 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
378 const int offset_row = in_yi * in_stide_in_bytes;
379
380 int16x8x2_t tmp =
381 {
382 {
383 vdupq_n_s16(0),
384 vdupq_n_s16(0)
385 }
386 };
387
388 tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), in_stride, dx_ptr[0], dy_ptr[0]), tmp.val[0], 0);
389 tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), in_stride, dx_ptr[2], dy_ptr[2]), tmp.val[0], 1);
390 tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), in_stride, dx_ptr[4], dy_ptr[4]), tmp.val[0], 2);
391 tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), in_stride, dx_ptr[6], dy_ptr[6]), tmp.val[0], 3);
392 tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), in_stride, dx_ptr[8], dy_ptr[8]), tmp.val[0], 4);
393 tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), in_stride, dx_ptr[10], dy_ptr[10]), tmp.val[0], 5);
394 tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), in_stride, dx_ptr[12], dy_ptr[12]), tmp.val[0], 6);
395 tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), in_stride, dx_ptr[14], dy_ptr[14]), tmp.val[0], 7);
396
397 tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), in_stride, dx_ptr[1], dy_ptr[1]), tmp.val[1], 0);
398 tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), in_stride, dx_ptr[3], dy_ptr[3]), tmp.val[1], 1);
399 tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), in_stride, dx_ptr[5], dy_ptr[5]), tmp.val[1], 2);
400 tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), in_stride, dx_ptr[7], dy_ptr[7]), tmp.val[1], 3);
401 tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), in_stride, dx_ptr[9], dy_ptr[9]), tmp.val[1], 4);
402 tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), in_stride, dx_ptr[11], dy_ptr[11]), tmp.val[1], 5);
403 tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), in_stride, dx_ptr[13], dy_ptr[13]), tmp.val[1], 6);
404 tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), in_stride, dx_ptr[15], dy_ptr[15]), tmp.val[1], 7);
405
406 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
407 },
408 in, offsets, dx, dy, out);
409 break;
410 }
411 case DataType::F32:
412 {
413 execute_window_loop(window, [&](const Coordinates & id)
414 {
415 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
416 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
417 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
418
419 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
420 const int offset_row = in_yi * in_stide_in_bytes;
421
422 float32x4x4_t tmp =
423 {
424 {
425 vdupq_n_f32(0),
426 vdupq_n_f32(0),
427 vdupq_n_f32(0),
428 vdupq_n_f32(0)
429 }
430 };
431
432 tmp.val[0] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), in_stride, dx_ptr[0], dy_ptr[0]), tmp.val[0], 0);
433 tmp.val[0] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), in_stride, dx_ptr[4], dy_ptr[4]), tmp.val[0], 1);
434 tmp.val[0] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), in_stride, dx_ptr[8], dy_ptr[8]), tmp.val[0], 2);
435 tmp.val[0] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), in_stride, dx_ptr[12], dy_ptr[12]), tmp.val[0], 3);
436
437 tmp.val[1] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), in_stride, dx_ptr[1], dy_ptr[1]), tmp.val[1], 0);
438 tmp.val[1] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), in_stride, dx_ptr[5], dy_ptr[5]), tmp.val[1], 1);
439 tmp.val[1] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), in_stride, dx_ptr[9], dy_ptr[9]), tmp.val[1], 2);
440 tmp.val[1] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), in_stride, dx_ptr[13], dy_ptr[13]), tmp.val[1], 3);
441
442 tmp.val[2] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), in_stride, dx_ptr[2], dy_ptr[2]), tmp.val[2], 0);
443 tmp.val[2] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), in_stride, dx_ptr[6], dy_ptr[6]), tmp.val[2], 1);
444 tmp.val[2] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), in_stride, dx_ptr[10], dy_ptr[10]), tmp.val[2], 2);
445 tmp.val[2] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), in_stride, dx_ptr[14], dy_ptr[14]), tmp.val[2], 3);
446
447 tmp.val[3] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), in_stride, dx_ptr[3], dy_ptr[3]), tmp.val[3], 0);
448 tmp.val[3] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), in_stride, dx_ptr[7], dy_ptr[7]), tmp.val[3], 1);
449 tmp.val[3] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), in_stride, dx_ptr[11], dy_ptr[11]), tmp.val[3], 2);
450 tmp.val[3] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), in_stride, dx_ptr[15], dy_ptr[15]), tmp.val[3], 3);
451
452 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
453 },
454 in, offsets, dx, dy, out);
455 break;
456 }
457 default:
458 ARM_COMPUTE_ERROR("Not supported");
459 break;
460 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100461}
462
463void NEScaleKernel::scale_area(const Window &window)
464{
465 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
466
467 // Don't increment in X and Y direction for the input tensor
468 // A pointer to the start of this plane is needed as base for the precomputed offsets
469 Window win_in(window);
470 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
471 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
472
473 Iterator in(_input, win_in);
474 Iterator out(_output, window);
475
476 const auto wr = static_cast<float>(_input->info()->dimension(0)) / static_cast<float>(_output->info()->dimension(0));
477 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
478 const auto w = _input->info()->dimension(0);
479 const auto h = _input->info()->dimension(1);
480 const size_t in_stride = _input->info()->strides_in_bytes()[1];
481
482 execute_window_loop(window, [&](const Coordinates & id)
483 {
484 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
485
486 uint8x8_t tmp0 = vdup_n_u8(0);
487 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
488 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1);
489 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2);
490 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3);
491 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4);
492 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5);
493 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6);
494 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7);
495
496 uint8x8_t tmp1 = vdup_n_u8(0);
497 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0);
498 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1);
499 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2);
500 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3);
501 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4);
502 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5);
503 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
504 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
505
506 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
507 },
508 in, out);
509}
510
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100511void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100512{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100513 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100514 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
515 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
516 ARM_COMPUTE_ERROR_ON(_func == nullptr);
517
518 (this->*_func)(window);
519}