Sadik Armagan | 581742d | 2019-08-12 14:11:37 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | #include "NeonTransposeConvolution2dWorkload.hpp" |
| 6 | |
| 7 | #include "NeonWorkloadUtils.hpp" |
| 8 | |
| 9 | #include <Profiling.hpp> |
| 10 | |
| 11 | #include <armnn/Types.hpp> |
| 12 | |
| 13 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 14 | |
| 15 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 16 | |
| 17 | #include <neon/workloads/NeonWorkloadUtils.hpp> |
| 18 | |
| 19 | #include <boost/cast.hpp> |
| 20 | |
| 21 | namespace armnn |
| 22 | { |
| 23 | |
| 24 | using namespace armcomputetensorutils; |
| 25 | |
| 26 | arm_compute::Status NeonTransposeConvolution2dWorkloadValidate(const TensorInfo& input, |
| 27 | const TensorInfo& output, |
| 28 | const TransposeConvolution2dDescriptor& descriptor, |
| 29 | const TensorInfo& weights, |
| 30 | const Optional<TensorInfo>& biases) |
| 31 | { |
| 32 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout); |
| 33 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
| 34 | const 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 | { |
| 41 | BOOST_ASSERT(biases.has_value()); |
| 42 | |
| 43 | aclBiasesInfo = BuildArmComputeTensorInfo(biases.value(), descriptor.m_DataLayout); |
| 44 | optionalAclBiasesInfo = &aclBiasesInfo; |
| 45 | } |
| 46 | |
| 47 | arm_compute::PadStrideInfo layerInfo = BuildArmComputePadStrideInfo(descriptor); |
| 48 | |
| 49 | return arm_compute::NEDeconvolutionLayer::validate(&aclInputInfo, |
| 50 | &aclWeightsInfo, |
| 51 | optionalAclBiasesInfo, |
| 52 | &aclOutputInfo, |
| 53 | layerInfo); |
| 54 | } |
| 55 | |
| 56 | NeonTransposeConvolution2dWorkload::NeonTransposeConvolution2dWorkload( |
| 57 | const TransposeConvolution2dQueueDescriptor& descriptor, const WorkloadInfo& info, |
| 58 | std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) |
| 59 | : BaseWorkload<TransposeConvolution2dQueueDescriptor>(descriptor, info) |
| 60 | { |
| 61 | m_Data.ValidateInputsOutputs("NeonTransposeConvolution2dWorkload", 1, 1); |
| 62 | |
| 63 | arm_compute::ITensor& input = boost::polymorphic_downcast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 64 | arm_compute::ITensor& output = boost::polymorphic_downcast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 65 | |
| 66 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 67 | input.info()->set_data_layout(aclDataLayout); |
| 68 | output.info()->set_data_layout(aclDataLayout); |
| 69 | |
| 70 | m_KernelTensor = std::make_unique<arm_compute::Tensor>(); |
| 71 | BuildArmComputeTensor(*m_KernelTensor, m_Data.m_Weight->GetTensorInfo(), m_Data.m_Parameters.m_DataLayout); |
| 72 | |
| 73 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 74 | { |
| 75 | m_BiasTensor = std::make_unique<arm_compute::Tensor>(); |
| 76 | BuildArmComputeTensor(*m_BiasTensor, m_Data.m_Bias->GetTensorInfo(), m_Data.m_Parameters.m_DataLayout); |
| 77 | } |
| 78 | |
| 79 | arm_compute::PadStrideInfo padStrideInfo = BuildArmComputePadStrideInfo(m_Data.m_Parameters); |
| 80 | |
| 81 | m_Layer = std::make_unique<arm_compute::NEDeconvolutionLayer>(memoryManager); |
| 82 | m_Layer->configure(&input, m_KernelTensor.get(), m_BiasTensor.get(), &output, padStrideInfo); |
| 83 | |
| 84 | BOOST_ASSERT(m_Layer); |
| 85 | |
| 86 | InitializeArmComputeTensorData(*m_KernelTensor, m_Data.m_Weight); |
| 87 | |
| 88 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 89 | { |
| 90 | InitializeArmComputeTensorData(*m_BiasTensor, m_Data.m_Bias); |
| 91 | } |
| 92 | |
| 93 | m_Layer->prepare(); |
| 94 | FreeUnusedTensors(); |
| 95 | } |
| 96 | |
| 97 | void NeonTransposeConvolution2dWorkload::Execute() const |
| 98 | { |
| 99 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonTransposeConvolution2dWorkload_Execute"); |
| 100 | m_Layer->run(); |
| 101 | } |
| 102 | |
| 103 | void NeonTransposeConvolution2dWorkload::FreeUnusedTensors() |
| 104 | { |
| 105 | FreeTensorIfUnused(m_KernelTensor); |
| 106 | FreeTensorIfUnused(m_BiasTensor); |
| 107 | } |
| 108 | |
| 109 | } // namespace armnn |