26 : FloatWorkload<LstmQueueDescriptor>(descriptor, info)
30 descriptor.m_Parameters,
34 arm_compute::LSTMParams<arm_compute::ICLTensor> lstm_param;
37 m_InputToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
38 BuildArmComputeTensor(*m_InputToForgetWeightsTensor,
m_Data.m_InputToForgetWeights->GetTensorInfo());
40 m_InputToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
41 BuildArmComputeTensor(*m_InputToCellWeightsTensor,
m_Data.m_InputToCellWeights->GetTensorInfo());
43 m_InputToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
44 BuildArmComputeTensor(*m_InputToOutputWeightsTensor,
m_Data.m_InputToOutputWeights->GetTensorInfo());
46 m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
47 BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor,
m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
49 m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
50 BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor,
m_Data.m_RecurrentToCellWeights->GetTensorInfo());
52 m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
53 BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor,
m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
55 m_ForgetGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
56 BuildArmComputeTensor(*m_ForgetGateBiasTensor,
m_Data.m_ForgetGateBias->GetTensorInfo());
58 m_CellBiasTensor = std::make_unique<arm_compute::CLTensor>();
59 BuildArmComputeTensor(*m_CellBiasTensor,
m_Data.m_CellBias->GetTensorInfo());
61 m_OutputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
62 BuildArmComputeTensor(*m_OutputGateBiasTensor,
m_Data.m_OutputGateBias->GetTensorInfo());
65 if (!
m_Data.m_Parameters.m_CifgEnabled)
67 m_InputToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
68 BuildArmComputeTensor(*m_InputToInputWeightsTensor,
m_Data.m_InputToInputWeights->GetTensorInfo());
70 m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
71 BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor,
m_Data.m_RecurrentToInputWeights->GetTensorInfo());
73 m_CellToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
74 if (
m_Data.m_CellToInputWeights !=
nullptr)
76 BuildArmComputeTensor(*m_CellToInputWeightsTensor,
m_Data.m_CellToInputWeights->GetTensorInfo());
79 m_InputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
80 BuildArmComputeTensor(*m_InputGateBiasTensor,
m_Data.m_InputGateBias->GetTensorInfo());
82 lstm_param.set_cifg_params(m_InputToInputWeightsTensor.get(),
83 m_RecurrentToInputWeightsTensor.get(),
84 m_Data.m_CellToInputWeights !=
nullptr ? m_CellToInputWeightsTensor.get() :
nullptr,
85 m_InputGateBiasTensor.get());
88 if (
m_Data.m_Parameters.m_ProjectionEnabled)
90 m_ProjectionWeightsTensor = std::make_unique<arm_compute::CLTensor>();
91 BuildArmComputeTensor(*m_ProjectionWeightsTensor,
m_Data.m_ProjectionWeights->GetTensorInfo());
93 m_ProjectionBiasTensor = std::make_unique<arm_compute::CLTensor>();
94 if (
m_Data.m_ProjectionBias !=
nullptr)
96 BuildArmComputeTensor(*m_ProjectionBiasTensor,
m_Data.m_ProjectionBias->GetTensorInfo());
99 lstm_param.set_projection_params(m_ProjectionWeightsTensor.get(),
100 m_Data.m_ProjectionBias !=
nullptr ? m_ProjectionBiasTensor.get() :
nullptr);
103 if (
m_Data.m_Parameters.m_PeepholeEnabled)
105 m_CellToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
106 BuildArmComputeTensor(*m_CellToForgetWeightsTensor,
m_Data.m_CellToForgetWeights->GetTensorInfo());
108 m_CellToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
109 BuildArmComputeTensor(*m_CellToOutputWeightsTensor,
m_Data.m_CellToOutputWeights->GetTensorInfo());
111 lstm_param.set_peephole_params(m_CellToForgetWeightsTensor.get(), m_CellToOutputWeightsTensor.get());
114 if (
m_Data.m_Parameters.m_LayerNormEnabled)
116 m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
117 m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
118 m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
119 m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
121 if (!
m_Data.m_Parameters.m_CifgEnabled)
123 BuildArmComputeTensor(*m_InputLayerNormWeightsTensor,
m_Data.m_InputLayerNormWeights->GetTensorInfo());
125 BuildArmComputeTensor(*m_ForgetLayerNormWeightsTensor,
m_Data.m_ForgetLayerNormWeights->GetTensorInfo());
126 BuildArmComputeTensor(*m_CellLayerNormWeightsTensor,
m_Data.m_CellLayerNormWeights->GetTensorInfo());
127 BuildArmComputeTensor(*m_OutputLayerNormWeightsTensor,
m_Data.m_OutputLayerNormWeights->GetTensorInfo());
129 lstm_param.set_layer_normalization_params(
m_Data.m_Parameters.m_CifgEnabled ?
nullptr :
130 m_InputLayerNormWeightsTensor.get(),
131 m_ForgetLayerNormWeightsTensor.get(),
132 m_CellLayerNormWeightsTensor.get(),
133 m_OutputLayerNormWeightsTensor.get());
136 const arm_compute::ICLTensor& input =
static_cast<IClTensorHandle*
>(
m_Data.
m_Inputs[0])->GetTensor();
137 const arm_compute::ICLTensor& output_state_in =
static_cast<IClTensorHandle*
>(
m_Data.
m_Inputs[1])->GetTensor();
138 arm_compute::ICLTensor& cell_state_in =
static_cast<IClTensorHandle*
>(
m_Data.
m_Inputs[2])->GetTensor();
140 arm_compute::ICLTensor& output_state_out =
static_cast<IClTensorHandle*
>(
m_Data.
m_Outputs[1])->GetTensor();
141 arm_compute::ICLTensor& cell_state_out =
static_cast<IClTensorHandle*
>(
m_Data.
m_Outputs[2])->GetTensor();
142 arm_compute::ICLTensor& output =
static_cast<IClTensorHandle*
>(
m_Data.
m_Outputs[3])->GetTensor();
145 const TensorInfo& inputTensorInfo =
info.m_InputTensorInfos[2];
146 const unsigned int batch_size = armnn::numeric_cast<unsigned int>(inputTensorInfo.GetShape()[0]);
147 const unsigned int num_units = armnn::numeric_cast<unsigned int>(inputTensorInfo.GetShape()[1]);
149 m_ScratchBuffer = std::make_unique<arm_compute::CLTensor>();
150 if (
m_Data.m_Parameters.m_CifgEnabled)
154 BuildArmComputeTensor(*m_ScratchBuffer, scratchBuffer1);
160 BuildArmComputeTensor(*m_ScratchBuffer, scratchBuffer2);
163 float cell_threshold =
m_Data.m_Parameters.m_ClippingThresCell;
164 float projection_threshold =
m_Data.m_Parameters.m_ClippingThresProj;
167 arm_compute::ActivationLayerInfo activationLayerInfo =
172 m_LstmLayer.configure(clCompileContext, &input, m_InputToForgetWeightsTensor.get(),
173 m_InputToCellWeightsTensor.get(), m_InputToOutputWeightsTensor.get(),
174 m_RecurrentToForgetWeightsTensor.get(), m_RecurrentToCellWeightsTensor.get(),
175 m_RecurrentToOutputWeightsTensor.get(), m_ForgetGateBiasTensor.get(),
176 m_CellBiasTensor.get(), m_OutputGateBiasTensor.get(), &output_state_in,
177 &cell_state_in, m_ScratchBuffer.get(), &output_state_out,
178 &cell_state_out, &output, lstm_param, activationLayerInfo,
179 cell_threshold, projection_threshold);
182 armcomputetensorutils::InitialiseArmComputeTensorEmpty(*m_ScratchBuffer);
194 if (!
m_Data.m_Parameters.m_CifgEnabled)
198 if (
m_Data.m_CellToInputWeights !=
nullptr)
205 if (
m_Data.m_Parameters.m_ProjectionEnabled)
208 if (
m_Data.m_ProjectionBias !=
nullptr)
214 if (
m_Data.m_Parameters.m_PeepholeEnabled)
220 if (
m_Data.m_Parameters.m_LayerNormEnabled)
222 if (!
m_Data.m_Parameters.m_CifgEnabled)
234 m_LstmLayer.prepare();