ArmNN
 24.02
NeonTransposeConvolution2dWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
6 
7 #include "NeonWorkloadUtils.hpp"
8 
9 #include <Profiling.hpp>
10 
11 #include <armnn/Types.hpp>
13 
15 
17 
19 
20 namespace armnn
21 {
22 
23 using namespace armcomputetensorutils;
24 
26  const TensorInfo& output,
27  const TransposeConvolution2dDescriptor& descriptor,
28  const TensorInfo& weights,
29  const Optional<TensorInfo>& biases)
30 {
31  const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
32  const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout);
33  const arm_compute::TensorInfo aclWeightsInfo = BuildArmComputeTensorInfo(weights, descriptor.m_DataLayout);
34 
35  arm_compute::TensorInfo aclBiasesInfo;
36  arm_compute::TensorInfo *optionalAclBiasesInfo = nullptr;
37 
38  if (descriptor.m_BiasEnabled)
39  {
40  ARMNN_ASSERT(biases.has_value());
41 
42  aclBiasesInfo = BuildArmComputeTensorInfo(biases.value(), descriptor.m_DataLayout);
43  optionalAclBiasesInfo = &aclBiasesInfo;
44  }
45 
46  arm_compute::PadStrideInfo layerInfo = BuildArmComputePadStrideInfo(descriptor);
47 
48  return arm_compute::NEDeconvolutionLayer::validate(&aclInputInfo,
49  &aclWeightsInfo,
50  optionalAclBiasesInfo,
51  &aclOutputInfo,
52  layerInfo);
53 }
54 
56  const TransposeConvolution2dQueueDescriptor& descriptor, const WorkloadInfo& info,
57  std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
59 {
60  m_Data.ValidateInputsOutputs("NeonTransposeConvolution2dWorkload", 1, 1);
61 
62  arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
63  arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(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  m_KernelTensor = std::make_unique<arm_compute::Tensor>();
70  BuildArmComputeTensor(*m_KernelTensor, m_Data.m_Weight->GetTensorInfo(), m_Data.m_Parameters.m_DataLayout);
71 
73  {
74  m_BiasTensor = std::make_unique<arm_compute::Tensor>();
75  BuildArmComputeTensor(*m_BiasTensor, m_Data.m_Bias->GetTensorInfo(), m_Data.m_Parameters.m_DataLayout);
76  }
77 
78  arm_compute::PadStrideInfo padStrideInfo = BuildArmComputePadStrideInfo(m_Data.m_Parameters);
79 
80  // Add details for profiling output
81  WorkloadInfo detailsInfo;
82 
83  detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos;
84  detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos;
86  if (descriptor.m_Parameters.m_BiasEnabled)
87  {
89  }
90 
91  // Report Profiling Details
92  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonTransposeConvolution2dWorkload_Construct",
93  descriptor.m_Parameters,
94  detailsInfo,
95  this->GetGuid());
96 
97  m_Layer = std::make_unique<arm_compute::NEDeconvolutionLayer>(memoryManager);
98  m_Layer->configure(&input, m_KernelTensor.get(), m_BiasTensor.get(), &output, padStrideInfo);
99 
100  ARMNN_ASSERT(m_Layer);
101 
103 
105  {
107  }
108 
109  m_Layer->prepare();
110  FreeUnusedTensors();
111 }
112 
114 {
115  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonTransposeConvolution2dWorkload_Execute");
116  m_Layer->run();
117 }
118 
119 void NeonTransposeConvolution2dWorkload::FreeUnusedTensors()
120 {
121  FreeTensorIfUnused(m_KernelTensor);
122  FreeTensorIfUnused(m_BiasTensor);
123 }
124 
125 } // namespace armnn
ARMNN_ASSERT
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
armnn::Optional
Definition: Optional.hpp:270
armnn::DataLayout
DataLayout
Definition: Types.hpp:62
armnn::QueueDescriptor::ValidateInputsOutputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Definition: WorkloadData.cpp:446
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::TransposeConvolution2dQueueDescriptor::m_Weight
const ConstTensorHandle * m_Weight
Definition: WorkloadData.hpp:551
Profiling.hpp
armnn::ConstTensorHandle::GetTensorInfo
const TensorInfo & GetTensorInfo() const
Definition: TensorHandle.hpp:40
armnn::InitializeArmComputeTensorData
void InitializeArmComputeTensorData(arm_compute::Tensor &tensor, TensorInfo tensorInfo, const ITensorHandle *handle)
Definition: NeonWorkloadUtils.hpp:68
armnn::WorkloadInfo::m_OutputTensorInfos
std::vector< TensorInfo > m_OutputTensorInfos
Definition: WorkloadInfo.hpp:19
armnn::QueueDescriptorWithParameters::m_Parameters
LayerDescriptor m_Parameters
Definition: WorkloadData.hpp:66
armnn::NeonTransposeConvolution2dWorkload::Execute
void Execute() const override
Definition: NeonTransposeConvolution2dWorkload.cpp:113
armnn::WorkloadInfo::m_WeightsTensorInfo
Optional< TensorInfo > m_WeightsTensorInfo
Definition: WorkloadInfo.hpp:21
armnn::WorkloadInfo::m_BiasTensorInfo
Optional< TensorInfo > m_BiasTensorInfo
Definition: WorkloadInfo.hpp:22
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.hpp
armnn::TransposeConvolution2dQueueDescriptor::m_Bias
const ConstTensorHandle * m_Bias
Definition: WorkloadData.hpp:552
armnn::BoostLogSeverityMapping::info
@ info
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::TransposeConvolution2dQueueDescriptor
Definition: WorkloadData.hpp:544
NeonTransposeConvolution2dWorkload.hpp
ARMNN_REPORT_PROFILING_WORKLOAD_DESC
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
armnn::BaseWorkload< TransposeConvolution2dQueueDescriptor >::m_Data
TransposeConvolution2dQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::WorkloadInfo::m_InputTensorInfos
std::vector< TensorInfo > m_InputTensorInfos
Definition: WorkloadInfo.hpp:18
NeonWorkloadUtils.hpp
armnn::NeonTransposeConvolution2dWorkload::NeonTransposeConvolution2dWorkload
NeonTransposeConvolution2dWorkload(const TransposeConvolution2dQueueDescriptor &descriptor, const WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager)
Definition: NeonTransposeConvolution2dWorkload.cpp:55
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::TransposeConvolution2dDescriptor
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
Definition: Descriptors.hpp:1440
Types.hpp
ArmComputeTensorUtils.hpp
armnn::TransposeConvolution2dDescriptor::m_BiasEnabled
bool m_BiasEnabled
Enable/disable bias.
Definition: Descriptors.hpp:1481
armnn::TransposeConvolution2dDescriptor::m_DataLayout
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Definition: Descriptors.hpp:1483
ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: NeonWorkloadUtils.hpp:32
armnn::NeonBaseWorkload
Definition: NeonBaseWorkload.hpp:13
armnn::OptionalReferenceSwitch< std::is_reference< T >::value, T >::value
const T & value() const
Definition: Optional.hpp:146
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26
armnn::OptionalBase::has_value
bool has_value() const noexcept
Definition: Optional.hpp:53
armnn::NeonTransposeConvolution2dWorkloadValidate
arm_compute::Status NeonTransposeConvolution2dWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const TransposeConvolution2dDescriptor &descriptor, const TensorInfo &weights, const Optional< TensorInfo > &biases)
Definition: NeonTransposeConvolution2dWorkload.cpp:25