ArmNN
 20.11
ClDepthwiseConvolutionWorkload Class Reference

#include <ClDepthwiseConvolutionWorkload.hpp>

Inheritance diagram for ClDepthwiseConvolutionWorkload:
BaseWorkload< DepthwiseConvolution2dQueueDescriptor > IWorkload

Public Member Functions

 ClDepthwiseConvolutionWorkload (const DepthwiseConvolution2dQueueDescriptor &descriptor, const WorkloadInfo &info)
 
void Execute () const override
 
- Public Member Functions inherited from BaseWorkload< DepthwiseConvolution2dQueueDescriptor >
 BaseWorkload (const DepthwiseConvolution2dQueueDescriptor &descriptor, const WorkloadInfo &info)
 
void PostAllocationConfigure () override
 
const DepthwiseConvolution2dQueueDescriptorGetData () const
 
profiling::ProfilingGuid GetGuid () const final
 
- Public Member Functions inherited from IWorkload
virtual ~IWorkload ()
 
virtual void RegisterDebugCallback (const DebugCallbackFunction &)
 

Protected Member Functions

void FreeUnusedTensors ()
 

Protected Attributes

std::unique_ptr< arm_compute::IFunction > m_DepthwiseConvolutionLayer
 
std::unique_ptr< arm_compute::CLTensor > m_KernelTensor
 
std::unique_ptr< arm_compute::CLTensor > m_BiasTensor
 
- Protected Attributes inherited from BaseWorkload< DepthwiseConvolution2dQueueDescriptor >
const DepthwiseConvolution2dQueueDescriptor m_Data
 
const profiling::ProfilingGuid m_Guid
 

Detailed Description

Definition at line 24 of file ClDepthwiseConvolutionWorkload.hpp.

Constructor & Destructor Documentation

◆ ClDepthwiseConvolutionWorkload()

Definition at line 76 of file ClDepthwiseConvolutionWorkload.cpp.

References armnn::ConvertWeightTensorFromArmnnToAcl(), TensorInfo::GetNumBytes(), ConstCpuTensorHandle::GetTensorInfo(), BaseWorkload< DepthwiseConvolution2dQueueDescriptor >::m_Data, DepthwiseConvolution2dDescriptor::m_DataLayout, ClDepthwiseConvolutionWorkload::m_KernelTensor, QueueDescriptorWithParameters< LayerDescriptor >::m_Parameters, and DepthwiseConvolution2dQueueDescriptor::m_Weight.

