15 using namespace armcomputetensorutils;
26 arm_compute::LSTMParams<arm_compute::ITensor> qLstmParams;
29 m_InputToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
30 BuildArmComputeTensor(*m_InputToForgetWeightsTensor,
m_Data.m_InputToForgetWeights->GetTensorInfo());
32 m_InputToCellWeightsTensor = std::make_unique<arm_compute::Tensor>();
33 BuildArmComputeTensor(*m_InputToCellWeightsTensor,
m_Data.m_InputToCellWeights->GetTensorInfo());
35 m_InputToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
36 BuildArmComputeTensor(*m_InputToOutputWeightsTensor,
m_Data.m_InputToOutputWeights->GetTensorInfo());
38 m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
39 BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor,
m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
41 m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::Tensor>();
42 BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor,
m_Data.m_RecurrentToCellWeights->GetTensorInfo());
44 m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
45 BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor,
m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
47 m_ForgetGateBiasTensor = std::make_unique<arm_compute::Tensor>();
48 BuildArmComputeTensor(*m_ForgetGateBiasTensor,
m_Data.m_ForgetGateBias->GetTensorInfo());
50 m_CellBiasTensor = std::make_unique<arm_compute::Tensor>();
51 BuildArmComputeTensor(*m_CellBiasTensor,
m_Data.m_CellBias->GetTensorInfo());
53 m_OutputGateBiasTensor = std::make_unique<arm_compute::Tensor>();
54 BuildArmComputeTensor(*m_OutputGateBiasTensor,
m_Data.m_OutputGateBias->GetTensorInfo());
57 if (
m_Data.m_Parameters.m_PeepholeEnabled)
59 m_CellToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
61 if (!
m_Data.m_Parameters.m_CifgEnabled)
64 BuildArmComputeTensor(*m_CellToInputWeightsTensor,
m_Data.m_CellToInputWeights->GetTensorInfo());
67 m_CellToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
68 BuildArmComputeTensor(*m_CellToForgetWeightsTensor,
m_Data.m_CellToForgetWeights->GetTensorInfo());
70 m_CellToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
71 BuildArmComputeTensor(*m_CellToOutputWeightsTensor,
m_Data.m_CellToOutputWeights->GetTensorInfo());
74 qLstmParams.set_peephole_params(m_CellToForgetWeightsTensor.get(),
75 m_CellToOutputWeightsTensor.get());
78 if (
m_Data.m_Parameters.m_ProjectionEnabled)
80 m_ProjectionWeightsTensor = std::make_unique<arm_compute::Tensor>();
81 BuildArmComputeTensor(*m_ProjectionWeightsTensor,
m_Data.m_ProjectionWeights->GetTensorInfo());
83 m_ProjectionBiasTensor = std::make_unique<arm_compute::Tensor>();
84 if (
m_Data.m_ProjectionBias !=
nullptr)
86 BuildArmComputeTensor(*m_ProjectionBiasTensor,
m_Data.m_ProjectionBias->GetTensorInfo());
90 qLstmParams.set_projection_params(
91 m_ProjectionWeightsTensor.get(),
92 m_Data.m_ProjectionBias !=
nullptr ? m_ProjectionBiasTensor.get() :
nullptr);
95 if (
m_Data.m_Parameters.m_LayerNormEnabled)
97 m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
99 if (!
m_Data.m_Parameters.m_CifgEnabled)
101 BuildArmComputeTensor(*m_InputLayerNormWeightsTensor,
m_Data.m_InputLayerNormWeights->GetTensorInfo());
104 m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
105 BuildArmComputeTensor(*m_ForgetLayerNormWeightsTensor,
m_Data.m_ForgetLayerNormWeights->GetTensorInfo());
107 m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
108 BuildArmComputeTensor(*m_CellLayerNormWeightsTensor,
m_Data.m_CellLayerNormWeights->GetTensorInfo());
110 m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
111 BuildArmComputeTensor(*m_OutputLayerNormWeightsTensor,
m_Data.m_OutputLayerNormWeights->GetTensorInfo());
114 qLstmParams.set_layer_normalization_params(
115 m_Data.m_InputLayerNormWeights !=
nullptr ? m_InputLayerNormWeightsTensor.get() :
nullptr,
116 m_ForgetLayerNormWeightsTensor.get(),
117 m_CellLayerNormWeightsTensor.get(),
118 m_OutputLayerNormWeightsTensor.get());
121 if (!
m_Data.m_Parameters.m_CifgEnabled)
123 m_InputToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
124 BuildArmComputeTensor(*m_InputToInputWeightsTensor,
m_Data.m_InputToInputWeights->GetTensorInfo());
126 m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
127 BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor,
m_Data.m_RecurrentToInputWeights->GetTensorInfo());
129 m_InputGateBiasTensor = std::make_unique<arm_compute::Tensor>();
130 BuildArmComputeTensor(*m_InputGateBiasTensor,
m_Data.m_InputGateBias->GetTensorInfo());
133 qLstmParams.set_cifg_params(
134 m_InputToInputWeightsTensor.get(),
135 m_RecurrentToInputWeightsTensor.get(),
136 m_Data.m_CellToInputWeights !=
nullptr ? m_CellToInputWeightsTensor.get() :
nullptr,
137 m_InputGateBiasTensor.get());
150 qLstmParams.set_cell_clip_params(
m_Data.m_Parameters.m_CellClip);
151 qLstmParams.set_projection_clip_params(
m_Data.m_Parameters.m_ProjectionClip);
152 qLstmParams.set_hidden_state_params(
m_Data.m_Parameters.m_HiddenStateZeroPoint,
153 m_Data.m_Parameters.m_HiddenStateScale);
154 qLstmParams.set_matmul_scale_params(
m_Data.m_Parameters.m_InputIntermediateScale,
155 m_Data.m_Parameters.m_ForgetIntermediateScale,
156 m_Data.m_Parameters.m_CellIntermediateScale,
157 m_Data.m_Parameters.m_OutputIntermediateScale);
160 m_QLstmLayer.configure(&input,
161 m_InputToForgetWeightsTensor.get(),
162 m_InputToCellWeightsTensor.get(),
163 m_InputToOutputWeightsTensor.get(),
164 m_RecurrentToForgetWeightsTensor.get(),
165 m_RecurrentToCellWeightsTensor.get(),
166 m_RecurrentToOutputWeightsTensor.get(),
167 m_ForgetGateBiasTensor.get(),
168 m_CellBiasTensor.get(),
169 m_OutputGateBiasTensor.get(),
191 if (!
m_Data.m_Parameters.m_CifgEnabled)
198 if (
m_Data.m_Parameters.m_ProjectionEnabled)
202 if (
m_Data.m_ProjectionBias !=
nullptr)
208 if (
m_Data.m_Parameters.m_PeepholeEnabled)
210 if (!
m_Data.m_Parameters.m_CifgEnabled)
219 if (
m_Data.m_Parameters.m_LayerNormEnabled)
221 if (!
m_Data.m_Parameters.m_CifgEnabled)
232 m_QLstmLayer.prepare();
252 arm_compute::LSTMParams<arm_compute::ITensorInfo> aclParamsInfo;
255 const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
256 const arm_compute::TensorInfo aclOutputStateInInfo = BuildArmComputeTensorInfo(outputStateIn);
257 const arm_compute::TensorInfo aclCellStateInInfo = BuildArmComputeTensorInfo(cellStateIn);
259 const arm_compute::TensorInfo aclOutputStateOutInfo = BuildArmComputeTensorInfo(outputStateOut);
260 const arm_compute::TensorInfo aclCellStateOutInfo = BuildArmComputeTensorInfo(cellStateOut);
261 const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
264 const arm_compute::TensorInfo aclInputToForgetWeightsInfo
266 const arm_compute::TensorInfo aclInputToCellWeightsInfo
268 const arm_compute::TensorInfo aclInputToOutputWeightsInfo
270 const arm_compute::TensorInfo aclRecurrentToForgetWeightsInfo
272 const arm_compute::TensorInfo aclRecurrentToCellWeightsInfo
274 const arm_compute::TensorInfo aclRecurrentToOutputWeightsInfo
276 const arm_compute::TensorInfo aclForgetGateBiasInfo
278 const arm_compute::TensorInfo aclCellBiasInfo
279 = BuildArmComputeTensorInfo(paramsInfo.
GetCellBias());
280 const arm_compute::TensorInfo aclOutputGateBiasInfo
284 arm_compute::TensorInfo aclInputToInputWeightsInfo;
285 arm_compute::TensorInfo aclRecurrentToInputWeightsInfo;
287 arm_compute::TensorInfo aclCellToInputWeightsInfo;
288 arm_compute::TensorInfo aclCellToForgetWeightsInfo;
289 arm_compute::TensorInfo aclCellToOutputWeightsInfo;
291 arm_compute::TensorInfo aclInputGateBiasInfo;
293 arm_compute::TensorInfo aclProjectionWeightsInfo;
294 arm_compute::TensorInfo aclProjectionBiasInfo;
296 arm_compute::TensorInfo aclInputLayerNormWeightsInfo;
297 arm_compute::TensorInfo aclForgetLayerNormWeightsInfo;
298 arm_compute::TensorInfo aclCellLayerNormWeightsInfo;
299 arm_compute::TensorInfo aclOutputLayerNormWeightsInfo;
313 aclParamsInfo.set_peephole_params(&aclCellToForgetWeightsInfo,
314 &aclCellToOutputWeightsInfo);
323 aclProjectionBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetProjectionBias());
327 aclParamsInfo.set_projection_params(
328 &aclProjectionWeightsInfo,
344 aclParamsInfo.set_layer_normalization_params(
346 &aclForgetLayerNormWeightsInfo,
347 &aclCellLayerNormWeightsInfo,
348 &aclOutputLayerNormWeightsInfo);
355 aclInputGateBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetInputGateBias());
358 aclParamsInfo.set_cifg_params(
359 &aclInputToInputWeightsInfo,
360 &aclRecurrentToInputWeightsInfo,
362 &aclInputGateBiasInfo);
366 aclParamsInfo.set_cell_clip_params(descriptor.
m_CellClip);
375 return arm_compute::NEQLSTMLayer::validate(&aclInputInfo,
376 &aclInputToForgetWeightsInfo,
377 &aclInputToCellWeightsInfo,
378 &aclInputToOutputWeightsInfo,
379 &aclRecurrentToForgetWeightsInfo,
380 &aclRecurrentToCellWeightsInfo,
381 &aclRecurrentToOutputWeightsInfo,
382 &aclForgetGateBiasInfo,
384 &aclOutputGateBiasInfo,
386 &aclOutputStateInInfo,
387 &aclCellStateOutInfo,
388 &aclOutputStateOutInfo,
393 void NeonQLstmWorkload::FreeUnusedTensors()
395 FreeTensorIfUnused(m_InputToInputWeightsTensor);
396 FreeTensorIfUnused(m_InputToForgetWeightsTensor);
397 FreeTensorIfUnused(m_InputToCellWeightsTensor);
398 FreeTensorIfUnused(m_InputToOutputWeightsTensor);
400 FreeTensorIfUnused(m_RecurrentToInputWeightsTensor);
401 FreeTensorIfUnused(m_RecurrentToForgetWeightsTensor);
402 FreeTensorIfUnused(m_RecurrentToCellWeightsTensor);
403 FreeTensorIfUnused(m_RecurrentToOutputWeightsTensor);
405 FreeTensorIfUnused(m_CellToInputWeightsTensor);
406 FreeTensorIfUnused(m_CellToForgetWeightsTensor);
407 FreeTensorIfUnused(m_CellToOutputWeightsTensor);
409 FreeTensorIfUnused(m_InputGateBiasTensor);
410 FreeTensorIfUnused(m_ForgetGateBiasTensor);
411 FreeTensorIfUnused(m_CellBiasTensor);
412 FreeTensorIfUnused(m_OutputGateBiasTensor);
414 FreeTensorIfUnused(m_ProjectionWeightsTensor);
415 FreeTensorIfUnused(m_ProjectionBiasTensor);
417 FreeTensorIfUnused(m_InputLayerNormWeightsTensor);
418 FreeTensorIfUnused(m_ForgetLayerNormWeightsTensor);
419 FreeTensorIfUnused(m_CellLayerNormWeightsTensor);
420 FreeTensorIfUnused(m_OutputLayerNormWeightsTensor);
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
NeonQLstmWorkload(const QLstmQueueDescriptor &descriptor, const WorkloadInfo &info)
virtual void Execute() const override
Copyright (c) 2021 ARM Limited and Contributors.
void InitializeArmComputeTensorData(arm_compute::Tensor &tensor, TensorInfo tensorInfo, const ITensorHandle *handle)
arm_compute::Status NeonQLstmWorkloadValidate(const TensorInfo &input, const TensorInfo &cellStateIn, const TensorInfo &outputStateIn, const TensorInfo &cellStateOut, const TensorInfo &outputStateOut, const TensorInfo &output, const QLstmDescriptor &descriptor, const LstmInputParamsInfo ¶msInfo)
A QLstmDescriptor for the QLstmLayer.
float m_CellIntermediateScale
Cell intermediate quantization scale.
float m_InputIntermediateScale
Input intermediate quantization scale.
bool m_PeepholeEnabled
Enable/disable peephole.
int32_t m_HiddenStateZeroPoint
Hidden State zero point.
bool m_LayerNormEnabled
Enable/disable layer normalization.
bool m_ProjectionEnabled
Enable/disable the projection layer.
float m_OutputIntermediateScale
Output intermediate quantization scale.
float m_ProjectionClip
Clipping threshold value for the projection.
float m_CellClip
Clipping threshold value for the cell state.
bool m_CifgEnabled
Enable/disable CIFG (coupled input & forget gate).
float m_HiddenStateScale
Hidden State quantization scale.
float m_ForgetIntermediateScale
Forget intermediate quantization scale.
std::vector< ITensorHandle * > m_Inputs
std::vector< ITensorHandle * > m_Outputs
LayerDescriptor m_Parameters
Contains information about TensorInfos of a layer.