blob: b1ced7e38ddafc5500f69eb99a0e72191cdc32ea [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
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100183 const int in_yi = std::floor((id.y() + 0.5f) * hr);
184 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
185 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
186 const int offset_row = in_yi_clamped * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187
188 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
189 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
190 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
191 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
192 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
193 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
194 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
195 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
196 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
197 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
198 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
199 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
200 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
201 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
202 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
203 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
204
205 vst1q_u8(out.ptr(), tmp);
206 },
207 in, offsets, out);
208 break;
209 }
210 case DataType::S16:
211 {
212 int16x8x2_t tmp =
213 {
214 {
215 vdupq_n_s16(0),
216 vdupq_n_s16(0)
217 }
218 };
219
220 execute_window_loop(window, [&](const Coordinates & id)
221 {
222 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
223
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100224 const int in_yi = (id.y() + 0.5f) * hr;
225 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100226
227 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
228 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
229 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
230 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
231 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
232 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
233 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
234 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
235
236 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
237 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
238 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
239 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
240 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
241 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
242 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
243 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
244
245 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
246 },
247 in, offsets, out);
248 break;
249 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100250 case DataType::F32:
251 {
252 float32x4x4_t tmp =
253 {
254 {
255 vdupq_n_f32(0),
256 vdupq_n_f32(0),
257 vdupq_n_f32(0),
258 vdupq_n_f32(0)
259 }
260 };
261
262 execute_window_loop(window, [&](const Coordinates & id)
263 {
264 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
265
266 const int in_yi = (id.y() + 0.5f) * hr;
267 const int offset_row = in_yi * input_stride;
268
269 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
270 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1);
271 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2);
272 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3);
273
274 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
275 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1);
276 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2);
277 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3);
278
279 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0);
280 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1);
281 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2);
282 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3);
283
284 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0);
285 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1);
286 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2);
287 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3);
288
289 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
290 },
291 in, offsets, out);
292 break;
293 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100294 default:
295 ARM_COMPUTE_ERROR("Not supported");
296 break;
297 }
298}
299
300void NEScaleKernel::scale_bilinear(const Window &window)
301{
Georgios Pinitas583137c2017-08-31 18:12:42 +0100302 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8, DataType::S16, DataType::F32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100303
304 // Compute the ratio between source height and destination height
305 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
306
307 // Don't increment in X and Y direction for the input tensor
308 // A pointer to the start of this plane is needed as base for the precomputed offsets
309 Window win_in(window);
310 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
311 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
312
313 Window win_off;
314 win_off.set(Window::DimX, window.x());
315 win_off.set(Window::DimY, window.y());
316
317 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
318 {
319 win_off.set(d, Window::Dimension(0, 0, 0));
320 }
321
322 Iterator in(_input, win_in);
323 Iterator out(_output, window);
324 Iterator offsets(_offsets, win_off);
325 Iterator dx(_dx, win_off);
326 Iterator dy(_dy, win_off);
327
328 /* Input image stride */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100329 const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1];
330 const size_t in_stride = in_stide_in_bytes / _input->info()->element_size();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100331
Georgios Pinitas583137c2017-08-31 18:12:42 +0100332 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100333 {
Georgios Pinitas583137c2017-08-31 18:12:42 +0100334 case DataType::U8:
335 {
336 execute_window_loop(window, [&](const Coordinates & id)
337 {
338 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
339 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
340 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
341 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100342
Georgios Pinitas583137c2017-08-31 18:12:42 +0100343 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
344 const int offset_row = in_yi * in_stide_in_bytes;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100345
Georgios Pinitas583137c2017-08-31 18:12:42 +0100346 uint8x8_t tmp0 = vdup_n_u8(0);
347 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0);
348 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1);
349 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2);
350 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3);
351 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4);
352 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5);
353 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6);
354 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 +0100355
Georgios Pinitas583137c2017-08-31 18:12:42 +0100356 uint8x8_t tmp1 = vdup_n_u8(0);
357 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0);
358 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1);
359 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2);
360 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3);
361 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4);
362 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5);
363 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6);
364 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 +0100365
Georgios Pinitas583137c2017-08-31 18:12:42 +0100366 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
367 },
368 in, offsets, dx, dy, out);
369 break;
370 }
371 case DataType::S16:
372 {
373 execute_window_loop(window, [&](const Coordinates & id)
374 {
375 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
376 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
377 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
378
379 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
380 const int offset_row = in_yi * in_stide_in_bytes;
381
382 int16x8x2_t tmp =
383 {
384 {
385 vdupq_n_s16(0),
386 vdupq_n_s16(0)
387 }
388 };
389
390 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);
391 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);
392 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);
393 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);
394 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);
395 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);
396 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);
397 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);
398
399 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);
400 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);
401 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);
402 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);
403 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);
404 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);
405 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);
406 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);
407
408 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
409 },
410 in, offsets, dx, dy, out);
411 break;
412 }
413 case DataType::F32:
414 {
415 execute_window_loop(window, [&](const Coordinates & id)
416 {
417 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
418 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
419 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
420
421 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
422 const int offset_row = in_yi * in_stide_in_bytes;
423
424 float32x4x4_t tmp =
425 {
426 {
427 vdupq_n_f32(0),
428 vdupq_n_f32(0),
429 vdupq_n_f32(0),
430 vdupq_n_f32(0)
431 }
432 };
433
434 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);
435 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);
436 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);
437 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);
438
439 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);
440 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);
441 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);
442 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);
443
444 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);
445 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);
446 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);
447 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);
448
449 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);
450 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);
451 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);
452 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);
453
454 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
455 },
456 in, offsets, dx, dy, out);
457 break;
458 }
459 default:
460 ARM_COMPUTE_ERROR("Not supported");
461 break;
462 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100463}
464
465void NEScaleKernel::scale_area(const Window &window)
466{
467 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
468
469 // Don't increment in X and Y direction for the input tensor
470 // A pointer to the start of this plane is needed as base for the precomputed offsets
471 Window win_in(window);
472 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
473 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
474
475 Iterator in(_input, win_in);
476 Iterator out(_output, window);
477
478 const auto wr = static_cast<float>(_input->info()->dimension(0)) / static_cast<float>(_output->info()->dimension(0));
479 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
480 const auto w = _input->info()->dimension(0);
481 const auto h = _input->info()->dimension(1);
482 const size_t in_stride = _input->info()->strides_in_bytes()[1];
483
484 execute_window_loop(window, [&](const Coordinates & id)
485 {
486 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
487
488 uint8x8_t tmp0 = vdup_n_u8(0);
489 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
490 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1);
491 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2);
492 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3);
493 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4);
494 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5);
495 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6);
496 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7);
497
498 uint8x8_t tmp1 = vdup_n_u8(0);
499 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0);
500 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1);
501 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2);
502 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3);
503 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4);
504 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5);
505 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
506 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
507
508 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
509 },
510 in, out);
511}
512
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100513void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100514{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100515 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100516 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
517 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
518 ARM_COMPUTE_ERROR_ON(_func == nullptr);
519
520 (this->*_func)(window);
521}