ArmNN
 21.11
ClDepthwiseConvolutionWorkload Class Reference

#include <ClDepthwiseConvolutionWorkload.hpp>

Inheritance diagram for ClDepthwiseConvolutionWorkload:
BaseWorkload< DepthwiseConvolution2dQueueDescriptor > IWorkload

Public Member Functions

 ClDepthwiseConvolutionWorkload (const DepthwiseConvolution2dQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
 
void Execute () const override
 
- Public Member Functions inherited from BaseWorkload< DepthwiseConvolution2dQueueDescriptor >
 BaseWorkload (const DepthwiseConvolution2dQueueDescriptor &descriptor, const WorkloadInfo &info)
 
void ExecuteAsync (WorkingMemDescriptor &workingMemDescriptor) override
 
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 >
DepthwiseConvolution2dQueueDescriptor m_Data
 
const profiling::ProfilingGuid m_Guid
 

Detailed Description

Definition at line 24 of file ClDepthwiseConvolutionWorkload.hpp.

Constructor & Destructor Documentation

◆ ClDepthwiseConvolutionWorkload()

ClDepthwiseConvolutionWorkload ( const DepthwiseConvolution2dQueueDescriptor descriptor,
const WorkloadInfo info,
const arm_compute::CLCompileContext &  clCompileContext 
)

Definition at line 75 of file ClDepthwiseConvolutionWorkload.cpp.

References ARMNN_REPORT_PROFILING_WORKLOAD_DESC, armnn::Convert1HWOTensorToAcl(), TensorInfo::GetNumBytes(), ConstTensorHandle::GetTensorInfo(), DepthwiseConvolution2dQueueDescriptor::m_Bias, DepthwiseConvolution2dDescriptor::m_BiasEnabled, WorkloadInfo::m_BiasTensorInfo, BaseWorkload< DepthwiseConvolution2dQueueDescriptor >::m_Data, DepthwiseConvolution2dDescriptor::m_DataLayout, WorkloadInfo::m_InputTensorInfos, ClDepthwiseConvolutionWorkload::m_KernelTensor, WorkloadInfo::m_OutputTensorInfos, QueueDescriptorWithParameters< LayerDescriptor >::m_Parameters, DepthwiseConvolution2dQueueDescriptor::m_Weight, and WorkloadInfo::m_WeightsTensorInfo.

79  : BaseWorkload<DepthwiseConvolution2dQueueDescriptor>(descriptor, info)
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;
86  detailsInfo.m_WeightsTensorInfo = armnn::Optional<armnn::TensorInfo>(descriptor.m_Weight->GetTensorInfo());
87  if (descriptor.m_Parameters.m_BiasEnabled)
88  {
89  detailsInfo.m_BiasTensorInfo = armnn::Optional<armnn::TensorInfo>(descriptor.m_Bias->GetTensorInfo());
90  }
91 
92  // Report Profiling Details
93  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClDepthwiseConvolutionWorkload_Construct",
94  descriptor.m_Parameters,
95  detailsInfo,
96  this->GetGuid());
97 
98  // ArmNN's weight format is usually [ M, I, H, W ] but for depthwise its [ 1, H, W, I*M]
99  // Permute to [ 1, I * M, H, W ] (if NCHW), as required by the compute library
100  ConstTensor weightPermuted;
101  unsigned int depthMultiplier;
102  std::unique_ptr<unsigned char[]> permuteBuffer(new unsigned char[m_Data.m_Weight->GetTensorInfo().GetNumBytes()]);
103  std::tie(weightPermuted, depthMultiplier) = Convert1HWOTensorToAcl(m_Data.m_Weight,
104  info.m_InputTensorInfos[0],
106  permuteBuffer.get());
107 
108  // Convert the weights into the compute library format
109  m_KernelTensor = std::make_unique<arm_compute::CLTensor>();
110  BuildArmComputeTensor(*m_KernelTensor, weightPermuted.GetInfo(), m_Data.m_Parameters.m_DataLayout);
111 
113  {
114  m_BiasTensor = std::make_unique<arm_compute::CLTensor>();
116  }
117 
118  const arm_compute::Size2D aclDilationInfo = BuildArmComputeSize2D(
121 
122 
123  std::string name = std::string("ClDepthwiseConvolutionWorkload");
124  m_Data.ValidateInputsOutputs(name, 1, 1);
125 
126  arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
127  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
128 
129  arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
130  input.info()->set_data_layout(aclDataLayout);
131  output.info()->set_data_layout(aclDataLayout);
132 
133  arm_compute::PadStrideInfo padStrideInfo = BuildArmComputePadStrideInfo(m_Data.m_Parameters);
134 
135  const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
136 
137  m_DepthwiseConvolutionLayer = std::make_unique<arm_compute::CLDepthwiseConvolutionLayer>();
138 
139  {
140  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClDepthwiseConvolutionWorkload_configure");
141  static_cast<arm_compute::CLDepthwiseConvolutionLayer*>(m_DepthwiseConvolutionLayer.get())->configure(
142  clCompileContext,
143  &input,
144  m_KernelTensor.get(),
145  m_BiasTensor.get(),
146  &output,
147  padStrideInfo,
148  depthMultiplier,
149  activationInfo,
150  aclDilationInfo);
151  }
153 
154  ScopedTensorHandle weightsPermutedHandle(weightPermuted);
155  InitializeArmComputeClTensorData(*m_KernelTensor, &weightsPermutedHandle);
156 
157  if (m_BiasTensor)
158  {
160  }
161 
162  m_DepthwiseConvolutionLayer->prepare();
164 }
bool m_BiasEnabled
Enable/disable bias.
DataLayout
Definition: Types.hpp:49
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
unsigned int GetNumBytes() const
Definition: Tensor.cpp:429
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.
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
const TensorInfo & GetTensorInfo() const
std::tuple< ConstTensor, unsigned int > Convert1HWOTensorToAcl(const ConstTensorHandle *weightTensor, const TensorInfo &inputInfo, const DataLayout dataLayout, void *permuteBuffer)
Weights for depthwise have a datalayout of [1,H,W,O] = [1,H,W,I*M] This function coverts a ConstCpuTe...
uint32_t m_DilationX
Dilation factor value for width dimension.
DepthwiseConvolution2dQueueDescriptor m_Data
Definition: Workload.hpp:58
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
std::unique_ptr< arm_compute::CLTensor > m_KernelTensor
std::vector< ITensorHandle * > m_Outputs
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstTensorHandle *handle)
std::vector< ITensorHandle * > m_Inputs

Member Function Documentation

◆ Execute()

void Execute ( ) const
overridevirtual

Implements IWorkload.

Definition at line 172 of file ClDepthwiseConvolutionWorkload.cpp.

References ARMNN_ASSERT, ARMNN_SCOPED_PROFILING_EVENT_CL_GUID, CHECK_LOCATION, BaseWorkload< DepthwiseConvolution2dQueueDescriptor >::GetGuid(), ClDepthwiseConvolutionWorkload::m_DepthwiseConvolutionLayer, and armnn::RunClFunction().

173 {
174  ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClDepthwiseConvolutionWorkload_Execute", this->GetGuid());
176 
178 }
#define ARMNN_SCOPED_PROFILING_EVENT_CL_GUID(name, guid)
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:209
profiling::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:55

◆ FreeUnusedTensors()

void FreeUnusedTensors ( )
protected

Definition at line 166 of file ClDepthwiseConvolutionWorkload.cpp.

167 {
168  FreeTensorIfUnused(m_KernelTensor);
169  FreeTensorIfUnused(m_BiasTensor);
170 }
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 39 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: