20 : FloatWorkload<LstmQueueDescriptor>(descriptor,
info)
22 arm_compute::LSTMParams<arm_compute::ITensor> lstm_param;
25 m_InputToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
26 BuildArmComputeTensor(*m_InputToForgetWeightsTensor,
m_Data.m_InputToForgetWeights->GetTensorInfo());
28 m_InputToCellWeightsTensor = std::make_unique<arm_compute::Tensor>();
29 BuildArmComputeTensor(*m_InputToCellWeightsTensor,
m_Data.m_InputToCellWeights->GetTensorInfo());
31 m_InputToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
32 BuildArmComputeTensor(*m_InputToOutputWeightsTensor,
m_Data.m_InputToOutputWeights->GetTensorInfo());
34 m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
35 BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor,
m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
37 m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::Tensor>();
38 BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor,
m_Data.m_RecurrentToCellWeights->GetTensorInfo());
40 m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
41 BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor,
m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
43 m_ForgetGateBiasTensor = std::make_unique<arm_compute::Tensor>();
44 BuildArmComputeTensor(*m_ForgetGateBiasTensor,
m_Data.m_ForgetGateBias->GetTensorInfo());
46 m_CellBiasTensor = std::make_unique<arm_compute::Tensor>();
47 BuildArmComputeTensor(*m_CellBiasTensor,
m_Data.m_CellBias->GetTensorInfo());
49 m_OutputGateBiasTensor = std::make_unique<arm_compute::Tensor>();
50 BuildArmComputeTensor(*m_OutputGateBiasTensor,
m_Data.m_OutputGateBias->GetTensorInfo());
53 if (!
m_Data.m_Parameters.m_CifgEnabled)
55 m_InputToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
56 BuildArmComputeTensor(*m_InputToInputWeightsTensor,
m_Data.m_InputToInputWeights->GetTensorInfo());
58 m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
59 BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor,
m_Data.m_RecurrentToInputWeights->GetTensorInfo());
61 m_CellToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
62 if (
m_Data.m_CellToInputWeights !=
nullptr)
64 BuildArmComputeTensor(*m_CellToInputWeightsTensor,
m_Data.m_CellToInputWeights->GetTensorInfo());
67 m_InputGateBiasTensor = std::make_unique<arm_compute::Tensor>();
68 BuildArmComputeTensor(*m_InputGateBiasTensor,
m_Data.m_InputGateBias->GetTensorInfo());
70 lstm_param.set_cifg_params(m_InputToInputWeightsTensor.get(),
71 m_RecurrentToInputWeightsTensor.get(),
72 m_Data.m_CellToInputWeights !=
nullptr ? m_CellToInputWeightsTensor.get() :
nullptr,
73 m_InputGateBiasTensor.get());
76 if (
m_Data.m_Parameters.m_ProjectionEnabled)
78 m_ProjectionWeightsTensor = std::make_unique<arm_compute::Tensor>();
79 BuildArmComputeTensor(*m_ProjectionWeightsTensor,
m_Data.m_ProjectionWeights->GetTensorInfo());
81 m_ProjectionBiasTensor = std::make_unique<arm_compute::Tensor>();
82 if (
m_Data.m_ProjectionBias !=
nullptr)
84 BuildArmComputeTensor(*m_ProjectionBiasTensor,
m_Data.m_ProjectionBias->GetTensorInfo());
87 lstm_param.set_projection_params(m_ProjectionWeightsTensor.get(),
88 m_Data.m_ProjectionBias !=
nullptr ? m_ProjectionBiasTensor.get() :
nullptr);
91 if (
m_Data.m_Parameters.m_PeepholeEnabled)
93 m_CellToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
94 BuildArmComputeTensor(*m_CellToForgetWeightsTensor,
m_Data.m_CellToForgetWeights->GetTensorInfo());
96 m_CellToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
97 BuildArmComputeTensor(*m_CellToOutputWeightsTensor,
m_Data.m_CellToOutputWeights->GetTensorInfo());
99 lstm_param.set_peephole_params(m_CellToForgetWeightsTensor.get(), m_CellToOutputWeightsTensor.get());
102 if (
m_Data.m_Parameters.m_LayerNormEnabled)
104 m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
105 if (!
m_Data.m_Parameters.m_CifgEnabled)
107 BuildArmComputeTensor(*m_InputLayerNormWeightsTensor,
m_Data.m_InputLayerNormWeights->GetTensorInfo());
110 m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
111 BuildArmComputeTensor(*m_ForgetLayerNormWeightsTensor,
m_Data.m_ForgetLayerNormWeights->GetTensorInfo());
113 m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
114 BuildArmComputeTensor(*m_CellLayerNormWeightsTensor,
m_Data.m_CellLayerNormWeights->GetTensorInfo());
116 m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
117 BuildArmComputeTensor(*m_OutputLayerNormWeightsTensor,
m_Data.m_OutputLayerNormWeights->GetTensorInfo());
119 lstm_param.set_layer_normalization_params(
m_Data.m_Parameters.m_CifgEnabled ?
120 nullptr : m_InputLayerNormWeightsTensor.get(),
121 m_ForgetLayerNormWeightsTensor.get(),
122 m_CellLayerNormWeightsTensor.get(),
123 m_OutputLayerNormWeightsTensor.get());
126 const arm_compute::ITensor& input =
static_cast<IAclTensorHandle*
>(
m_Data.
m_Inputs[0])->GetTensor();
127 const arm_compute::ITensor& output_state_in =
static_cast<IAclTensorHandle*
>(
m_Data.
m_Inputs[1])->GetTensor();
128 const arm_compute::ITensor& cell_state_in =
static_cast<IAclTensorHandle*
>(
m_Data.
m_Inputs[2])->GetTensor();
130 arm_compute::ITensor& output_state_out =
static_cast<IAclTensorHandle*
>(
m_Data.
m_Outputs[1])->GetTensor();
131 arm_compute::ITensor& cell_state_out =
static_cast<IAclTensorHandle*
>(
m_Data.
m_Outputs[2])->GetTensor();
132 arm_compute::ITensor& output =
static_cast<IAclTensorHandle*
>(
m_Data.
m_Outputs[3])->GetTensor();
135 const TensorInfo& inputTensorInfo =
info.m_InputTensorInfos[2];
136 const unsigned int batch_size =
armnn::numeric_cast<
unsigned int>(inputTensorInfo.GetShape()[0]);
137 const unsigned int num_units =
armnn::numeric_cast<
unsigned int>(inputTensorInfo.GetShape()[1]);
139 m_ScratchBuffer = std::make_unique<arm_compute::Tensor>();
140 if (
m_Data.m_Parameters.m_CifgEnabled)
144 BuildArmComputeTensor(*m_ScratchBuffer, scratchBuffer1);
150 BuildArmComputeTensor(*m_ScratchBuffer, scratchBuffer2);
153 float cell_threshold =
m_Data.m_Parameters.m_ClippingThresCell;
154 float projection_threshold =
m_Data.m_Parameters.m_ClippingThresProj;
157 arm_compute::ActivationLayerInfo activationLayerInfo;
158 if (
m_Data.m_Parameters.m_ActivationFunc == 0)
162 else if (
m_Data.m_Parameters.m_ActivationFunc == 1)
164 activationLayerInfo = arm_compute::ActivationLayerInfo(
165 arm_compute::ActivationLayerInfo::ActivationFunction::RELU);
167 else if (
m_Data.m_Parameters.m_ActivationFunc == 3)
169 activationLayerInfo = arm_compute::ActivationLayerInfo(
170 arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.0);
172 else if (
m_Data.m_Parameters.m_ActivationFunc == 4)
174 activationLayerInfo = arm_compute::ActivationLayerInfo(
175 arm_compute::ActivationLayerInfo::ActivationFunction::TANH, 1.0, 1.0);
177 else if (
m_Data.m_Parameters.m_ActivationFunc == 6)
179 activationLayerInfo = arm_compute::ActivationLayerInfo(
180 arm_compute::ActivationLayerInfo::ActivationFunction::LOGISTIC);
188 m_LstmLayer.configure(&input, m_InputToForgetWeightsTensor.get(), m_InputToCellWeightsTensor.get(),
189 m_InputToOutputWeightsTensor.get(), m_RecurrentToForgetWeightsTensor.get(),
190 m_RecurrentToCellWeightsTensor.get(), m_RecurrentToOutputWeightsTensor.get(),
191 m_ForgetGateBiasTensor.get(), m_CellBiasTensor.get(), m_OutputGateBiasTensor.get(),
192 &output_state_in, &cell_state_in, m_ScratchBuffer.get(), &output_state_out,
193 &cell_state_out, &output, lstm_param, activationLayerInfo,
194 cell_threshold, projection_threshold);
196 armcomputetensorutils::InitialiseArmComputeTensorEmpty(*m_ScratchBuffer);
199 m_Data.m_InputToForgetWeights);
201 m_Data.m_InputToCellWeights);
203 m_Data.m_InputToOutputWeights);
205 m_Data.m_RecurrentToForgetWeights);
207 m_Data.m_RecurrentToCellWeights);
209 m_Data.m_RecurrentToOutputWeights);
217 if (!
m_Data.m_Parameters.m_CifgEnabled)
220 m_Data.m_InputToInputWeights);
222 m_Data.m_RecurrentToInputWeights);
223 if (
m_Data.m_CellToInputWeights !=
nullptr)
226 m_Data.m_CellToInputWeights);
232 if (
m_Data.m_Parameters.m_ProjectionEnabled)
235 m_Data.m_ProjectionWeights);
236 if (
m_Data.m_ProjectionBias !=
nullptr)
243 if (
m_Data.m_Parameters.m_PeepholeEnabled)
246 m_Data.m_CellToForgetWeights);
248 m_Data.m_CellToOutputWeights);
251 if (
m_Data.m_Parameters.m_LayerNormEnabled)
253 if (!
m_Data.m_Parameters.m_CifgEnabled)
264 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 InitializeArmComputeTensorData(arm_compute::Tensor &tensor, const ConstTensorHandle *handle)
std::vector< ITensorHandle * > m_Inputs