ArmNN
 24.08
NeonTransposeConvolution2dWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019-2024 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  {
41  biases.has_value(),
42  "NeonTransposeConvolution2dWorkload: Bias was enabled in the descriptor but no value was supplied.");
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 
57  const TransposeConvolution2dQueueDescriptor& descriptor, const WorkloadInfo& info,
58  std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
60 {
61  m_Data.ValidateInputsOutputs("NeonTransposeConvolution2dWorkload", 1, 1);
62 
63  arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
64  arm_compute::ITensor& output = PolymorphicDowncast<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 
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  // Add details for profiling output
82  WorkloadInfo detailsInfo;
83 
84  detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos;
85  detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos;
87  if (descriptor.m_Parameters.m_BiasEnabled)
88  {
90  }
91 
92  // Report Profiling Details
93  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonTransposeConvolution2dWorkload_Construct",
94  descriptor.m_Parameters,
95  detailsInfo,
96  this->GetGuid());
97 
98  m_Layer = std::make_unique<arm_compute::NEDeconvolutionLayer>(memoryManager);
99  m_Layer->configure(&input, m_KernelTensor.get(), m_BiasTensor.get(), &output, padStrideInfo);
100 
102 
104  {
106  }
107 
108  m_Layer->prepare();
109  FreeUnusedTensors();
110 }
111 
113 {
114  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonTransposeConvolution2dWorkload_Execute");
115  m_Layer->run();
116 }
117 
118 void NeonTransposeConvolution2dWorkload::FreeUnusedTensors()
119 {
120  FreeTensorIfUnused(m_KernelTensor);
121  FreeTensorIfUnused(m_BiasTensor);
122 }
123 
124 } // namespace armnn
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:447
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:69
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:112
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:56
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:33
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
ARMNN_THROW_INVALIDARG_MSG_IF_FALSE
#define ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(_cond, _str)
Definition: Exceptions.hpp:210