Ellen Norris-Thompson | 37e6868 | 2019-07-15 14:23:30 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "NeonResizeWorkload.hpp" |
| 7 | |
| 8 | #include "NeonWorkloadUtils.hpp" |
| 9 | |
| 10 | #include <aclCommon/ArmComputeUtils.hpp> |
| 11 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 12 | #include <armnn/utility/PolymorphicDowncast.hpp> |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 13 | #include <backendsCommon/TensorHandle.hpp> |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 14 | |
Ellen Norris-Thompson | 37e6868 | 2019-07-15 14:23:30 +0100 | [diff] [blame] | 15 | #include <neon/NeonTensorHandle.hpp> |
| 16 | |
| 17 | using namespace armnn::armcomputetensorutils; |
| 18 | |
| 19 | namespace armnn |
| 20 | { |
| 21 | |
| 22 | arm_compute::Status NeonResizeWorkloadValidate(const TensorInfo& input, |
| 23 | const TensorInfo& output, |
| 24 | const ResizeDescriptor& descriptor) |
| 25 | { |
| 26 | arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input); |
| 27 | arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output); |
| 28 | |
| 29 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(descriptor.m_DataLayout); |
| 30 | aclInputInfo.set_data_layout(aclDataLayout); |
| 31 | aclOutputInfo.set_data_layout(aclDataLayout); |
| 32 | |
| 33 | arm_compute::InterpolationPolicy aclInterpolationPolicy = |
| 34 | ConvertResizeMethodToAclInterpolationPolicy(descriptor.m_Method); |
| 35 | |
David Monahan | 9b14bfc | 2020-06-30 15:57:56 +0100 | [diff] [blame] | 36 | arm_compute::SamplingPolicy samplingPolicy = descriptor.m_HalfPixelCenters ? arm_compute::SamplingPolicy::CENTER : |
| 37 | arm_compute::SamplingPolicy::TOP_LEFT; |
| 38 | |
Teresa Charlin | ef05cdb | 2020-10-05 09:53:18 +0100 | [diff] [blame] | 39 | bool usePadding = false; |
| 40 | |
Ellen Norris-Thompson | 37e6868 | 2019-07-15 14:23:30 +0100 | [diff] [blame] | 41 | return arm_compute::NEScale::validate(&aclInputInfo, |
| 42 | &aclOutputInfo, |
David Monahan | 9b14bfc | 2020-06-30 15:57:56 +0100 | [diff] [blame] | 43 | arm_compute::ScaleKernelInfo(aclInterpolationPolicy, |
| 44 | arm_compute::BorderMode::REPLICATE, |
| 45 | arm_compute::PixelValue(0.f), |
| 46 | samplingPolicy, |
Teresa Charlin | ef05cdb | 2020-10-05 09:53:18 +0100 | [diff] [blame] | 47 | usePadding, |
David Monahan | 9b14bfc | 2020-06-30 15:57:56 +0100 | [diff] [blame] | 48 | descriptor.m_AlignCorners)); |
| 49 | |
Ellen Norris-Thompson | 37e6868 | 2019-07-15 14:23:30 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | NeonResizeWorkload::NeonResizeWorkload(const ResizeQueueDescriptor& descriptor, |
| 53 | const WorkloadInfo& info) |
| 54 | : BaseWorkload<ResizeQueueDescriptor>(descriptor, info) |
| 55 | { |
| 56 | m_Data.ValidateInputsOutputs("NeonResizeWorkload", 1, 1); |
| 57 | |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 58 | arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 59 | arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
Ellen Norris-Thompson | 37e6868 | 2019-07-15 14:23:30 +0100 | [diff] [blame] | 60 | |
| 61 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 62 | input.info()->set_data_layout(aclDataLayout); |
| 63 | output.info()->set_data_layout(aclDataLayout); |
| 64 | |
| 65 | arm_compute::InterpolationPolicy aclInterpolationPolicy = |
| 66 | ConvertResizeMethodToAclInterpolationPolicy(descriptor.m_Parameters.m_Method); |
| 67 | |
David Monahan | 9b14bfc | 2020-06-30 15:57:56 +0100 | [diff] [blame] | 68 | arm_compute::SamplingPolicy samplingPolicy = descriptor.m_Parameters.m_HalfPixelCenters |
| 69 | ? arm_compute::SamplingPolicy::CENTER |
| 70 | : arm_compute::SamplingPolicy::TOP_LEFT; |
| 71 | |
Teresa Charlin | ef05cdb | 2020-10-05 09:53:18 +0100 | [diff] [blame] | 72 | bool usePadding = false; |
| 73 | |
Ellen Norris-Thompson | 37e6868 | 2019-07-15 14:23:30 +0100 | [diff] [blame] | 74 | m_ResizeLayer.configure(&input, |
| 75 | &output, |
David Monahan | 9b14bfc | 2020-06-30 15:57:56 +0100 | [diff] [blame] | 76 | arm_compute::ScaleKernelInfo(aclInterpolationPolicy, |
| 77 | arm_compute::BorderMode::REPLICATE, |
| 78 | arm_compute::PixelValue(0.f), |
| 79 | samplingPolicy, |
Teresa Charlin | ef05cdb | 2020-10-05 09:53:18 +0100 | [diff] [blame] | 80 | usePadding, |
David Monahan | 9b14bfc | 2020-06-30 15:57:56 +0100 | [diff] [blame] | 81 | descriptor.m_Parameters.m_AlignCorners)); |
Ellen Norris-Thompson | 37e6868 | 2019-07-15 14:23:30 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | void NeonResizeWorkload::Execute() const |
| 85 | { |
| 86 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonResizeWorkload_Execute"); |
| 87 | m_ResizeLayer.run(); |
| 88 | } |
| 89 | |
| 90 | } //namespace armnn |