15 using namespace armcomputetensorutils;
19 const arm_compute::CLCompileContext& clCompileContext)
22 arm_compute::LSTMParams<arm_compute::ICLTensor> qLstmParams;
25 m_InputToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
28 m_InputToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
31 m_InputToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
34 m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
37 m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
40 m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
43 m_ForgetGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
46 m_CellBiasTensor = std::make_unique<arm_compute::CLTensor>();
49 m_OutputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
55 m_CellToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
63 m_CellToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
66 m_CellToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
70 qLstmParams.set_peephole_params(m_CellToForgetWeightsTensor.get(),
71 m_CellToOutputWeightsTensor.get());
76 m_ProjectionWeightsTensor = std::make_unique<arm_compute::CLTensor>();
79 m_ProjectionBiasTensor = std::make_unique<arm_compute::CLTensor>();
86 qLstmParams.set_projection_params(
87 m_ProjectionWeightsTensor.get(),
93 m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
100 m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
103 m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
106 m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
110 qLstmParams.set_layer_normalization_params(
112 m_ForgetLayerNormWeightsTensor.get(),
113 m_CellLayerNormWeightsTensor.get(),
114 m_OutputLayerNormWeightsTensor.get());
119 m_InputToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
122 m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
125 m_InputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
129 qLstmParams.set_cifg_params(
130 m_InputToInputWeightsTensor.get(),
131 m_RecurrentToInputWeightsTensor.get(),
133 m_InputGateBiasTensor.get());
156 m_QLstmLayer.configure(clCompileContext,
158 m_InputToForgetWeightsTensor.get(),
159 m_InputToCellWeightsTensor.get(),
160 m_InputToOutputWeightsTensor.get(),
161 m_RecurrentToForgetWeightsTensor.get(),
162 m_RecurrentToCellWeightsTensor.get(),
163 m_RecurrentToOutputWeightsTensor.get(),
164 m_ForgetGateBiasTensor.get(),
165 m_CellBiasTensor.get(),
166 m_OutputGateBiasTensor.get(),
227 m_QLstmLayer.prepare();
246 arm_compute::LSTMParams<arm_compute::ITensorInfo> aclParamsInfo;
249 const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
250 const arm_compute::TensorInfo aclOutputStateInInfo = BuildArmComputeTensorInfo(outputStateIn);
251 const arm_compute::TensorInfo aclCellStateInInfo = BuildArmComputeTensorInfo(cellStateIn);
253 const arm_compute::TensorInfo aclOutputStateOutInfo = BuildArmComputeTensorInfo(outputStateOut);
254 const arm_compute::TensorInfo aclCellStateOutInfo = BuildArmComputeTensorInfo(cellStateOut);
255 const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
258 const arm_compute::TensorInfo aclInputToForgetWeightsInfo
260 const arm_compute::TensorInfo aclInputToCellWeightsInfo
262 const arm_compute::TensorInfo aclInputToOutputWeightsInfo
264 const arm_compute::TensorInfo aclRecurrentToForgetWeightsInfo
266 const arm_compute::TensorInfo aclRecurrentToCellWeightsInfo
268 const arm_compute::TensorInfo aclRecurrentToOutputWeightsInfo
270 const arm_compute::TensorInfo aclForgetGateBiasInfo
272 const arm_compute::TensorInfo aclCellBiasInfo
273 = BuildArmComputeTensorInfo(paramsInfo.
GetCellBias());
274 const arm_compute::TensorInfo aclOutputGateBiasInfo
278 arm_compute::TensorInfo aclInputToInputWeightsInfo;
279 arm_compute::TensorInfo aclRecurrentToInputWeightsInfo;
281 arm_compute::TensorInfo aclCellToInputWeightsInfo;
282 arm_compute::TensorInfo aclCellToForgetWeightsInfo;
283 arm_compute::TensorInfo aclCellToOutputWeightsInfo;
285 arm_compute::TensorInfo aclInputGateBiasInfo;
287 arm_compute::TensorInfo aclProjectionWeightsInfo;
288 arm_compute::TensorInfo aclProjectionBiasInfo;
290 arm_compute::TensorInfo aclInputLayerNormWeightsInfo;
291 arm_compute::TensorInfo aclForgetLayerNormWeightsInfo;
292 arm_compute::TensorInfo aclCellLayerNormWeightsInfo;
293 arm_compute::TensorInfo aclOutputLayerNormWeightsInfo;
307 aclParamsInfo.set_peephole_params(&aclCellToForgetWeightsInfo,
308 &aclCellToOutputWeightsInfo);
317 aclProjectionBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetProjectionBias());
321 aclParamsInfo.set_projection_params(
322 &aclProjectionWeightsInfo,
338 aclParamsInfo.set_layer_normalization_params(
340 &aclForgetLayerNormWeightsInfo,
341 &aclCellLayerNormWeightsInfo,
342 &aclOutputLayerNormWeightsInfo);
349 aclInputGateBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetInputGateBias());
352 aclParamsInfo.set_cifg_params(
353 &aclInputToInputWeightsInfo,
354 &aclRecurrentToInputWeightsInfo,
356 &aclInputGateBiasInfo);
360 aclParamsInfo.set_cell_clip_params(descriptor.
m_CellClip);
369 return arm_compute::CLQLSTMLayer::validate(&aclInputInfo,
370 &aclInputToForgetWeightsInfo,
371 &aclInputToCellWeightsInfo,
372 &aclInputToOutputWeightsInfo,
373 &aclRecurrentToForgetWeightsInfo,
374 &aclRecurrentToCellWeightsInfo,
375 &aclRecurrentToOutputWeightsInfo,
376 &aclForgetGateBiasInfo,
378 &aclOutputGateBiasInfo,
380 &aclOutputStateInInfo,
381 &aclCellStateOutInfo,
382 &aclOutputStateOutInfo,
387 void ClQLstmWorkload::FreeUnusedTensors()
389 FreeTensorIfUnused(m_InputToInputWeightsTensor);
390 FreeTensorIfUnused(m_InputToForgetWeightsTensor);
391 FreeTensorIfUnused(m_InputToCellWeightsTensor);
392 FreeTensorIfUnused(m_InputToOutputWeightsTensor);
394 FreeTensorIfUnused(m_RecurrentToInputWeightsTensor);
395 FreeTensorIfUnused(m_RecurrentToForgetWeightsTensor);
396 FreeTensorIfUnused(m_RecurrentToCellWeightsTensor);
397 FreeTensorIfUnused(m_RecurrentToOutputWeightsTensor);
399 FreeTensorIfUnused(m_CellToInputWeightsTensor);
400 FreeTensorIfUnused(m_CellToForgetWeightsTensor);
401 FreeTensorIfUnused(m_CellToOutputWeightsTensor);
403 FreeTensorIfUnused(m_InputGateBiasTensor);
404 FreeTensorIfUnused(m_ForgetGateBiasTensor);
405 FreeTensorIfUnused(m_CellBiasTensor);
406 FreeTensorIfUnused(m_OutputGateBiasTensor);
408 FreeTensorIfUnused(m_ProjectionWeightsTensor);
409 FreeTensorIfUnused(m_ProjectionBiasTensor);
411 FreeTensorIfUnused(m_InputLayerNormWeightsTensor);
412 FreeTensorIfUnused(m_ForgetLayerNormWeightsTensor);
413 FreeTensorIfUnused(m_CellLayerNormWeightsTensor);
414 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) 2021 ARM Limited and Contributors.
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.
ClQLstmWorkload(const QLstmQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
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
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