From 0eed305680ade0c48d07f592c4c4a8aaaad077b7 Mon Sep 17 00:00:00 2001 From: Gunes Bayir Date: Sun, 4 Sep 2022 21:00:10 +0100 Subject: =?UTF-8?q?Optimize=20FP32/16=20Bilinear=20Scale=20Kernel=20for=20?= =?UTF-8?q?Neon=E2=84=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch removes index and weight pre-computations where it's not used and reduces some calculations inside the inner-most loop of Scale. Resolves: COMPMID-5452 Change-Id: Ie149b1b76a90a8cb659ada0f97aef78caf69932f Signed-off-by: Gunes Bayir Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/8220 Benchmark: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Gian Marco Iodice Comments-Addressed: Arm Jenkins --- src/runtime/NEON/functions/NEScale.cpp | 58 ++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 23 deletions(-) (limited to 'src/runtime/NEON') diff --git a/src/runtime/NEON/functions/NEScale.cpp b/src/runtime/NEON/functions/NEScale.cpp index 9f48e78a5a..74ab860d91 100644 --- a/src/runtime/NEON/functions/NEScale.cpp +++ b/src/runtime/NEON/functions/NEScale.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2021 Arm Limited. + * Copyright (c) 2016-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -75,34 +75,46 @@ void NEScale::configure(ITensor *input, ITensor *output, const ScaleKernelInfo & TensorShape shape(output->info()->dimension(idx_width)); shape.set(1, output->info()->dimension(idx_height), false); - const TensorInfo tensor_info_dxdy(shape, Format::F32); - const TensorInfo tensor_info_offsets(shape, Format::S32); + bool precompute_indices_weights = arm_compute::scale_utils::is_precomputation_required(data_layout, input->info()->data_type(), policy_to_use); - _impl->dx.allocator()->init(tensor_info_dxdy); - _impl->dy.allocator()->init(tensor_info_dxdy); - _impl->offsets.allocator()->init(tensor_info_offsets); - switch(policy_to_use) + if(precompute_indices_weights == true) { - case InterpolationPolicy::NEAREST_NEIGHBOR: - { - // Allocate once the configure methods have been called - _impl->offsets.allocator()->allocate(); - break; - } - case InterpolationPolicy::BILINEAR: + const TensorInfo tensor_info_dxdy(shape, Format::F32); + const TensorInfo tensor_info_offsets(shape, Format::S32); + + _impl->dx.allocator()->init(tensor_info_dxdy); + _impl->dy.allocator()->init(tensor_info_dxdy); + _impl->offsets.allocator()->init(tensor_info_offsets); + switch(policy_to_use) { - // Allocate once the configure methods have been called - _impl->dx.allocator()->allocate(); - _impl->dy.allocator()->allocate(); - _impl->offsets.allocator()->allocate(); - break; + case InterpolationPolicy::NEAREST_NEIGHBOR: + { + // Allocate once the configure methods have been called + _impl->offsets.allocator()->allocate(); + break; + } + case InterpolationPolicy::BILINEAR: + { + // Allocate once the configure methods have been called + _impl->dx.allocator()->allocate(); + _impl->dy.allocator()->allocate(); + _impl->offsets.allocator()->allocate(); + break; + } + case InterpolationPolicy::AREA: + { + break; + } + default: + ARM_COMPUTE_ERROR("Unsupported interpolation mode"); } - case InterpolationPolicy::AREA: + } + else + { + if(policy_to_use != InterpolationPolicy::NEAREST_NEIGHBOR && policy_to_use != InterpolationPolicy::BILINEAR && policy_to_use != InterpolationPolicy::AREA) { - break; - } - default: ARM_COMPUTE_ERROR("Unsupported interpolation mode"); + } } } -- cgit v1.2.1