ArmNN
 25.11
Loading...
Searching...
No Matches
ClTransposeConvolution2dWorkload.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//
5
7
8#include "ClWorkloadUtils.hpp"
9
10#include <cl/ClLayerSupport.hpp>
11#include <cl/ClTensorHandle.hpp>
12#include <cl/ClLayerSupport.hpp>
13
16
18
19#include <arm_compute/runtime/CL/functions/CLDeconvolutionLayer.h>
20
21namespace armnn
22{
23
24using namespace armcomputetensorutils;
25
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 {
41 if (!biases.has_value())
42 {
43 return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR,
44 "ArmNN ClTransposeConv2dWorkload has empty bias value."};
45 }
46 aclBiasesInfo = BuildArmComputeTensorInfo(biases.value(), descriptor.m_DataLayout);
47 optionalAclBiasesInfo = &aclBiasesInfo;
48 }
49
50 arm_compute::PadStrideInfo padStrideInfo = BuildArmComputePadStrideInfo(descriptor);
51
52 return arm_compute::CLDeconvolutionLayer::validate(&aclInputInfo,
53 &aclWeightsInfo,
54 optionalAclBiasesInfo,
55 &aclOutputInfo,
56 padStrideInfo);
57}
58
61 const WorkloadInfo& info,
62 std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager,
63 const arm_compute::CLCompileContext& clCompileContext)
65 , m_Layer(memoryManager)
66{
67 // Add details for profiling output
68 WorkloadInfo detailsInfo;
69
70 detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos;
71 detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos;
73 if (descriptor.m_Parameters.m_BiasEnabled)
74 {
76 }
77
78 // Report Profiling Details
79 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClTransposeConvolution2dWorkload_Construct",
80 descriptor.m_Parameters,
81 detailsInfo,
82 this->GetGuid());
83
84 const TensorInfo& weightInfo = m_Data.m_Weight->GetTensorInfo();
85
86 m_WeightsTensor = std::make_unique<arm_compute::CLTensor>();
87 BuildArmComputeTensor(*m_WeightsTensor, weightInfo, m_Data.m_Parameters.m_DataLayout);
88
89 if (m_Data.m_Parameters.m_BiasEnabled)
90 {
91 m_BiasesTensor = std::make_unique<arm_compute::CLTensor>();
92 BuildArmComputeTensor(*m_BiasesTensor, m_Data.m_Bias->GetTensorInfo(), m_Data.m_Parameters.m_DataLayout);
93 }
94
95 m_Data.ValidateInputsOutputs("ClTransposeConvolution2dWorkload", 1, 1);
96
97 arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
98 arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
99
100 arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
101
102 input.info()->set_data_layout(aclDataLayout);
103 output.info()->set_data_layout(aclDataLayout);
104
105 arm_compute::PadStrideInfo padStrideInfo = BuildArmComputePadStrideInfo(m_Data.m_Parameters);
106 {
107 ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClTransposeConvolution2dWorkload_configure");
108 m_Layer.configure(clCompileContext, &input, m_WeightsTensor.get(), m_BiasesTensor.get(), &output,
109 padStrideInfo);
110 }
111
112 InitializeArmComputeClTensorData(*m_WeightsTensor, m_Data.m_Weight);
113 if (m_BiasesTensor)
114 {
115 InitializeArmComputeClTensorData(*m_BiasesTensor, m_Data.m_Bias);
116 }
117
118 m_Layer.prepare();
119
120 FreeUnusedTensors();
121}
122
124{
125 ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClTransposeConvolution2dWorkload_Execute");
126 RunClFunction(m_Layer, CHECK_LOCATION());
127}
128
129void ClTransposeConvolution2dWorkload::FreeUnusedTensors()
130{
131 FreeTensorIfUnused(m_WeightsTensor);
132 FreeTensorIfUnused(m_BiasesTensor);
133}
134
135} // namespace armnn
#define ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
#define CHECK_LOCATION()
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
ClBaseWorkload(const TransposeConvolution2dQueueDescriptor &descriptor, const WorkloadInfo &info)
ClTransposeConvolution2dWorkload(const TransposeConvolution2dQueueDescriptor &descriptor, const WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager, const arm_compute::CLCompileContext &clCompileContext)
const TensorInfo & GetTensorInfo() const
bool has_value() const noexcept
Definition Optional.hpp:53
Copyright (c) 2021 ARM Limited and Contributors.
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
arm_compute::Status ClTransposeConvolution2dWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const TransposeConvolution2dDescriptor &descriptor, const TensorInfo &weights, const Optional< TensorInfo > &biases)
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstTensorHandle *handle)
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Contains information about TensorInfos of a layer.
Optional< TensorInfo > m_BiasTensorInfo
std::vector< TensorInfo > m_OutputTensorInfos
std::vector< TensorInfo > m_InputTensorInfos
Optional< TensorInfo > m_WeightsTensorInfo