79  : BaseWorkload<DepthwiseConvolution2dQueueDescriptor>(descriptor, info)
80 {
81  // Allocate a buffer for the swizzling of the weight tensor
82  std::unique_ptr<unsigned char[]> permuteBuffer(new unsigned char[m_Data.m_Weight->GetTensorInfo().GetNumBytes()]);
83 
84  // Convert the weight format from ArmNN's [ M, I, H, W ] (does NOT depend on the data layout) to either
85  // [ 1, H, W, I * M ] (if NHWC) or [ 1, I * M, H, W ] (if NCHW), as required by the compute library
86  ConstTensor weightPermuted = ConvertWeightTensorFromArmnnToAcl(m_Data.m_Weight,
88  permuteBuffer.get());
89 
90  // Convert the weights into the compute library format
91  m_KernelTensor = std::make_unique<arm_compute::CLTensor>();
92  BuildArmComputeTensor(*m_KernelTensor, weightPermuted.GetInfo(), m_Data.m_Parameters.m_DataLayout);
93 
95  {
96  m_BiasTensor = std::make_unique<arm_compute::CLTensor>();
98  }
99 
100  const arm_compute::Size2D aclDilationInfo = BuildArmComputeSize2D(
103 
104 
105  std::string name = std::string("ClDepthwiseConvolutionWorkload");
106  m_Data.ValidateInputsOutputs(name, 1, 1);
107 
108  arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
109  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
110 
111  arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
112  input.info()->set_data_layout(aclDataLayout);
113  output.info()->set_data_layout(aclDataLayout);
114 
115  // ArmNN's weight format is [ M, I, H, W ]
116  auto& weightInfo = m_Data.m_Weight->GetTensorInfo();
117 
118  // Get the depth multiplier
119  const unsigned int depthMultiplier = weightInfo.GetShape()[0];
120 
121  arm_compute::PadStrideInfo padStrideInfo = BuildArmComputePadStrideInfo(m_Data.m_Parameters);
122 
123  const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
124 
125  m_DepthwiseConvolutionLayer = std::make_unique<arm_compute::CLDepthwiseConvolutionLayer>();
126  static_cast<arm_compute::CLDepthwiseConvolutionLayer*>(m_DepthwiseConvolutionLayer.get())->configure(
127  &input,
128  m_KernelTensor.get(),
129  m_BiasTensor.get(),
130  &output,
131  padStrideInfo,
132  depthMultiplier,
133  activationInfo,
134  aclDilationInfo);
135 
137 
138  ScopedCpuTensorHandle weightsPermutedHandle(weightPermuted);
139  InitializeArmComputeClTensorData(*m_KernelTensor, &weightsPermutedHandle);
140 
141  if (m_BiasTensor)
142  {
144  }
145 
146  m_DepthwiseConvolutionLayer->prepare();
148 }
bool m_BiasEnabled
Enable/disable bias.
DataLayout
Definition: Types.hpp:50
const TensorShape & GetShape() const
Definition: Tensor.hpp:187
armnn::ConstTensor ConvertWeightTensorFromArmnnToAcl(const ConstCpuTensorHandle *weightTensor, DataLayout dataLayout, void *permuteBuffer)
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstCpuTensorHandle *handle)
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
const DepthwiseConvolution2dQueueDescriptor m_Data
Definition: Workload.hpp:46
unsigned int GetNumBytes() const
Definition: Tensor.cpp:418
std::unique_ptr< arm_compute::IFunction > m_DepthwiseConvolutionLayer
arm_compute::ActivationLayerInfo ConvertAdditionalInfoToAclActivationLayerInfo(const QueueDescriptor &queueDescriptor)
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
std::unique_ptr< arm_compute::CLTensor > m_BiasTensor
uint32_t m_DilationY
Dilation factor value for height dimension.
uint32_t m_DilationX
Dilation factor value for width dimension.
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
std::unique_ptr< arm_compute::CLTensor > m_KernelTensor
std::vector< ITensorHandle * > m_Outputs
std::vector< ITensorHandle * > m_Inputs
const TensorInfo & GetTensorInfo() const

Member Function Documentation

◆ Execute()

void Execute ( ) const
overridevirtual

Implements IWorkload.

Definition at line 156 of file ClDepthwiseConvolutionWorkload.cpp.

References ARMNN_ASSERT, ARMNN_SCOPED_PROFILING_EVENT_CL, CHECK_LOCATION, ClDepthwiseConvolutionWorkload::m_DepthwiseConvolutionLayer, and armnn::RunClFunction().

157 {
158  ARMNN_SCOPED_PROFILING_EVENT_CL("ClDepthwiseConvolutionWorkload_Execute");
160 
162 }
#define ARMNN_SCOPED_PROFILING_EVENT_CL(name)
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
std::unique_ptr< arm_compute::IFunction > m_DepthwiseConvolutionLayer
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
#define CHECK_LOCATION()
Definition: Exceptions.hpp:197

◆ FreeUnusedTensors()

void FreeUnusedTensors ( )
protected

Definition at line 150 of file ClDepthwiseConvolutionWorkload.cpp.

151 {
152  FreeTensorIfUnused(m_KernelTensor);
153  FreeTensorIfUnused(m_BiasTensor);
154 }
std::unique_ptr< arm_compute::CLTensor > m_BiasTensor
std::unique_ptr< arm_compute::CLTensor > m_KernelTensor

Member Data Documentation

◆ m_BiasTensor

std::unique_ptr<arm_compute::CLTensor> m_BiasTensor
protected

Definition at line 38 of file ClDepthwiseConvolutionWorkload.hpp.

◆ m_DepthwiseConvolutionLayer

std::unique_ptr<arm_compute::IFunction> m_DepthwiseConvolutionLayer
protected

◆ m_KernelTensor

std::unique_ptr<arm_compute::CLTensor> m_KernelTensor
protected

The documentation for this class was generated from the following files: