ArmNN
 24.02
NeonLstmFloatWorkload Class Reference

#include <NeonLstmFloatWorkload.hpp>

Inheritance diagram for NeonLstmFloatWorkload:
[legend]
Collaboration diagram for NeonLstmFloatWorkload:
[legend]

Public Member Functions

 NeonLstmFloatWorkload (const LstmQueueDescriptor &descriptor, const WorkloadInfo &info)
 
virtual 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)
 
virtual const std::string & GetName () const override
 
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
 
const std::string m_Name
 

Detailed Description

Definition at line 19 of file NeonLstmFloatWorkload.hpp.

Constructor & Destructor Documentation

◆ NeonLstmFloatWorkload()

NeonLstmFloatWorkload ( const LstmQueueDescriptor descriptor,
const WorkloadInfo info 
)

Definition at line 20 of file NeonLstmFloatWorkload.cpp.

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

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 247 of file NeonLstmFloatWorkload.cpp.

248 {
249  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonLstmFloatWorkload_Execute");
250  m_LstmLayer.run();
251 }

References ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID.

◆ ReplaceInputTensorHandle()

void ReplaceInputTensorHandle ( ITensorHandle tensorHandle,
unsigned int  slot 
)
overridevirtual

Reimplemented from BaseWorkload< QueueDescriptor >.

Definition at line 417 of file NeonLstmFloatWorkload.cpp.

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

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 434 of file NeonLstmFloatWorkload.cpp.

435 {
436  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
437  this->m_Data.m_Inputs[slot] = tensorHandle;
438  try
439  {
440  Reconfigure();
441  }
443  {
444  // Cannot reconfigure, revert the slot back and throw the exception.
445  this->m_Data.m_Inputs[slot] = backupHandle;
446  throw e;
447  }
448 }

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


The documentation for this class was generated from the following files:
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::DataType::Float32
@ Float32
armnn::InitializeArmComputeTensorData
void InitializeArmComputeTensorData(arm_compute::Tensor &tensor, TensorInfo tensorInfo, const ITensorHandle *handle)
Definition: NeonWorkloadUtils.hpp:68
armnn::ConvertLstmActivationFuncToAclLayerInfo
arm_compute::ActivationLayerInfo ConvertLstmActivationFuncToAclLayerInfo(uint32_t activationFunction)
Definition: ArmComputeUtils.hpp:118
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
armnn::BaseWorkload::GetGuid
arm::pipe::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:67
armnn::BaseWorkload::m_Data
QueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::UnimplementedException
Definition: Exceptions.hpp:98
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::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26