Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClTransposeConvolution2dWorkload.hpp" |
| 7 | |
| 8 | #include "ClWorkloadUtils.hpp" |
| 9 | |
| 10 | #include <cl/ClLayerSupport.hpp> |
| 11 | #include <cl/ClTensorHandle.hpp> |
| 12 | #include <cl/ClLayerSupport.hpp> |
| 13 | |
| 14 | #include <aclCommon/ArmComputeUtils.hpp> |
| 15 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 16 | |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 17 | #include <backendsCommon/TensorHandle.hpp> |
Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 18 | |
| 19 | #include <arm_compute/runtime/CL/functions/CLDeconvolutionLayer.h> |
| 20 | |
| 21 | namespace armnn |
| 22 | { |
| 23 | |
| 24 | using namespace armcomputetensorutils; |
| 25 | |
| 26 | arm_compute::Status ClTransposeConvolution2dWorkloadValidate(const TensorInfo& input, |
| 27 | const TensorInfo& output, |
| 28 | const TransposeConvolution2dDescriptor& descriptor, |
| 29 | const TensorInfo& weights, |
| 30 | const Optional<TensorInfo>& biases) |
| 31 | { |
| 32 | arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout); |
| 33 | arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
| 34 | arm_compute::TensorInfo aclWeightsInfo = BuildArmComputeTensorInfo(weights, descriptor.m_DataLayout); |
| 35 | |
| 36 | arm_compute::TensorInfo aclBiasesInfo; |
| 37 | arm_compute::TensorInfo *optionalAclBiasesInfo = nullptr; |
| 38 | |
| 39 | if (descriptor.m_BiasEnabled) |
| 40 | { |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 41 | ARMNN_ASSERT(biases.has_value()); |
Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 42 | |
| 43 | aclBiasesInfo = BuildArmComputeTensorInfo(biases.value(), descriptor.m_DataLayout); |
| 44 | optionalAclBiasesInfo = &aclBiasesInfo; |
| 45 | } |
| 46 | |
| 47 | arm_compute::PadStrideInfo padStrideInfo = BuildArmComputePadStrideInfo(descriptor); |
| 48 | |
Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 49 | return arm_compute::CLDeconvolutionLayer::validate(&aclInputInfo, |
| 50 | &aclWeightsInfo, |
| 51 | optionalAclBiasesInfo, |
| 52 | &aclOutputInfo, |
Nikhil Raj | b6a9ecc | 2019-07-15 15:08:22 +0100 | [diff] [blame] | 53 | padStrideInfo); |
Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | ClTransposeConvolution2dWorkload::ClTransposeConvolution2dWorkload( |
| 57 | const TransposeConvolution2dQueueDescriptor& descriptor, |
| 58 | const WorkloadInfo& info, |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 59 | std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager, |
| 60 | const arm_compute::CLCompileContext& clCompileContext) : |
Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 61 | BaseWorkload<TransposeConvolution2dQueueDescriptor>(descriptor, info), |
| 62 | m_Layer(memoryManager) |
| 63 | { |
| 64 | const TensorInfo& weightInfo = m_Data.m_Weight->GetTensorInfo(); |
| 65 | |
| 66 | m_WeightsTensor = std::make_unique<arm_compute::CLTensor>(); |
| 67 | BuildArmComputeTensor(*m_WeightsTensor, weightInfo, m_Data.m_Parameters.m_DataLayout); |
| 68 | |
Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 69 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 70 | { |
| 71 | m_BiasesTensor = std::make_unique<arm_compute::CLTensor>(); |
| 72 | BuildArmComputeTensor(*m_BiasesTensor, m_Data.m_Bias->GetTensorInfo(), m_Data.m_Parameters.m_DataLayout); |
| 73 | } |
| 74 | |
| 75 | m_Data.ValidateInputsOutputs("ClTransposeConvolution2dWorkload", 1, 1); |
| 76 | |
| 77 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 78 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 79 | |
| 80 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 81 | |
| 82 | input.info()->set_data_layout(aclDataLayout); |
| 83 | output.info()->set_data_layout(aclDataLayout); |
| 84 | |
Aron Virginas-Tar | 6f3785d | 2019-07-22 15:30:22 +0100 | [diff] [blame] | 85 | arm_compute::PadStrideInfo padStrideInfo = BuildArmComputePadStrideInfo(m_Data.m_Parameters); |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 86 | m_Layer.configure(clCompileContext, &input, m_WeightsTensor.get(), m_BiasesTensor.get(), &output, padStrideInfo); |
Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 87 | |
| 88 | InitializeArmComputeClTensorData(*m_WeightsTensor, m_Data.m_Weight); |
| 89 | if (m_BiasesTensor) |
| 90 | { |
| 91 | InitializeArmComputeClTensorData(*m_BiasesTensor, m_Data.m_Bias); |
| 92 | } |
| 93 | |
| 94 | m_Layer.prepare(); |
| 95 | |
| 96 | FreeUnusedTensors(); |
| 97 | } |
| 98 | |
| 99 | void ClTransposeConvolution2dWorkload::Execute() const |
| 100 | { |
| 101 | ARMNN_SCOPED_PROFILING_EVENT_CL("ClTransposeConvolution2dWorkload_Execute"); |
| 102 | RunClFunction(m_Layer, CHECK_LOCATION()); |
| 103 | } |
| 104 | |
| 105 | void ClTransposeConvolution2dWorkload::FreeUnusedTensors() |
| 106 | { |
| 107 | FreeTensorIfUnused(m_WeightsTensor); |
| 108 | FreeTensorIfUnused(m_BiasesTensor); |
| 109 | } |
| 110 | |
| 111 | } // namespace armnn |