Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClResizeWorkload.hpp" |
| 7 | |
| 8 | #include "ClWorkloadUtils.hpp" |
| 9 | |
| 10 | #include <aclCommon/ArmComputeUtils.hpp> |
| 11 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 12 | |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 13 | #include <backendsCommon/TensorHandle.hpp> |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 14 | |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 15 | #include <cl/ClTensorHandle.hpp> |
| 16 | |
| 17 | using namespace armnn::armcomputetensorutils; |
| 18 | |
| 19 | namespace armnn |
| 20 | { |
| 21 | |
| 22 | arm_compute::Status ClResizeWorkloadValidate(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 | |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 39 | return arm_compute::CLScale::validate(&aclInputInfo, |
| 40 | &aclOutputInfo, |
David Monahan | 9b14bfc | 2020-06-30 15:57:56 +0100 | [diff] [blame] | 41 | arm_compute::ScaleKernelInfo(aclInterpolationPolicy, |
| 42 | arm_compute::BorderMode::REPLICATE, |
| 43 | arm_compute::PixelValue(0.f), |
| 44 | samplingPolicy, |
| 45 | true, |
| 46 | descriptor.m_AlignCorners)); |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 47 | } |
| 48 | |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 49 | ClResizeWorkload::ClResizeWorkload(const ResizeQueueDescriptor& descriptor, |
| 50 | const WorkloadInfo& info, |
| 51 | const arm_compute::CLCompileContext& clCompileContext) |
| 52 | : BaseWorkload<ResizeQueueDescriptor>(descriptor, info) |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 53 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 54 | // Report Profiling Details |
| 55 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClResizeWorkload_Construct", |
| 56 | descriptor.m_Parameters, |
| 57 | info, |
| 58 | this->GetGuid()); |
| 59 | |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 60 | m_Data.ValidateInputsOutputs("ClResizeWorkload", 1, 1); |
| 61 | |
| 62 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 63 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 64 | |
| 65 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 66 | input.info()->set_data_layout(aclDataLayout); |
| 67 | output.info()->set_data_layout(aclDataLayout); |
| 68 | |
| 69 | arm_compute::InterpolationPolicy aclInterpolationPolicy = |
| 70 | ConvertResizeMethodToAclInterpolationPolicy(descriptor.m_Parameters.m_Method); |
| 71 | |
David Monahan | 9b14bfc | 2020-06-30 15:57:56 +0100 | [diff] [blame] | 72 | arm_compute::SamplingPolicy samplingPolicy = descriptor.m_Parameters.m_HalfPixelCenters |
| 73 | ? arm_compute::SamplingPolicy::CENTER |
| 74 | : arm_compute::SamplingPolicy::TOP_LEFT; |
| 75 | |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 76 | m_ResizeLayer.configure(clCompileContext, |
| 77 | &input, |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 78 | &output, |
David Monahan | 9b14bfc | 2020-06-30 15:57:56 +0100 | [diff] [blame] | 79 | arm_compute::ScaleKernelInfo(aclInterpolationPolicy, |
| 80 | arm_compute::BorderMode::REPLICATE, |
| 81 | arm_compute::PixelValue(0.f), |
| 82 | samplingPolicy, |
| 83 | true, |
| 84 | descriptor.m_Parameters.m_AlignCorners)); |
| 85 | |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | void ClResizeWorkload::Execute() const |
| 89 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 90 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClResizeWorkload_Execute", this->GetGuid()); |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 91 | RunClFunction(m_ResizeLayer, CHECK_LOCATION()); |
| 92 | } |
| 93 | |
| 94 | } //namespace armnn |