ArmNN
 24.08
ClConvolution3dWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021-2023 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>
16 
17 #include <arm_compute/runtime/CL/functions/CLConv3D.h>
18 
19 namespace armnn
20 {
21 using namespace armcomputetensorutils;
22 
24  const TensorInfo& output,
25  const Convolution3dDescriptor& descriptor,
26  const TensorInfo& weights,
27  const Optional<TensorInfo>& biases,
28  bool isFastMathEnabled,
29  const ActivationDescriptor* activationDescriptor)
30 {
31  const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
32  const arm_compute::TensorInfo aclWeightsInfo = BuildArmComputeTensorInfo(weights, descriptor.m_DataLayout);
33 
34  arm_compute::TensorInfo aclBiasesInfo;
35  arm_compute::TensorInfo* optionalAclBiasesInfo = nullptr;
36  if (descriptor.m_BiasEnabled)
37  {
38  if (!biases.has_value())
39  {
40  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR,
41  "ArmNN ClConvolution3dWorkload has empty bias value."};
42  }
43  aclBiasesInfo = BuildArmComputeTensorInfo(biases.value(), descriptor.m_DataLayout);
44  optionalAclBiasesInfo = &aclBiasesInfo;
45  }
46 
47  const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout);
48 
49  const arm_compute::Conv3dInfo aclConv3DInfo = ComputeConv3DInfo(descriptor,
50  isFastMathEnabled,
51  activationDescriptor);
52 
53  return arm_compute::CLConv3D::validate(&aclInputInfo,
54  &aclWeightsInfo,
55  optionalAclBiasesInfo,
56  &aclOutputInfo,
57  aclConv3DInfo);
58 }
59 
61  const WorkloadInfo& info,
62  std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager,
63  const arm_compute::CLCompileContext& clCompileContext,
64  const bool isFastMathEnabled)
66  , m_ConvolutionLayer()
67 {
68  IgnoreUnused(memoryManager);
69 
70  uint32_t numInputs = m_Data.m_Parameters.m_BiasEnabled ? 3: 2;
71  m_Data.ValidateInputsOutputs("ClConvolution3dWorkload", numInputs, 1);
72 
73  arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
74  arm_compute::ICLTensor& weights = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
75  arm_compute::ICLTensor* biasesPtr = nullptr;
77  {
78  biasesPtr = &static_cast<IClTensorHandle*>(m_Data.m_Inputs[2])->GetTensor();
79  }
80  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
81 
82  arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
83  input.info()->set_data_layout(aclDataLayout);
84  weights.info()->set_data_layout(aclDataLayout);
85  output.info()->set_data_layout(aclDataLayout);
86 
87  const arm_compute::Conv3dInfo aclConv3DInfo = ComputeConv3DInfo(descriptor,
88  isFastMathEnabled);
89 
90  {
91  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClConvolution3dWorkload_configure");
92  m_ConvolutionLayer.configure(clCompileContext,
93  &input,
94  &weights,
95  biasesPtr,
96  &output,
97  aclConv3DInfo);
98  }
99  // Add details for profiling output
100  WorkloadInfo detailsInfo;
101 
102  detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos;
103  detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos;
104 
105  // Report Profiling Details
106  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClConvolution3dWorkload_Construct",
107  descriptor.m_Parameters,
108  detailsInfo,
109  this->GetGuid());
110 
111  // Force Compute Library to perform the necessary copying and reshaping, after which
112  // delete all the input tensors that will no longer be needed
113  m_ConvolutionLayer.prepare();
114 }
115 
117 {
118  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClConvolution3dWorkload_Execute");
119  RunClFunction(m_ConvolutionLayer, CHECK_LOCATION());
120 }
121 
122 } //namespace armnn
armnn::ActivationDescriptor
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:36
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
ClLayerSupport.hpp
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::ClConvolution3dWorkload::Execute
void Execute() const override
Definition: ClConvolution3dWorkload.cpp:116
armnn::ClBaseWorkload
Definition: ClBaseWorkload.hpp:13
armnn::ComputeConv3DInfo
arm_compute::Conv3dInfo ComputeConv3DInfo(const armnn::Convolution3dDescriptor descriptor, bool isFastMathEnabled, const ActivationDescriptor *activationDescriptor)
Utility function used to setup an arm_compute::Conv3dInfo object from convolution3d descriptor.
Definition: ArmComputeUtils.hpp:261
armnn::Convolution3dQueueDescriptor
Definition: WorkloadData.hpp:216
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_SCOPED_PROFILING_EVENT_CL_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: ClWorkloadUtils.hpp:36
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
ClWorkloadUtils.hpp
ArmComputeUtils.hpp
armnn::Convolution3dDescriptor
A Convolution3dDescriptor for the Convolution3dLayer.
Definition: Descriptors.hpp:588
armnn::BoostLogSeverityMapping::info
@ info
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
ARMNN_REPORT_PROFILING_WORKLOAD_DESC
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
ClConvolution3dWorkload.hpp
armnn::IClTensorHandle
Definition: IClTensorHandle.hpp:13
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
ClTensorHandle.hpp
armnn::BaseWorkload< Convolution3dQueueDescriptor >::m_Data
Convolution3dQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::RunClFunction
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
Definition: ClWorkloadUtils.hpp:167
armnn::ClConvolution3dWorkloadValidate
arm_compute::Status ClConvolution3dWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const Convolution3dDescriptor &descriptor, const TensorInfo &weights, const Optional< TensorInfo > &biases, bool isFastMathEnabled, const ActivationDescriptor *activationDescriptor)
Definition: ClConvolution3dWorkload.cpp:23
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::WorkloadInfo::m_InputTensorInfos
std::vector< TensorInfo > m_InputTensorInfos
Definition: WorkloadInfo.hpp:18
armnn::ClConvolution3dWorkload::ClConvolution3dWorkload
ClConvolution3dWorkload(const Convolution3dQueueDescriptor &descriptor, const WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager, const arm_compute::CLCompileContext &clCompileContext, const bool isFastMathEnabled=false)
Definition: ClConvolution3dWorkload.cpp:60
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::Convolution3dDescriptor::m_BiasEnabled
bool m_BiasEnabled
Enable/disable bias.
Definition: Descriptors.hpp:653
ArmComputeTensorUtils.hpp
armnn::Convolution3dDescriptor::m_DataLayout
DataLayout m_DataLayout
The data layout to be used (NDHWC, NCDHW).
Definition: Descriptors.hpp:655
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