ArmNN
 20.05
ClQLstmWorkload Class Reference

#include <ClQLstmWorkload.hpp>

Inheritance diagram for ClQLstmWorkload:
BaseWorkload< QLstmQueueDescriptor > IWorkload

Public Member Functions

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

Additional Inherited Members

- Protected Attributes inherited from BaseWorkload< QLstmQueueDescriptor >
const QLstmQueueDescriptor m_Data
 
const profiling::ProfilingGuid m_Guid
 

Detailed Description

Definition at line 19 of file ClQLstmWorkload.hpp.

Constructor & Destructor Documentation

◆ ClQLstmWorkload()

ClQLstmWorkload ( const QLstmQueueDescriptor descriptor,
const WorkloadInfo info 
)

Definition at line 17 of file ClQLstmWorkload.cpp.

18  : BaseWorkload<QLstmQueueDescriptor>(descriptor, info)
19 {
20  arm_compute::LSTMParams<arm_compute::ICLTensor> qLstmParams;
21 
22  // Mandatory params
23  m_InputToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
24  BuildArmComputeTensor(*m_InputToForgetWeightsTensor, m_Data.m_InputToForgetWeights->GetTensorInfo());
25 
26  m_InputToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
27  BuildArmComputeTensor(*m_InputToCellWeightsTensor, m_Data.m_InputToCellWeights->GetTensorInfo());
28 
29  m_InputToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
30  BuildArmComputeTensor(*m_InputToOutputWeightsTensor, m_Data.m_InputToOutputWeights->GetTensorInfo());
31 
32  m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
33  BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor, m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
34 
35  m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
36  BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor, m_Data.m_RecurrentToCellWeights->GetTensorInfo());
37 
38  m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
39  BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor, m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
40 
41  m_ForgetGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
42  BuildArmComputeTensor(*m_ForgetGateBiasTensor, m_Data.m_ForgetGateBias->GetTensorInfo());
43 
44  m_CellBiasTensor = std::make_unique<arm_compute::CLTensor>();
45  BuildArmComputeTensor(*m_CellBiasTensor, m_Data.m_CellBias->GetTensorInfo());
46 
47  m_OutputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
48  BuildArmComputeTensor(*m_OutputGateBiasTensor, m_Data.m_OutputGateBias->GetTensorInfo());
49 
50  // Create tensors for optional params if they are enabled
52  {
53  m_CellToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
54 
56  {
57  // In ACL this is categorised as a CIFG param and not a Peephole param
58  BuildArmComputeTensor(*m_CellToInputWeightsTensor, m_Data.m_CellToInputWeights->GetTensorInfo());
59  }
60 
61  m_CellToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
62  BuildArmComputeTensor(*m_CellToForgetWeightsTensor, m_Data.m_CellToForgetWeights->GetTensorInfo());
63 
64  m_CellToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
65  BuildArmComputeTensor(*m_CellToOutputWeightsTensor, m_Data.m_CellToOutputWeights->GetTensorInfo());
66 
67  // Set Peephole params
68  qLstmParams.set_peephole_params(m_CellToForgetWeightsTensor.get(),
69  m_CellToOutputWeightsTensor.get());
70  }
71 
73  {
74  m_ProjectionWeightsTensor = std::make_unique<arm_compute::CLTensor>();
75  BuildArmComputeTensor(*m_ProjectionWeightsTensor, m_Data.m_ProjectionWeights->GetTensorInfo());
76 
77  m_ProjectionBiasTensor = std::make_unique<arm_compute::CLTensor>();
78  if (m_Data.m_ProjectionBias != nullptr)
79  {
80  BuildArmComputeTensor(*m_ProjectionBiasTensor, m_Data.m_ProjectionBias->GetTensorInfo());
81  }
82 
83  // Set projection params
84  qLstmParams.set_projection_params(
85  m_ProjectionWeightsTensor.get(),
86  m_Data.m_ProjectionBias != nullptr ? m_ProjectionBiasTensor.get() : nullptr);
87  }
88 
90  {
91  m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
92 
94  {
95  BuildArmComputeTensor(*m_InputLayerNormWeightsTensor, m_Data.m_InputLayerNormWeights->GetTensorInfo());
96  }
97 
98  m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
99  BuildArmComputeTensor(*m_ForgetLayerNormWeightsTensor, m_Data.m_ForgetLayerNormWeights->GetTensorInfo());
100 
101  m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
102  BuildArmComputeTensor(*m_CellLayerNormWeightsTensor, m_Data.m_CellLayerNormWeights->GetTensorInfo());
103 
104  m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
105  BuildArmComputeTensor(*m_OutputLayerNormWeightsTensor, m_Data.m_OutputLayerNormWeights->GetTensorInfo());
106 
107  qLstmParams.set_layer_normalization_params(
108  m_Data.m_InputLayerNormWeights != nullptr ? m_InputLayerNormWeightsTensor.get() : nullptr,
109  m_ForgetLayerNormWeightsTensor.get(),
110  m_CellLayerNormWeightsTensor.get(),
111  m_OutputLayerNormWeightsTensor.get());
112  }
113 
115  {
116  m_InputToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
117  BuildArmComputeTensor(*m_InputToInputWeightsTensor, m_Data.m_InputToInputWeights->GetTensorInfo());
118 
119  m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
120  BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor, m_Data.m_RecurrentToInputWeights->GetTensorInfo());
121 
122  m_InputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
123  BuildArmComputeTensor(*m_InputGateBiasTensor, m_Data.m_InputGateBias->GetTensorInfo());
124 
125  qLstmParams.set_cifg_params(
126  m_InputToInputWeightsTensor.get(),
127  m_RecurrentToInputWeightsTensor.get(),
128  m_Data.m_CellToInputWeights != nullptr ? m_CellToInputWeightsTensor.get() : nullptr,
129  m_InputGateBiasTensor.get());
130  }
131 
132  // Input/Output tensors
133  const arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
134  const arm_compute::ICLTensor& outputStateIn = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
135  const arm_compute::ICLTensor& cellStateIn = static_cast<IClTensorHandle*>(m_Data.m_Inputs[2])->GetTensor();
136 
137  arm_compute::ICLTensor& outputStateOut = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
138  arm_compute::ICLTensor& cellStateOut = static_cast<IClTensorHandle*>(m_Data.m_Outputs[1])->GetTensor();
139  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[2])->GetTensor();
140 
141  // Set scalar descriptor params
142  qLstmParams.set_cell_clip_params(m_Data.m_Parameters.m_CellClip);
143  qLstmParams.set_projection_clip_params(m_Data.m_Parameters.m_ProjectionClip);
144  qLstmParams.set_hidden_state_params(m_Data.m_Parameters.m_HiddenStateZeroPoint,
146  qLstmParams.set_matmul_scale_params(m_Data.m_Parameters.m_InputIntermediateScale,
150 
151  m_QLstmLayer.configure(&input,
152  m_InputToForgetWeightsTensor.get(),
153  m_InputToCellWeightsTensor.get(),
154  m_InputToOutputWeightsTensor.get(),
155  m_RecurrentToForgetWeightsTensor.get(),
156  m_RecurrentToCellWeightsTensor.get(),
157  m_RecurrentToOutputWeightsTensor.get(),
158  m_ForgetGateBiasTensor.get(),
159  m_CellBiasTensor.get(),
160  m_OutputGateBiasTensor.get(),
161  &cellStateIn,
162  &outputStateIn,
163  &cellStateOut,
164  &outputStateOut,
165  &output,
166  qLstmParams);
167 
168  // InitializeArmComputeTensorData for mandatory params
169  InitializeArmComputeClTensorData(*m_InputToForgetWeightsTensor, m_Data.m_InputToForgetWeights);
170  InitializeArmComputeClTensorData(*m_InputToCellWeightsTensor, m_Data.m_InputToCellWeights);
171  InitializeArmComputeClTensorData(*m_InputToOutputWeightsTensor, m_Data.m_InputToOutputWeights);
172 
173  InitializeArmComputeClTensorData(*m_RecurrentToForgetWeightsTensor, m_Data.m_RecurrentToForgetWeights);
174  InitializeArmComputeClTensorData(*m_RecurrentToCellWeightsTensor, m_Data.m_RecurrentToCellWeights);
175  InitializeArmComputeClTensorData(*m_RecurrentToOutputWeightsTensor, m_Data.m_RecurrentToOutputWeights);
176 
177  InitializeArmComputeClTensorData(*m_ForgetGateBiasTensor, m_Data.m_ForgetGateBias);
179  InitializeArmComputeClTensorData(*m_OutputGateBiasTensor, m_Data.m_OutputGateBias);
180 
182  {
183  InitializeArmComputeClTensorData(*m_InputToInputWeightsTensor, m_Data.m_InputToInputWeights);
184  InitializeArmComputeClTensorData(*m_RecurrentToInputWeightsTensor, m_Data.m_RecurrentToInputWeights);
186  }
187 
189  {
190  InitializeArmComputeClTensorData(*m_ProjectionWeightsTensor, m_Data.m_ProjectionWeights);
191 
192  if (m_Data.m_ProjectionBias != nullptr)
193  {
194  InitializeArmComputeClTensorData(*m_ProjectionBiasTensor, m_Data.m_ProjectionBias);
195  }
196  }
197 
199  {
201  {
202  InitializeArmComputeClTensorData(*m_CellToInputWeightsTensor, m_Data.m_CellToInputWeights);
203  }
204 
205  InitializeArmComputeClTensorData(*m_CellToForgetWeightsTensor, m_Data.m_CellToForgetWeights);
206  InitializeArmComputeClTensorData(*m_CellToOutputWeightsTensor, m_Data.m_CellToOutputWeights);
207  }
208 
210  {
212  {
213  InitializeArmComputeClTensorData(*m_InputLayerNormWeightsTensor, m_Data.m_InputLayerNormWeights);
214  }
215  InitializeArmComputeClTensorData(*m_ForgetLayerNormWeightsTensor, m_Data.m_ForgetLayerNormWeights);
216  InitializeArmComputeClTensorData(*m_CellLayerNormWeightsTensor, m_Data.m_CellLayerNormWeights);
217  InitializeArmComputeClTensorData(*m_OutputLayerNormWeightsTensor, m_Data.m_OutputLayerNormWeights);
218  }
219 
220  m_QLstmLayer.prepare();
221 
222  FreeUnusedTensors();
223 }
const ConstCpuTensorHandle * m_CellToForgetWeights
const ConstCpuTensorHandle * m_ProjectionWeights
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstCpuTensorHandle *handle)
bool m_PeepholeEnabled
Enable/disable peephole.
const ConstCpuTensorHandle * m_ProjectionBias
float m_HiddenStateScale
Hidden State quantization scale.
const ConstCpuTensorHandle * m_ForgetLayerNormWeights
const QLstmQueueDescriptor m_Data
Definition: Workload.hpp:46
float m_OutputIntermediateScale
Output intermediate quantization scale.
const ConstCpuTensorHandle * m_CellLayerNormWeights
const ConstCpuTensorHandle * m_RecurrentToCellWeights
const ConstCpuTensorHandle * m_RecurrentToInputWeights
const ConstCpuTensorHandle * m_OutputGateBias
const ConstCpuTensorHandle * m_CellBias
const ConstCpuTensorHandle * m_CellToOutputWeights
const ConstCpuTensorHandle * m_OutputLayerNormWeights
bool m_LayerNormEnabled
Enable/disable layer normalization.
const ConstCpuTensorHandle * m_InputToForgetWeights
float m_ProjectionClip
Clipping threshold value for the projection.
float m_InputIntermediateScale
Input intermediate quantization scale.
float m_ForgetIntermediateScale
Forget intermediate quantization scale.
const ConstCpuTensorHandle * m_CellToInputWeights
float m_CellClip
Clipping threshold value for the cell state.
const ConstCpuTensorHandle * m_RecurrentToOutputWeights
std::vector< ITensorHandle * > m_Outputs
bool m_ProjectionEnabled
Enable/disable the projection layer.
const ConstCpuTensorHandle * m_InputGateBias
std::vector< ITensorHandle * > m_Inputs
const ConstCpuTensorHandle * m_InputLayerNormWeights
const ConstCpuTensorHandle * m_RecurrentToForgetWeights
const ConstCpuTensorHandle * m_ForgetGateBias
float m_CellIntermediateScale
Cell intermediate quantization scale.
const ConstCpuTensorHandle * m_InputToOutputWeights
bool m_CifgEnabled
Enable/disable CIFG (coupled input & forget gate).
const TensorInfo & GetTensorInfo() const
const ConstCpuTensorHandle * m_InputToInputWeights
int32_t m_HiddenStateZeroPoint
Hidden State zero point.
const ConstCpuTensorHandle * m_InputToCellWeights

Member Function Documentation

◆ Execute()

void Execute ( ) const
overridevirtual

Implements IWorkload.

Definition at line 225 of file ClQLstmWorkload.cpp.

226 {
227  m_QLstmLayer.run();
228 }

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