From d473386e4d5e0edcf55e13a2bf3c422a23fac0de Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Tue, 9 Jul 2019 14:21:06 +0100 Subject: COMPMID-2447: Align TFlite nearest neighbor NE/CL functions with ACL Change-Id: Idd7b23247491d6e2e31d19b2a8aa522470ca174c Signed-off-by: Michalis Spyrou Reviewed-on: https://review.mlplatform.org/c/1500 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas --- src/core/NEON/kernels/NEScaleKernel.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/core/NEON/kernels') diff --git a/src/core/NEON/kernels/NEScaleKernel.cpp b/src/core/NEON/kernels/NEScaleKernel.cpp index 4a51627a20..8e9a34637b 100644 --- a/src/core/NEON/kernels/NEScaleKernel.cpp +++ b/src/core/NEON/kernels/NEScaleKernel.cpp @@ -169,7 +169,7 @@ std::pair validate_and_configure_window(ITensorInfo *input, ITen template inline void scale_nearest_nhwc_core(const ITensor *input, const ITensor *offsets, ITensor *output, - float hr, Window window, const Window &win_in, size_t stride_w, size_t stride_h, size_t stride_c) + float hr, Window window, const Window &win_in, size_t stride_w, size_t stride_h, size_t stride_c, float sampling_offset) { const int window_step_x = 16 / sizeof(T); const auto window_start_x = static_cast(window.x().start()); @@ -185,7 +185,7 @@ inline void scale_nearest_nhwc_core(const ITensor *input, const ITensor *offsets execute_window_loop(window, [&](const Coordinates & id) { const int32_t offset = *reinterpret_cast(offsets->ptr_to_element(Coordinates(id.y(), id.z()))); - const int in_yi = (id.z() + 0.5f) * hr; + const int in_yi = std::floor((id.z() + sampling_offset) * hr); const int offset_row = in_yi * stride_h; int32_t x = window_start_x; for(; x < window_end_x - window_step_x; x += window_step_x) @@ -459,7 +459,7 @@ void NEScaleKernel::scale_nearest_nchw(const Window &window) const auto offsets_ptr = reinterpret_cast(offsets.ptr()); const uint8_t *const in_ptr = in.ptr(); - const int in_yi = std::floor((id.y() + 0.5f) * hr); + const int in_yi = std::floor((id.y() + _sampling_offset) * hr); const int in_yi_clamped = std::min(static_cast(_input->info()->dimension(1)), std::max(in_yi, -1)); ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast(_input->info()->dimension(1))); const int offset_row = in_yi_clamped * input_stride; @@ -500,7 +500,7 @@ void NEScaleKernel::scale_nearest_nchw(const Window &window) { const auto offsets_ptr = reinterpret_cast(offsets.ptr()); - const int in_yi = (id.y() + 0.5f) * hr; + const int in_yi = std::floor((id.y() + _sampling_offset) * hr); const int offset_row = in_yi * input_stride; tmp.val[0] = vsetq_lane_s16(*reinterpret_cast(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0); @@ -541,7 +541,7 @@ void NEScaleKernel::scale_nearest_nchw(const Window &window) { const auto offsets_ptr = reinterpret_cast(offsets.ptr()); - const int in_yi = (id.y() + 0.5f) * hr; + const int in_yi = std::floor((id.y() + _sampling_offset) * hr); const int offset_row = in_yi * input_stride; tmp.val[0] = vsetq_lane_f16(*reinterpret_cast(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0); @@ -584,7 +584,7 @@ void NEScaleKernel::scale_nearest_nchw(const Window &window) { const auto offsets_ptr = reinterpret_cast(offsets.ptr()); - const int in_yi = (id.y() + 0.5f) * hr; + const int in_yi = std::floor((id.y() + _sampling_offset) * hr); const int offset_row = in_yi * input_stride; tmp.val[0] = vsetq_lane_f32(*reinterpret_cast(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0); @@ -614,7 +614,6 @@ void NEScaleKernel::scale_nearest_nchw(const Window &window) } default: ARM_COMPUTE_ERROR("Not supported"); - break; } } @@ -936,7 +935,7 @@ void NEScaleKernel::scale_nhwc(const Window &window) { if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) { - scale_nearest_nhwc_core(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c); + scale_nearest_nhwc_core(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset); } else { @@ -949,7 +948,7 @@ void NEScaleKernel::scale_nhwc(const Window &window) { if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) { - scale_nearest_nhwc_core(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c); + scale_nearest_nhwc_core(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset); } else { @@ -964,7 +963,7 @@ void NEScaleKernel::scale_nhwc(const Window &window) if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) { scale_nearest_nhwc_core(_input, _offsets, _output, hr, - window, win_in, input_stride_w, input_stride_h, input_stride_c); + window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset); } else { @@ -978,7 +977,7 @@ void NEScaleKernel::scale_nhwc(const Window &window) { if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) { - scale_nearest_nhwc_core(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c); + scale_nearest_nhwc_core(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset); } else { -- cgit v1.2.1