ArmNN
 23.02
ClLstmFloatWorkload Class Reference

#include <ClLstmFloatWorkload.hpp>

Inheritance diagram for ClLstmFloatWorkload:
TypedWorkload< QueueDescriptor, DataTypes > BaseWorkload< QueueDescriptor > IWorkload

Public Member Functions

 ClLstmFloatWorkload (const LstmQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
 
void Execute () const override
 
void ReplaceInputTensorHandle (ITensorHandle *tensorHandle, unsigned int slot) override
 
void ReplaceOutputTensorHandle (ITensorHandle *tensorHandle, unsigned int slot) override
 
- Public Member Functions inherited from TypedWorkload< QueueDescriptor, DataTypes >
 TypedWorkload (const QueueDescriptor &descriptor, const WorkloadInfo &info)
 
- Public Member Functions inherited from BaseWorkload< QueueDescriptor >
 BaseWorkload (const QueueDescriptor &descriptor, const WorkloadInfo &info)
 
void ExecuteAsync (ExecutionData &executionData) override
 
void PostAllocationConfigure () override
 
const QueueDescriptorGetData () const
 
arm::pipe::ProfilingGuid GetGuid () const final
 
virtual bool SupportsTensorHandleReplacement () const override
 
- Public Member Functions inherited from IWorkload
virtual ~IWorkload ()
 
virtual void RegisterDebugCallback (const DebugCallbackFunction &)
 
virtual armnn::Optional< armnn::MemoryRequirementsGetMemoryRequirements ()
 

Additional Inherited Members

- Protected Attributes inherited from BaseWorkload< QueueDescriptor >
QueueDescriptor m_Data
 
const arm::pipe::ProfilingGuid m_Guid
 

Detailed Description

Definition at line 18 of file ClLstmFloatWorkload.hpp.

Constructor & Destructor Documentation

◆ ClLstmFloatWorkload()

ClLstmFloatWorkload ( const LstmQueueDescriptor descriptor,
const WorkloadInfo info,
const arm_compute::CLCompileContext &  clCompileContext 
)

Definition at line 23 of file ClLstmFloatWorkload.cpp.

26  : FloatWorkload<LstmQueueDescriptor>(descriptor, info)
27 {
28  // Report Profiling Details
29  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClLstmFloatWorkload_Construct",
30  descriptor.m_Parameters,
31  info,
32  GetGuid());
33 
34  arm_compute::LSTMParams<arm_compute::ICLTensor> lstm_param;
35 
36  // Basic parameters
37  m_InputToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
38  BuildArmComputeTensor(*m_InputToForgetWeightsTensor, m_Data.m_InputToForgetWeights->GetTensorInfo());
39 
40  m_InputToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
41  BuildArmComputeTensor(*m_InputToCellWeightsTensor, m_Data.m_InputToCellWeights->GetTensorInfo());
42 
43  m_InputToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
44  BuildArmComputeTensor(*m_InputToOutputWeightsTensor, m_Data.m_InputToOutputWeights->GetTensorInfo());
45 
46  m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
47  BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor, m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
48 
49  m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
50  BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor, m_Data.m_RecurrentToCellWeights->GetTensorInfo());
51 
52  m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
53  BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor, m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
54 
55  m_ForgetGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
56  BuildArmComputeTensor(*m_ForgetGateBiasTensor, m_Data.m_ForgetGateBias->GetTensorInfo());
57 
58  m_CellBiasTensor = std::make_unique<arm_compute::CLTensor>();
59  BuildArmComputeTensor(*m_CellBiasTensor, m_Data.m_CellBias->GetTensorInfo());
60 
61  m_OutputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
62  BuildArmComputeTensor(*m_OutputGateBiasTensor, m_Data.m_OutputGateBias->GetTensorInfo());
63 
64  // for future reference: check the AndroidNN API for the logic here
65  if (!m_Data.m_Parameters.m_CifgEnabled)
66  {
67  m_InputToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
68  BuildArmComputeTensor(*m_InputToInputWeightsTensor, m_Data.m_InputToInputWeights->GetTensorInfo());
69 
70  m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
71  BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor, m_Data.m_RecurrentToInputWeights->GetTensorInfo());
72 
73  m_CellToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
74  if (m_Data.m_CellToInputWeights != nullptr)
75  {
76  BuildArmComputeTensor(*m_CellToInputWeightsTensor, m_Data.m_CellToInputWeights->GetTensorInfo());
77  }
78 
79  m_InputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
80  BuildArmComputeTensor(*m_InputGateBiasTensor, m_Data.m_InputGateBias->GetTensorInfo());
81 
82  lstm_param.set_cifg_params(m_InputToInputWeightsTensor.get(),
83  m_RecurrentToInputWeightsTensor.get(),
84  m_Data.m_CellToInputWeights != nullptr ? m_CellToInputWeightsTensor.get() : nullptr,
85  m_InputGateBiasTensor.get());
86  }
87 
88  if (m_Data.m_Parameters.m_ProjectionEnabled)
89  {
90  m_ProjectionWeightsTensor = std::make_unique<arm_compute::CLTensor>();
91  BuildArmComputeTensor(*m_ProjectionWeightsTensor, m_Data.m_ProjectionWeights->GetTensorInfo());
92 
93  m_ProjectionBiasTensor = std::make_unique<arm_compute::CLTensor>();
94  if (m_Data.m_ProjectionBias != nullptr)
95  {
96  BuildArmComputeTensor(*m_ProjectionBiasTensor, m_Data.m_ProjectionBias->GetTensorInfo());
97  }
98 
99  lstm_param.set_projection_params(m_ProjectionWeightsTensor.get(),
100  m_Data.m_ProjectionBias != nullptr ? m_ProjectionBiasTensor.get() : nullptr);
101  }
102 
103  if (m_Data.m_Parameters.m_PeepholeEnabled)
104  {
105  m_CellToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
106  BuildArmComputeTensor(*m_CellToForgetWeightsTensor, m_Data.m_CellToForgetWeights->GetTensorInfo());
107 
108  m_CellToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
109  BuildArmComputeTensor(*m_CellToOutputWeightsTensor, m_Data.m_CellToOutputWeights->GetTensorInfo());
110 
111  lstm_param.set_peephole_params(m_CellToForgetWeightsTensor.get(), m_CellToOutputWeightsTensor.get());
112  }
113 
114  if (m_Data.m_Parameters.m_LayerNormEnabled)
115  {
116  m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
117  m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
118  m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
119  m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
120 
121  if (!m_Data.m_Parameters.m_CifgEnabled)
122  {
123  BuildArmComputeTensor(*m_InputLayerNormWeightsTensor, m_Data.m_InputLayerNormWeights->GetTensorInfo());
124  }
125  BuildArmComputeTensor(*m_ForgetLayerNormWeightsTensor, m_Data.m_ForgetLayerNormWeights->GetTensorInfo());
126  BuildArmComputeTensor(*m_CellLayerNormWeightsTensor, m_Data.m_CellLayerNormWeights->GetTensorInfo());
127  BuildArmComputeTensor(*m_OutputLayerNormWeightsTensor, m_Data.m_OutputLayerNormWeights->GetTensorInfo());
128 
129  lstm_param.set_layer_normalization_params(m_Data.m_Parameters.m_CifgEnabled ? nullptr :
130  m_InputLayerNormWeightsTensor.get(),
131  m_ForgetLayerNormWeightsTensor.get(),
132  m_CellLayerNormWeightsTensor.get(),
133  m_OutputLayerNormWeightsTensor.get());
134  }
135 
136  const arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
137  const arm_compute::ICLTensor& output_state_in = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
138  arm_compute::ICLTensor& cell_state_in = static_cast<IClTensorHandle*>(m_Data.m_Inputs[2])->GetTensor();
139 
140  arm_compute::ICLTensor& output_state_out = static_cast<IClTensorHandle*>(m_Data.m_Outputs[1])->GetTensor();
141  arm_compute::ICLTensor& cell_state_out = static_cast<IClTensorHandle*>(m_Data.m_Outputs[2])->GetTensor();
142  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[3])->GetTensor();
143 
144  // Get the batch_size and the num_units from the cellStateIn dimensions
145  const TensorInfo& inputTensorInfo = info.m_InputTensorInfos[2];
146  const unsigned int batch_size = armnn::numeric_cast<unsigned int>(inputTensorInfo.GetShape()[0]);
147  const unsigned int num_units = armnn::numeric_cast<unsigned int>(inputTensorInfo.GetShape()[1]);
148 
149  m_ScratchBuffer = std::make_unique<arm_compute::CLTensor>();
150  if (m_Data.m_Parameters.m_CifgEnabled)
151  {
152  // 2D tensor with dimensions [num_units * 3, batch_size] with CIFG
153  armnn::TensorInfo scratchBuffer1({ batch_size, num_units * 3 }, DataType::Float32);
154  BuildArmComputeTensor(*m_ScratchBuffer, scratchBuffer1);
155  }
156  else
157  {
158  // scratch_buffer [num_units * 4, batch_size] without CIFG
159  armnn::TensorInfo scratchBuffer2({ batch_size, num_units * 4 }, DataType::Float32);
160  BuildArmComputeTensor(*m_ScratchBuffer, scratchBuffer2);
161  }
162 
163  float cell_threshold = m_Data.m_Parameters.m_ClippingThresCell;
164  float projection_threshold = m_Data.m_Parameters.m_ClippingThresProj;
165 
166  // for preparing the object for the class ActivationLayerInfo, we need to consider 5 situations
167  arm_compute::ActivationLayerInfo activationLayerInfo =
168  ConvertLstmActivationFuncToAclLayerInfo(m_Data.m_Parameters.m_ActivationFunc);
169 
170  {
171  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClLstmFloatWorkload_configure");
172  m_LstmLayer.configure(clCompileContext, &input, m_InputToForgetWeightsTensor.get(),
173  m_InputToCellWeightsTensor.get(), m_InputToOutputWeightsTensor.get(),
174  m_RecurrentToForgetWeightsTensor.get(), m_RecurrentToCellWeightsTensor.get(),
175  m_RecurrentToOutputWeightsTensor.get(), m_ForgetGateBiasTensor.get(),
176  m_CellBiasTensor.get(), m_OutputGateBiasTensor.get(), &output_state_in,
177  &cell_state_in, m_ScratchBuffer.get(), &output_state_out,
178  &cell_state_out, &output, lstm_param, activationLayerInfo,
179  cell_threshold, projection_threshold);
180  }
181 
182  armcomputetensorutils::InitialiseArmComputeTensorEmpty(*m_ScratchBuffer);
183 
184  InitializeArmComputeClTensorData(*m_InputToForgetWeightsTensor, m_Data.m_InputToForgetWeights);
185  InitializeArmComputeClTensorData(*m_InputToCellWeightsTensor, m_Data.m_InputToCellWeights);
186  InitializeArmComputeClTensorData(*m_InputToOutputWeightsTensor, m_Data.m_InputToOutputWeights);
187  InitializeArmComputeClTensorData(*m_RecurrentToForgetWeightsTensor, m_Data.m_RecurrentToForgetWeights);
188  InitializeArmComputeClTensorData(*m_RecurrentToCellWeightsTensor, m_Data.m_RecurrentToCellWeights);
189  InitializeArmComputeClTensorData(*m_RecurrentToOutputWeightsTensor, m_Data.m_RecurrentToOutputWeights);
190  InitializeArmComputeClTensorData(*m_ForgetGateBiasTensor, m_Data.m_ForgetGateBias);
191  InitializeArmComputeClTensorData(*m_CellBiasTensor, m_Data.m_CellBias);
192  InitializeArmComputeClTensorData(*m_OutputGateBiasTensor, m_Data.m_OutputGateBias);
193 
194  if (!m_Data.m_Parameters.m_CifgEnabled)
195  {
196  InitializeArmComputeClTensorData(*m_InputToInputWeightsTensor, m_Data.m_InputToInputWeights);
197  InitializeArmComputeClTensorData(*m_RecurrentToInputWeightsTensor, m_Data.m_RecurrentToInputWeights);
198  if (m_Data.m_CellToInputWeights != nullptr)
199  {
200  InitializeArmComputeClTensorData(*m_CellToInputWeightsTensor, m_Data.m_CellToInputWeights);
201  }
202  InitializeArmComputeClTensorData(*m_InputGateBiasTensor, m_Data.m_InputGateBias);
203  }
204 
205  if (m_Data.m_Parameters.m_ProjectionEnabled)
206  {
207  InitializeArmComputeClTensorData(*m_ProjectionWeightsTensor, m_Data.m_ProjectionWeights);
208  if (m_Data.m_ProjectionBias != nullptr)
209  {
210  InitializeArmComputeClTensorData(*m_ProjectionBiasTensor, m_Data.m_ProjectionBias);
211  }
212  }
213 
214  if (m_Data.m_Parameters.m_PeepholeEnabled)
215  {
216  InitializeArmComputeClTensorData(*m_CellToForgetWeightsTensor, m_Data.m_CellToForgetWeights);
217  InitializeArmComputeClTensorData(*m_CellToOutputWeightsTensor, m_Data.m_CellToOutputWeights);
218  }
219 
220  if (m_Data.m_Parameters.m_LayerNormEnabled)
221  {
222  if (!m_Data.m_Parameters.m_CifgEnabled)
223  {
224  InitializeArmComputeClTensorData(*m_InputLayerNormWeightsTensor, m_Data.m_InputLayerNormWeights);
225  }
226 
227  InitializeArmComputeClTensorData(*m_ForgetLayerNormWeightsTensor, m_Data.m_ForgetLayerNormWeights);
228  InitializeArmComputeClTensorData(*m_CellLayerNormWeightsTensor, m_Data.m_CellLayerNormWeights);
229  InitializeArmComputeClTensorData(*m_OutputLayerNormWeightsTensor, m_Data.m_OutputLayerNormWeights);
230  }
231 
232  // Force Compute Library to perform the necessary copying and reshaping, after which
233  // delete all the input tensors that will no longer be needed
234  m_LstmLayer.prepare();
235  FreeUnusedTensors();
236 }

