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>();
108 qLstmParams.set_layer_normalization_params(
110 m_ForgetLayerNormWeightsTensor.get(),
111 m_CellLayerNormWeightsTensor.get(),
112 m_OutputLayerNormWeightsTensor.get());
117 m_InputToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
120 m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
123 m_InputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
127 qLstmParams.set_cifg_params(
128 m_InputToInputWeightsTensor.get(),
129 m_RecurrentToInputWeightsTensor.get(),
131 m_InputGateBiasTensor.get());
154 m_QLstmLayer.configure(&input,
155 m_InputToForgetWeightsTensor.get(),
156 m_InputToCellWeightsTensor.get(),
157 m_InputToOutputWeightsTensor.get(),
158 m_RecurrentToForgetWeightsTensor.get(),
159 m_RecurrentToCellWeightsTensor.get(),
160 m_RecurrentToOutputWeightsTensor.get(),
161 m_ForgetGateBiasTensor.get(),
162 m_CellBiasTensor.get(),
163 m_OutputGateBiasTensor.get(),
224 m_QLstmLayer.prepare();
243 arm_compute::LSTMParams<arm_compute::ITensorInfo> aclParamsInfo;
246 const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
247 const arm_compute::TensorInfo aclOutputStateInInfo = BuildArmComputeTensorInfo(outputStateIn);
248 const arm_compute::TensorInfo aclCellStateInInfo = BuildArmComputeTensorInfo(cellStateIn);
250 const arm_compute::TensorInfo aclOutputStateOutInfo = BuildArmComputeTensorInfo(outputStateOut);
251 const arm_compute::TensorInfo aclCellStateOutInfo = BuildArmComputeTensorInfo(cellStateOut);
252 const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
255 const arm_compute::TensorInfo aclInputToForgetWeightsInfo
257 const arm_compute::TensorInfo aclInputToCellWeightsInfo
259 const arm_compute::TensorInfo aclInputToOutputWeightsInfo
261 const arm_compute::TensorInfo aclRecurrentToForgetWeightsInfo
263 const arm_compute::TensorInfo aclRecurrentToCellWeightsInfo
265 const arm_compute::TensorInfo aclRecurrentToOutputWeightsInfo
267 const arm_compute::TensorInfo aclForgetGateBiasInfo
269 const arm_compute::TensorInfo aclCellBiasInfo
270 = BuildArmComputeTensorInfo(paramsInfo.
GetCellBias());
271 const arm_compute::TensorInfo aclOutputGateBiasInfo
275 arm_compute::TensorInfo aclInputToInputWeightsInfo;
276 arm_compute::TensorInfo aclRecurrentToInputWeightsInfo;
278 arm_compute::TensorInfo aclCellToInputWeightsInfo;
279 arm_compute::TensorInfo aclCellToForgetWeightsInfo;
280 arm_compute::TensorInfo aclCellToOutputWeightsInfo;
282 arm_compute::TensorInfo aclInputGateBiasInfo;
284 arm_compute::TensorInfo aclProjectionWeightsInfo;
285 arm_compute::TensorInfo aclProjectionBiasInfo;
287 arm_compute::TensorInfo aclInputLayerNormWeightsInfo;
288 arm_compute::TensorInfo aclForgetLayerNormWeightsInfo;
289 arm_compute::TensorInfo aclCellLayerNormWeightsInfo;
290 arm_compute::TensorInfo aclOutputLayerNormWeightsInfo;
304 aclParamsInfo.set_peephole_params(&aclCellToForgetWeightsInfo,
305 &aclCellToOutputWeightsInfo);
314 aclProjectionBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetProjectionBias());
318 aclParamsInfo.set_projection_params(
319 &aclProjectionWeightsInfo,
335 aclParamsInfo.set_layer_normalization_params(
337 &aclForgetLayerNormWeightsInfo,
338 &aclCellLayerNormWeightsInfo,
339 &aclOutputLayerNormWeightsInfo);
346 aclInputGateBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetInputGateBias());
349 aclParamsInfo.set_cifg_params(
350 &aclInputToInputWeightsInfo,
351 &aclRecurrentToInputWeightsInfo,
353 &aclInputGateBiasInfo);
357 aclParamsInfo.set_cell_clip_params(descriptor.
m_CellClip);
366 return arm_compute::CLQLSTMLayer::validate(&aclInputInfo,
367 &aclInputToForgetWeightsInfo,
368 &aclInputToCellWeightsInfo,
369 &aclInputToOutputWeightsInfo,
370 &aclRecurrentToForgetWeightsInfo,
371 &aclRecurrentToCellWeightsInfo,
372 &aclRecurrentToOutputWeightsInfo,
373 &aclForgetGateBiasInfo,
375 &aclOutputGateBiasInfo,
377 &aclOutputStateInInfo,
378 &aclCellStateOutInfo,
379 &aclOutputStateOutInfo,
384 void ClQLstmWorkload::FreeUnusedTensors()
386 FreeTensorIfUnused(m_InputToInputWeightsTensor);
387 FreeTensorIfUnused(m_InputToForgetWeightsTensor);
388 FreeTensorIfUnused(m_InputToCellWeightsTensor);
389 FreeTensorIfUnused(m_InputToOutputWeightsTensor);
391 FreeTensorIfUnused(m_RecurrentToInputWeightsTensor);
392 FreeTensorIfUnused(m_RecurrentToForgetWeightsTensor);
393 FreeTensorIfUnused(m_RecurrentToCellWeightsTensor);
394 FreeTensorIfUnused(m_RecurrentToOutputWeightsTensor);
396 FreeTensorIfUnused(m_CellToInputWeightsTensor);
397 FreeTensorIfUnused(m_CellToForgetWeightsTensor);
398 FreeTensorIfUnused(m_CellToOutputWeightsTensor);
400 FreeTensorIfUnused(m_InputGateBiasTensor);
401 FreeTensorIfUnused(m_ForgetGateBiasTensor);
402 FreeTensorIfUnused(m_CellBiasTensor);
403 FreeTensorIfUnused(m_OutputGateBiasTensor);
405 FreeTensorIfUnused(m_ProjectionWeightsTensor);
406 FreeTensorIfUnused(m_ProjectionBiasTensor);
408 FreeTensorIfUnused(m_InputLayerNormWeightsTensor);
409 FreeTensorIfUnused(m_ForgetLayerNormWeightsTensor);
410 FreeTensorIfUnused(m_CellLayerNormWeightsTensor);
411 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