blob: 67bca65f582c8697e149845ffdb8f6571f6e7907 [file] [log] [blame]
Sheri Zhang23adc4c2021-01-05 12:48:45 +00001/*
alerah014cbcb842022-02-28 06:38:08 +02002 * Copyright (c) 2021-2022 Arm Limited.
Sheri Zhang23adc4c2021-01-05 12:48:45 +00003 *
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 */
alerah014cbcb842022-02-28 06:38:08 +020024
Sheri Zhang23adc4c2021-01-05 12:48:45 +000025#include "arm_compute/core/Helpers.h"
26#include "arm_compute/core/ITensorPack.h"
27#include "arm_compute/core/Window.h"
28#include "src/core/NEON/NEMath.h"
29#include "src/core/NEON/wrapper/wrapper.h"
Sheri Zhang23adc4c2021-01-05 12:48:45 +000030#include "src/core/helpers/ScaleHelpers.h"
31#include "src/core/helpers/ScaleHelpers.h"
32#include "src/core/utils/ScaleUtils.h"
33#include "support/Rounding.h"
34
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010035#include <arm_sve.h>
Sheri Zhang23adc4c2021-01-05 12:48:45 +000036#include <cmath>
37#include <cstddef>
38
Sheri Zhang23adc4c2021-01-05 12:48:45 +000039namespace arm_compute
40{
41namespace
42{
43void qasymm8_signed_sve_scale_nearest(const ITensor *src, ITensor *dst, const ITensor *offsets,
44 float sampling_offset, bool align_corners, const Window &window)
45{
46 const size_t in_stride_c = src->info()->dimension(0) + src->info()->padding().left + src->info()->padding().right;
47 const size_t in_stride_w = src->info()->dimension(1) + src->info()->padding().top + src->info()->padding().bottom;
48 const size_t in_stride_wc = in_stride_w * in_stride_c;
49 const size_t in_dim_h = src->info()->dimension(2);
50
51 // Compute the ratio between source height and destination height
52 const auto hr = scale_utils::calculate_resize_ratio(in_dim_h, dst->info()->dimension(2), align_corners);
53 const auto window_start_x = static_cast<int32_t>(window.x().start());
54 const auto window_end_x = static_cast<int32_t>(window.x().end());
55
56 Window win(window);
57 win.set(Window::DimX, Window::Dimension(0, 1, 1));
58 Iterator out(dst, win);
59
60 const uint8_t *in_ptr_start = src->buffer() + src->info()->offset_first_element_in_bytes();
61 const unsigned int in_stride_bytes_hwc = src->info()->strides_in_bytes()[3];
62
63 execute_window_loop(win, [&](const Coordinates & id)
64 {
65 const int32_t offset = *reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z()))) * in_stride_c;
66 const auto in_hi = static_cast<int>(align_corners ? utils::rounding::round_half_away_from_zero((id.z() + sampling_offset) * hr) : std::floor((id.z() + sampling_offset) * hr));
67 const int offset_row = in_hi * in_stride_wc;
68 const auto in_ptr = reinterpret_cast<const int8_t *>(in_ptr_start + in_stride_bytes_hwc * id[3]);
69 const auto out_ptr = reinterpret_cast<int8_t *>(out.ptr());
70
71 // Compute S elements per iteration
72 int x = window_start_x;
73 svbool_t pg = svwhilelt_b8(x, window_end_x);
74 do
75 {
76 // Store results
77 svst1_s8(pg, out_ptr + x, svld1_s8(pg, in_ptr + offset + offset_row + x));
78
79 x += svcntw();
80 pg = svwhilelt_b8(x, window_end_x);
81 }
82 while(svptest_any(svptrue_b8(), pg));
83 },
84 out);
85}
Sheri Zhang23adc4c2021-01-05 12:48:45 +000086}
87namespace cpu
88{
89void qasymm8_signed_sve_scale(const ITensor *src, ITensor *dst, const ITensor *offsets, const ITensor *dx, const ITensor *dy,
90 InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, float sampling_offset,
91 bool align_corners, const Window &window)
92{
Gunes Bayirc4f27432022-09-11 15:59:19 +010093 ARM_COMPUTE_UNUSED(dx, dy, border_mode, constant_border_value);
94 if(policy == InterpolationPolicy::NEAREST_NEIGHBOR)
Sheri Zhang23adc4c2021-01-05 12:48:45 +000095 {
96 qasymm8_signed_sve_scale_nearest(src, dst, offsets, sampling_offset, align_corners, window);
97 }
Gunes Bayirc4f27432022-09-11 15:59:19 +010098 else
99 {
100 ARM_COMPUTE_ERROR("Not Implemented");
101 }
Sheri Zhang23adc4c2021-01-05 12:48:45 +0000102}
103} // namespace cpu
104} // namespace arm_compute