ArmNN
 24.02
NeonConvolution3dWorkload.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 
13 
14 #include <arm_compute/runtime/NEON/functions/NEConv3D.h>
15 
16 #include <armnn/Types.hpp>
17 #include <Half.hpp>
18 
19 namespace armnn
20 {
21 
22 using namespace armcomputetensorutils;
23 
25  const TensorInfo& output,
26  const Convolution3dDescriptor& descriptor,
27  const TensorInfo& weights,
28  const Optional<TensorInfo>& biases,
29  bool isFastMathEnabled,
30  const ActivationDescriptor* activationDescriptor)
31 {
32  const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
33  const arm_compute::TensorInfo aclWeightsInfo = BuildArmComputeTensorInfo(weights, descriptor.m_DataLayout);
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 NeonConvolution3dWorkload has empty bias value."};
42  }
43 
44  aclBiasesInfo = BuildArmComputeTensorInfo(biases.value(), descriptor.m_DataLayout);
45  optionalAclBiasesInfo = &aclBiasesInfo;
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::NEConv3D::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 bool isFastMathEnabled)
65 {
66  IgnoreUnused(memoryManager);
67 
68  using arm_compute::NEConv3D;
69  uint32_t numInputs = m_Data.m_Parameters.m_BiasEnabled ? 3: 2;
70  m_Data.ValidateInputsOutputs("NeonConvolution3dWorkload", numInputs, 1);
71 
72  arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
73  arm_compute::ITensor& weights = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
74  arm_compute::ITensor* biasesPtr = nullptr;
76  {
77  biasesPtr = &PolymorphicDowncast<IAclTensorHandle *>(m_Data.m_Inputs[2])->GetTensor();
78  }
79  arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
80 
81  arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
82  input.info()->set_data_layout(aclDataLayout);
83  weights.info()->set_data_layout(aclDataLayout);
84  output.info()->set_data_layout(aclDataLayout);
85 
86  const arm_compute::Conv3dInfo aclConv3DInfo = ComputeConv3DInfo(descriptor, isFastMathEnabled);
87 
88  auto convolutionLayer = std::make_unique<arm_compute::NEConv3D>();
89  convolutionLayer->configure(&input,
90  &weights,
91  biasesPtr,
92  &output,
93  aclConv3DInfo);
94 
95  // Add details for profiling output
96  WorkloadInfo detailsInfo;
97 
98  detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos;
99  detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos;
100 
101  // Report Profiling Details
102  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonConvolution3dWorkload_Construct",
103  descriptor.m_Parameters,
104  detailsInfo,
105  this->GetGuid());
106 
107  m_ConvolutionLayer.reset(convolutionLayer.release());
108 
109  ARMNN_ASSERT(m_ConvolutionLayer);
110 
111  m_ConvolutionLayer->prepare();
112 }
113 
115 {
116  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonConvolution3dWorkload_Execute");
117  m_ConvolutionLayer->run();
118 }
119 
120 } //namespace armnn
ARMNN_ASSERT
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
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::NeonConvolution3dWorkloadValidate
arm_compute::Status NeonConvolution3dWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const Convolution3dDescriptor &descriptor, const TensorInfo &weights, const Optional< TensorInfo > &biases, bool isFastMathEnabled, const ActivationDescriptor *activationDescriptor)
Definition: NeonConvolution3dWorkload.cpp:24
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
NeonConvolution3dWorkload.hpp
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:288
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::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.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::NeonConvolution3dWorkload::NeonConvolution3dWorkload
NeonConvolution3dWorkload(const Convolution3dQueueDescriptor &descriptor, const WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager, const bool isFastMathENabled=false)
Definition: NeonConvolution3dWorkload.cpp:60
ARMNN_REPORT_PROFILING_WORKLOAD_DESC
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
Half.hpp
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
armnn::BaseWorkload< Convolution3dQueueDescriptor >::m_Data
Convolution3dQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::WorkloadInfo::m_InputTensorInfos
std::vector< TensorInfo > m_InputTensorInfos
Definition: WorkloadInfo.hpp:18
NeonWorkloadUtils.hpp
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
Types.hpp
ArmComputeTensorUtils.hpp
armnn::Convolution3dDescriptor::m_DataLayout
DataLayout m_DataLayout
The data layout to be used (NDHWC, NCDHW).
Definition: Descriptors.hpp:655
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::NeonConvolution3dWorkload::Execute
void Execute() const override
Definition: NeonConvolution3dWorkload.cpp:114
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