15 using namespace armcomputetensorutils;
19 const arm_compute::CLCompileContext& clCompileContext)
28 arm_compute::LSTMParams<arm_compute::ICLTensor> qLstmParams;
31 m_InputToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
34 m_InputToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
37 m_InputToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
40 m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
43 m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
46 m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
49 m_ForgetGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
52 m_CellBiasTensor = std::make_unique<arm_compute::CLTensor>();
55 m_OutputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
61 m_CellToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
69 m_CellToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
72 m_CellToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
76 qLstmParams.set_peephole_params(m_CellToForgetWeightsTensor.get(),
77 m_CellToOutputWeightsTensor.get());
82 m_ProjectionWeightsTensor = std::make_unique<arm_compute::CLTensor>();
85 m_ProjectionBiasTensor = std::make_unique<arm_compute::CLTensor>();
92 qLstmParams.set_projection_params(
93 m_ProjectionWeightsTensor.get(),
99 m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
106 m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
109 m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
112 m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
116 qLstmParams.set_layer_normalization_params(
118 m_ForgetLayerNormWeightsTensor.get(),
119 m_CellLayerNormWeightsTensor.get(),
120 m_OutputLayerNormWeightsTensor.get());
125 m_InputToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
128 m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
131 m_InputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
135 qLstmParams.set_cifg_params(
136 m_InputToInputWeightsTensor.get(),
137 m_RecurrentToInputWeightsTensor.get(),
139 m_InputGateBiasTensor.get());
162 m_QLstmLayer.configure(clCompileContext,
164 m_InputToForgetWeightsTensor.get(),
165 m_InputToCellWeightsTensor.get(),
166 m_InputToOutputWeightsTensor.get(),
167 m_RecurrentToForgetWeightsTensor.get(),
168 m_RecurrentToCellWeightsTensor.get(),
169 m_RecurrentToOutputWeightsTensor.get(),
170 m_ForgetGateBiasTensor.get(),
171 m_CellBiasTensor.get(),
172 m_OutputGateBiasTensor.get(),
233 m_QLstmLayer.prepare();
253 arm_compute::LSTMParams<arm_compute::ITensorInfo> aclParamsInfo;
256 const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
257 const arm_compute::TensorInfo aclOutputStateInInfo = BuildArmComputeTensorInfo(outputStateIn);
258 const arm_compute::TensorInfo aclCellStateInInfo = BuildArmComputeTensorInfo(cellStateIn);
260 const arm_compute::TensorInfo aclOutputStateOutInfo = BuildArmComputeTensorInfo(outputStateOut);
261 const arm_compute::TensorInfo aclCellStateOutInfo = BuildArmComputeTensorInfo(cellStateOut);
262 const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
265 const arm_compute::TensorInfo aclInputToForgetWeightsInfo
267 const arm_compute::TensorInfo aclInputToCellWeightsInfo
269 const arm_compute::TensorInfo aclInputToOutputWeightsInfo
271 const arm_compute::TensorInfo aclRecurrentToForgetWeightsInfo
273 const arm_compute::TensorInfo aclRecurrentToCellWeightsInfo
275 const arm_compute::TensorInfo aclRecurrentToOutputWeightsInfo
277 const arm_compute::TensorInfo aclForgetGateBiasInfo
279 const arm_compute::TensorInfo aclCellBiasInfo
280 = BuildArmComputeTensorInfo(paramsInfo.
GetCellBias());
281 const arm_compute::TensorInfo aclOutputGateBiasInfo
285 arm_compute::TensorInfo aclInputToInputWeightsInfo;
286 arm_compute::TensorInfo aclRecurrentToInputWeightsInfo;
288 arm_compute::TensorInfo aclCellToInputWeightsInfo;
289 arm_compute::TensorInfo aclCellToForgetWeightsInfo;
290 arm_compute::TensorInfo aclCellToOutputWeightsInfo;
292 arm_compute::TensorInfo aclInputGateBiasInfo;
294 arm_compute::TensorInfo aclProjectionWeightsInfo;
295 arm_compute::TensorInfo aclProjectionBiasInfo;
297 arm_compute::TensorInfo aclInputLayerNormWeightsInfo;
298 arm_compute::TensorInfo aclForgetLayerNormWeightsInfo;
299 arm_compute::TensorInfo aclCellLayerNormWeightsInfo;
300 arm_compute::TensorInfo aclOutputLayerNormWeightsInfo;
314 aclParamsInfo.set_peephole_params(&aclCellToForgetWeightsInfo,
315 &aclCellToOutputWeightsInfo);
324 aclProjectionBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetProjectionBias());
328 aclParamsInfo.set_projection_params(
329 &aclProjectionWeightsInfo,
345 aclParamsInfo.set_layer_normalization_params(
347 &aclForgetLayerNormWeightsInfo,
348 &aclCellLayerNormWeightsInfo,
349 &aclOutputLayerNormWeightsInfo);
356 aclInputGateBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetInputGateBias());
359 aclParamsInfo.set_cifg_params(
360 &aclInputToInputWeightsInfo,
361 &aclRecurrentToInputWeightsInfo,
363 &aclInputGateBiasInfo);
367 aclParamsInfo.set_cell_clip_params(descriptor.
m_CellClip);
376 return arm_compute::CLQLSTMLayer::validate(&aclInputInfo,
377 &aclInputToForgetWeightsInfo,
378 &aclInputToCellWeightsInfo,
379 &aclInputToOutputWeightsInfo,
380 &aclRecurrentToForgetWeightsInfo,
381 &aclRecurrentToCellWeightsInfo,
382 &aclRecurrentToOutputWeightsInfo,
383 &aclForgetGateBiasInfo,
385 &aclOutputGateBiasInfo,
387 &aclOutputStateInInfo,
388 &aclCellStateOutInfo,
389 &aclOutputStateOutInfo,
394 void ClQLstmWorkload::FreeUnusedTensors()
396 FreeTensorIfUnused(m_InputToInputWeightsTensor);
397 FreeTensorIfUnused(m_InputToForgetWeightsTensor);
398 FreeTensorIfUnused(m_InputToCellWeightsTensor);
399 FreeTensorIfUnused(m_InputToOutputWeightsTensor);
401 FreeTensorIfUnused(m_RecurrentToInputWeightsTensor);
402 FreeTensorIfUnused(m_RecurrentToForgetWeightsTensor);
403 FreeTensorIfUnused(m_RecurrentToCellWeightsTensor);
404 FreeTensorIfUnused(m_RecurrentToOutputWeightsTensor);
406 FreeTensorIfUnused(m_CellToInputWeightsTensor);
407 FreeTensorIfUnused(m_CellToForgetWeightsTensor);
408 FreeTensorIfUnused(m_CellToOutputWeightsTensor);
410 FreeTensorIfUnused(m_InputGateBiasTensor);
411 FreeTensorIfUnused(m_ForgetGateBiasTensor);
412 FreeTensorIfUnused(m_CellBiasTensor);
413 FreeTensorIfUnused(m_OutputGateBiasTensor);
415 FreeTensorIfUnused(m_ProjectionWeightsTensor);
416 FreeTensorIfUnused(m_ProjectionBiasTensor);
418 FreeTensorIfUnused(m_InputLayerNormWeightsTensor);
419 FreeTensorIfUnused(m_ForgetLayerNormWeightsTensor);
420 FreeTensorIfUnused(m_CellLayerNormWeightsTensor);
421 FreeTensorIfUnused(m_OutputLayerNormWeightsTensor);
const ConstTensorHandle * m_CellLayerNormWeights
const ConstTensorHandle * m_ProjectionWeights
#define ARMNN_SCOPED_PROFILING_EVENT_CL_GUID(name, guid)
const ConstTensorHandle * m_ForgetGateBias
const ConstTensorHandle * m_InputToOutputWeights
bool m_PeepholeEnabled
Enable/disable peephole.
virtual void Execute() const override
float m_HiddenStateScale
Hidden State quantization scale.
const ConstTensorHandle * m_InputToInputWeights
const ConstTensorHandle * m_CellToOutputWeights
float m_OutputIntermediateScale
Output intermediate quantization scale.
const ConstTensorHandle * m_CellToInputWeights
Copyright (c) 2021 ARM Limited and Contributors.
LayerDescriptor m_Parameters
const ConstTensorHandle * m_ForgetLayerNormWeights
const TensorInfo & GetTensorInfo() const
bool m_LayerNormEnabled
Enable/disable layer normalization.
QLstmQueueDescriptor m_Data
float m_ProjectionClip
Clipping threshold value for the projection.
const ConstTensorHandle * m_InputToForgetWeights
float m_InputIntermediateScale
Input intermediate quantization scale.
const ConstTensorHandle * m_CellBias
A QLstmDescriptor for the QLstmLayer.
const ConstTensorHandle * m_InputLayerNormWeights
profiling::ProfilingGuid GetGuid() const final
float m_ForgetIntermediateScale
Forget intermediate quantization scale.
const ConstTensorHandle * m_InputToCellWeights
float m_CellClip
Clipping threshold value for the cell state.
const ConstTensorHandle * m_CellToForgetWeights
ClQLstmWorkload(const QLstmQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
const ConstTensorHandle * m_ProjectionBias
std::vector< ITensorHandle * > m_Outputs
const ConstTensorHandle * m_RecurrentToCellWeights
bool m_ProjectionEnabled
Enable/disable the projection layer.
const ConstTensorHandle * m_InputGateBias
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Contains information about TensorInfos of 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)
const ConstTensorHandle * m_OutputGateBias
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstTensorHandle *handle)
std::vector< ITensorHandle * > m_Inputs
const ConstTensorHandle * m_OutputLayerNormWeights
float m_CellIntermediateScale
Cell intermediate quantization scale.
const ConstTensorHandle * m_RecurrentToOutputWeights
const ConstTensorHandle * m_RecurrentToInputWeights
bool m_CifgEnabled
Enable/disable CIFG (coupled input & forget gate).
const ConstTensorHandle * m_RecurrentToForgetWeights
int32_t m_HiddenStateZeroPoint
Hidden State zero point.