aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/NEON/functions/NEScale.cpp
diff options
context:
space:
mode:
authorManuel Bottini <manuel.bottini@arm.com>2020-08-26 16:28:38 +0100
committerManuel Bottini <manuel.bottini@arm.com>2020-10-02 13:55:52 +0000
commitfc2f6d0427e1d886fcccc68867d1af1ccd96608b (patch)
tree7b8d65c9354f65fa92a6c15106ffc55f3c79403c /src/runtime/NEON/functions/NEScale.cpp
parent9aa05a67b58b65603fd52d76690a17a155e89030 (diff)
downloadComputeLibrary-fc2f6d0427e1d886fcccc68867d1af1ccd96608b.tar.gz
COMPMID-3145: Remove padding from NEScaleKernel
Change-Id: I530b12c6270d7dbeb3ef7af62484842ebcb65925 Signed-off-by: Manuel Bottini <manuel.bottini@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4000 Tested-by: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com> Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com>
Diffstat (limited to 'src/runtime/NEON/functions/NEScale.cpp')
-rw-r--r--src/runtime/NEON/functions/NEScale.cpp65
1 files changed, 16 insertions, 49 deletions
diff --git a/src/runtime/NEON/functions/NEScale.cpp b/src/runtime/NEON/functions/NEScale.cpp
index 424049f24a..2278f07a1c 100644
--- a/src/runtime/NEON/functions/NEScale.cpp
+++ b/src/runtime/NEON/functions/NEScale.cpp
@@ -44,7 +44,7 @@ namespace arm_compute
{
namespace
{
-void precompute_dx_dy_offsets(ITensor *dx, ITensor *dy, ITensor *offsets, float wr, float hr, size_t input_element_size, SamplingPolicy sampling_policy, bool align_corners)
+void precompute_dx_dy_offsets(ITensor *dx, ITensor *dy, ITensor *offsets, float wr, float hr, SamplingPolicy sampling_policy, bool align_corners)
{
ARM_COMPUTE_ERROR_ON(nullptr == offsets);
ARM_COMPUTE_UNUSED(sampling_policy);
@@ -72,7 +72,7 @@ void precompute_dx_dy_offsets(ITensor *dx, ITensor *dy, ITensor *offsets, float
const int in_xi = std::floor(in_x);
const int in_yi = std::floor(in_y);
- *reinterpret_cast<int32_t *>(offsets_it.ptr()) = in_xi * static_cast<int>(input_element_size);
+ *reinterpret_cast<int32_t *>(offsets_it.ptr()) = in_xi;
*reinterpret_cast<float *>(dx_it.ptr()) = in_x - in_xi;
*reinterpret_cast<float *>(dy_it.ptr()) = in_y - in_yi;
},
@@ -85,23 +85,17 @@ void precompute_dx_dy_offsets(ITensor *dx, ITensor *dy, ITensor *offsets, float
execute_window_loop(win, [&](const Coordinates & id)
{
- const float float_in_xi = (id.x() + sampling_offset) * wr;
- const auto in_xi = static_cast<size_t>(align_corners ? arm_compute::utils::rounding::round_half_away_from_zero(float_in_xi) : std::floor(float_in_xi));
-
- *reinterpret_cast<int32_t *>(offsets_it.ptr()) = in_xi * input_element_size;
+ const float float_in_xi = (id.x() + sampling_offset) * wr;
+ const auto in_xi = static_cast<size_t>(align_corners ? arm_compute::utils::rounding::round_half_away_from_zero(float_in_xi) : std::floor(float_in_xi));
+ *reinterpret_cast<int32_t *>(offsets_it.ptr()) = in_xi;
},
offsets_it);
}
}
} // namespace
-NEScale::NEScale() // NOLINT
- : _offsets(),
- _dx(),
- _dy(),
- _scale_kernel(),
- _border_handler(),
- _use_padding(true)
+NEScale::NEScale()
+ : _offsets(), _dx(), _dy()
{
}
@@ -110,7 +104,6 @@ void NEScale::configure(ITensor *input, ITensor *output, const ScaleKernelInfo &
ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
ARM_COMPUTE_ERROR_THROW_ON(NEScale::validate(input->info(), output->info(), info));
- _use_padding = info.use_padding;
const bool is_align_corners_used = info.align_corners && arm_compute::scale_utils::is_align_corners_allowed_sampling_policy(info.sampling_policy);
// Get data layout and width/height indices
@@ -119,18 +112,17 @@ void NEScale::configure(ITensor *input, ITensor *output, const ScaleKernelInfo &
const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
// Get the tensor shape
- const TensorShape shape(output->info()->dimension(idx_width), output->info()->dimension(idx_height));
+ TensorShape shape(output->info()->dimension(idx_width));
+ shape.set(1, output->info()->dimension(idx_height), false);
// Compute the ratio between source width/height and destination width/height
const auto wr = arm_compute::scale_utils::calculate_resize_ratio(input->info()->dimension(idx_width), output->info()->dimension(idx_width), is_align_corners_used);
const auto hr = arm_compute::scale_utils::calculate_resize_ratio(input->info()->dimension(idx_height), output->info()->dimension(idx_height), is_align_corners_used);
- // Get the element size of the input image
- const size_t input_element_size = input->info()->element_size();
-
// Area interpolation behaves as Nearest Neighbour in case of up-sampling
const auto policy_to_use = (info.interpolation_policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) ? InterpolationPolicy::NEAREST_NEIGHBOR : info.interpolation_policy;
+ auto scale_kernel = arm_compute::support::cpp14::make_unique<NEScaleKernel>();
switch(policy_to_use)
{
case InterpolationPolicy::NEAREST_NEIGHBOR:
@@ -138,13 +130,13 @@ void NEScale::configure(ITensor *input, ITensor *output, const ScaleKernelInfo &
TensorInfo tensor_info_offsets(shape, Format::S32);
_offsets.allocator()->init(tensor_info_offsets);
- _scale_kernel.configure(input, nullptr, nullptr, &_offsets, output, info);
+ scale_kernel->configure(input, nullptr, nullptr, &_offsets, output, info);
// Allocate once the configure methods have been called
_offsets.allocator()->allocate();
// Pre-compute offsets for nearest interpolation
- precompute_dx_dy_offsets(nullptr, nullptr, &_offsets, wr, hr, input_element_size, info.sampling_policy, is_align_corners_used);
+ precompute_dx_dy_offsets(nullptr, nullptr, &_offsets, wr, hr, info.sampling_policy, is_align_corners_used);
break;
}
case InterpolationPolicy::BILINEAR:
@@ -156,7 +148,7 @@ void NEScale::configure(ITensor *input, ITensor *output, const ScaleKernelInfo &
_dx.allocator()->init(tensor_info_dxdy);
_dy.allocator()->init(tensor_info_dxdy);
- _scale_kernel.configure(input, &_dx, &_dy, &_offsets, output, info);
+ scale_kernel->configure(input, &_dx, &_dy, &_offsets, output, info);
// Allocate once the configure methods have been called
_offsets.allocator()->allocate();
@@ -164,27 +156,18 @@ void NEScale::configure(ITensor *input, ITensor *output, const ScaleKernelInfo &
_dy.allocator()->allocate();
// Pre-compute dx, dy and offsets for bilinear interpolation
- precompute_dx_dy_offsets(&_dx, &_dy, &_offsets, wr, hr, input_element_size, info.sampling_policy, is_align_corners_used);
+ precompute_dx_dy_offsets(&_dx, &_dy, &_offsets, wr, hr, info.sampling_policy, is_align_corners_used);
break;
}
case InterpolationPolicy::AREA:
{
- _scale_kernel.configure(input, nullptr, nullptr, nullptr, output, info);
+ scale_kernel->configure(input, nullptr, nullptr, nullptr, output, info);
break;
}
default:
ARM_COMPUTE_ERROR("Unsupported interpolation mode");
}
- if(info.use_padding)
- {
- _border_handler.configure(input, _scale_kernel.border_size(), info.border_mode, info.constant_border_value);
- }
-}
-
-void NEScale::configure(ITensor *input, ITensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, bool use_padding,
- bool align_corners)
-{
- configure(input, output, ScaleKernelInfo{ policy, border_mode, constant_border_value, sampling_policy, use_padding, align_corners });
+ _kernel = std::move(scale_kernel);
}
Status NEScale::validate(const ITensorInfo *input, const ITensorInfo *output, const ScaleKernelInfo &info)
@@ -225,20 +208,4 @@ Status NEScale::validate(const ITensorInfo *input, const ITensorInfo *output, co
ARM_COMPUTE_RETURN_ON_ERROR(NEScaleKernel::validate(input->clone().get(), dx, dy, offsets, output->clone().get(), info));
return Status{};
}
-
-Status NEScale::validate(const ITensorInfo *input, const ITensorInfo *output, InterpolationPolicy policy,
- BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, bool use_padding, bool align_corners)
-{
- ARM_COMPUTE_RETURN_ON_ERROR(NEScale::validate(input, output, ScaleKernelInfo{ policy, border_mode, constant_border_value, sampling_policy, use_padding, align_corners }));
- return Status{};
-}
-
-void NEScale::run()
-{
- if(_use_padding)
- {
- NEScheduler::get().schedule(&_border_handler, Window::DimZ);
- }
- NEScheduler::get().schedule(&_scale_kernel, Window::DimY);
-}
} // namespace arm_compute