References ARMNN_REPORT_PROFILING_WORKLOAD_DESC, BaseWorkload< QueueDescriptor >::GetGuid(), armnn::info, and QueueDescriptorWithParameters< LayerDescriptor >::m_Parameters.

Member Function Documentation

◆ Execute()

void Execute ( ) const
overridevirtual

Implements IWorkload.

Definition at line 238 of file ClLstmFloatWorkload.cpp.

239 {
240  ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClLstmFloatWorkload_Execute", GetGuid());
241  RunClFunction(m_LstmLayer, CHECK_LOCATION());
242 }

References ARMNN_SCOPED_PROFILING_EVENT_CL_GUID, CHECK_LOCATION, BaseWorkload< QueueDescriptor >::GetGuid(), and armnn::RunClFunction().

◆ ReplaceInputTensorHandle()

void ReplaceInputTensorHandle ( ITensorHandle tensorHandle,
unsigned int  slot 
)
overridevirtual

Reimplemented from BaseWorkload< QueueDescriptor >.

Definition at line 396 of file ClLstmFloatWorkload.cpp.

397 {
398  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
399  this->m_Data.m_Inputs[slot] = tensorHandle;
400  try
401  {
402  Reconfigure();
403  }
405  {
406  // Cannot reconfigure, revert the slot back and throw the exception.
407  this->m_Data.m_Inputs[slot] = backupHandle;
408  throw e;
409  }
410 }

