21 : FloatWorkload<LstmQueueDescriptor>(descriptor,
info)
23 arm_compute::LSTMParams<arm_compute::ICLTensor> lstm_param;
26 m_InputToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
27 BuildArmComputeTensor(*m_InputToForgetWeightsTensor,
m_Data.m_InputToForgetWeights->GetTensorInfo());
29 m_InputToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
30 BuildArmComputeTensor(*m_InputToCellWeightsTensor,
m_Data.m_InputToCellWeights->GetTensorInfo());
32 m_InputToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
33 BuildArmComputeTensor(*m_InputToOutputWeightsTensor,
m_Data.m_InputToOutputWeights->GetTensorInfo());
35 m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
36 BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor,
m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
38 m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
39 BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor,
m_Data.m_RecurrentToCellWeights->GetTensorInfo());
41 m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
42 BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor,
m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
44 m_ForgetGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
45 BuildArmComputeTensor(*m_ForgetGateBiasTensor,
m_Data.m_ForgetGateBias->GetTensorInfo());
47 m_CellBiasTensor = std::make_unique<arm_compute::CLTensor>();
48 BuildArmComputeTensor(*m_CellBiasTensor,
m_Data.m_CellBias->GetTensorInfo());
50 m_OutputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
51 BuildArmComputeTensor(*m_OutputGateBiasTensor,
m_Data.m_OutputGateBias->GetTensorInfo());
54 if (!
m_Data.m_Parameters.m_CifgEnabled)
56 m_InputToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
57 BuildArmComputeTensor(*m_InputToInputWeightsTensor,
m_Data.m_InputToInputWeights->GetTensorInfo());
59 m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
60 BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor,
m_Data.m_RecurrentToInputWeights->GetTensorInfo());
62 m_CellToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
63 if (
m_Data.m_CellToInputWeights !=
nullptr)
65 BuildArmComputeTensor(*m_CellToInputWeightsTensor,
m_Data.m_CellToInputWeights->GetTensorInfo());
68 m_InputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
69 BuildArmComputeTensor(*m_InputGateBiasTensor,
m_Data.m_InputGateBias->GetTensorInfo());
71 lstm_param.set_cifg_params(m_InputToInputWeightsTensor.get(),
72 m_RecurrentToInputWeightsTensor.get(),
73 m_Data.m_CellToInputWeights !=
nullptr ? m_CellToInputWeightsTensor.get() :
nullptr,
74 m_InputGateBiasTensor.get());
77 if (
m_Data.m_Parameters.m_ProjectionEnabled)
79 m_ProjectionWeightsTensor = std::make_unique<arm_compute::CLTensor>();
80 BuildArmComputeTensor(*m_ProjectionWeightsTensor,
m_Data.m_ProjectionWeights->GetTensorInfo());
82 m_ProjectionBiasTensor = std::make_unique<arm_compute::CLTensor>();
83 if (
m_Data.m_ProjectionBias !=
nullptr)
85 BuildArmComputeTensor(*m_ProjectionBiasTensor,
m_Data.m_ProjectionBias->GetTensorInfo());
88 lstm_param.set_projection_params(m_ProjectionWeightsTensor.get(),
89 m_Data.m_ProjectionBias !=
nullptr ? m_ProjectionBiasTensor.get() :
nullptr);
92 if (
m_Data.m_Parameters.m_PeepholeEnabled)
94 m_CellToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
95 BuildArmComputeTensor(*m_CellToForgetWeightsTensor,
m_Data.m_CellToForgetWeights->GetTensorInfo());
97 m_CellToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
98 BuildArmComputeTensor(*m_CellToOutputWeightsTensor,
m_Data.m_CellToOutputWeights->GetTensorInfo());
100 lstm_param.set_peephole_params(m_CellToForgetWeightsTensor.get(), m_CellToOutputWeightsTensor.get());
103 if (
m_Data.m_Parameters.m_LayerNormEnabled)
105 m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
106 m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
107 m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
108 m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
110 if (!
m_Data.m_Parameters.m_CifgEnabled)
112 BuildArmComputeTensor(*m_InputLayerNormWeightsTensor,
m_Data.m_InputLayerNormWeights->GetTensorInfo());
114 BuildArmComputeTensor(*m_ForgetLayerNormWeightsTensor,
m_Data.m_ForgetLayerNormWeights->GetTensorInfo());
115 BuildArmComputeTensor(*m_CellLayerNormWeightsTensor,
m_Data.m_CellLayerNormWeights->GetTensorInfo());
116 BuildArmComputeTensor(*m_OutputLayerNormWeightsTensor,
m_Data.m_OutputLayerNormWeights->GetTensorInfo());
118 lstm_param.set_layer_normalization_params(
m_Data.m_Parameters.m_CifgEnabled ?
nullptr :
119 m_InputLayerNormWeightsTensor.get(),
120 m_ForgetLayerNormWeightsTensor.get(),
121 m_CellLayerNormWeightsTensor.get(),
122 m_OutputLayerNormWeightsTensor.get());
125 const arm_compute::ICLTensor& input =
static_cast<IClTensorHandle*
>(
m_Data.
m_Inputs[0])->GetTensor();
126 const arm_compute::ICLTensor& output_state_in =
static_cast<IClTensorHandle*
>(
m_Data.
m_Inputs[1])->GetTensor();
127 const arm_compute::ICLTensor& cell_state_in =
static_cast<IClTensorHandle*
>(
m_Data.
m_Inputs[2])->GetTensor();
129 arm_compute::ICLTensor& output_state_out =
static_cast<IClTensorHandle*
>(
m_Data.
m_Outputs[1])->GetTensor();
130 arm_compute::ICLTensor& cell_state_out =
static_cast<IClTensorHandle*
>(
m_Data.
m_Outputs[2])->GetTensor();
131 arm_compute::ICLTensor& output =
static_cast<IClTensorHandle*
>(
m_Data.
m_Outputs[3])->GetTensor();
134 const TensorInfo& inputTensorInfo =
info.m_InputTensorInfos[2];
135 const unsigned int batch_size =
boost::numeric_cast<
unsigned int>(inputTensorInfo.GetShape()[0]);
136 const unsigned int num_units =
boost::numeric_cast<
unsigned int>(inputTensorInfo.GetShape()[1]);
138 m_ScratchBuffer = std::make_unique<arm_compute::CLTensor>();
139 if (
m_Data.m_Parameters.m_CifgEnabled)
143 BuildArmComputeTensor(*m_ScratchBuffer, scratchBuffer1);
149 BuildArmComputeTensor(*m_ScratchBuffer, scratchBuffer2);
152 float cell_threshold =
m_Data.m_Parameters.m_ClippingThresCell;
153 float projection_threshold =
m_Data.m_Parameters.m_ClippingThresProj;
156 arm_compute::ActivationLayerInfo activationLayerInfo;
157 if (
m_Data.m_Parameters.m_ActivationFunc == 0)
161 else if (
m_Data.m_Parameters.m_ActivationFunc == 1)
163 activationLayerInfo = arm_compute::ActivationLayerInfo(
164 arm_compute::ActivationLayerInfo::ActivationFunction::RELU);
166 else if (
m_Data.m_Parameters.m_ActivationFunc == 3)
168 activationLayerInfo = arm_compute::ActivationLayerInfo(
169 arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.0);
171 else if (
m_Data.m_Parameters.m_ActivationFunc == 4)
173 activationLayerInfo = arm_compute::ActivationLayerInfo(
174 arm_compute::ActivationLayerInfo::ActivationFunction::TANH, 1.0, 1.0);
176 else if (
m_Data.m_Parameters.m_ActivationFunc == 6)
178 activationLayerInfo = arm_compute::ActivationLayerInfo(
179 arm_compute::ActivationLayerInfo::ActivationFunction::LOGISTIC);
186 m_LstmLayer.configure(&input, m_InputToForgetWeightsTensor.get(), m_InputToCellWeightsTensor.get(),
187 m_InputToOutputWeightsTensor.get(), m_RecurrentToForgetWeightsTensor.get(),
188 m_RecurrentToCellWeightsTensor.get(), m_RecurrentToOutputWeightsTensor.get(),
189 m_ForgetGateBiasTensor.get(), m_CellBiasTensor.get(), m_OutputGateBiasTensor.get(),
190 &output_state_in, &cell_state_in, m_ScratchBuffer.get(), &output_state_out,
191 &cell_state_out, &output, lstm_param, activationLayerInfo,
192 cell_threshold, projection_threshold);
194 armcomputetensorutils::InitialiseArmComputeTensorEmpty(*m_ScratchBuffer);
206 if (!
m_Data.m_Parameters.m_CifgEnabled)
210 if (
m_Data.m_CellToInputWeights !=
nullptr)
217 if (
m_Data.m_Parameters.m_ProjectionEnabled)
220 if (
m_Data.m_ProjectionBias !=
nullptr)
226 if (
m_Data.m_Parameters.m_PeepholeEnabled)
232 if (
m_Data.m_Parameters.m_LayerNormEnabled)
234 if (!
m_Data.m_Parameters.m_CifgEnabled)
246 m_LstmLayer.prepare();
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstCpuTensorHandle *handle)
const QueueDescriptor m_Data
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
std::vector< ITensorHandle * > m_Outputs
Base class for all ArmNN exceptions so that users can filter to just those.
std::vector< ITensorHandle * > m_Inputs