25 : FloatWorkload<LstmQueueDescriptor>(descriptor,
info)
27 arm_compute::LSTMParams<arm_compute::ICLTensor> lstm_param;
30 m_InputToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
31 BuildArmComputeTensor(*m_InputToForgetWeightsTensor,
m_Data.m_InputToForgetWeights->GetTensorInfo());
33 m_InputToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
34 BuildArmComputeTensor(*m_InputToCellWeightsTensor,
m_Data.m_InputToCellWeights->GetTensorInfo());
36 m_InputToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
37 BuildArmComputeTensor(*m_InputToOutputWeightsTensor,
m_Data.m_InputToOutputWeights->GetTensorInfo());
39 m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
40 BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor,
m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
42 m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
43 BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor,
m_Data.m_RecurrentToCellWeights->GetTensorInfo());
45 m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
46 BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor,
m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
48 m_ForgetGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
49 BuildArmComputeTensor(*m_ForgetGateBiasTensor,
m_Data.m_ForgetGateBias->GetTensorInfo());
51 m_CellBiasTensor = std::make_unique<arm_compute::CLTensor>();
52 BuildArmComputeTensor(*m_CellBiasTensor,
m_Data.m_CellBias->GetTensorInfo());
54 m_OutputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
55 BuildArmComputeTensor(*m_OutputGateBiasTensor,
m_Data.m_OutputGateBias->GetTensorInfo());
58 if (!
m_Data.m_Parameters.m_CifgEnabled)
60 m_InputToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
61 BuildArmComputeTensor(*m_InputToInputWeightsTensor,
m_Data.m_InputToInputWeights->GetTensorInfo());
63 m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
64 BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor,
m_Data.m_RecurrentToInputWeights->GetTensorInfo());
66 m_CellToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
67 if (
m_Data.m_CellToInputWeights !=
nullptr)
69 BuildArmComputeTensor(*m_CellToInputWeightsTensor,
m_Data.m_CellToInputWeights->GetTensorInfo());
72 m_InputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
73 BuildArmComputeTensor(*m_InputGateBiasTensor,
m_Data.m_InputGateBias->GetTensorInfo());
75 lstm_param.set_cifg_params(m_InputToInputWeightsTensor.get(),
76 m_RecurrentToInputWeightsTensor.get(),
77 m_Data.m_CellToInputWeights !=
nullptr ? m_CellToInputWeightsTensor.get() :
nullptr,
78 m_InputGateBiasTensor.get());
81 if (
m_Data.m_Parameters.m_ProjectionEnabled)
83 m_ProjectionWeightsTensor = std::make_unique<arm_compute::CLTensor>();
84 BuildArmComputeTensor(*m_ProjectionWeightsTensor,
m_Data.m_ProjectionWeights->GetTensorInfo());
86 m_ProjectionBiasTensor = std::make_unique<arm_compute::CLTensor>();
87 if (
m_Data.m_ProjectionBias !=
nullptr)
89 BuildArmComputeTensor(*m_ProjectionBiasTensor,
m_Data.m_ProjectionBias->GetTensorInfo());
92 lstm_param.set_projection_params(m_ProjectionWeightsTensor.get(),
93 m_Data.m_ProjectionBias !=
nullptr ? m_ProjectionBiasTensor.get() :
nullptr);
96 if (
m_Data.m_Parameters.m_PeepholeEnabled)
98 m_CellToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
99 BuildArmComputeTensor(*m_CellToForgetWeightsTensor,
m_Data.m_CellToForgetWeights->GetTensorInfo());
101 m_CellToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
102 BuildArmComputeTensor(*m_CellToOutputWeightsTensor,
m_Data.m_CellToOutputWeights->GetTensorInfo());
104 lstm_param.set_peephole_params(m_CellToForgetWeightsTensor.get(), m_CellToOutputWeightsTensor.get());
107 if (
m_Data.m_Parameters.m_LayerNormEnabled)
109 m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
110 m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
111 m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
112 m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
114 if (!
m_Data.m_Parameters.m_CifgEnabled)
116 BuildArmComputeTensor(*m_InputLayerNormWeightsTensor,
m_Data.m_InputLayerNormWeights->GetTensorInfo());
118 BuildArmComputeTensor(*m_ForgetLayerNormWeightsTensor,
m_Data.m_ForgetLayerNormWeights->GetTensorInfo());
119 BuildArmComputeTensor(*m_CellLayerNormWeightsTensor,
m_Data.m_CellLayerNormWeights->GetTensorInfo());
120 BuildArmComputeTensor(*m_OutputLayerNormWeightsTensor,
m_Data.m_OutputLayerNormWeights->GetTensorInfo());
122 lstm_param.set_layer_normalization_params(
m_Data.m_Parameters.m_CifgEnabled ?
nullptr :
123 m_InputLayerNormWeightsTensor.get(),
124 m_ForgetLayerNormWeightsTensor.get(),
125 m_CellLayerNormWeightsTensor.get(),
126 m_OutputLayerNormWeightsTensor.get());
129 const arm_compute::ICLTensor& input =
static_cast<IClTensorHandle*
>(
m_Data.
m_Inputs[0])->GetTensor();
130 const arm_compute::ICLTensor& output_state_in =
static_cast<IClTensorHandle*
>(
m_Data.
m_Inputs[1])->GetTensor();
131 arm_compute::ICLTensor& cell_state_in =
static_cast<IClTensorHandle*
>(
m_Data.
m_Inputs[2])->GetTensor();
133 arm_compute::ICLTensor& output_state_out =
static_cast<IClTensorHandle*
>(
m_Data.
m_Outputs[1])->GetTensor();
134 arm_compute::ICLTensor& cell_state_out =
static_cast<IClTensorHandle*
>(
m_Data.
m_Outputs[2])->GetTensor();
135 arm_compute::ICLTensor& output =
static_cast<IClTensorHandle*
>(
m_Data.
m_Outputs[3])->GetTensor();
138 const TensorInfo& inputTensorInfo =
info.m_InputTensorInfos[2];
139 const unsigned int batch_size =
armnn::numeric_cast<
unsigned int>(inputTensorInfo.GetShape()[0]);
140 const unsigned int num_units =
armnn::numeric_cast<
unsigned int>(inputTensorInfo.GetShape()[1]);
142 m_ScratchBuffer = std::make_unique<arm_compute::CLTensor>();
143 if (
m_Data.m_Parameters.m_CifgEnabled)
147 BuildArmComputeTensor(*m_ScratchBuffer, scratchBuffer1);
153 BuildArmComputeTensor(*m_ScratchBuffer, scratchBuffer2);
156 float cell_threshold =
m_Data.m_Parameters.m_ClippingThresCell;
157 float projection_threshold =
m_Data.m_Parameters.m_ClippingThresProj;
160 arm_compute::ActivationLayerInfo activationLayerInfo;
161 if (
m_Data.m_Parameters.m_ActivationFunc == 0)
165 else if (
m_Data.m_Parameters.m_ActivationFunc == 1)
167 activationLayerInfo = arm_compute::ActivationLayerInfo(
168 arm_compute::ActivationLayerInfo::ActivationFunction::RELU);
170 else if (
m_Data.m_Parameters.m_ActivationFunc == 3)
172 activationLayerInfo = arm_compute::ActivationLayerInfo(
173 arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.0);
175 else if (
m_Data.m_Parameters.m_ActivationFunc == 4)
177 activationLayerInfo = arm_compute::ActivationLayerInfo(
178 arm_compute::ActivationLayerInfo::ActivationFunction::TANH, 1.0, 1.0);
180 else if (
m_Data.m_Parameters.m_ActivationFunc == 6)
182 activationLayerInfo = arm_compute::ActivationLayerInfo(
183 arm_compute::ActivationLayerInfo::ActivationFunction::LOGISTIC);
190 m_LstmLayer.configure(clCompileContext, &input, m_InputToForgetWeightsTensor.get(),
191 m_InputToCellWeightsTensor.get(), m_InputToOutputWeightsTensor.get(),
192 m_RecurrentToForgetWeightsTensor.get(), m_RecurrentToCellWeightsTensor.get(),
193 m_RecurrentToOutputWeightsTensor.get(), m_ForgetGateBiasTensor.get(),
194 m_CellBiasTensor.get(), m_OutputGateBiasTensor.get(), &output_state_in,
195 &cell_state_in, m_ScratchBuffer.get(), &output_state_out,
196 &cell_state_out, &output, lstm_param, activationLayerInfo,
197 cell_threshold, projection_threshold);
199 armcomputetensorutils::InitialiseArmComputeTensorEmpty(*m_ScratchBuffer);
211 if (!
m_Data.m_Parameters.m_CifgEnabled)
215 if (
m_Data.m_CellToInputWeights !=
nullptr)
222 if (
m_Data.m_Parameters.m_ProjectionEnabled)
225 if (
m_Data.m_ProjectionBias !=
nullptr)
231 if (
m_Data.m_Parameters.m_PeepholeEnabled)
237 if (
m_Data.m_Parameters.m_LayerNormEnabled)
239 if (!
m_Data.m_Parameters.m_CifgEnabled)
251 m_LstmLayer.prepare();
std::vector< ITensorHandle * > m_Outputs
Base class for all ArmNN exceptions so that users can filter to just those.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstTensorHandle *handle)
std::vector< ITensorHandle * > m_Inputs