15 using namespace armcomputetensorutils;
20 arm_compute::LSTMParams<arm_compute::ICLTensor> qLstmParams;
23 m_InputToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
26 m_InputToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
29 m_InputToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
32 m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
35 m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
38 m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
41 m_ForgetGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
44 m_CellBiasTensor = std::make_unique<arm_compute::CLTensor>();
47 m_OutputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
53 m_CellToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
61 m_CellToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
64 m_CellToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
68 qLstmParams.set_peephole_params(m_CellToForgetWeightsTensor.get(),
69 m_CellToOutputWeightsTensor.get());
74 m_ProjectionWeightsTensor = std::make_unique<arm_compute::CLTensor>();
77 m_ProjectionBiasTensor = std::make_unique<arm_compute::CLTensor>();
84 qLstmParams.set_projection_params(
85 m_ProjectionWeightsTensor.get(),
91 m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
98 m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
101 m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
104 m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
107 qLstmParams.set_layer_normalization_params(
109 m_ForgetLayerNormWeightsTensor.get(),
110 m_CellLayerNormWeightsTensor.get(),
111 m_OutputLayerNormWeightsTensor.get());
116 m_InputToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
119 m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
122 m_InputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
125 qLstmParams.set_cifg_params(
126 m_InputToInputWeightsTensor.get(),
127 m_RecurrentToInputWeightsTensor.get(),
129 m_InputGateBiasTensor.get());
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(),
220 m_QLstmLayer.prepare();
239 arm_compute::LSTMParams<arm_compute::ITensorInfo> aclParamsInfo;
242 const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
243 const arm_compute::TensorInfo aclOutputStateInInfo = BuildArmComputeTensorInfo(outputStateIn);
244 const arm_compute::TensorInfo aclCellStateInInfo = BuildArmComputeTensorInfo(cellStateIn);
246 const arm_compute::TensorInfo aclOutputStateOutInfo = BuildArmComputeTensorInfo(outputStateOut);
247 const arm_compute::TensorInfo aclCellStateOutInfo = BuildArmComputeTensorInfo(cellStateOut);
248 const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
251 const arm_compute::TensorInfo aclInputToForgetWeightsInfo
253 const arm_compute::TensorInfo aclInputToCellWeightsInfo
255 const arm_compute::TensorInfo aclInputToOutputWeightsInfo
257 const arm_compute::TensorInfo aclRecurrentToForgetWeightsInfo
259 const arm_compute::TensorInfo aclRecurrentToCellWeightsInfo
261 const arm_compute::TensorInfo aclRecurrentToOutputWeightsInfo
263 const arm_compute::TensorInfo aclForgetGateBiasInfo
265 const arm_compute::TensorInfo aclCellBiasInfo
266 = BuildArmComputeTensorInfo(paramsInfo.
GetCellBias());
267 const arm_compute::TensorInfo aclOutputGateBiasInfo
271 arm_compute::TensorInfo aclInputToInputWeightsInfo;
272 arm_compute::TensorInfo aclRecurrentToInputWeightsInfo;
273 arm_compute::TensorInfo aclCellToInputWeightsInfo;
274 arm_compute::TensorInfo aclCellToForgetWeightsInfo;
275 arm_compute::TensorInfo aclCellToOutputWeightsInfo;
276 arm_compute::TensorInfo aclInputGateBiasInfo;
277 arm_compute::TensorInfo aclProjectionWeightsInfo;
278 arm_compute::TensorInfo aclProjectionBiasInfo;
279 arm_compute::TensorInfo aclInputLayerNormWeightsInfo;
280 arm_compute::TensorInfo aclForgetLayerNormWeightsInfo;
281 arm_compute::TensorInfo aclCellLayerNormWeightsInfo;
282 arm_compute::TensorInfo aclOutputLayerNormWeightsInfo;
295 aclParamsInfo.set_peephole_params(&aclCellToForgetWeightsInfo,
296 &aclCellToOutputWeightsInfo);
305 aclProjectionBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetProjectionBias());
308 aclParamsInfo.set_projection_params(
309 &aclProjectionWeightsInfo,
324 aclParamsInfo.set_layer_normalization_params(
326 &aclForgetLayerNormWeightsInfo,
327 &aclCellLayerNormWeightsInfo,
328 &aclOutputLayerNormWeightsInfo);
335 aclInputGateBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetInputGateBias());
338 aclParamsInfo.set_cifg_params(
339 &aclInputToInputWeightsInfo,
340 &aclRecurrentToInputWeightsInfo,
342 &aclInputGateBiasInfo);
345 aclParamsInfo.set_cell_clip_params(descriptor.
m_CellClip);
353 return arm_compute::CLQLSTMLayer::validate(&aclInputInfo,
354 &aclInputToForgetWeightsInfo,
355 &aclInputToCellWeightsInfo,
356 &aclInputToOutputWeightsInfo,
357 &aclRecurrentToForgetWeightsInfo,
358 &aclRecurrentToCellWeightsInfo,
359 &aclRecurrentToOutputWeightsInfo,
360 &aclForgetGateBiasInfo,
362 &aclOutputGateBiasInfo,
364 &aclOutputStateInInfo,
365 &aclCellStateOutInfo,
366 &aclOutputStateOutInfo,
371 void ClQLstmWorkload::FreeUnusedTensors()
373 FreeTensorIfUnused(m_InputToInputWeightsTensor);
374 FreeTensorIfUnused(m_InputToForgetWeightsTensor);
375 FreeTensorIfUnused(m_InputToCellWeightsTensor);
376 FreeTensorIfUnused(m_InputToOutputWeightsTensor);
378 FreeTensorIfUnused(m_RecurrentToInputWeightsTensor);
379 FreeTensorIfUnused(m_RecurrentToForgetWeightsTensor);
380 FreeTensorIfUnused(m_RecurrentToCellWeightsTensor);
381 FreeTensorIfUnused(m_RecurrentToOutputWeightsTensor);
383 FreeTensorIfUnused(m_CellToInputWeightsTensor);
384 FreeTensorIfUnused(m_CellToForgetWeightsTensor);
385 FreeTensorIfUnused(m_CellToOutputWeightsTensor);
387 FreeTensorIfUnused(m_InputGateBiasTensor);
388 FreeTensorIfUnused(m_ForgetGateBiasTensor);
389 FreeTensorIfUnused(m_CellBiasTensor);
390 FreeTensorIfUnused(m_OutputGateBiasTensor);
392 FreeTensorIfUnused(m_ProjectionWeightsTensor);
393 FreeTensorIfUnused(m_ProjectionBiasTensor);
395 FreeTensorIfUnused(m_InputLayerNormWeightsTensor);
396 FreeTensorIfUnused(m_ForgetLayerNormWeightsTensor);
397 FreeTensorIfUnused(m_CellLayerNormWeightsTensor);
398 FreeTensorIfUnused(m_OutputLayerNormWeightsTensor);
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
virtual void Execute() const override
float m_HiddenStateScale
Hidden State quantization scale.
const ConstCpuTensorHandle * m_ForgetLayerNormWeights
const QLstmQueueDescriptor m_Data
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
Copyright (c) 2020 ARM Limited.
LayerDescriptor m_Parameters
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.
A QLstmDescriptor for the QLstmLayer.
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
Contains information about inputs and outputs to a layer.
arm_compute::Status ClQLstmWorkloadValidate(const TensorInfo &input, const TensorInfo &cellStateIn, const TensorInfo &outputStateIn, const TensorInfo &cellStateOut, const TensorInfo &outputStateOut, const TensorInfo &output, const QLstmDescriptor &descriptor, const LstmInputParamsInfo ¶msInfo)
std::vector< ITensorHandle * > m_Inputs
const ConstCpuTensorHandle * m_InputLayerNormWeights
const ConstCpuTensorHandle * m_RecurrentToForgetWeights
ClQLstmWorkload(const QLstmQueueDescriptor &descriptor, const WorkloadInfo &info)
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