References BaseWorkload< QueueDescriptor >::m_Data, and QueueDescriptor::m_Inputs.

◆ ReplaceOutputTensorHandle()

void ReplaceOutputTensorHandle ( ITensorHandle tensorHandle,
unsigned int  slot 
)
overridevirtual

Reimplemented from BaseWorkload< QueueDescriptor >.

Definition at line 413 of file ClLstmFloatWorkload.cpp.

414 {
415  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
416  this->m_Data.m_Inputs[slot] = tensorHandle;
417  try
418  {
419  Reconfigure();
420  }
422  {
423  // Cannot reconfigure, revert the slot back and throw the exception.
424  this->m_Data.m_Inputs[slot] = backupHandle;
425  throw e;
426  }
427 }

References BaseWorkload< QueueDescriptor >::m_Data, and QueueDescriptor::m_Inputs.


The documentation for this class was generated from the following files:
armnn::InitializeArmComputeClTensorData
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstTensorHandle *handle)
Definition: ClWorkloadUtils.hpp:116
armnn::BaseWorkload::GetGuid
arm::pipe::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:61
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::ConvertLstmActivationFuncToAclLayerInfo
arm_compute::ActivationLayerInfo ConvertLstmActivationFuncToAclLayerInfo(uint32_t activationFunction)
Definition: ArmComputeUtils.hpp:116
armnn::BaseWorkload::m_Data
QueueDescriptor m_Data
Definition: Workload.hpp:83
armnn::UnimplementedException
Definition: Exceptions.hpp:98
ARMNN_SCOPED_PROFILING_EVENT
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
armnn::DataType::Float32
@ Float32
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::RunClFunction
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
Definition: ClWorkloadUtils.hpp:160
armnn::Compute::Undefined
@ Undefined
ARMNN_REPORT_PROFILING_WORKLOAD_DESC
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
ARMNN_SCOPED_PROFILING_EVENT_CL_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_CL_GUID(name, guid)
Definition: ClWorkloadUtils.hpp:28
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26
armnn::BoostLogSeverityMapping::info
@ info