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 | |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 76 | { |
| 77 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClResizeWorkload_configure"); |
| 78 | m_ResizeLayer.configure(clCompileContext, |
| 79 | &input, |
| 80 | &output, |
| 81 | arm_compute::ScaleKernelInfo(aclInterpolationPolicy, |
| 82 | arm_compute::BorderMode::REPLICATE, |
| 83 | arm_compute::PixelValue(0.f), |
| 84 | samplingPolicy, |
| 85 | true, |
| 86 | descriptor.m_Parameters.m_AlignCorners)); |
| 87 | } |
David Monahan | 9b14bfc | 2020-06-30 15:57:56 +0100 | [diff] [blame] | 88 | |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | void ClResizeWorkload::Execute() const |
| 92 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 93 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClResizeWorkload_Execute", this->GetGuid()); |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 94 | RunClFunction(m_ResizeLayer, CHECK_LOCATION()); |
| 95 | } |
| 96 | |
| 97 | } //namespace armnn |