aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorManuel Bottini <manuel.bottini@arm.com>2021-02-19 18:16:44 +0000
committerSheri Zhang <sheri.zhang@arm.com>2021-03-16 11:11:04 +0000
commit10b3826723e1e2f62a4e635801128ddf4438e50c (patch)
treea4e187c2b82f0d5ca4e93ae70babfbfd45d087b2 /src/core
parent42bd26560daa799dbb825a7c6aade61c7ca132a2 (diff)
downloadComputeLibrary-10b3826723e1e2f62a4e635801128ddf4438e50c.tar.gz
Port Arm(R) Neon(TM) Scale to new API
Partially resolves: COMPMID-4190 Change-Id: I0c1e32ff6176775c9b7bf547899a791fd318ba0a Signed-off-by: Manuel Bottini <manuel.bottini@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5192 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: TeresaARM <teresa.charlinreyes@arm.com> Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com> Reviewed-by: Sheri Zhang <sheri.zhang@arm.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/NEON/NEKernels.h1
-rw-r--r--src/core/NEON/kernels/NEScaleKernel.h122
-rw-r--r--src/core/cpu/kernels/CpuScaleKernel.cpp (renamed from src/core/NEON/kernels/NEScaleKernel.cpp)287
-rw-r--r--src/core/cpu/kernels/CpuScaleKernel.h111
-rw-r--r--src/core/cpu/kernels/scale/neon/fp16.cpp (renamed from src/core/NEON/kernels/scale/impl/NEON/fp16.cpp)0
-rw-r--r--src/core/cpu/kernels/scale/neon/integer.cpp (renamed from src/core/NEON/kernels/scale/impl/NEON/integer.cpp)0
-rw-r--r--src/core/cpu/kernels/scale/neon/list.h (renamed from src/core/NEON/kernels/scale/impl/NEON/list.h)0
-rw-r--r--src/core/cpu/kernels/scale/neon/qasymm8.cpp (renamed from src/core/NEON/kernels/scale/impl/NEON/qasymm8.cpp)38
-rw-r--r--src/core/cpu/kernels/scale/neon/qasymm8_signed.cpp (renamed from src/core/NEON/kernels/scale/impl/NEON/qasymm8_signed.cpp)38
-rw-r--r--src/core/cpu/kernels/scale/sve/fp16.cpp (renamed from src/core/NEON/kernels/scale/impl/SVE/fp16.cpp)0
-rw-r--r--src/core/cpu/kernels/scale/sve/fp32.cpp (renamed from src/core/NEON/kernels/scale/impl/SVE/fp32.cpp)0
-rw-r--r--src/core/cpu/kernels/scale/sve/integer.cpp (renamed from src/core/NEON/kernels/scale/impl/SVE/integer.cpp)0
-rw-r--r--src/core/cpu/kernels/scale/sve/list.h (renamed from src/core/NEON/kernels/scale/impl/SVE/list.h)0
-rw-r--r--src/core/cpu/kernels/scale/sve/qasymm8.cpp (renamed from src/core/NEON/kernels/scale/impl/SVE/qasymm8.cpp)0
-rw-r--r--src/core/cpu/kernels/scale/sve/qasymm8_signed.cpp (renamed from src/core/NEON/kernels/scale/impl/SVE/qasymm8_signed.cpp)0
15 files changed, 299 insertions, 298 deletions
diff --git a/src/core/NEON/NEKernels.h b/src/core/NEON/NEKernels.h
index 6a7e856d8b..973c0f2d31 100644
--- a/src/core/NEON/NEKernels.h
+++ b/src/core/NEON/NEKernels.h
@@ -82,7 +82,6 @@
#include "src/core/NEON/kernels/NERemapKernel.h"
#include "src/core/NEON/kernels/NEReorgLayerKernel.h"
#include "src/core/NEON/kernels/NEReverseKernel.h"
-#include "src/core/NEON/kernels/NEScaleKernel.h"
#include "src/core/NEON/kernels/NESelectKernel.h"
#include "src/core/NEON/kernels/NESpaceToBatchLayerKernel.h"
#include "src/core/NEON/kernels/NESpaceToDepthLayerKernel.h"
diff --git a/src/core/NEON/kernels/NEScaleKernel.h b/src/core/NEON/kernels/NEScaleKernel.h
deleted file mode 100644
index 32fa8d7fb2..0000000000
--- a/src/core/NEON/kernels/NEScaleKernel.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (c) 2016-2021 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#ifndef ARM_COMPUTE_NESCALEKERNEL_H
-#define ARM_COMPUTE_NESCALEKERNEL_H
-
-#include "arm_compute/core/KernelDescriptors.h"
-#include "src/core/NEON/INEKernel.h"
-
-namespace arm_compute
-{
-class ITensor;
-
-/** Neon kernel to perform scaling on a tensor */
-class NEScaleKernel : public INEKernel
-{
-public:
- const char *name() const override
- {
- return "NEScaleKernel";
- }
- /** Default constructor */
- NEScaleKernel();
- /** Prevent instances of this class from being copied (As this class contains pointers) */
- NEScaleKernel(const NEScaleKernel &) = delete;
- /** Prevent instances of this class from being copied (As this class contains pointers) */
- NEScaleKernel &operator=(const NEScaleKernel &) = delete;
- /** Allow instances of this class to be moved */
- NEScaleKernel(NEScaleKernel &&) = default;
- /** Allow instances of this class to be moved */
- NEScaleKernel &operator=(NEScaleKernel &&) = default;
- /** Default destructor */
- ~NEScaleKernel() = default;
-
- /** Initialise the kernel's inputs, output and interpolation policy
- *
- * @note dx, dy and offsets have the same dimensions (width and height) of the output tensor
- * @note Using @p policy Area only supports data layout NCHW and input data type U8.
- *
- * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/U8/S16/F16/F32.
- * @param[in] dx Pixel's distance between the X real coordinate and the smallest X following integer. Data type supported: F32
- * @param[in] dy Pixel's distance between the Y real coordinate and the smallest Y following integer. Data type supported: F32
- * @param[in] offsets Offset to access the pixel with NEAREST interpolation or the top-left pixel with BILINEAR interpolation in the input tensor. Data type supported: S32.
- * @param[out] output Destination tensor. Data types supported: Same as @p input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane.
- * @param[in] info @ref ScaleKernelInfo to use for configuration
- */
- void configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output,
- const ScaleKernelInfo &info);
- /** Static function to check if given info will lead to a valid configuration of @ref NEScaleKernel
- *
- * @note dx, dy and offsets have the same dimensions (width and height) of the output tensor
- * @note Using @p policy Area only supports data layout NCHW and input data type U8.
- *
- * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/U8/S16/F16/F32.
- * @param[in] dx Pixel's distance between the X real coordinate and the smallest X following integer. Data type supported: F32
- * @param[in] dy Pixel's distance between the Y real coordinate and the smallest Y following integer. Data type supported: F32
- * @param[in] offsets Offset to access the pixel with NEAREST interpolation or the top-left pixel with BILINEAR interpolation in the input tensor. Data type supported: S32.
- * @param[in] output Destination tensor. Data types supported: Same as @p input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane.
- * @param[in] info @ref ScaleKernelInfo to use for validation
- */
- static Status validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *output,
- const ScaleKernelInfo &info);
-
- // Inherited methods overridden:
- void run(const Window &window, const ThreadInfo &info) override;
-
-private:
- /** function to perform scale using area interpolation on the given window
- *
- * @note Used only in case down-sampling.
- */
- void scale_area_nchw_u8(const Window &window);
-
- /** function to perform scale using bilinear interpolation on the given window */
- template <typename T>
- void scale_bilinear_nchw(const Window &window);
- /** function to perform scale using bilinear interpolation on the given window */
- template <typename T>
- void scale_bilinear_qasymm(const Window &window);
-
- /** function to perform scale using nearest neighbour on the given window */
- template <typename T>
- void scale_nearest_nchw(const Window &window);
-
- /** Scale function to use for the particular function to use */
- using ScaleFunctionPtr = void (NEScaleKernel::*)(const Window &window);
-
- ScaleFunctionPtr _func;
- const ITensor *_offsets;
- const ITensor *_dx;
- const ITensor *_dy;
- const ITensor *_input;
- ITensor *_output;
- InterpolationPolicy _policy;
- BorderMode _border_mode;
- PixelValue _constant_border_value;
- float _sampling_offset;
- bool _align_corners;
- DataLayout _data_layout;
-};
-} // namespace arm_compute
-#endif /*ARM_COMPUTE_NESCALEKERNEL_H */
diff --git a/src/core/NEON/kernels/NEScaleKernel.cpp b/src/core/cpu/kernels/CpuScaleKernel.cpp
index 6b9aa51aaa..22d1332a55 100644
--- a/src/core/NEON/kernels/NEScaleKernel.cpp
+++ b/src/core/cpu/kernels/CpuScaleKernel.cpp
@@ -21,27 +21,32 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include "src/core/NEON/kernels/NEScaleKernel.h"
+#include "src/core/cpu/kernels/CpuScaleKernel.h"
#include "arm_compute/core/Helpers.h"
#include "arm_compute/core/Window.h"
#include "arm_compute/core/utils/misc/Utility.h"
#include "src/core/AccessWindowStatic.h"
#include "src/core/CPP/Validate.h"
-#include "src/core/NEON/kernels/scale/impl/NEON/list.h"
-#include "src/core/NEON/kernels/scale/impl/SVE/list.h"
#include "src/core/NEON/wrapper/wrapper.h"
#include "src/core/common/Registrars.h"
+#include "src/core/cpu/kernels/scale/neon/list.h"
+#include "src/core/cpu/kernels/scale/sve/list.h"
#include "src/core/helpers/AutoConfiguration.h"
#include "src/core/helpers/ScaleHelpers.h"
#include "src/core/helpers/WindowHelpers.h"
#include "src/core/utils/ScaleUtils.h"
#include "support/Rounding.h"
+
#include <arm_neon.h>
#include <map>
namespace arm_compute
{
+namespace cpu
+{
+namespace kernels
+{
namespace
{
struct ScaleSelectorData
@@ -145,24 +150,24 @@ const ScaleKernel *get_implementation(const ScaleSelectorData &data)
return nullptr;
}
-Status validate_arguments(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
- const ITensorInfo *offsets, ITensorInfo *output, const ScaleKernelInfo &info)
+Status validate_arguments(const ITensorInfo *src, const ITensorInfo *dx, const ITensorInfo *dy,
+ const ITensorInfo *offsets, ITensorInfo *dst, const ScaleKernelInfo &info)
{
- const auto *uk = get_implementation(ScaleSelectorData{ input->data_type() });
+ const auto *uk = get_implementation(ScaleSelectorData{ src->data_type() });
ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr);
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
- ARM_COMPUTE_RETURN_ERROR_ON(output == input);
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(dst);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, dst);
+ ARM_COMPUTE_RETURN_ERROR_ON(dst == src);
ARM_COMPUTE_RETURN_ERROR_ON(info.sampling_policy != SamplingPolicy::CENTER && info.sampling_policy != SamplingPolicy::TOP_LEFT);
ARM_COMPUTE_UNUSED(info.constant_border_value);
ARM_COMPUTE_RETURN_ERROR_ON_MSG(info.use_padding, "Padding is not supported");
- const DataLayout data_layout = info.data_layout == DataLayout::UNKNOWN ? input->data_layout() : info.data_layout;
+ const DataLayout data_layout = info.data_layout == DataLayout::UNKNOWN ? src->data_layout() : info.data_layout;
const auto width_index = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
const auto height_index = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
- const auto output_width = output->dimension(width_index);
- const auto output_height = output->dimension(height_index);
+ const auto output_width = dst->dimension(width_index);
+ const auto output_height = dst->dimension(height_index);
ARM_COMPUTE_RETURN_ERROR_ON(output_width == 0);
ARM_COMPUTE_RETURN_ERROR_ON(output_height == 0);
@@ -183,41 +188,36 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *dx, const
if(info.interpolation_policy == InterpolationPolicy::AREA)
{
ARM_COMPUTE_RETURN_ERROR_ON(data_layout != DataLayout::NCHW);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::U8);
}
return Status{};
}
} // namespace
-NEScaleKernel::NEScaleKernel()
- : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr), _policy(), _border_mode(), _constant_border_value(PixelValue()), _sampling_offset(0),
- _align_corners(false), _data_layout(DataLayout::UNKNOWN)
+CpuScaleKernel::CpuScaleKernel()
+ : _func(nullptr), _policy(), _border_mode(), _constant_border_value(PixelValue()), _sampling_offset(0), _align_corners(false), _data_layout(DataLayout::UNKNOWN)
{
}
-void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets,
- ITensor *output, const ScaleKernelInfo &info)
+void CpuScaleKernel::configure(const ITensorInfo *src, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets,
+ ITensorInfo *dst, const ScaleKernelInfo &info)
{
- ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
+ ARM_COMPUTE_UNUSED(dx, dy, offsets);
+ ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst);
// Perform validation step
- ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(),
- dx != nullptr ? dx->info() : nullptr,
- dy != nullptr ? dy->info() : nullptr,
- offsets != nullptr ? offsets->info() : nullptr,
- output->info(),
+ ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src,
+ dx,
+ dy,
+ offsets,
+ dst,
info));
// Get data layout and width/height indices
- _data_layout = info.data_layout == DataLayout::UNKNOWN ? input->info()->data_layout() : info.data_layout;
+ _data_layout = info.data_layout == DataLayout::UNKNOWN ? src->data_layout() : info.data_layout;
const int idx_width = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH);
const int idx_height = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT);
- _input = input;
- _output = output;
- _offsets = offsets;
- _dx = dx;
- _dy = dy;
_policy = info.interpolation_policy;
_border_mode = info.border_mode;
_constant_border_value = info.constant_border_value;
@@ -229,8 +229,8 @@ void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITe
}
// Compute the ratio between source width/height and destination width/height
- const auto wr = scale_utils::calculate_resize_ratio(input->info()->dimension(idx_width), output->info()->dimension(idx_width), _align_corners);
- const auto hr = scale_utils::calculate_resize_ratio(input->info()->dimension(idx_height), output->info()->dimension(idx_height), _align_corners);
+ const auto wr = scale_utils::calculate_resize_ratio(src->dimension(idx_width), dst->dimension(idx_width), _align_corners);
+ const auto hr = scale_utils::calculate_resize_ratio(src->dimension(idx_height), dst->dimension(idx_height), _align_corners);
// Area interpolation behaves as Nearest Neighbour in case of up-sampling
_policy = (_policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) ? InterpolationPolicy::NEAREST_NEIGHBOR : _policy;
@@ -241,37 +241,38 @@ void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITe
_constant_border_value = PixelValue();
}
+#ifdef ENABLE_NCHW_KERNELS
// Configure scale function to run
if(_data_layout == DataLayout::NCHW)
{
std::string function_to_call("scale_");
- function_to_call += string_from_data_type(_input->info()->data_type()) + "_";
+ function_to_call += string_from_data_type(src->data_type()) + "_";
function_to_call += string_from_data_layout(_data_layout) + "_";
function_to_call += string_from_interpolation_policy(_policy);
static std::map<std::string, ScaleFunctionPtr> map_function =
{
- { "scale_U8_NCHW_AREA_CONSTANT", &NEScaleKernel::scale_area_nchw_u8 },
+ { "scale_U8_NCHW_AREA_CONSTANT", &CpuScaleKernel::scale_area_nchw_u8 },
- { "scale_U8_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_nchw<uint8_t> },
- { "scale_U8_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<uint8_t> },
+ { "scale_U8_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_nchw<uint8_t> },
+ { "scale_U8_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<uint8_t> },
- { "scale_QASYMM8_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_qasymm<uint8_t> },
- { "scale_QASYMM8_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<uint8_t> },
+ { "scale_QASYMM8_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_qasymm<uint8_t> },
+ { "scale_QASYMM8_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<uint8_t> },
- { "scale_QASYMM8_SIGNED_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_qasymm<int8_t> },
- { "scale_QASYMM8_SIGNED_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<int8_t> },
+ { "scale_QASYMM8_SIGNED_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_qasymm<int8_t> },
+ { "scale_QASYMM8_SIGNED_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<int8_t> },
- { "scale_S16_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_nchw<int16_t> },
- { "scale_S16_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<int16_t> },
+ { "scale_S16_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_nchw<int16_t> },
+ { "scale_S16_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<int16_t> },
#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
- { "scale_F16_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_nchw<float16_t> },
- { "scale_F16_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<float16_t> },
+ { "scale_F16_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_nchw<float16_t> },
+ { "scale_F16_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<float16_t> },
#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
- { "scale_F32_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_nchw<float> },
- { "scale_F32_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<float> },
+ { "scale_F32_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_nchw<float> },
+ { "scale_F32_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<float> },
};
auto it = map_function.find(function_to_call);
if(it != map_function.end())
@@ -279,19 +280,22 @@ void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITe
_func = it->second;
}
}
+#endif // ENABLE_NCHW_KERNELS
// Configure window
- Window win = calculate_max_window(*output->info(), Steps());
- INEKernel::configure(win);
+ Window win = calculate_max_window(*dst, Steps());
+ ICpuKernel::configure(win);
}
+#ifdef ENABLE_NCHW_KERNELS
template <typename T>
-void NEScaleKernel::scale_nearest_nchw(const Window &window)
+void CpuScaleKernel::scale_nearest_nchw(const ITensor *src, ITensor *dst, const ITensor *dx, const ITensor *dy, const ITensor *offsets, const Window &window)
{
- const size_t in_stride_x = _input->info()->dimension(0) + _input->info()->padding().left + _input->info()->padding().right;
+ ARM_COMPUTE_UNUSED(dx, dy);
+ const size_t in_stride_x = src->info()->dimension(0) + src->info()->padding().left + src->info()->padding().right;
// Compute the ratio between source height and destination height
- const auto hr = scale_utils::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners);
+ const auto hr = scale_utils::calculate_resize_ratio(src->info()->dimension(1), dst->info()->dimension(1), _align_corners);
// Don't increment in X and Y direction for the input tensor
// A pointer to the start of this plane is needed as base for the precomputed offsets
@@ -303,30 +307,32 @@ void NEScaleKernel::scale_nearest_nchw(const Window &window)
Window win_off;
win_off.set(Window::DimX, window[Window::DimX]);
win_off.set(Window::DimY, window[Window::DimY]);
- for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
+ for(size_t d = Window::DimZ; d < offsets->info()->num_dimensions(); ++d)
{
win_off.set(d, Window::Dimension(0, 0, 0));
}
// Create iterators
- Iterator in(_input, win_in);
- Iterator out(_output, window);
- Iterator offsets(_offsets, win_off);
+ Iterator src_i(src, win_in);
+ Iterator dst_i(dst, window);
+ Iterator offsets_i(offsets, win_off);
execute_window_loop(window, [&](const Coordinates & id)
{
- const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
- const auto in_yi = static_cast<int32_t>(_align_corners ? utils::rounding::round_half_away_from_zero((id.y() + _sampling_offset) * hr) : std::floor((id.y() + _sampling_offset) * hr));
- const int32_t offset_row = in_yi * in_stride_x;
- *reinterpret_cast<T *>(out.ptr()) = *(reinterpret_cast<const T *>(in.ptr()) + offsets_ptr[0] + offset_row);
+ const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets_i.ptr());
+ const auto in_yi = static_cast<int32_t>(_align_corners ? utils::rounding::round_half_away_from_zero((id.y() + _sampling_offset) * hr) : std::floor((
+ id.y() + _sampling_offset)
+ * hr));
+ const int32_t offset_row = in_yi * in_stride_x;
+ *reinterpret_cast<T *>(dst_i.ptr()) = *(reinterpret_cast<const T *>(src_i.ptr()) + offsets_ptr[0] + offset_row);
},
- in, offsets, out);
+ src_i, offsets_i, dst_i);
}
template <typename T>
-void NEScaleKernel::scale_bilinear_nchw(const Window &window)
+void CpuScaleKernel::scale_bilinear_nchw(const ITensor *src, ITensor *dst, const ITensor *dx, const ITensor *dy, const ITensor *offsets, const Window &window)
{
// Compute the ratio between source height and destination height
- const auto hr = scale_utils::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners);
+ const auto hr = scale_utils::calculate_resize_ratio(src->info()->dimension(1), dst->info()->dimension(1), _align_corners);
Window win_off;
win_off.set(Window::DimX, window.x());
win_off.set(Window::DimY, window.y());
@@ -337,20 +343,20 @@ void NEScaleKernel::scale_bilinear_nchw(const Window &window)
win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
- for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
+ for(size_t d = Window::DimZ; d < offsets->info()->num_dimensions(); ++d)
{
win_off.set(d, Window::Dimension(0, 0, 0));
}
- Iterator in(_input, win_in);
- Iterator out(_output, window);
- Iterator offsets(_offsets, win_off);
- Iterator dx(_dx, win_off);
- Iterator dy(_dy, win_off);
+ Iterator src_i(src, win_in);
+ Iterator dst_i(dst, window);
+ Iterator offsets_i(offsets, win_off);
+ Iterator dx_i(dx, win_off);
+ Iterator dy_i(dy, win_off);
- const int32_t in_dim_w = _input->info()->dimension(0);
- const int32_t in_dim_h = _input->info()->dimension(1);
- const int32_t in_stride_w = in_dim_w + _input->info()->padding().left + _input->info()->padding().right;
+ const int32_t in_dim_w = src->info()->dimension(0);
+ const int32_t in_dim_h = src->info()->dimension(1);
+ const int32_t in_stride_w = in_dim_w + src->info()->padding().left + src->info()->padding().right;
if(_border_mode == BorderMode::CONSTANT)
{
@@ -363,10 +369,10 @@ void NEScaleKernel::scale_bilinear_nchw(const Window &window)
execute_window_loop(window, [&](const Coordinates & id)
{
const int32_t index_h = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
- const auto index_w = *(reinterpret_cast<const int32_t *>(offsets.ptr()));
- const auto dx_val = *(reinterpret_cast<const float *>(dx.ptr()));
- const auto dy_val = *(reinterpret_cast<const float *>(dy.ptr()));
- const auto pixel_row_ptr = reinterpret_cast<const T *>(in.ptr());
+ const auto index_w = *(reinterpret_cast<const int32_t *>(offsets_i.ptr()));
+ const auto dx_val = *(reinterpret_cast<const float *>(dx_i.ptr()));
+ const auto dy_val = *(reinterpret_cast<const float *>(dy_i.ptr()));
+ const auto pixel_row_ptr = reinterpret_cast<const T *>(src_i.ptr());
const auto a00 = (0 <= index_w && index_w < in_dim_w && 0 <= index_h && index_h < in_dim_h) ? (*(pixel_row_ptr + index_w + index_h * in_stride_w)) : const_border_value;
const auto a01 = (-1 <= index_w && index_w < in_dim_w - 1 && 0 <= index_h && index_h < in_dim_h) ? (*(pixel_row_ptr + index_w + 1 + index_h * in_stride_w)) : const_border_value;
@@ -379,19 +385,19 @@ void NEScaleKernel::scale_bilinear_nchw(const Window &window)
(*(pixel_row_ptr + index_w + 1 + index_h * in_stride_w + in_stride_w)) :
const_border_value;
- *reinterpret_cast<T *>(out.ptr()) = static_cast<T>(scale_helpers::delta_bilinear(a00, a01, a10, a11, dx_val, dy_val));
+ *reinterpret_cast<T *>(dst_i.ptr()) = static_cast<T>(scale_helpers::delta_bilinear(a00, a01, a10, a11, dx_val, dy_val));
},
- in, offsets, dx, dy, out);
+ src_i, offsets_i, dx_i, dy_i, dst_i);
}
else if(_border_mode == BorderMode::REPLICATE)
{
execute_window_loop(window, [&](const Coordinates & id)
{
const int index_h = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
- const auto index_w = *(reinterpret_cast<const int32_t *>(offsets.ptr()));
- const auto dx_val = *(reinterpret_cast<const float *>(dx.ptr()));
- const auto dy_val = *(reinterpret_cast<const float *>(dy.ptr()));
- const auto pixel_row_ptr = reinterpret_cast<const T *>(in.ptr());
+ const auto index_w = *(reinterpret_cast<const int32_t *>(offsets_i.ptr()));
+ const auto dx_val = *(reinterpret_cast<const float *>(dx_i.ptr()));
+ const auto dy_val = *(reinterpret_cast<const float *>(dy_i.ptr()));
+ const auto pixel_row_ptr = reinterpret_cast<const T *>(src_i.ptr());
auto clamped_x = utility::clamp<int>(index_w, 0, in_dim_w - 1);
auto clamped_x1 = utility::clamp<int>(index_w + 1, 0, in_dim_w - 1);
@@ -403,9 +409,9 @@ void NEScaleKernel::scale_bilinear_nchw(const Window &window)
const auto a10 = *(pixel_row_ptr + clamped_x + clamped_y1 * in_stride_w);
const auto a11 = *(pixel_row_ptr + clamped_x1 + clamped_y1 * in_stride_w);
- *reinterpret_cast<T *>(out.ptr()) = static_cast<T>(scale_helpers::delta_bilinear(a00, a01, a10, a11, dx_val, dy_val));
+ *reinterpret_cast<T *>(dst_i.ptr()) = static_cast<T>(scale_helpers::delta_bilinear(a00, a01, a10, a11, dx_val, dy_val));
},
- in, offsets, dx, dy, out);
+ src_i, offsets_i, dx_i, dy_i, dst_i);
}
else
{
@@ -413,11 +419,12 @@ void NEScaleKernel::scale_bilinear_nchw(const Window &window)
}
}
-void NEScaleKernel::scale_area_nchw_u8(const Window &window)
+void CpuScaleKernel::scale_area_nchw_u8(const ITensor *src, ITensor *dst, const ITensor *dx, const ITensor *dy, const ITensor *offsets, const Window &window)
{
+ ARM_COMPUTE_UNUSED(dx, dy, offsets);
using namespace scale_helpers;
- ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
+ ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::U8);
// Don't increment in width/height/channels for the input tensor
// A pointer to the start of this plane is needed as base for the precomputed offsets
@@ -426,18 +433,18 @@ void NEScaleKernel::scale_area_nchw_u8(const Window &window)
win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
- Iterator in(_input, win_in);
- Iterator out(_output, window);
+ Iterator src_i(src, win_in);
+ Iterator dst_i(dst, window);
- const auto wr = scale_utils::calculate_resize_ratio(_input->info()->dimension(0), _output->info()->dimension(0), _align_corners);
- const auto hr = scale_utils::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners);
- const auto w = _input->info()->dimension(0);
- const auto h = _input->info()->dimension(1);
- const size_t in_stride = _input->info()->strides_in_bytes()[1];
+ const auto wr = scale_utils::calculate_resize_ratio(src->info()->dimension(0), dst->info()->dimension(0), _align_corners);
+ const auto hr = scale_utils::calculate_resize_ratio(src->info()->dimension(1), dst->info()->dimension(1), _align_corners);
+ const auto w = src->info()->dimension(0);
+ const auto h = src->info()->dimension(1);
+ const size_t in_stride = src->info()->strides_in_bytes()[1];
execute_window_loop(window, [&](const Coordinates & id)
{
- const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
+ const auto in_ptr = reinterpret_cast<const uint8_t *>(src_i.ptr());
uint8x8_t tmp0 = vdup_n_u8(0);
tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
@@ -459,20 +466,20 @@ void NEScaleKernel::scale_area_nchw_u8(const Window &window)
tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
- vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
+ vst1q_u8(dst_i.ptr(), vcombine_u8(tmp0, tmp1));
},
- in, out);
+ src_i, dst_i);
}
template <typename T>
-void NEScaleKernel::scale_bilinear_qasymm(const Window &window)
+void CpuScaleKernel::scale_bilinear_qasymm(const ITensor *src, ITensor *dst, const ITensor *dx, const ITensor *dy, const ITensor *offsets, const Window &window)
{
// Get data layout and width/height indices
const int idx_width = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH);
const int idx_height = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT);
// Compute the ratio between source height and destination height
- const auto hr = scale_utils::calculate_resize_ratio(_input->info()->dimension(idx_height), _output->info()->dimension(idx_height), _align_corners);
+ const auto hr = scale_utils::calculate_resize_ratio(src->info()->dimension(idx_height), dst->info()->dimension(idx_height), _align_corners);
Window win_off;
win_off.set(Window::DimX, Window::Dimension(0, 0, 0));
win_off.set(Window::DimY, Window::Dimension(0, 0, 0));
@@ -483,21 +490,21 @@ void NEScaleKernel::scale_bilinear_qasymm(const Window &window)
win_in.set(idx_width, Window::Dimension(0, 0, 0));
win_in.set(idx_height, Window::Dimension(0, 0, 0));
- for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
+ for(size_t d = Window::DimZ; d < offsets->info()->num_dimensions(); ++d)
{
win_off.set(d, Window::Dimension(0, 0, 0));
}
- Iterator in(_input, win_in);
- Iterator out(_output, window);
+ Iterator src_i(src, win_in);
+ Iterator dst_i(dst, window);
- const int32_t in_dim_w = _input->info()->dimension(idx_width);
- const int32_t in_dim_h = _input->info()->dimension(idx_height);
- const int32_t stride_w = _input->info()->strides_in_bytes()[idx_width];
- const int32_t stride_h = _input->info()->strides_in_bytes()[idx_height];
+ const int32_t in_dim_w = src->info()->dimension(idx_width);
+ const int32_t in_dim_h = src->info()->dimension(idx_height);
+ const int32_t stride_w = src->info()->strides_in_bytes()[idx_width];
+ const int32_t stride_h = src->info()->strides_in_bytes()[idx_height];
- const UniformQuantizationInfo iq_info = _input->info()->quantization_info().uniform();
- const UniformQuantizationInfo oq_info = _output->info()->quantization_info().uniform();
+ const UniformQuantizationInfo iq_info = src->info()->quantization_info().uniform();
+ const UniformQuantizationInfo oq_info = dst->info()->quantization_info().uniform();
if(_border_mode == BorderMode::CONSTANT)
{
@@ -510,10 +517,10 @@ void NEScaleKernel::scale_bilinear_qasymm(const Window &window)
execute_window_loop(window, [&](const Coordinates & id)
{
const int32_t index_h = std::floor((id[idx_height] + _sampling_offset) * hr - _sampling_offset);
- const int32_t index_w = *(reinterpret_cast<const int32_t *>(_offsets->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dx_val = *(reinterpret_cast<const float *>(_dx->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dy_val = *(reinterpret_cast<const float *>(_dy->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto pixel_row_ptr = reinterpret_cast<const T *>(in.ptr());
+ const int32_t index_w = *(reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
+ const auto dx_val = *(reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
+ const auto dy_val = *(reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
+ const auto pixel_row_ptr = reinterpret_cast<const T *>(src_i.ptr());
const auto a00 = (0 <= index_w && index_w < in_dim_w && 0 <= index_h && index_h < in_dim_h) ?
(*(pixel_row_ptr + index_w * stride_w + index_h * stride_h)) :
@@ -528,23 +535,23 @@ void NEScaleKernel::scale_bilinear_qasymm(const Window &window)
(*(pixel_row_ptr + (index_w + 1) * stride_w + (index_h + 1) * stride_h)) :
const_border_value;
- const float inp00 = Qasymm8QuantizationHelper<T>::dequantize(a00, iq_info);
- const float inp01 = Qasymm8QuantizationHelper<T>::dequantize(a01, iq_info);
- const float inp10 = Qasymm8QuantizationHelper<T>::dequantize(a10, iq_info);
- const float inp11 = Qasymm8QuantizationHelper<T>::dequantize(a11, iq_info);
- *reinterpret_cast<T *>(out.ptr()) = Qasymm8QuantizationHelper<T>::quantize(scale_helpers::delta_bilinear(inp00, inp01, inp10, inp11, dx_val, dy_val), oq_info);
+ const float inp00 = Qasymm8QuantizationHelper<T>::dequantize(a00, iq_info);
+ const float inp01 = Qasymm8QuantizationHelper<T>::dequantize(a01, iq_info);
+ const float inp10 = Qasymm8QuantizationHelper<T>::dequantize(a10, iq_info);
+ const float inp11 = Qasymm8QuantizationHelper<T>::dequantize(a11, iq_info);
+ *reinterpret_cast<T *>(dst_i.ptr()) = Qasymm8QuantizationHelper<T>::quantize(scale_helpers::delta_bilinear(inp00, inp01, inp10, inp11, dx_val, dy_val), oq_info);
},
- in, out);
+ src_i, dst_i);
}
else if(_border_mode == BorderMode::REPLICATE)
{
execute_window_loop(window, [&](const Coordinates & id)
{
const int index_h = std::floor((id[idx_height] + _sampling_offset) * hr - _sampling_offset);
- const int32_t index_w = *(reinterpret_cast<const int32_t *>(_offsets->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dx_val = *(reinterpret_cast<const float *>(_dx->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dy_val = *(reinterpret_cast<const float *>(_dy->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto pixel_row_ptr = reinterpret_cast<const T *>(in.ptr());
+ const int32_t index_w = *(reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
+ const auto dx_val = *(reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
+ const auto dy_val = *(reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
+ const auto pixel_row_ptr = reinterpret_cast<const T *>(src_i.ptr());
auto clamped_w = utility::clamp<int>(index_w, 0, in_dim_w - 1);
auto clamped_w1 = utility::clamp<int>(index_w + 1, 0, in_dim_w - 1);
@@ -556,42 +563,56 @@ void NEScaleKernel::scale_bilinear_qasymm(const Window &window)
const auto a10 = *(pixel_row_ptr + clamped_w * stride_w + clamped_h1 * stride_h);
const auto a11 = *(pixel_row_ptr + clamped_w1 * stride_w + clamped_h1 * stride_h);
- const float inp00 = Qasymm8QuantizationHelper<T>::dequantize(a00, iq_info);
- const float inp01 = Qasymm8QuantizationHelper<T>::dequantize(a01, iq_info);
- const float inp10 = Qasymm8QuantizationHelper<T>::dequantize(a10, iq_info);
- const float inp11 = Qasymm8QuantizationHelper<T>::dequantize(a11, iq_info);
- *reinterpret_cast<T *>(out.ptr()) = Qasymm8QuantizationHelper<T>::quantize(scale_helpers::delta_bilinear(inp00, inp01, inp10, inp11, dx_val, dy_val), oq_info);
+ const float inp00 = Qasymm8QuantizationHelper<T>::dequantize(a00, iq_info);
+ const float inp01 = Qasymm8QuantizationHelper<T>::dequantize(a01, iq_info);
+ const float inp10 = Qasymm8QuantizationHelper<T>::dequantize(a10, iq_info);
+ const float inp11 = Qasymm8QuantizationHelper<T>::dequantize(a11, iq_info);
+ *reinterpret_cast<T *>(dst_i.ptr()) = Qasymm8QuantizationHelper<T>::quantize(scale_helpers::delta_bilinear(inp00, inp01, inp10, inp11, dx_val, dy_val), oq_info);
},
- in, out);
+ src_i, dst_i);
}
else
{
ARM_COMPUTE_ERROR("Not implemented");
}
}
+#endif // ENABLE_NCHW_KERNELS
-Status NEScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
- const ITensorInfo *offsets, ITensorInfo *output, const ScaleKernelInfo &info)
+Status CpuScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
+ const ITensorInfo *offsets, ITensorInfo *output, const ScaleKernelInfo &info)
{
ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, dx, dy, offsets, output, info));
return Status{};
}
-void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
+void CpuScaleKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
{
ARM_COMPUTE_UNUSED(info);
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
- ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
+ ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICpuKernel::window(), window);
ARM_COMPUTE_ERROR_ON(_func == nullptr && _data_layout == DataLayout::NCHW);
+ const auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
+ auto dst = tensors.get_tensor(TensorType::ACL_DST);
+ const auto dx = tensors.get_const_tensor(TensorType::ACL_INT_0);
+ const auto dy = tensors.get_const_tensor(TensorType::ACL_INT_1);
+ const auto offsets = tensors.get_const_tensor(TensorType::ACL_INT_2);
+
if(_data_layout == DataLayout::NCHW)
{
- (this->*_func)(window);
+ (this->*_func)(src, dst, dx, dy, offsets, window);
}
else
{
- const auto *uk = get_implementation(ScaleSelectorData{ _input->info()->data_type() });
- uk->ukernel(_input, _output, _offsets, _dx, _dy, _policy, _border_mode, _constant_border_value, _sampling_offset, _align_corners, window);
+ const auto *uk = get_implementation(ScaleSelectorData{ src->info()->data_type() });
+ uk->ukernel(src, dst, offsets, dx, dy, _policy, _border_mode, _constant_border_value, _sampling_offset, _align_corners, window);
}
}
+
+const char *CpuScaleKernel::name() const
+{
+ return "CpuScaleKernel";
+}
+} // namespace kernels
+} // namespace cpu
} // namespace arm_compute
diff --git a/src/core/cpu/kernels/CpuScaleKernel.h b/src/core/cpu/kernels/CpuScaleKernel.h
new file mode 100644
index 0000000000..c1de8e0736
--- /dev/null
+++ b/src/core/cpu/kernels/CpuScaleKernel.h
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef ARM_COMPUTE_CPU_SCALEKERNEL_H
+#define ARM_COMPUTE_CPU_SCALEKERNEL_H
+
+#include "arm_compute/core/KernelDescriptors.h"
+#include "src/core/common/Macros.h"
+#include "src/core/cpu/ICpuKernel.h"
+
+namespace arm_compute
+{
+namespace cpu
+{
+namespace kernels
+{
+/** Arm(R) Neon(TM) kernel to perform scaling on a tensor */
+class CpuScaleKernel : public ICpuKernel
+{
+public:
+ /** Default constructor */
+ CpuScaleKernel();
+ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuScaleKernel);
+ /** Initialise the kernel's inputs, output and interpolation policy
+ *
+ * @note dx, dy and offsets have the same dimensions (width and height) of the output tensor
+ * @note Using @p policy Area only supports data layout NCHW and input data type U8.
+ *
+ * @param[in] src Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/U8/S16/F16/F32.
+ * @param[in] dx Distance x tensor info. Pixel's distance between the X real coordinate and the smallest X following integer. Data type supported: F32
+ * @param[in] dy Distance y tensor info. Pixel's distance between the Y real coordinate and the smallest Y following integer. Data type supported: F32
+ * @param[in] offsets Offset tensor info. Offset to access the pixel with NEAREST interpolation or the top-left pixel with BILINEAR interpolation in the input tensor. Data type supported: S32.
+ * @param[out] dst Destination tensor info. Data types supported: Same as @p input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane.
+ * @param[in] info @ref ScaleKernelInfo to use for configuration
+ */
+ void configure(const ITensorInfo *src, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *dst,
+ const ScaleKernelInfo &info);
+ /** Static function to check if given info will lead to a valid configuration of @ref CpuScaleKernel
+ *
+ * @note dx, dy and offsets have the same dimensions (width and height) of the output tensor
+ * @note Using @p policy Area only supports data layout NCHW and input data type U8.
+ *
+ * @param[in] src Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/U8/S16/F16/F32.
+ * @param[in] dx Distance x tensor info. Pixel's distance between the X real coordinate and the smallest X following integer. Data type supported: F32
+ * @param[in] dy Distance y tensor info. Pixel's distance between the Y real coordinate and the smallest Y following integer. Data type supported: F32
+ * @param[in] offsets Offset tensor info. Offset to access the pixel with NEAREST interpolation or the top-left pixel with BILINEAR interpolation in the input tensor. Data type supported: S32.
+ * @param[in] dst Destination tensor info. Data types supported: Same as @p input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane.
+ * @param[in] info @ref ScaleKernelInfo to use for validation
+ */
+ static Status validate(const ITensorInfo *src, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *dst,
+ const ScaleKernelInfo &info);
+
+ // Inherited methods overridden:
+ void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
+ const char *name() const override;
+
+private:
+#ifdef ENABLE_NCHW_KERNELS
+ /** function to perform scale using area interpolation on the given window
+ *
+ * @note Used only in case down-sampling.
+ */
+ void scale_area_nchw_u8(const ITensor *src, ITensor *dst, const ITensor *dx, const ITensor *dy, const ITensor *offsets, const Window &window);
+
+ /** function to perform scale using bilinear interpolation on the given window */
+ template <typename T>
+ void scale_bilinear_nchw(const ITensor *src, ITensor *dst, const ITensor *dx, const ITensor *dy, const ITensor *offsets, const Window &window);
+ /** function to perform scale using bilinear interpolation on the given window */
+ template <typename T>
+ void scale_bilinear_qasymm(const ITensor *src, ITensor *dst, const ITensor *dx, const ITensor *dy, const ITensor *offsets, const Window &window);
+
+ /** function to perform scale using nearest neighbour on the given window */
+ template <typename T>
+ void scale_nearest_nchw(const ITensor *src, ITensor *dst, const ITensor *dx, const ITensor *dy, const ITensor *offsets, const Window &window);
+#endif // ENABLE_NCHW_KERNELS
+
+ /** Scale function to use for the particular function to use */
+ using ScaleFunctionPtr = void (CpuScaleKernel::*)(const ITensor *, ITensor *, const ITensor *, const ITensor *, const ITensor *, const Window &window);
+
+ ScaleFunctionPtr _func;
+ InterpolationPolicy _policy;
+ BorderMode _border_mode;
+ PixelValue _constant_border_value;
+ float _sampling_offset;
+ bool _align_corners;
+ DataLayout _data_layout;
+};
+} // namespace kernels
+} // namespace cpu
+} // namespace arm_compute
+#endif /*ARM_COMPUTE_CPU_SCALEKERNEL_H */
diff --git a/src/core/NEON/kernels/scale/impl/NEON/fp16.cpp b/src/core/cpu/kernels/scale/neon/fp16.cpp
index 0ad66cab1c..0ad66cab1c 100644
--- a/src/core/NEON/kernels/scale/impl/NEON/fp16.cpp
+++ b/src/core/cpu/kernels/scale/neon/fp16.cpp
diff --git a/src/core/NEON/kernels/scale/impl/NEON/integer.cpp b/src/core/cpu/kernels/scale/neon/integer.cpp
index a2359aac94..a2359aac94 100644
--- a/src/core/NEON/kernels/scale/impl/NEON/integer.cpp
+++ b/src/core/cpu/kernels/scale/neon/integer.cpp
diff --git a/src/core/NEON/kernels/scale/impl/NEON/list.h b/src/core/cpu/kernels/scale/neon/list.h
index c91242f5b2..c91242f5b2 100644
--- a/src/core/NEON/kernels/scale/impl/NEON/list.h
+++ b/src/core/cpu/kernels/scale/neon/list.h
diff --git a/src/core/NEON/kernels/scale/impl/NEON/qasymm8.cpp b/src/core/cpu/kernels/scale/neon/qasymm8.cpp
index 536ad2cd17..90302ce889 100644
--- a/src/core/NEON/kernels/scale/impl/NEON/qasymm8.cpp
+++ b/src/core/cpu/kernels/scale/neon/qasymm8.cpp
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include "src/core/NEON/kernels/scale/impl/NEON/list.h"
+#include "src/core/cpu/kernels/scale/neon/list.h"
namespace arm_compute
{
@@ -31,13 +31,9 @@ void qasymm8_neon_scale_bilinear(const ITensor *src, ITensor *dst, const ITensor
BorderMode border_mode, PixelValue constant_border_value, float sampling_offset,
bool align_corners, const Window &window)
{
- // Get data layout and width/height indices
- const DataLayout data_layout = src->info()->data_layout();
- const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
- const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
-
+ // Data layout is NHWC
// Compute the ratio between source height and destination height
- const auto hr = scale_utils::calculate_resize_ratio(src->info()->dimension(idx_height), dst->info()->dimension(idx_height), align_corners);
+ const auto hr = scale_utils::calculate_resize_ratio(src->info()->dimension(2), dst->info()->dimension(2), align_corners);
Window win_off;
win_off.set(Window::DimX, Window::Dimension(0, 0, 0));
win_off.set(Window::DimY, Window::Dimension(0, 0, 0));
@@ -45,8 +41,8 @@ void qasymm8_neon_scale_bilinear(const ITensor *src, ITensor *dst, const ITensor
// Don't increment in X and Y direction for the input tensor
// A pointer to the start of this plane is needed as base for the precomputed offsets
Window win_in(window);
- win_in.set(idx_width, Window::Dimension(0, 0, 0));
- win_in.set(idx_height, Window::Dimension(0, 0, 0));
+ win_in.set(1, Window::Dimension(0, 0, 0));
+ win_in.set(2, Window::Dimension(0, 0, 0));
for(size_t d = Window::DimZ; d < offsets->info()->num_dimensions(); ++d)
{
@@ -56,10 +52,10 @@ void qasymm8_neon_scale_bilinear(const ITensor *src, ITensor *dst, const ITensor
Iterator in(src, win_in);
Iterator out(dst, window);
- const int32_t in_dim_w = src->info()->dimension(idx_width);
- const int32_t in_dim_h = src->info()->dimension(idx_height);
- const int32_t stride_w = src->info()->strides_in_bytes()[idx_width];
- const int32_t stride_h = src->info()->strides_in_bytes()[idx_height];
+ const int32_t in_dim_w = src->info()->dimension(1);
+ const int32_t in_dim_h = src->info()->dimension(2);
+ const int32_t stride_w = src->info()->strides_in_bytes()[1];
+ const int32_t stride_h = src->info()->strides_in_bytes()[2];
const UniformQuantizationInfo iq_info = src->info()->quantization_info().uniform();
const UniformQuantizationInfo oq_info = dst->info()->quantization_info().uniform();
@@ -69,10 +65,10 @@ void qasymm8_neon_scale_bilinear(const ITensor *src, ITensor *dst, const ITensor
const uint8_t const_border_value = static_cast<uint8_t>(constant_border_value.get<uint8_t>());
execute_window_loop(window, [&](const Coordinates & id)
{
- const int32_t index_h = std::floor((id[idx_height] + sampling_offset) * hr - sampling_offset);
- const int32_t index_w = *(reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dx_val = *(reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dy_val = *(reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
+ const int32_t index_h = std::floor((id[2] + sampling_offset) * hr - sampling_offset);
+ const int32_t index_w = *(reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id[1], id[2]))));
+ const auto dx_val = *(reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id[1], id[2]))));
+ const auto dy_val = *(reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id[1], id[2]))));
const auto pixel_row_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
const auto a00 = (0 <= index_w && index_w < in_dim_w && 0 <= index_h && index_h < in_dim_h) ?
@@ -100,10 +96,10 @@ void qasymm8_neon_scale_bilinear(const ITensor *src, ITensor *dst, const ITensor
{
execute_window_loop(window, [&](const Coordinates & id)
{
- const int index_h = std::floor((id[idx_height] + sampling_offset) * hr - sampling_offset);
- const int32_t index_w = *(reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dx_val = *(reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dy_val = *(reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
+ const int index_h = std::floor((id[2] + sampling_offset) * hr - sampling_offset);
+ const int32_t index_w = *(reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id[1], id[2]))));
+ const auto dx_val = *(reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id[1], id[2]))));
+ const auto dy_val = *(reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id[1], id[2]))));
const auto pixel_row_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
auto clamped_w = utility::clamp<int>(index_w, 0, in_dim_w - 1);
diff --git a/src/core/NEON/kernels/scale/impl/NEON/qasymm8_signed.cpp b/src/core/cpu/kernels/scale/neon/qasymm8_signed.cpp
index 149cdf478f..07d6c6ef03 100644
--- a/src/core/NEON/kernels/scale/impl/NEON/qasymm8_signed.cpp
+++ b/src/core/cpu/kernels/scale/neon/qasymm8_signed.cpp
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include "src/core/NEON/kernels/scale/impl/NEON/list.h"
+#include "src/core/cpu/kernels/scale/neon/list.h"
namespace arm_compute
{
@@ -31,13 +31,9 @@ void qasymm8_signed_neon_scale_bilinear(const ITensor *src, ITensor *dst, const
BorderMode border_mode, PixelValue constant_border_value, float sampling_offset,
bool align_corners, const Window &window)
{
- // Get data layout and width/height indices
- const DataLayout data_layout = src->info()->data_layout();
- const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
- const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
-
+ // Data layout is NHWC
// Compute the ratio between source height and destination height
- const auto hr = scale_utils::calculate_resize_ratio(src->info()->dimension(idx_height), dst->info()->dimension(idx_height), align_corners);
+ const auto hr = scale_utils::calculate_resize_ratio(src->info()->dimension(2), dst->info()->dimension(2), align_corners);
Window win_off;
win_off.set(Window::DimX, Window::Dimension(0, 0, 0));
win_off.set(Window::DimY, Window::Dimension(0, 0, 0));
@@ -45,8 +41,8 @@ void qasymm8_signed_neon_scale_bilinear(const ITensor *src, ITensor *dst, const
// Don't increment in X and Y direction for the input tensor
// A pointer to the start of this plane is needed as base for the precomputed offsets
Window win_in(window);
- win_in.set(idx_width, Window::Dimension(0, 0, 0));
- win_in.set(idx_height, Window::Dimension(0, 0, 0));
+ win_in.set(1, Window::Dimension(0, 0, 0));
+ win_in.set(2, Window::Dimension(0, 0, 0));
for(size_t d = Window::DimZ; d < offsets->info()->num_dimensions(); ++d)
{
@@ -56,10 +52,10 @@ void qasymm8_signed_neon_scale_bilinear(const ITensor *src, ITensor *dst, const
Iterator in(src, win_in);
Iterator out(dst, window);
- const int32_t in_dim_w = src->info()->dimension(idx_width);
- const int32_t in_dim_h = src->info()->dimension(idx_height);
- const int32_t stride_w = src->info()->strides_in_bytes()[idx_width];
- const int32_t stride_h = src->info()->strides_in_bytes()[idx_height];
+ const int32_t in_dim_w = src->info()->dimension(1);
+ const int32_t in_dim_h = src->info()->dimension(2);
+ const int32_t stride_w = src->info()->strides_in_bytes()[1];
+ const int32_t stride_h = src->info()->strides_in_bytes()[2];
const UniformQuantizationInfo iq_info = src->info()->quantization_info().uniform();
const UniformQuantizationInfo oq_info = dst->info()->quantization_info().uniform();
@@ -69,10 +65,10 @@ void qasymm8_signed_neon_scale_bilinear(const ITensor *src, ITensor *dst, const
const int8_t const_border_value = static_cast<int8_t>(constant_border_value.get<int8_t>());
execute_window_loop(window, [&](const Coordinates & id)
{
- const int32_t index_h = std::floor((id[idx_height] + sampling_offset) * hr - sampling_offset);
- const int32_t index_w = *(reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dx_val = *(reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dy_val = *(reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
+ const int32_t index_h = std::floor((id[2] + sampling_offset) * hr - sampling_offset);
+ const int32_t index_w = *(reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id[1], id[2]))));
+ const auto dx_val = *(reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id[1], id[2]))));
+ const auto dy_val = *(reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id[1], id[2]))));
const auto pixel_row_ptr = reinterpret_cast<const int8_t *>(in.ptr());
const auto a00 = (0 <= index_w && index_w < in_dim_w && 0 <= index_h && index_h < in_dim_h) ?
@@ -100,10 +96,10 @@ void qasymm8_signed_neon_scale_bilinear(const ITensor *src, ITensor *dst, const
{
execute_window_loop(window, [&](const Coordinates & id)
{
- const int index_h = std::floor((id[idx_height] + sampling_offset) * hr - sampling_offset);
- const int32_t index_w = *(reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dx_val = *(reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
- const auto dy_val = *(reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id[idx_width], id[idx_height]))));
+ const int index_h = std::floor((id[2] + sampling_offset) * hr - sampling_offset);
+ const int32_t index_w = *(reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id[1], id[2]))));
+ const auto dx_val = *(reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id[1], id[2]))));
+ const auto dy_val = *(reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id[1], id[2]))));
const auto pixel_row_ptr = reinterpret_cast<const int8_t *>(in.ptr());
auto clamped_w = utility::clamp<int>(index_w, 0, in_dim_w - 1);
diff --git a/src/core/NEON/kernels/scale/impl/SVE/fp16.cpp b/src/core/cpu/kernels/scale/sve/fp16.cpp
index 99f08dbdf9..99f08dbdf9 100644
--- a/src/core/NEON/kernels/scale/impl/SVE/fp16.cpp
+++ b/src/core/cpu/kernels/scale/sve/fp16.cpp
diff --git a/src/core/NEON/kernels/scale/impl/SVE/fp32.cpp b/src/core/cpu/kernels/scale/sve/fp32.cpp
index 94055ae953..94055ae953 100644
--- a/src/core/NEON/kernels/scale/impl/SVE/fp32.cpp
+++ b/src/core/cpu/kernels/scale/sve/fp32.cpp
diff --git a/src/core/NEON/kernels/scale/impl/SVE/integer.cpp b/src/core/cpu/kernels/scale/sve/integer.cpp
index 2a724ece31..2a724ece31 100644
--- a/src/core/NEON/kernels/scale/impl/SVE/integer.cpp
+++ b/src/core/cpu/kernels/scale/sve/integer.cpp
diff --git a/src/core/NEON/kernels/scale/impl/SVE/list.h b/src/core/cpu/kernels/scale/sve/list.h
index b9c3a10a78..b9c3a10a78 100644
--- a/src/core/NEON/kernels/scale/impl/SVE/list.h
+++ b/src/core/cpu/kernels/scale/sve/list.h
diff --git a/src/core/NEON/kernels/scale/impl/SVE/qasymm8.cpp b/src/core/cpu/kernels/scale/sve/qasymm8.cpp
index c475ad615c..c475ad615c 100644
--- a/src/core/NEON/kernels/scale/impl/SVE/qasymm8.cpp
+++ b/src/core/cpu/kernels/scale/sve/qasymm8.cpp
diff --git a/src/core/NEON/kernels/scale/impl/SVE/qasymm8_signed.cpp b/src/core/cpu/kernels/scale/sve/qasymm8_signed.cpp
index b39b75abba..b39b75abba 100644
--- a/src/core/NEON/kernels/scale/impl/SVE/qasymm8_signed.cpp
+++ b/src/core/cpu/kernels/scale/sve/qasymm8_signed.cpp