ArmNN
 22.05.01
UnidirectionalSequenceLstmTestImpl.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
9 
11 
14 
15 #include <ResolveType.hpp>
16 
17 namespace {
18 
19 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
21 UnidirectionalSequenceLstmTimeMajorSingleBatchTestImpl(
22  armnn::IWorkloadFactory& workloadFactory,
24  const armnn::ITensorHandleFactory& tensorHandleFactory,
25  const std::vector<T>& input,
26  const std::vector<T>& outputExpected,
27  const armnn::TensorShape& inputShape,
28  const armnn::TensorShape& outputExpectedShape,
29  float qScale = 0.0f,
30  int32_t qOffset = 0,
31  armnn::DataType constantDataType = armnn::DataType::Float32)
32 {
33  IgnoreUnused(memoryManager);
34  unsigned int batchSize = armnn::numeric_cast<unsigned int>(inputShape[0]);
35  unsigned int inputSize = armnn::numeric_cast<unsigned int>(inputShape[2]);
36  unsigned int outputSize = armnn::numeric_cast<unsigned int>(outputExpectedShape[2]);
37  unsigned numUnits = outputSize;
38 
39  armnn::TensorInfo inputTensorInfo({1, batchSize , inputSize}, ArmnnType, qScale, qOffset );
40  armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, ArmnnType, qScale, qOffset);
41  armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, ArmnnType, qScale, qOffset);
42  armnn::TensorInfo outputStateOutTensorInfo({ batchSize, 1, outputSize }, ArmnnType, qScale, qOffset);
43  armnn::TensorInfo cellStateOutTensorInfo({ batchSize, 1, outputSize }, ArmnnType, qScale, qOffset);
44  armnn::TensorInfo outputTensorInfo({1, batchSize, outputSize}, ArmnnType, qScale, qOffset);
45 
46  std::vector<T> inputVector;
47  inputVector.assign(input.data(), input.data() + (batchSize * inputSize));
48 
49  std::vector<T> cellStateInVector(batchSize * numUnits, T());
50  std::vector<T> outputStateInVector(batchSize * outputSize, T());
51 
52  std::vector<T> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
53  std::vector<T> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
54  std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
55 
56  std::vector<T> outputVector;
57  outputVector.assign(outputExpected.data(), outputExpected.data() + (batchSize * outputSize));
58 
59  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
60  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
61  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
62  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
63  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
64 
65  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
66  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
67  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
68  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
69  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
70 
73 
74  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
75  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
76  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
77 
78  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
79  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
80  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
81 
82  armnn::TensorInfo tensorInfo4({numUnits}, constantDataType , qScale, qOffset);
83  armnn::TensorInfo tensorInfo8({numUnits, 2}, constantDataType, qScale, qOffset);
84  armnn::TensorInfo tensorInfo16({numUnits, 4}, constantDataType, qScale, qOffset);
85 
86  std::vector<float> inputToInputWeights = {-0.45018822f, -0.02338299f, -0.0870589f,
87  -0.34550029f, 0.04266912f, -0.15680569f,
88  -0.34856534f, 0.43890524f};
89 
90  std::vector<float> inputToForgetWeights = { 0.09701663f, 0.20334584f, -0.50592935f,
91  -0.31343272f, -0.40032279f, 0.44781327f,
92  0.01387155f, -0.35593212f};
93 
94  std::vector<float> inputToCellWeights = { -0.50013041f, 0.1370284f, 0.11810488f, 0.2013163f,
95  -0.20583314f, 0.44344562f, 0.22077113f,
96  -0.29909778f};
97 
98  std::vector<float> inputToOutputWeights = { -0.25065863f, -0.28290087f, 0.04613829f,
99  0.40525138f, 0.44272184f, 0.03897077f,
100  -0.1556896f, 0.19487578f};
101 
102  std::vector<float> recurrentToInputWeights = {-0.0063535f, -0.2042388f, 0.31454784f,
103  -0.35746509f, 0.28902304f, 0.08183324f,
104  -0.16555229f, 0.02286911f, -0.13566875f,
105  0.03034258f, 0.48091322f, -0.12528998f,
106  0.24077177f, -0.51332325f, -0.33502164f,
107  0.10629296f};
108 
109  std::vector<float> recurrentToForgetWeights = { -0.48684245f, -0.06655136f, 0.42224967f,
110  0.2112639f, 0.27654213f, 0.20864892f,
111  -0.07646349f, 0.45877004f, 0.00141793f,
112  -0.14609534f, 0.36447752f, 0.09196436f,
113  0.28053468f, 0.01560611f, -0.20127171f,
114  -0.01140004f};
115 
116  std::vector<float> recurrentToCellWeights = { -0.3407414f, 0.24443203f, -0.2078532f,
117  0.26320225f, 0.05695659f, -0.00123841f,
118  -0.4744786f, -0.35869038f, -0.06418842f,
119  -0.13502428f, -0.501764f, 0.22830659f,
120  -0.46367589f, 0.26016325f, -0.03894562f,
121  -0.16368064f};
122 
123  std::vector<float> recurrentToOutputWeights = { 0.43385774f, -0.17194885f, 0.2718237f,
124  0.09215671f, 0.24107647f, -0.39835793f,
125  0.18212086f, 0.01301402f, 0.48572797f,
126  -0.50656658f, 0.20047462f, -0.20607421f,
127  -0.51818722f, -0.15390486f, 0.0468148f,
128  0.39922136f};
129 
130  std::vector<float> cellToInputWeights = {0., 0., 0., 0.};
131 
132  std::vector<float> inputGateBias = {0., 0., 0., 0.};
133 
134  std::vector<float> forgetGateBias = {1., 1., 1., 1.};
135 
136  std::vector<float> cellBias = {0., 0., 0., 0.};
137 
138  std::vector<float> outputGateBias = {0., 0., 0., 0.};
139 
140  armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfo8);
141  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfo8);
142  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfo8);
143  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfo8);
144  armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfo16);
145  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfo16);
146  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfo16);
147  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfo16);
148  armnn::ScopedTensorHandle cellToInputWeightsTensor(tensorInfo4);
149  armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfo4);
150  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfo4);
151  armnn::ScopedTensorHandle cellBiasTensor(tensorInfo4);
152  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfo4);
153 
154  AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data());
155  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
156  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
157  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
158  AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data());
159  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
160  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
161  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
162  AllocateAndCopyDataToITensorHandle(&cellToInputWeightsTensor, cellToInputWeights.data());
163  AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data());
164  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
165  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
166  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
167 
168  data.m_InputToInputWeights = &inputToInputWeightsTensor;
169  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
170  data.m_InputToCellWeights = &inputToCellWeightsTensor;
171  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
172  data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
173  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
174  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
175  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
176  data.m_InputGateBias = &inputGateBiasTensor;
177  data.m_ForgetGateBias = &forgetGateBiasTensor;
178  data.m_CellBias = &cellBiasTensor;
179  data.m_OutputGateBias = &outputGateBiasTensor;
180 
181  // Flags to set test configuration
183  data.m_Parameters.m_CifgEnabled = false;
184  data.m_Parameters.m_PeepholeEnabled = false;
185  data.m_Parameters.m_ProjectionEnabled = false;
188  data.m_Parameters.m_TimeMajor = true;
189 
190  std::unique_ptr<armnn::IWorkload> workload
191  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
192  inputHandle->Allocate();
193  outputStateInHandle->Allocate();
194  cellStateInHandle->Allocate();
195 
196  outputStateOutHandle->Allocate();
197  cellStateOutHandle->Allocate();
198  outputHandle->Allocate();
199 
200  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
201  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
202  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
203 
204  workload->Execute();
205 
206  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
207  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
208  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
209 
210  return LayerTestResult<T, 3>(actualOutput,
211  outputVector,
212  outputHandle->GetShape(),
213  outputTensorInfo.GetShape());
214 }
215 
216 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
217 LayerTestResult<T, 3> UnidirectionalSequenceLstmLayerFloat32TestImpl(
218  armnn::IWorkloadFactory& workloadFactory,
220  const armnn::ITensorHandleFactory& tensorHandleFactory,
221  const std::vector<T>& input,
222  const std::vector<T>& outputExpected,
223  const armnn::TensorShape& inputShape,
224  const armnn::TensorShape& outputExpectedShape,
225  float qScale = 0.0f,
226  int32_t qOffset = 0,
227  armnn::DataType constantDataType = armnn::DataType::Float32) {
228  IgnoreUnused(memoryManager);
229  unsigned int batchSize = armnn::numeric_cast<unsigned int>(inputShape[0]);
230  unsigned int timeSize = armnn::numeric_cast<unsigned int>(inputShape[1]);
231  unsigned int inputSize = armnn::numeric_cast<unsigned int>(inputShape[2]);
232  unsigned int outputSize = armnn::numeric_cast<unsigned int>(outputExpectedShape[2]);
233  unsigned numUnits = outputSize;
234 
235  armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, ArmnnType, qScale, qOffset);
236  armnn::TensorInfo cellStateInTensorInfo({batchSize, numUnits}, ArmnnType, qScale, qOffset);
237  armnn::TensorInfo outputStateInTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset);
238  armnn::TensorInfo outputStateOutTensorInfo({batchSize, timeSize, outputSize}, ArmnnType, qScale, qOffset);
239  armnn::TensorInfo cellStateOutTensorInfo({batchSize, timeSize, outputSize}, ArmnnType, qScale, qOffset);
240  armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, ArmnnType, qScale, qOffset);
241 
242  std::vector<T> inputVector;
243  inputVector.assign(input.data(), input.data() + (batchSize * timeSize * inputSize));
244 
245  std::vector<T> cellStateInVector(batchSize * numUnits, T());
246  std::vector<T> outputStateInVector(batchSize * outputSize, T());
247 
248  std::vector<T> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
249  std::vector<T> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
250  std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
251 
252  std::vector<T> outputVector;
253  outputVector.assign(outputExpected.data(), outputExpected.data() + (batchSize * timeSize * outputSize));
254 
255  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
256  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
257  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
258  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
259  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
260 
261  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
262  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
263  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
264  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
265  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
266 
268  armnn::WorkloadInfo info;
269 
270  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
271  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
272  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
273 
274  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
275  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
276  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
277 
278  armnn::TensorInfo tensorInfo4({numUnits}, constantDataType, qScale, qOffset);
279  armnn::TensorInfo tensorInfo12({numUnits, 3}, constantDataType, qScale, qOffset);
280  armnn::TensorInfo tensorInfo16({numUnits, 4}, constantDataType, qScale, qOffset);
281 
282  std::vector<float> inputToInputWeights = { -0.49536117f, -0.0556083915f, -0.102400711f,
283  -0.117484632f, 0.3298470976f, -0.1179017122f,
284  0.214305695f, 0.42135173085f, 0.003878414626f,
285  -0.348303917f, -0.1881275477f, 0.0343011027f };
286 
287  std::vector<float> inputToForgetWeights = { 0.2415594226f, 0.15400093799f, 0.4566498398f,
288  -0.3810434485f, 0.268383264f, -0.009807467424f,
289  -0.3522925403f, -0.24275735512f, -0.28344226125f,
290  0.13512269116f, -0.4932442977f, -0.10039821991f };
291 
292  std::vector<float> inputToCellWeights = { -0.2504855627f, 0.184490025045f, -0.2480507493f,
293  0.386399507f, -0.259465157985f, -0.16545993089f,
294  -0.4230232555f, 0.341664791103f, -0.18127849691f,
295  -0.2277662414f, -0.55275535589f, 0.34184026718f };
296 
297  std::vector<float> inputToOutputWeights = { 0.2303854227f, 0.5218806862f, -0.4865379333f,
298  0.53969591851f, 0.23393625035f, -0.27140527306f,
299  0.50009280443f, 0.07511717046f, 0.3998299249f,
300  -0.51717478049f, 0.1889653282f, -0.367323637f };
301 
302  std::vector<float> recurrentToInputWeights = { -0.128009796112f, 0.1995525098f, -0.07745539397f, 0.1558421701f,
303  -0.265254765766f, -0.38837709614f, -0.05636804124f, 0.4259087456f,
304  0.17628988623f, 0.3877420127f, 0.53300309181f, -0.0959980934f,
305  0.00302857416f, 0.3266998827f, -0.142509296562f, -0.04433270756f };
306 
307  std::vector<float> recurrentToForgetWeights = { -0.09499983487f, -0.08814888417f, -0.04834804721f, 0.1516668247f,
308  -0.3967529535f, -0.06463699788f, 0.4952811002f, 0.003274492938f,
309  -0.0968840941f, 0.17928104102f, 0.0031281141592f, -0.3387276584f,
310  -0.3587934076f, 0.06705895066f, 0.22463923692f, 0.1961955726f };
311 
312  std::vector<float> recurrentToCellWeights = { -0.21938985582f, -0.3023648226f, -0.1170005202f, -0.3509177422f,
313  -0.4286288613f, 0.2726137042f, 0.09216640889f, -0.06551410215f,
314  0.20453298098f, 0.2393476665f, 0.11846517771f, 0.2630801796f,
315  0.3954237699f, -0.19407111404f, 0.30412107706f, -0.27342408554f };
316 
317  std::vector<float> recurrentToOutputWeights = { -0.32921677827f, 0.32624614238f, -0.1388191282f, -0.17879831790f,
318  -0.15185534954f, -0.16918526583f, -0.10087361183f, -0.5436913968f,
319  0.016758225858f, 0.30454617738f, -0.41493862867f, -0.005565764375f,
320  -0.12584099173f, -0.12319286912f, 0.2407919466f, -0.08879069983f };
321 
322  std::vector<float> inputGateBias = { 0., 0., 0., 0. };
323 
324  std::vector<float> forgetGateBias = { 1., 1., 1., 1. };
325 
326  std::vector<float> cellBias = { 0., 0., 0., 0. };
327 
328  std::vector<float> outputGateBias = { 0., 0., 0., 0. };
329 
330  armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfo12);
331  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfo12);
332  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfo12);
333  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfo12);
334  armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfo16);
335  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfo16);
336  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfo16);
337  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfo16);
338  armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfo4);
339  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfo4);
340  armnn::ScopedTensorHandle cellBiasTensor(tensorInfo4);
341  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfo4);
342 
343  AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data());
344  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
345  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
346  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
347  AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data());
348  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
349  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
350  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
351  AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data());
352  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
353  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
354  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
355 
356  data.m_InputToInputWeights = &inputToInputWeightsTensor;
357  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
358  data.m_InputToCellWeights = &inputToCellWeightsTensor;
359  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
360  data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
361  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
362  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
363  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
364  data.m_InputGateBias = &inputGateBiasTensor;
365  data.m_ForgetGateBias = &forgetGateBiasTensor;
366  data.m_CellBias = &cellBiasTensor;
367  data.m_OutputGateBias = &outputGateBiasTensor;
368 
369  // Flags to set test configuration
373  data.m_Parameters.m_CifgEnabled = false;
374  data.m_Parameters.m_PeepholeEnabled = false;
375  data.m_Parameters.m_ProjectionEnabled = false;
376  data.m_Parameters.m_TimeMajor = false;
377 
378  std::unique_ptr<armnn::IWorkload> workload
379  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
380  inputHandle->Allocate();
381  outputStateInHandle->Allocate();
382  cellStateInHandle->Allocate();
383 
384  outputStateOutHandle->Allocate();
385  cellStateOutHandle->Allocate();
386  outputHandle->Allocate();
387 
388  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
389  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
390  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
391 
392  workload->Execute();
393 
394  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
395  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
396  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
397 
398  return LayerTestResult<T, 3>(actualOutput,
399  outputVector,
400  outputHandle->GetShape(),
401  outputTensorInfo.GetShape());
402 }
403 
404 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
406 UnidirectionalSequenceLstmLayerFloat32TimeMajorTestImpl(
407  armnn::IWorkloadFactory& workloadFactory,
409  const armnn::ITensorHandleFactory& tensorHandleFactory,
410  const std::vector<T>& input,
411  const std::vector<T>& outputExpected,
412  const armnn::TensorShape& inputShape,
413  const armnn::TensorShape& outputExpectedShape,
414  float qScale = 0.0f,
415  int32_t qOffset = 0,
416  armnn::DataType constantDataType = armnn::DataType::Float32) {
417  IgnoreUnused(memoryManager);
418  unsigned int batchSize = armnn::numeric_cast<unsigned int>(inputShape[1]);
419  unsigned int timeSize = armnn::numeric_cast<unsigned int>(inputShape[0]);
420  unsigned int inputSize = armnn::numeric_cast<unsigned int>(inputShape[2]);
421  unsigned int outputSize = armnn::numeric_cast<unsigned int>(outputExpectedShape[2]);
422  unsigned numUnits = outputSize;
423 
424  armnn::TensorInfo inputTensorInfo({timeSize, batchSize, inputSize}, ArmnnType, qScale, qOffset);
425  armnn::TensorInfo cellStateInTensorInfo({batchSize, numUnits}, ArmnnType, qScale, qOffset);
426  armnn::TensorInfo outputStateInTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset);
427  armnn::TensorInfo outputStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
428  armnn::TensorInfo cellStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
429  armnn::TensorInfo outputTensorInfo({timeSize, batchSize, outputSize}, ArmnnType, qScale, qOffset);
430 
431  std::vector<T> inputVector;
432  inputVector.assign(input.data(), input.data() + (batchSize * timeSize * inputSize));
433 
434  std::vector<T> cellStateInVector(batchSize * numUnits, T());
435  std::vector<T> outputStateInVector(batchSize * outputSize, T());
436 
437  std::vector<T> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
438  std::vector<T> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
439  std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
440 
441  std::vector<T> outputVector;
442  outputVector.assign(outputExpected.data(), outputExpected.data() + (batchSize * timeSize * outputSize));
443 
444  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
445  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
446  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
447  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
448  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
449 
450  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
451  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
452  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
453  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
454  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
455 
457  armnn::WorkloadInfo info;
458 
459  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
460  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
461  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
462 
463  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
464  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
465  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
466 
467  armnn::TensorInfo tensorInfo4({numUnits}, constantDataType, qScale, qOffset);
468  armnn::TensorInfo tensorInfo12({numUnits, 3}, constantDataType, qScale, qOffset);
469  armnn::TensorInfo tensorInfo16({numUnits, 4}, constantDataType, qScale, qOffset);
470 
471  std::vector<float> inputToInputWeights = { 0.27277296781539917f, 0.3813590407371521f, -0.394489049911499f,
472  0.2782636880874634f, -0.3793870210647583f, -0.018918335437774658f,
473  0.2724653482437134f, -0.19314253330230713f, -0.2947450876235962f,
474  -0.30253493785858154f, 0.4241350293159485f, -0.22560018301010132f };
475 
476  std::vector<float> inputToForgetWeights = { -0.2667974531650543f, -0.05505800247192383f, -0.20932340621948242f,
477  -0.14345619082450867f, 0.09666192531585693f, -0.2604355812072754f,
478  -0.2681812047958374f, -0.3314584493637085f, 0.4485899806022644f,
479  -0.23467743396759033f, 0.5072842240333557f, -0.4192768931388855f };
480 
481  std::vector<float> inputToCellWeights = { -0.15782442688941956f, -0.027530014514923096f, 0.4789854884147644f,
482  0.23227906227111816f, 0.28259342908859253f, -0.030095696449279785f,
483  0.10071521997451782f, -0.08535495400428772f, 0.18563997745513916f,
484  -0.3049069046974182f, -0.478048175573349f, 0.025234103202819824f };
485 
486  std::vector<float> inputToOutputWeights = { -0.04584759473800659f, -0.2716066539287567f, 0.012970447540283203f,
487  -0.4729190170764923f, -0.37422770261764526f, 0.49352723360061646f,
488  0.3163864016532898f, -0.436781644821167f, -0.33074596524238586f,
489  -0.32885751128196716f, -0.40959352254867554f, -0.2124689817428589f };
490 
491  std::vector<float> recurrentToInputWeights = { 0.23788475990f, -0.24948765337f, 0.50044941902f, 0.14431896805f,
492  -0.115940228137f, -0.717082679f, -0.17208620906f, 0.17850610617f,
493  -0.16702319684f, -0.11384502053f, -0.309785276245f, -0.3316611672f,
494  0.52380162477f, -0.06839632987f, -0.391478359627f, -0.10756178963f };
495 
496  std::vector<float> recurrentToForgetWeights = { 0.11383482068f, 0.1676601767f, -0.08550968004f, 0.03399394089f,
497  0.08042152225f, -0.2133381964f, 0.05182432704f, 0.38161808255f,
498  -0.5018365979f, -0.08043262364f, 0.07894329014f, -0.07547105155f,
499  0.12047368288f, 0.2986997961f, 0.0485043078f, -0.13372567296f };
500 
501  std::vector<float> recurrentToCellWeights = { 0.0433832928545f, 0.07587072294f, -0.120520234107f, 0.604576051f,
502  -0.434353142986f, 0.009314475068f, 0.005085289478f, 0.08488202038f,
503  -0.00025437487886f, 0.15245915082f, -0.1936587542f, 0.004754020f,
504  -0.1582719236f, 0.3307867646f, 0.0236605107784f, 0.307716339826f };
505 
506  std::vector<float> recurrentToOutputWeights = { -0.079031050201f, 0.041414566286f, -0.583727357285f, 0.1025384515f,
507  -0.172372072937f, 0.09214124082f, 0.178184121827f, -0.2439443916f,
508  0.104485116899f, 0.2600405514f, 0.064414866268f, 0.24141204357f,
509  0.281875759363f, -0.14234502664f, 0.15126448862f, -0.24421440064f };
510 
511  std::vector<float> inputGateBias = { 0., 0., 0., 0. };
512 
513  std::vector<float> forgetGateBias = { 1., 1., 1., 1. };
514 
515  std::vector<float> cellBias = { 0., 0., 0., 0. };
516 
517  std::vector<float> outputGateBias = { 0., 0., 0., 0. };
518 
519  armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfo12);
520  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfo12);
521  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfo12);
522  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfo12);
523  armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfo16);
524  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfo16);
525  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfo16);
526  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfo16);
527  armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfo4);
528  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfo4);
529  armnn::ScopedTensorHandle cellBiasTensor(tensorInfo4);
530  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfo4);
531 
532  AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data());
533  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
534  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
535  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
536  AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data());
537  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
538  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
539  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
540  AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data());
541  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
542  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
543  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
544 
545  data.m_InputToInputWeights = &inputToInputWeightsTensor;
546  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
547  data.m_InputToCellWeights = &inputToCellWeightsTensor;
548  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
549  data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
550  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
551  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
552  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
553  data.m_InputGateBias = &inputGateBiasTensor;
554  data.m_ForgetGateBias = &forgetGateBiasTensor;
555  data.m_CellBias = &cellBiasTensor;
556  data.m_OutputGateBias = &outputGateBiasTensor;
557 
558  // Flags to set test configuration
562  data.m_Parameters.m_CifgEnabled = false;
563  data.m_Parameters.m_PeepholeEnabled = false;
564  data.m_Parameters.m_ProjectionEnabled = false;
565  data.m_Parameters.m_TimeMajor = true;
566 
567  std::unique_ptr<armnn::IWorkload> workload
568  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
569  inputHandle->Allocate();
570  outputStateInHandle->Allocate();
571  cellStateInHandle->Allocate();
572 
573  outputStateOutHandle->Allocate();
574  cellStateOutHandle->Allocate();
575  outputHandle->Allocate();
576 
577  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
578  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
579  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
580 
581  workload->Execute();
582 
583  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
584  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
585  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
586 
587  return LayerTestResult<T, 3>(actualOutput,
588  outputVector,
589  outputHandle->GetShape(),
590  outputTensorInfo.GetShape());
591 }
592 
593 } // anonymous namespace
594 
596  armnn::IWorkloadFactory& workloadFactory,
598  const armnn::ITensorHandleFactory& tensorHandleFactory)
599 {
600  armnn::TensorInfo inputDesc({1, 2, 2}, armnn::DataType::Float32);
601  std::vector<float> input = {2., 3., 3., 4.};
602 
603  armnn::TensorInfo outputDesc({1, 2, 4}, armnn::DataType::Float32);
604  std::vector<float> expectedOutput =
605  {-0.02973187f, 0.1229473f, 0.20885126f, -0.15358765f,
606  -0.0185422f, 0.11281417f, 0.24466537f, -0.1826292f};
607 
608  return UnidirectionalSequenceLstmTimeMajorSingleBatchTestImpl<armnn::DataType::Float32>(
609  workloadFactory, memoryManager, tensorHandleFactory,
610  input, expectedOutput, inputDesc.GetShape(), outputDesc.GetShape());
611 }
612 
614  armnn::IWorkloadFactory& workloadFactory,
616  const armnn::ITensorHandleFactory& tensorHandleFactory) {
617  armnn::TensorInfo inputInfo({3, 1, 3}, armnn::DataType::Float32);
618  std::vector<float> input = { 1., 2., 3., 4., 5., 4., 3., 2., 1. };
619 
620  armnn::TensorInfo outputInfo({3, 1, 4}, armnn::DataType::Float32);
621  std::vector<float> expectedOutput = { -0.0714901f, -0.162117f, -0.175168f, -0.0232934f,
622  -0.0424661f, -0.231802f, -0.513374f, -0.00680323f,
623  -0.0668735f, 0.204078f, -0.42765f, -0.0312321f };
624  return UnidirectionalSequenceLstmLayerFloat32TestImpl<armnn::DataType::Float32>(
625  workloadFactory, memoryManager, tensorHandleFactory,
626  input, expectedOutput, inputInfo.GetShape(), outputInfo.GetShape());
627 }
628 
630  armnn::IWorkloadFactory& workloadFactory,
632  const armnn::ITensorHandleFactory& tensorHandleFactory) {
633  armnn::TensorInfo inputInfo({3, 2, 3}, armnn::DataType::Float32);
634  std::vector<float> input = { 1., 2., 3., 4., 5., 4.,
635  3., 2., 1., 2., 3., 4.,
636  5., 4., 3., 2., 1., 2. };
637 
638  armnn::TensorInfo outputInfo({3, 2, 4}, armnn::DataType::Float32);
639  std::vector<float> expectedOutput = { -0.07149004f, -0.1621171f, -0.17516759f, -0.0232934225f,
640  -0.16810727f, -0.41412935f, -0.5498753f, -0.00803578f,
641  -0.06687349f, 0.204077631f, -0.4276504f, -0.03123213f,
642  -0.12000261f, -0.0941918f, -0.45639035f, -0.02870186f,
643  -0.03429216f, 0.20824050f, -0.6569892f, -0.004152651f,
644  -0.10493034f, 0.14210969f, -0.58347696f, -0.03297536f };
645  return UnidirectionalSequenceLstmLayerFloat32TestImpl<armnn::DataType::Float32>(
646  workloadFactory, memoryManager, tensorHandleFactory,
647  input, expectedOutput, inputInfo.GetShape(), outputInfo.GetShape());
648 }
649 
651  armnn::IWorkloadFactory& workloadFactory,
653  const armnn::ITensorHandleFactory& tensorHandleFactory) {
654  armnn::TensorInfo inputInfo({2, 3, 3}, armnn::DataType::Float32);
655  std::vector<float> input = { 1., 2., 3., 4., 5., 4.,
656  3., 2., 1., 2., 3., 4.,
657  5., 4., 3., 2., 1., 2. };
658 
659  armnn::TensorInfo outputInfo({2, 3, 4}, armnn::DataType::Float32);
660  std::vector<float> expectedOutput = { 0.135657698f, 0.124672532f, 0.0212090332f, -0.0530203655f,
661  0.106138252f, 0.0404792242f, 0.0151643595f, -0.00675163185f,
662  -0.0128514022f, 0.0644884035f, 0.0709072053f, -0.0454045124f,
663  0.16288602f, 0.16649379f, 0.02770456f, -0.03698075f,
664  0.11171641f, 0.043119f , 0.0762981f , -0.01228541f,
665  0.10439701f, 0.21439962f, 0.11919238f, -0.08390583f };
666  return UnidirectionalSequenceLstmLayerFloat32TimeMajorTestImpl<armnn::DataType::Float32>(
667  workloadFactory, memoryManager, tensorHandleFactory,
668  input, expectedOutput, inputInfo.GetShape(), outputInfo.GetShape());
669 }
670 
672  armnn::IWorkloadFactory& workloadFactory,
674  const armnn::ITensorHandleFactory& tensorHandleFactory)
675 {
676  IgnoreUnused(memoryManager);
677  unsigned int batchSize = 2;
678  unsigned int timeSize = 3;
679  unsigned int outputSize = 5;
680  unsigned int inputSize = 4;
681  unsigned numUnits = 6;
682 
683  armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32);
684  armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, armnn::DataType::Float32);
685  armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, armnn::DataType::Float32);
686  armnn::TensorInfo outputStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
687  armnn::TensorInfo cellStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
688  armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
689 
690  const std::vector<float> inputVector = { 1., 2., 3., 4., 5., 4.,
691  3., 2., 1., 2., 3., 4.,
692  5., 4., 3., 2., 1., 2.,
693  1., 2., 3., 4., 5., 4.};
694 
695  std::vector<float> cellStateInVector(batchSize * numUnits, 0.f);
696  std::vector<float> outputStateInVector(batchSize * outputSize, 0.f);
697 
698  std::vector<float> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
699  std::vector<float> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
700  std::vector<float> actualOutput(outputTensorInfo.GetNumElements());
701 
702  const std::vector<float> expectedOutput = { -0.0135612f, -0.0263441f, 0.0314008f, -0.00883455f, 0.00763052f,
703  -0.00126877f, -0.0292959f, 0.0449957f, -0.00976195f, -0.00492338f,
704  -0.0175702f, -0.0431753f, 0.0597117f, -0.0169154f, 0.0142087f,
705  0.00472515f, -0.0196355f, 0.0342524f, -0.00407936f, -0.0253189f,
706  -0.00512944f, -0.0293754f, 0.0512771f, -0.0151874f, -0.0246433f,
707  -0.00744986f, -0.0345103f, 0.0450666f, -0.00944991f, 0.0127171f };
708 
709  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
710  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
711  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
712  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
713  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
714 
715  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
716  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
717  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
718  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
719  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
720 
722  armnn::WorkloadInfo info;
723 
724  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
725  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
726  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
727 
728  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
729  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
730  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
731 
732  armnn::TensorInfo tensorInfo5({outputSize}, armnn::DataType::Float32);
733  armnn::TensorInfo tensorInfo6({numUnits}, armnn::DataType::Float32);
734  armnn::TensorInfo tensorInfo6x4({numUnits, inputSize}, armnn::DataType::Float32);
735  armnn::TensorInfo tensorInfo6x5({numUnits, outputSize}, armnn::DataType::Float32);
736  armnn::TensorInfo tensorInfo5x6({outputSize, numUnits}, armnn::DataType::Float32);
737 
738  std::vector<float> inputToInputWeights = { 0.021393683f, 0.06124551f, 0.046905167f, -0.014657677f,
739  -0.03149463f, 0.09171803f, 0.14647801f, 0.10797193f,
740  -0.0057968358f, 0.0019193048f, -0.2726754f, 0.10154029f,
741  -0.018539885f, 0.080349885f, -0.10262385f, -0.022599787f,
742  -0.09121155f, -0.008675967f, -0.045206103f, -0.0821282f,
743  -0.008045952f, 0.015478081f, 0.055217247f, 0.038719587f };
744 
745  std::vector<float> inputToForgetWeights = { -0.0018401089f, -0.004852237f, 0.03698424f, 0.014181704f,
746  0.028273236f, -0.016726194f, -0.05249759f, -0.10204261f,
747  0.00861066f, -0.040979505f, -0.009899187f, 0.01923892f,
748  -0.028177269f, -0.08535103f, -0.14585495f, 0.10662567f,
749  -0.01909731f, -0.017883534f, -0.0047269356f, -0.045103323f,
750  0.0030784295f, 0.076784775f, 0.07463696f, 0.094531395f};
751 
752  std::vector<float> inputToCellWeights = { -0.04580283f, -0.09549462f, -0.032418985f, -0.06454633f,
753  -0.043528453f, 0.043018587f, -0.049152344f, -0.12418144f,
754  -0.078985475f, -0.07596889f, 0.019484362f, -0.11434962f,
755  -0.0074034138f, -0.06314844f, -0.092981495f, 0.0062155537f,
756  -0.025034338f, -0.0028890965f, 0.048929527f, 0.06235075f,
757  0.10665918f, -0.032036792f, -0.08505916f, -0.10843358f };
758 
759  std::vector<float> inputToOutputWeights = { -0.0998932f, -0.07201956f, -0.052803773f, -0.15629593f,
760  -0.15001918f, -0.07650751f, 0.02359855f, -0.075155355f,
761  -0.08037709f, -0.15093534f, 0.029517552f, -0.04751393f,
762  0.010350531f, -0.02664851f, -0.016839722f, -0.023121163f,
763  0.0077019283f, 0.012851257f, -0.05040649f, -0.0129761f,
764  -0.021737747f, -0.038305793f, -0.06870586f, -0.01481247f };
765 
766  std::vector<float> inputGateBias = { 0.02234832f, 0.14757581f, 0.18176508f,
767  0.10380666f, 0.053110216f, -0.06928846f };
768 
769  std::vector<float> forgetGateBias = { 0.035185695f, -0.042891346f, -0.03032477f,
770  0.23027696f, 0.11098921f, 0.08989442f };
771 
772  std::vector<float> cellBias = { -0.024379363f, 0.0055531194f, 0.23377132f,
773  0.033463873f, -0.1483596f, 0.029460307f };
774 
775  std::vector<float> outputGateBias = { 0.046159424f, -0.0012809046f, 0.03563469f,
776  0.12648113f, 0.027195795f, 0.35373217f };
777 
778  std::vector<float> recurrentToInputWeights = { -0.001374326f, -0.078856036f, 0.10672688f, 0.029162422f,
779  -0.11585556f, 0.02557986f, -0.13446963f, -0.035785314f,
780  -0.01244275f, 0.025961924f, -0.02337298f, -0.044228926f,
781  -0.055839065f, -0.046598054f, -0.010546039f, -0.06900766f,
782  0.027239809f, 0.022582639f, -0.013296484f, -0.05459212f,
783  0.08981f, -0.045407712f, 0.08682226f, -0.06867011f,
784  -0.14390695f, -0.02916037f, 0.000996957f, 0.091420636f,
785  0.14283475f, -0.07390571f };
786 
787  std::vector<float> recurrentToCellWeights = { -0.037322544f, 0.018592842f, 0.0056175636f, -0.06253426f,
788  0.055647098f, -0.05713207f, -0.05626563f, 0.005559383f,
789  0.03375411f, -0.025757805f, -0.088049285f, 0.06017052f,
790  -0.06570978f, 0.007384076f, 0.035123326f, -0.07920549f,
791  0.053676967f, 0.044480428f, -0.07663568f, 0.0071805613f,
792  0.08089997f, 0.05143358f, 0.038261272f, 0.03339287f,
793  -0.027673481f, 0.044746667f, 0.028349208f, 0.020090483f,
794  -0.019443132f, -0.030755889f };
795 
796  std::vector<float> recurrentToForgetWeights = { -0.057784554f, -0.026057621f, -0.068447545f, -0.022581743f,
797  0.14811787f, 0.10826372f, 0.09471067f, 0.03987225f,
798  -0.0039523416f, 0.00030638507f, 0.053185795f, 0.10572994f,
799  0.08414449f, -0.022036452f, -0.00066928595f, -0.09203576f,
800  0.032950465f, -0.10985798f, -0.023809856f, 0.0021431844f,
801  -0.02196096f, -0.00326074f, 0.00058621005f, -0.074678116f,
802  -0.06193199f, 0.055729095f, 0.03736828f, 0.020123724f,
803  0.061878487f, -0.04729229f };
804 
805  std::vector<float> recurrentToOutputWeights = { 0.025825322f, -0.05813119f, 0.09495884f,
806  -0.045984812f,-0.01255415f, -0.0026479573f,
807  -0.08196161f, -0.054914974f, -0.0046604523f,
808  -0.029587349f, -0.044576716f, -0.07480124f,
809  -0.082868785f, 0.023254942f, 0.027502948f,
810  -0.0039728214f, -0.08683098f, -0.08116779f,
811  -0.014675607f, -0.037924774f, -0.023314456f,
812  -0.007401714f, -0.09255757f, 0.029460307f,
813  -0.08829125f, -0.005139627f, -0.08989442f,
814  -0.0555066f, 0.13596267f, 0.025062224f };
815 
816  std::vector<float> cellToInputWeights = { 0.040369894f, 0.030746894f, 0.24704495f,
817  0.018586371f, -0.037586458f, -0.15312155f };
818 
819  std::vector<float> cellToForgetWeights = { -0.01998659f, -0.15568835f, -0.24248174f,
820  -0.012770197f, 0.041331276f, -0.072311886f };
821 
822  std::vector<float> cellToOutputWeights = { 0.08286371f, -0.08261836f, -0.51210177f,
823  0.002913762f, 0.17764764f, -0.5495371f };
824 
825  std::vector<float> projectionWeights = { -0.009802181f, 0.09401916f, 0.0717386f, -0.13895074f, 0.09641832f,
826  0.060420845f, 0.08539281f, 0.054285463f, 0.061395317f, 0.034448683f,
827  -0.042991187f, 0.019801661f, -0.16840284f, -0.015726732f, -0.23041931f,
828  -0.024478018f, -0.10959692f, -0.013875541f, 0.18600968f, -0.061274476f,
829  0.0138165f, -0.08160894f, -0.07661644f, 0.032372914f, 0.16169067f,
830  0.22465782f, -0.03993472f, -0.004017731f, 0.08633481f, -0.28869787f };
831 
832  std::vector<float> projectionBiasVector(outputSize, 0.f); //{outputSize}
833 
834  armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfo6x4);
835  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfo6x4);
836  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfo6x4);
837  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfo6x4);
838  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfo6x5);
839  armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfo6x5);
840  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfo6x5);
841  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfo6x5);
842  armnn::ScopedTensorHandle cellToInputWeightsTensor(tensorInfo6);
843  armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfo6);
844  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfo6);
845  armnn::ScopedTensorHandle cellBiasTensor(tensorInfo6);
846  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfo6);
847  armnn::ScopedTensorHandle cellToForgetWeightsTensor(tensorInfo6);
848  armnn::ScopedTensorHandle cellToOutputWeightsTensor(tensorInfo6);
849  armnn::ScopedTensorHandle projectionWeightsTensor(tensorInfo5x6);
850  armnn::ScopedTensorHandle projectionBiasTensor(tensorInfo5);
851 
852  AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data());
853  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
854  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
855  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
856  AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data());
857  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
858  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
859  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
860  AllocateAndCopyDataToITensorHandle(&cellToInputWeightsTensor, cellToInputWeights.data());
861  AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data());
862  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
863  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
864  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
865  AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, cellToForgetWeights.data());
866  AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, cellToOutputWeights.data());
867  AllocateAndCopyDataToITensorHandle(&projectionWeightsTensor, projectionWeights.data());
868  AllocateAndCopyDataToITensorHandle(&projectionBiasTensor, projectionBiasVector.data());
869 
870  data.m_InputToInputWeights = &inputToInputWeightsTensor;
871  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
872  data.m_InputToCellWeights = &inputToCellWeightsTensor;
873  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
874  data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
875  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
876  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
877  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
878  data.m_CellToInputWeights = &cellToInputWeightsTensor;
879  data.m_InputGateBias = &inputGateBiasTensor;
880  data.m_ForgetGateBias = &forgetGateBiasTensor;
881  data.m_CellBias = &cellBiasTensor;
882  data.m_OutputGateBias = &outputGateBiasTensor;
883  data.m_CellToForgetWeights = &cellToForgetWeightsTensor;
884  data.m_CellToOutputWeights = &cellToOutputWeightsTensor;
885  data.m_ProjectionWeights = &projectionWeightsTensor;
886  data.m_ProjectionBias = &projectionBiasTensor;
887 
888  // Flags to set test configuration
890  data.m_Parameters.m_CifgEnabled = false;
891  data.m_Parameters.m_PeepholeEnabled = true;
892  data.m_Parameters.m_ProjectionEnabled = true;
893  data.m_Parameters.m_LayerNormEnabled = false;
894  data.m_Parameters.m_TimeMajor = false;
895  data.m_Parameters.m_ClippingThresCell = 10.0f;
896 
897 
898  std::unique_ptr<armnn::IWorkload> workload
899  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
900  inputHandle->Allocate();
901  outputStateInHandle->Allocate();
902  cellStateInHandle->Allocate();
903 
904  outputStateOutHandle->Allocate();
905  cellStateOutHandle->Allocate();
906  outputHandle->Allocate();
907 
908  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
909  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
910  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
911 
912  workload->Execute();
913 
914  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
915  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
916  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
917 
918  return LayerTestResult<float, 3>(actualOutput,
919  expectedOutput,
920  outputHandle->GetShape(),
921  outputTensorInfo.GetShape());
922 }
923 
925  armnn::IWorkloadFactory& workloadFactory,
927  const armnn::ITensorHandleFactory& tensorHandleFactory)
928 {
929  IgnoreUnused(memoryManager);
930  unsigned int batchSize = 3;
931  unsigned int timeSize = 2;
932  unsigned int outputSize = 4;
933  unsigned int inputSize = 3;
934  unsigned numUnits = 5;
935 
936  armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32);
937  armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, armnn::DataType::Float32);
938  armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, armnn::DataType::Float32);
939  armnn::TensorInfo outputStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
940  armnn::TensorInfo cellStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
941  armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
942 
943  const std::vector<float> inputVector = { 1., 2., 3., 4., 5., 4.,
944  3., 2., 1., 2., 3., 4.,
945  5., 4., 3., 2., 1., 2. };
946 
947  std::vector<float> cellStateInVector(batchSize * numUnits, 0.f);
948  std::vector<float> outputStateInVector(batchSize * outputSize, 0.f);
949 
950  std::vector<float> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
951  std::vector<float> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
952  std::vector<float> actualOutput(outputTensorInfo.GetNumElements());
953 
954  const std::vector<float> expectedOutput = { 0.0642256f, 0.0343966f, 0.184122f, 0.114717f,
955  0.11458f, 0.0407109f, 0.300327f, 0.174301f,
956  0.0864761f, 0.0362912f, 0.178635f, 0.115689f,
957  0.108008f, 0.0386623f, 0.273471f, 0.167115f,
958  0.0859545f, 0.0331481f, 0.186051f, 0.11888f,
959  0.106649f, 0.0276847f, 0.229863f, 0.166958f };
960 
961  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
962  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
963  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
964  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
965  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
966 
967  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
968  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
969  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
970  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
971  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
972 
974  armnn::WorkloadInfo info;
975 
976  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
977  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
978  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
979 
980  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
981  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
982  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
983 
984  armnn::TensorInfo tensorInfo4({outputSize}, armnn::DataType::Float32);
985  armnn::TensorInfo tensorInfo5({numUnits}, armnn::DataType::Float32);
986  armnn::TensorInfo tensorInfo5x3({numUnits, inputSize}, armnn::DataType::Float32);
987  armnn::TensorInfo tensorInfo5x4({numUnits, outputSize}, armnn::DataType::Float32);
988  armnn::TensorInfo tensorInfo4x5({outputSize, numUnits}, armnn::DataType::Float32);
989 
990  std::vector<float> inputToInputWeights = { -0.49536117f, -0.0556083915f, -0.102400711f,
991  -0.117484632f, 0.3298470976f, -0.1179017122f,
992  0.214305695f, 0.42135173085f, 0.003878414626f,
993  -0.348303917f, -0.1881275477f, 0.0343011027f,
994  -0.38837709614f, -0.05636804124f, 0.4259087456f};
995 
996  std::vector<float> inputToForgetWeights = { 0.2415594226f, 0.15400093799f, 0.4566498398f,
997  -0.3810434485f, 0.268383264f, -0.009807467424f,
998  -0.3522925403f, -0.24275735512f, -0.28344226125f,
999  0.13512269116f, -0.4932442977f, -0.10039821991f,
1000  0.2726137042f, 0.09216640889f, -0.06551410215f};
1001 
1002  std::vector<float> inputToCellWeights = { -0.2504855627f, 0.184490025045f, -0.2480507493f,
1003  0.386399507f, -0.259465157985f, -0.16545993089f,
1004  -0.4230232555f, 0.341664791103f, -0.18127849691f,
1005  -0.2277662414f, -0.55275535589f, 0.34184026718f,
1006  0.3954237699f, -0.19407111404f, 0.30412107706f};
1007 
1008  std::vector<float> inputToOutputWeights = { 0.2303854227f, 0.5218806862f, -0.4865379333f,
1009  0.53969591851f, 0.23393625035f, -0.27140527306f,
1010  0.50009280443f, 0.07511717046f, 0.3998299249f,
1011  -0.51717478049f, 0.1889653282f, -0.367323637f,
1012  -0.12584099173f, -0.12319286912f, 0.2407919466f};
1013 
1014  std::vector<float> inputGateBias{ 0.03f, 0.15f, 0.22f, 0.38f, 0.05f };
1015  std::vector<float> forgetGateBias{ 0.1f, -0.3f, -0.2f, 0.1f, 0.4f };
1016  std::vector<float> cellBias{ -0.05f, 0.72f, 0.25f, 0.08f, 0.1f };
1017  std::vector<float> outputGateBias{ 0.05f, -0.01f, 0.2f, 0.1f, -0.2f };
1018 
1019  std::vector<float> recurrentToInputWeights = { -0.128009796112f, 0.1995525098f, -0.07745539397f, 0.1558421701f,
1020  -0.265254765766f, -0.38837709614f, -0.05636804124f, 0.4259087456f,
1021  0.17628988623f, 0.3877420127f, 0.53300309181f, -0.0959980934f,
1022  0.00302857416f, 0.3266998827f, -0.142509296562f, -0.04433270756f,
1023  0.54066205f, -0.32668582f, -0.43562764f, -0.56094903f };
1024 
1025  std::vector<float> recurrentToForgetWeights = { -0.09499983487f, -0.08814888417f, -0.04834804721f, 0.1516668247f,
1026  -0.3967529535f, -0.06463699788f, 0.4952811002f, 0.003274492938f,
1027  -0.0968840941f, 0.17928104102f, 0.0031281141592f, -0.3387276584f,
1028  -0.3587934076f, 0.06705895066f, 0.22463923692f, 0.1961955726f,
1029  0.01841056f, -0.32764608f, -0.33027974f, -0.10826075f };
1030 
1031  std::vector<float> recurrentToCellWeights = { -0.21938985582f, -0.3023648226f, -0.1170005202f, -0.3509177422f,
1032  -0.4286288613f, 0.2726137042f, 0.09216640889f, -0.06551410215f,
1033  0.20453298098f, 0.2393476665f, 0.11846517771f, 0.2630801796f,
1034  0.3954237699f, -0.19407111404f, 0.30412107706f, -0.27342408554f,
1035  0.19069612f, -0.03026325f, -0.54532051f, 0.33003211f };
1036 
1037  std::vector<float> recurrentToOutputWeights = { -0.32921677827f, 0.32624614238f, -0.1388191282f, -0.17879831790f,
1038  -0.15185534954f, -0.16918526583f, -0.10087361183f, -0.5436913968f,
1039  0.016758225858f, 0.30454617738f, -0.41493862867f, -0.005565764375f,
1040  -0.12584099173f, -0.12319286912f, 0.2407919466f, -0.08879069983f,
1041  0.11178309f, 0.09481031f, -0.26424935f, 0.46261835f };
1042 
1043  std::vector<float> cellToInputWeights { 0.05f, 0.1f, 0.25f, 0.15f, -0.02f };
1044  std::vector<float> cellToForgetWeights { -0.02f, -0.15f, -0.25f, -0.03f, 0.15f };
1045  std::vector<float> cellToOutputWeights { 0.1f, -0.1f, -0.5f, 0.05f, 0.01f };
1046 
1047  std::vector<float> projectionWeights{ -0.1f, 0.2f, 0.01f, -0.2f,
1048  0.1f, 0.5f, 0.3f, 0.08f,
1049  0.07f, 0.2f, -0.4f, 0.2f,
1050  0.5f, -0.4f, 0.3f, -0.2f,
1051  0.3f, 0.08f, -0.07f, 0.2f};
1052 
1053  std::vector<float> projectionBiasVector(outputSize, 0.f); //{outputSize}
1054 
1055  std::vector<float> inputLayerNormWeights{ 0.1f, 0.2f, 0.3f, 0.5f, 0.8f };
1056  std::vector<float> forgetLayerNormWeights{ 0.1f, 0.2f, 0.3f, 0.5f, 0.2f };
1057  std::vector<float> cellLayerNormWeights{ 0.7f, 0.2f, 0.3f, 0.8f, 0.5f };
1058  std::vector<float> outputLayerNormWeights{ 0.6f, 0.2f, 0.2f, 0.5f, 0.1f };
1059 
1060  armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfo5x3);
1061  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfo5x3);
1062  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfo5x3);
1063  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfo5x3);
1064  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfo5x4);
1065  armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfo5x4);
1066  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfo5x4);
1067  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfo5x4);
1068  armnn::ScopedTensorHandle cellToInputWeightsTensor(tensorInfo5);
1069  armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfo5);
1070  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfo5);
1071  armnn::ScopedTensorHandle cellBiasTensor(tensorInfo5);
1072  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfo5);
1073  armnn::ScopedTensorHandle cellToForgetWeightsTensor(tensorInfo5);
1074  armnn::ScopedTensorHandle cellToOutputWeightsTensor(tensorInfo5);
1075  armnn::ScopedTensorHandle projectionWeightsTensor(tensorInfo4x5);
1076  armnn::ScopedTensorHandle projectionBiasTensor(tensorInfo4);
1077 
1078  armnn::ScopedTensorHandle inputLayerNormWeightsTensor(tensorInfo5);
1079  armnn::ScopedTensorHandle forgetLayerNormWeightsTensor(tensorInfo5);
1080  armnn::ScopedTensorHandle cellLayerNormWeightsTensor(tensorInfo5);
1081  armnn::ScopedTensorHandle outputLayerNormWeightsTensor(tensorInfo5);
1082 
1083  AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data());
1084  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
1085  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
1086  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
1087  AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data());
1088  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
1089  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
1090  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
1091  AllocateAndCopyDataToITensorHandle(&cellToInputWeightsTensor, cellToInputWeights.data());
1092  AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data());
1093  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
1094  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
1095  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
1096  AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, cellToForgetWeights.data());
1097  AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, cellToOutputWeights.data());
1098  AllocateAndCopyDataToITensorHandle(&projectionWeightsTensor, projectionWeights.data());
1099  AllocateAndCopyDataToITensorHandle(&projectionBiasTensor, projectionBiasVector.data());
1100 
1101  AllocateAndCopyDataToITensorHandle(&inputLayerNormWeightsTensor, inputLayerNormWeights.data());
1102  AllocateAndCopyDataToITensorHandle(&forgetLayerNormWeightsTensor, forgetLayerNormWeights.data());
1103  AllocateAndCopyDataToITensorHandle(&cellLayerNormWeightsTensor, cellLayerNormWeights.data());
1104  AllocateAndCopyDataToITensorHandle(&outputLayerNormWeightsTensor, outputLayerNormWeights.data());
1105 
1106  data.m_InputToInputWeights = &inputToInputWeightsTensor;
1107  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
1108  data.m_InputToCellWeights = &inputToCellWeightsTensor;
1109  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
1110  data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
1111  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
1112  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
1113  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
1114  data.m_CellToInputWeights = &cellToInputWeightsTensor;
1115  data.m_InputGateBias = &inputGateBiasTensor;
1116  data.m_ForgetGateBias = &forgetGateBiasTensor;
1117  data.m_CellBias = &cellBiasTensor;
1118  data.m_OutputGateBias = &outputGateBiasTensor;
1119  data.m_CellToForgetWeights = &cellToForgetWeightsTensor;
1120  data.m_CellToOutputWeights = &cellToOutputWeightsTensor;
1121  data.m_ProjectionWeights = &projectionWeightsTensor;
1122  data.m_ProjectionBias = &projectionBiasTensor;
1123 
1124  data.m_InputLayerNormWeights = &inputLayerNormWeightsTensor;
1125  data.m_ForgetLayerNormWeights = &forgetLayerNormWeightsTensor;
1126  data.m_CellLayerNormWeights = &cellLayerNormWeightsTensor;
1127  data.m_OutputLayerNormWeights = &outputLayerNormWeightsTensor;
1128 
1129  // Flags to set test configuration
1130  data.m_Parameters.m_ActivationFunc = 4;
1131  data.m_Parameters.m_CifgEnabled = false;
1132  data.m_Parameters.m_PeepholeEnabled = true;
1133  data.m_Parameters.m_ProjectionEnabled = true;
1134  data.m_Parameters.m_LayerNormEnabled = true;
1135  data.m_Parameters.m_TimeMajor = false;
1136  data.m_Parameters.m_ClippingThresCell = 10.0f;
1137 
1138  std::unique_ptr<armnn::IWorkload> workload
1139  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
1140  inputHandle->Allocate();
1141  outputStateInHandle->Allocate();
1142  cellStateInHandle->Allocate();
1143 
1144  outputStateOutHandle->Allocate();
1145  cellStateOutHandle->Allocate();
1146  outputHandle->Allocate();
1147 
1148  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
1149  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
1150  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
1151 
1152  workload->Execute();
1153 
1154  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
1155  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
1156  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
1157 
1158  return LayerTestResult<float, 3>(actualOutput,
1159  expectedOutput,
1160  outputHandle->GetShape(),
1161  outputTensorInfo.GetShape());
1162 }
1163 
1165  armnn::IWorkloadFactory& workloadFactory,
1167  const armnn::ITensorHandleFactory& tensorHandleFactory)
1168 {
1169  IgnoreUnused(memoryManager);
1170  unsigned int batchSize = 3;
1171  unsigned int timeSize = 2;
1172  unsigned int inputSize = 3;
1173  unsigned int outputSize = 4;
1174  unsigned numUnits = outputSize;
1175 
1176  armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32);
1177  armnn::TensorInfo cellStateInTensorInfo({batchSize, numUnits}, armnn::DataType::Float32);
1178  armnn::TensorInfo outputStateInTensorInfo({batchSize, outputSize}, armnn::DataType::Float32);
1179  armnn::TensorInfo outputStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1180  armnn::TensorInfo cellStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1181  armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1182 
1183  std::vector<float> inputVector = { 1., 2., 3., 4., 5., 4.,
1184  3., 2., 1., 2., 3., 4.,
1185  5., 4., 3., 2., 1., 2. };
1186 
1187  std::vector<float> cellStateInVector(batchSize * numUnits, 0.f);
1188  std::vector<float> outputStateInVector(batchSize * outputSize, 0.f);
1189 
1190  std::vector<float> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
1191  std::vector<float> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
1192  std::vector<float> actualOutput(outputTensorInfo.GetNumElements());
1193 
1194  std::vector<float> outputVector = { -0.0129257f, -0.070531f, -0.153508f, -0.0392391f,
1195  -0.0300169f, -0.195717f, -0.528679f, -0.0818106f,
1196  -0.0332748f, 0.155429f, -0.353966f, -0.0801505f,
1197  -0.032312f, -0.0407911f, -0.435053f, -0.0932317f,
1198  -0.0108233f, 0.165584f, -0.640424f, -0.0447535f,
1199  -0.031675f, 0.125987f, -0.526695f, -0.110093f };
1200 
1201  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
1202  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
1203  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
1204  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
1205  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
1206 
1207  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
1208  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
1209  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
1210  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
1211  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
1212 
1214  armnn::WorkloadInfo info;
1215 
1216  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
1217  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
1218  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
1219 
1220  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
1221  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
1222  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1223 
1224  armnn::TensorInfo tensorInfo4({numUnits}, armnn::DataType::Float32);
1225  armnn::TensorInfo tensorInfo12({numUnits, 3}, armnn::DataType::Float32);
1226  armnn::TensorInfo tensorInfo16({numUnits, 4}, armnn::DataType::Float32);
1227 
1228  std::vector<float> inputToForgetWeights = { 0.2415594226f, 0.15400093799f, 0.4566498398f,
1229  -0.3810434485f, 0.268383264f, -0.009807467424f,
1230  -0.3522925403f, -0.24275735512f, -0.28344226125f,
1231  0.13512269116f, -0.4932442977f, -0.10039821991f };
1232 
1233  std::vector<float> inputToCellWeights = { -0.2504855627f, 0.184490025045f, -0.2480507493f,
1234  0.386399507f, -0.259465157985f, -0.16545993089f,
1235  -0.4230232555f, 0.341664791103f, -0.18127849691f,
1236  -0.2277662414f, -0.55275535589f, 0.34184026718f };
1237 
1238  std::vector<float> inputToOutputWeights = { 0.2303854227f, 0.5218806862f, -0.4865379333f,
1239  0.53969591851f, 0.23393625035f, -0.27140527306f,
1240  0.50009280443f, 0.07511717046f, 0.3998299249f,
1241  -0.51717478049f, 0.1889653282f, -0.367323637f };
1242 
1243  std::vector<float> recurrentToForgetWeights = { -0.09499983487f, -0.08814888417f, -0.04834804721f, 0.1516668247f,
1244  -0.3967529535f, -0.06463699788f, 0.4952811002f, 0.003274492938f,
1245  -0.0968840941f, 0.17928104102f, 0.0031281141592f, -0.3387276584f,
1246  -0.3587934076f, 0.06705895066f, 0.22463923692f, 0.1961955726f };
1247 
1248  std::vector<float> recurrentToCellWeights = { -0.21938985582f, -0.3023648226f, -0.1170005202f, -0.3509177422f,
1249  -0.4286288613f, 0.2726137042f, 0.09216640889f, -0.06551410215f,
1250  0.20453298098f, 0.2393476665f, 0.11846517771f, 0.2630801796f,
1251  0.3954237699f, -0.19407111404f, 0.30412107706f, -0.27342408554f };
1252 
1253  std::vector<float> recurrentToOutputWeights = { -0.32921677827f, 0.32624614238f, -0.1388191282f, -0.17879831790f,
1254  -0.15185534954f, -0.16918526583f, -0.10087361183f, -0.5436913968f,
1255  0.016758225858f, 0.30454617738f, -0.41493862867f, -0.005565764375f,
1256  -0.12584099173f, -0.12319286912f, 0.2407919466f, -0.08879069983f };
1257 
1258  std::vector<float> cellToForgetWeights{ 0.47485286f, -0.51955009f, -0.24458408f, 0.31544167f };
1259 
1260  std::vector<float> cellToOutputWeights{ -0.17135078f, 0.82760304f, 0.85573703f, -0.77109635f };
1261 
1262  std::vector<float> forgetGateBias = { 1., 1., 1., 1. };
1263 
1264  std::vector<float> cellBias = { 0., 0., 0., 0. };
1265 
1266  std::vector<float> outputGateBias = { 0., 0., 0., 0. };
1267 
1268  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfo12);
1269  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfo12);
1270  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfo12);
1271  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfo16);
1272  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfo16);
1273  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfo16);
1274  armnn::ScopedTensorHandle cellToForgetWeightsTensor(tensorInfo4);
1275  armnn::ScopedTensorHandle cellToOutputWeightsTensor(tensorInfo4);
1276  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfo4);
1277  armnn::ScopedTensorHandle cellBiasTensor(tensorInfo4);
1278  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfo4);
1279 
1280  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
1281  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
1282  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
1283  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
1284  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
1285  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
1286  AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, cellToForgetWeights.data());
1287  AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, cellToOutputWeights.data());
1288  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
1289  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
1290  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
1291 
1292  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
1293  data.m_InputToCellWeights = &inputToCellWeightsTensor;
1294  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
1295  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
1296  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
1297  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
1298  data.m_CellToForgetWeights = &cellToForgetWeightsTensor;
1299  data.m_CellToOutputWeights = &cellToOutputWeightsTensor;
1300  data.m_ForgetGateBias = &forgetGateBiasTensor;
1301  data.m_CellBias = &cellBiasTensor;
1302  data.m_OutputGateBias = &outputGateBiasTensor;
1303 
1304  // Flags to set test configuration
1307  data.m_Parameters.m_ActivationFunc = 4;
1308  data.m_Parameters.m_CifgEnabled = true;
1309  data.m_Parameters.m_PeepholeEnabled = true;
1310  data.m_Parameters.m_ProjectionEnabled = false;
1311  data.m_Parameters.m_TimeMajor = false;
1312 
1313  std::unique_ptr<armnn::IWorkload> workload
1314  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
1315  inputHandle->Allocate();
1316  outputStateInHandle->Allocate();
1317  cellStateInHandle->Allocate();
1318 
1319  outputStateOutHandle->Allocate();
1320  cellStateOutHandle->Allocate();
1321  outputHandle->Allocate();
1322 
1323  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
1324  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
1325  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
1326 
1327  workload->Execute();
1328 
1329  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
1330  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
1331  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
1332 
1333  return LayerTestResult<float, 3>(actualOutput,
1334  outputVector,
1335  outputHandle->GetShape(),
1336  outputTensorInfo.GetShape());
1337 }
1338 
1340  armnn::IWorkloadFactory& workloadFactory,
1342  const armnn::ITensorHandleFactory& tensorHandleFactory)
1343 {
1344  IgnoreUnused(memoryManager);
1345  unsigned int batchSize = 3;
1346  unsigned int timeSize = 2;
1347  unsigned int inputSize = 3;
1348  unsigned int outputSize = 4;
1349  unsigned numUnits = outputSize;
1350 
1351  armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32);
1352  armnn::TensorInfo cellStateInTensorInfo({batchSize, numUnits}, armnn::DataType::Float32);
1353  armnn::TensorInfo outputStateInTensorInfo({batchSize, outputSize}, armnn::DataType::Float32);
1354  armnn::TensorInfo outputStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1355  armnn::TensorInfo cellStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1356  armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1357 
1358  const std::vector<float> inputVector = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f,
1359  0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f,
1360  0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f };
1361 
1362  std::vector<float> cellStateInVector(batchSize * numUnits, 0.f);
1363  std::vector<float> outputStateInVector(batchSize * outputSize, 0.f);
1364 
1365  std::vector<float> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
1366  std::vector<float> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
1367  std::vector<float> actualOutput(outputTensorInfo.GetNumElements());
1368 
1369  const std::vector<float> outputVector = { -0.0142517f, -0.0198845f, -0.0120569f, -0.0116868f,
1370  -0.0350714f, -0.0343202f, -0.047504f, -0.0569789f,
1371  -0.0146346f, 0.0106663f, -0.0247238f, -0.0319502f,
1372  -0.0294759f, -0.0129935f, -0.0444175f, -0.0444354f,
1373  -0.0280855f, 0.00545101f, -0.051422f, -0.0463838f,
1374  -0.0310702f, 0.00915739f, -0.0625207f, -0.0482648f };
1375 
1376  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
1377  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
1378  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
1379  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
1380  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
1381 
1382  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
1383  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
1384  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
1385  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
1386  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
1387 
1388 
1390  armnn::WorkloadInfo info;
1391 
1392  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
1393  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
1394  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
1395 
1396  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
1397  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
1398  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1399 
1400  armnn::TensorInfo tensorInfoNumFp({numUnits}, armnn::DataType::Float32);
1401  armnn::TensorInfo tensorInfoNumInput({numUnits, inputSize}, armnn::DataType::QAsymmS8, 0.1f, 0);
1402  armnn::TensorInfo tensorInfoNumOutput({numUnits, outputSize}, armnn::DataType::QAsymmS8, 0.1f, 0);
1403 
1404  std::vector<int8_t> inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3 };
1405  std::vector<int8_t> inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 };
1406  std::vector<int8_t> inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 };
1407  std::vector<int8_t> inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 };
1408 
1409  std::vector<int8_t> recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -1, -1 };
1410  std::vector<int8_t> recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 };
1411  std::vector<int8_t> recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 };
1412  std::vector<int8_t> recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 };
1413 
1414  std::vector<float> inputGateBias = { 0., 0., 0., 0. };
1415  std::vector<float> forgetGateBias = { 1., 1., 1., 1. };
1416  std::vector<float> cellBias = { 0., 0., 0., 0. };
1417  std::vector<float> outputGateBias = { 0., 0., 0., 0. };
1418 
1419  armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfoNumInput);
1420  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfoNumInput);
1421  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfoNumInput);
1422  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfoNumInput);
1423  armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfoNumOutput);
1424  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfoNumOutput);
1425  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfoNumOutput);
1426  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfoNumOutput);
1427  armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfoNumFp);
1428  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfoNumFp);
1429  armnn::ScopedTensorHandle cellBiasTensor(tensorInfoNumFp);
1430  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfoNumFp);
1431 
1432  AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data());
1433  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
1434  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
1435  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
1436  AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data());
1437  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
1438  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
1439  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
1440  AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data());
1441  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
1442  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
1443  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
1444 
1445  data.m_InputToInputWeights = &inputToInputWeightsTensor;
1446  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
1447  data.m_InputToCellWeights = &inputToCellWeightsTensor;
1448  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
1449  data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
1450  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
1451  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
1452  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
1453  data.m_InputGateBias = &inputGateBiasTensor;
1454  data.m_ForgetGateBias = &forgetGateBiasTensor;
1455  data.m_CellBias = &cellBiasTensor;
1456  data.m_OutputGateBias = &outputGateBiasTensor;
1457 
1458  // Flags to set test configuration
1461  data.m_Parameters.m_ActivationFunc = 4;
1462  data.m_Parameters.m_CifgEnabled = false;
1463  data.m_Parameters.m_PeepholeEnabled = false;
1464  data.m_Parameters.m_ProjectionEnabled = false;
1465  data.m_Parameters.m_TimeMajor = false;
1466 
1467  std::unique_ptr<armnn::IWorkload> workload
1468  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
1469  inputHandle->Allocate();
1470  outputStateInHandle->Allocate();
1471  cellStateInHandle->Allocate();
1472 
1473  outputStateOutHandle->Allocate();
1474  cellStateOutHandle->Allocate();
1475  outputHandle->Allocate();
1476 
1477  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
1478  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
1479  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
1480 
1481  workload->Execute();
1482 
1483  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
1484  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
1485  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
1486 
1487  return LayerTestResult<float, 3>(actualOutput,
1488  outputVector,
1489  outputHandle->GetShape(),
1490  outputTensorInfo.GetShape());
1491 }
1492 
1494  armnn::IWorkloadFactory& workloadFactory,
1496  const armnn::ITensorHandleFactory& tensorHandleFactory)
1497 {
1498  IgnoreUnused(memoryManager);
1499  unsigned int batchSize = 3;
1500  unsigned int timeSize = 2;
1501  unsigned int inputSize = 3;
1502  unsigned int outputSize = 4;
1503  unsigned numUnits = outputSize;
1504 
1505  armnn::TensorInfo inputTensorInfo({timeSize, batchSize, inputSize}, armnn::DataType::Float32);
1506  armnn::TensorInfo cellStateInTensorInfo({batchSize, numUnits}, armnn::DataType::Float32);
1507  armnn::TensorInfo outputStateInTensorInfo({batchSize, outputSize}, armnn::DataType::Float32);
1508  armnn::TensorInfo outputStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1509  armnn::TensorInfo cellStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1510  armnn::TensorInfo outputTensorInfo({timeSize, batchSize, outputSize}, armnn::DataType::Float32);
1511 
1512  const std::vector<float> inputVector = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f,
1513  0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f,
1514  0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f };
1515 
1516  std::vector<float> cellStateInVector(batchSize * numUnits, 0.f);
1517  std::vector<float> outputStateInVector(batchSize * outputSize, 0.f);
1518 
1519  std::vector<float> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
1520  std::vector<float> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
1521  std::vector<float> actualOutput(outputTensorInfo.GetNumElements());
1522 
1523  const std::vector<float> outputVector = { -0.0142517f, -0.0198845f, -0.0120122f, -0.0116868f,
1524  -0.0261295f, -0.0188487f, -0.0345463f, -0.049733f,
1525  -0.0146346f, 0.0106663f, -0.0247238f, -0.0319502f,
1526  -0.0291863f, -0.0369402f, -0.0354071f, -0.0296529f,
1527  -0.0419539f, -0.00617731f, -0.0814796f, -0.0804005f,
1528  -0.0244737f, 0.0119905f, -0.0457527f, -0.0331862f };
1529  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
1530  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
1531  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
1532  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
1533  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
1534 
1535  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
1536  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
1537  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
1538  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
1539  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
1540 
1541 
1543  armnn::WorkloadInfo info;
1544 
1545  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
1546  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
1547  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
1548 
1549  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
1550  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
1551  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1552 
1553  armnn::TensorInfo tensorInfoNumFp({numUnits}, armnn::DataType::Float32);
1554  armnn::TensorInfo tensorInfoNumInput({numUnits, inputSize}, armnn::DataType::QAsymmS8, 0.1f, 0);
1555  armnn::TensorInfo tensorInfoNumOutput({numUnits, outputSize}, armnn::DataType::QAsymmS8, 0.1f, 0);
1556 
1557  std::vector<int8_t> inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3 };
1558  std::vector<int8_t> inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 };
1559  std::vector<int8_t> inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 };
1560  std::vector<int8_t> inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 };
1561 
1562  std::vector<int8_t> recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -1, -1 };
1563  std::vector<int8_t> recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 };
1564  std::vector<int8_t> recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 };
1565  std::vector<int8_t> recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 };
1566 
1567 
1568  std::vector<float> inputGateBias = { 0., 0., 0., 0. };
1569  std::vector<float> forgetGateBias = { 1., 1., 1., 1. };
1570  std::vector<float> cellBias = { 0., 0., 0., 0. };
1571  std::vector<float> outputGateBias = { 0., 0., 0., 0. };
1572 
1573  armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfoNumInput);
1574  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfoNumInput);
1575  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfoNumInput);
1576  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfoNumInput);
1577  armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfoNumOutput);
1578  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfoNumOutput);
1579  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfoNumOutput);
1580  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfoNumOutput);
1581  armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfoNumFp);
1582  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfoNumFp);
1583  armnn::ScopedTensorHandle cellBiasTensor(tensorInfoNumFp);
1584  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfoNumFp);
1585 
1586  AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data());
1587  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
1588  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
1589  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
1590  AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data());
1591  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
1592  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
1593  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
1594  AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data());
1595  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
1596  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
1597  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
1598 
1599  data.m_InputToInputWeights = &inputToInputWeightsTensor;
1600  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
1601  data.m_InputToCellWeights = &inputToCellWeightsTensor;
1602  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
1603  data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
1604  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
1605  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
1606  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
1607  data.m_InputGateBias = &inputGateBiasTensor;
1608  data.m_ForgetGateBias = &forgetGateBiasTensor;
1609  data.m_CellBias = &cellBiasTensor;
1610  data.m_OutputGateBias = &outputGateBiasTensor;
1611 
1612  // Flags to set test configuration
1615  data.m_Parameters.m_ActivationFunc = 4;
1616  data.m_Parameters.m_CifgEnabled = false;
1617  data.m_Parameters.m_PeepholeEnabled = false;
1618  data.m_Parameters.m_ProjectionEnabled = false;
1619  data.m_Parameters.m_TimeMajor = true;
1620 
1621  std::unique_ptr<armnn::IWorkload> workload
1622  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
1623  inputHandle->Allocate();
1624  outputStateInHandle->Allocate();
1625  cellStateInHandle->Allocate();
1626 
1627  outputStateOutHandle->Allocate();
1628  cellStateOutHandle->Allocate();
1629  outputHandle->Allocate();
1630 
1631  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
1632  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
1633  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
1634 
1635  workload->Execute();
1636 
1637  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
1638  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
1639  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
1640 
1641  return LayerTestResult<float, 3>(actualOutput,
1642  outputVector,
1643  outputHandle->GetShape(),
1644  outputTensorInfo.GetShape());
1645 }
1646 
1648  armnn::IWorkloadFactory& workloadFactory,
1650  const armnn::ITensorHandleFactory& tensorHandleFactory)
1651 {
1652  IgnoreUnused(memoryManager);
1653  unsigned int batchSize = 3;
1654  unsigned int timeSize = 2;
1655  unsigned int outputSize = 4;
1656  unsigned int inputSize = 3;
1657  unsigned numUnits = 4;
1658 
1659  armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32);
1660  armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, armnn::DataType::Float32);
1661  armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, armnn::DataType::Float32);
1662  armnn::TensorInfo outputStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1663  armnn::TensorInfo cellStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1664  armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1665 
1666  const std::vector<float> inputVector = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f,
1667  0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f,
1668  0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f };
1669 
1670  std::vector<float> cellStateInVector(batchSize * numUnits, 0.f);
1671  std::vector<float> outputStateInVector(batchSize * outputSize, 0.f);
1672 
1673  std::vector<float> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
1674  std::vector<float> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
1675  std::vector<float> actualOutput(outputTensorInfo.GetNumElements());
1676 
1677  const std::vector<float> expectedOutput = { 0.612103f, 1.56788f, 0.31966f, 1.42956f,
1678  0.909718f, 3.07916f, -0.560586f, 3.8907f,
1679  0.753671f, 1.77485f, 0.365122f, 1.60077f,
1680  0.812644f, 2.79092f, -0.605396f, 3.61742f,
1681  0.791857f, 1.64353f, 0.316588f, 1.55192f,
1682  0.807265f, 2.47012f, -0.539598f, 3.25654f };
1683 
1684  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
1685  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
1686  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
1687  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
1688  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
1689 
1690  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
1691  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
1692  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
1693  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
1694  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
1695 
1697  armnn::WorkloadInfo info;
1698 
1699  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
1700  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
1701  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
1702 
1703  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
1704  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
1705  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1706 
1707  armnn::TensorInfo tensorInfoOut({outputSize}, armnn::DataType::Float32);
1708  armnn::TensorInfo tensorInfoNumFp({numUnits}, armnn::DataType::Float32);
1709  armnn::TensorInfo tensorInfoNum({numUnits}, armnn::DataType::QAsymmS8, 0.1f, 0);
1710  armnn::TensorInfo tensorInfoNumInput({numUnits, inputSize}, armnn::DataType::QAsymmS8, 0.1f, 0);
1711  armnn::TensorInfo tensorInfoNumOutput({numUnits, outputSize}, armnn::DataType::QAsymmS8, 0.1f, 0);
1712  armnn::TensorInfo tensorInfoOutNum({outputSize, numUnits}, armnn::DataType::QAsymmS8, 0.1f, 0);
1713 
1714  std::vector<int8_t> inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3 };
1715  std::vector<int8_t> inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 };
1716  std::vector<int8_t> inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 };
1717  std::vector<int8_t> inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 };
1718 
1719  std::vector<int8_t> recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -1, -1 };
1720  std::vector<int8_t> recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 };
1721  std::vector<int8_t> recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 };
1722  std::vector<int8_t> recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 };
1723 
1724  std::vector<float> inputGateBias = { 0.02234832f, 0.14757581f, 0.18176508f, 0.10380666f};
1725  std::vector<float> forgetGateBias = { 0.035185695f, -0.042891346f, -0.3032477f, 0.23027696f};
1726  std::vector<float> cellBias = { -0.124379363f, 0.55531194f, 0.23377132f, 0.033463873f };
1727  std::vector<float> outputGateBias = { 0.046159424f, -0.12809046f, 0.03563469f, 0.12648113f };
1728 
1729  std::vector<int8_t> cellToInputWeights = { 5, 10, 25, 15 };
1730  std::vector<int8_t> cellToForgetWeights = { -5, 15, 25, 3 };
1731  std::vector<int8_t> cellToOutputWeights = { 10, -10, -5, 50 };
1732 
1733  std::vector<int8_t> projectionWeights = { -25, 51, 3, -5, 25, 127, 77, 20, 18, 51, -10, 51, -25, 88, 77, -13 };
1734 
1735  std::vector<float> projectionBiasVector(outputSize, 0.f); //{outputSize}
1736 
1737  armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfoNumInput);
1738  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfoNumInput);
1739  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfoNumInput);
1740  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfoNumInput);
1741  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfoNumOutput);
1742  armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfoNumOutput);
1743  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfoNumOutput);
1744  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfoNumOutput);
1745  armnn::ScopedTensorHandle cellToInputWeightsTensor(tensorInfoNum);
1746  armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfoNumFp);
1747  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfoNumFp);
1748  armnn::ScopedTensorHandle cellBiasTensor(tensorInfoNumFp);
1749  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfoNumFp);
1750  armnn::ScopedTensorHandle cellToForgetWeightsTensor(tensorInfoNum);
1751  armnn::ScopedTensorHandle cellToOutputWeightsTensor(tensorInfoNum);
1752  armnn::ScopedTensorHandle projectionWeightsTensor(tensorInfoOutNum);
1753  armnn::ScopedTensorHandle projectionBiasTensor(tensorInfoOut);
1754 
1755  AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data());
1756  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
1757  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
1758  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
1759  AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data());
1760  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
1761  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
1762  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
1763  AllocateAndCopyDataToITensorHandle(&cellToInputWeightsTensor, cellToInputWeights.data());
1764  AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data());
1765  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
1766  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
1767  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
1768  AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, cellToForgetWeights.data());
1769  AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, cellToOutputWeights.data());
1770  AllocateAndCopyDataToITensorHandle(&projectionWeightsTensor, projectionWeights.data());
1771  AllocateAndCopyDataToITensorHandle(&projectionBiasTensor, projectionBiasVector.data());
1772 
1773  data.m_InputToInputWeights = &inputToInputWeightsTensor;
1774  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
1775  data.m_InputToCellWeights = &inputToCellWeightsTensor;
1776  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
1777  data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
1778  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
1779  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
1780  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
1781  data.m_CellToInputWeights = &cellToInputWeightsTensor;
1782  data.m_InputGateBias = &inputGateBiasTensor;
1783  data.m_ForgetGateBias = &forgetGateBiasTensor;
1784  data.m_CellBias = &cellBiasTensor;
1785  data.m_OutputGateBias = &outputGateBiasTensor;
1786  data.m_CellToForgetWeights = &cellToForgetWeightsTensor;
1787  data.m_CellToOutputWeights = &cellToOutputWeightsTensor;
1788  data.m_ProjectionWeights = &projectionWeightsTensor;
1789  data.m_ProjectionBias = &projectionBiasTensor;
1790 
1791  // Flags to set test configuration
1792  data.m_Parameters.m_ActivationFunc = 4;
1793  data.m_Parameters.m_CifgEnabled = false;
1794  data.m_Parameters.m_PeepholeEnabled = true;
1795  data.m_Parameters.m_ProjectionEnabled = true;
1796  data.m_Parameters.m_LayerNormEnabled = false;
1797  data.m_Parameters.m_TimeMajor = false;
1798  data.m_Parameters.m_ClippingThresCell = 10.0f;
1799 
1800 
1801  std::unique_ptr<armnn::IWorkload> workload
1802  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
1803  inputHandle->Allocate();
1804  outputStateInHandle->Allocate();
1805  cellStateInHandle->Allocate();
1806 
1807  outputStateOutHandle->Allocate();
1808  cellStateOutHandle->Allocate();
1809  outputHandle->Allocate();
1810 
1811  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
1812  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
1813  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
1814 
1815  workload->Execute();
1816 
1817  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
1818  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
1819  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
1820 
1821  return LayerTestResult<float, 3>(actualOutput,
1822  expectedOutput,
1823  outputHandle->GetShape(),
1824  outputTensorInfo.GetShape());
1825 }
1826 
1828  armnn::IWorkloadFactory& workloadFactory,
1830  const armnn::ITensorHandleFactory& tensorHandleFactory)
1831 {
1832  IgnoreUnused(memoryManager);
1833  unsigned int batchSize = 3;
1834  unsigned int timeSize = 2;
1835  unsigned int outputSize = 4;
1836  unsigned int inputSize = 3;
1837  unsigned numUnits = 5;
1838 
1839  armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32);
1840  armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, armnn::DataType::Float32);
1841  armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, armnn::DataType::Float32);
1842  armnn::TensorInfo outputStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1843  armnn::TensorInfo cellStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1844  armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
1845 
1846  const std::vector<float> inputVector = { 1., 8., 3., 4., 5., 4.,
1847  3., 2., 1., 2., 3., 4.,
1848  5., 4., 3., 2., 1., 2. };
1849 
1850  std::vector<float> cellStateInVector(batchSize * numUnits, 0.f);
1851  std::vector<float> outputStateInVector(batchSize * outputSize, 0.f);
1852 
1853  std::vector<float> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
1854  std::vector<float> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
1855  std::vector<float> actualOutput(outputTensorInfo.GetNumElements());
1856 
1857  const std::vector<float> expectedOutput = { 0.0471276f, 0.0168155f, 0.0789885f, 0.16550f,
1858  0.0643133f, -0.0400722f, 0.100593f, 0.197722f,
1859  0.0465562f, -0.0600682f, 0.0622087f, 0.115053f,
1860  0.056287f, -0.0566218f, 0.0856832f, 0.148484f,
1861  0.0457859f, -0.0588112f, 0.0623636f, 0.114333f,
1862  0.0509271f, -0.0754262f, 0.058600f, 0.0801288f };
1863 
1864  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
1865  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
1866  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
1867  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
1868  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
1869 
1870  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
1871  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
1872  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
1873  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
1874  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
1875 
1877  armnn::WorkloadInfo info;
1878 
1879  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
1880  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
1881  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
1882 
1883  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
1884  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
1885  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1886 
1887  armnn::TensorInfo tensorInfoOut({outputSize}, armnn::DataType::Float32);
1888  armnn::TensorInfo tensorInfoNumFp({numUnits}, armnn::DataType::Float32);
1889  armnn::TensorInfo tensorInfoNum({numUnits}, armnn::DataType::QAsymmS8, 0.1f, 0);
1890  armnn::TensorInfo tensorInfoNumInput({numUnits, inputSize}, armnn::DataType::QAsymmS8, 0.1f, 0);
1891  armnn::TensorInfo tensorInfoNumOutput({numUnits, outputSize}, armnn::DataType::QAsymmS8, 0.1f, 0);
1892  armnn::TensorInfo tensorInfoOutNum({outputSize, numUnits}, armnn::DataType::QAsymmS8, 0.1f, 0);
1893 
1894  std::vector<int8_t> inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3, 2, 2, -4 };
1895  std::vector<int8_t> inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1, -3, -2, -4 };
1896  std::vector<int8_t> inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3, 2, 5, -4 };
1897  std::vector<int8_t> inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4, -4, -1, -1 };
1898 
1899  std::vector<float> inputGateBias = { 0.03f, 0.15f, 0.22f, 0.38f, 0.05f };
1900  std::vector<float> forgetGateBias = { 0.1f, -0.3f, -0.2f, 0.1f, 0.4f };
1901  std::vector<float> cellBias = { -0.05f, 0.72f, 0.25f, 0.08f, 0.1f };
1902  std::vector<float> outputGateBias = { 0.05f, -0.01f, 0.2f, 0.1f, -0.2f };
1903 
1904  std::vector<int8_t> recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3,
1905  5, -1, 1, 3, -1, -1, -1, 4, 2, 3 };
1906 
1907  std::vector<int8_t> recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3,
1908  5, -1, 1, 3, -2, -1, -1, 2, 2, 1 };
1909 
1910  std::vector<int8_t> recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2,
1911  1, 2, 3, -2, 3, -3, -1, -5, 1, 3 };
1912 
1913  std::vector<int8_t> recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3,
1914  -4, -1, -1, -1, 2, -1, 5, 1, -3, -4 };
1915 
1916  std::vector<int8_t> cellToInputWeights = { 5, 3, 8, -5, 2 };
1917  std::vector<int8_t> cellToForgetWeights = { -2, -7, 5, -3, 4 };
1918  std::vector<int8_t> cellToOutputWeights = { 9, -10 , -5, 5, 1 };
1919 
1920  std::vector<int8_t> projectionWeights = { -1, 2, 1, -2, 1, 5, 3, 8, 7, 2,
1921  -4, 2, 5, -4, 3, -2, 3, 8, -7, 2 };
1922 
1923  std::vector<float> projectionBiasVector(outputSize, 0.f); //{outputSize}
1924 
1925  std::vector<float> inputLayerNormWeights = { 0.1f, 0.2f, -0.3f, -0.1f, 0.5f };
1926  std::vector<float> forgetLayerNormWeights = { -0.1f, 0.2f, 0.3f, 0.5f, 0.2f };
1927  std::vector<float> cellLayerNormWeights = { 0.5f, 0.2f, 0.3f, 0.4f, -0.5f };
1928  std::vector<float> outputLayerNormWeights = { 0.6f, -0.2f, -0.2f, 0.5f, 0.1f };
1929 
1930  armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfoNumInput);
1931  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfoNumInput);
1932  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfoNumInput);
1933  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfoNumInput);
1934  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfoNumOutput);
1935  armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfoNumOutput);
1936  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfoNumOutput);
1937  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfoNumOutput);
1938  armnn::ScopedTensorHandle cellToInputWeightsTensor(tensorInfoNum);
1939  armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfoNumFp);
1940  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfoNumFp);
1941  armnn::ScopedTensorHandle cellBiasTensor(tensorInfoNumFp);
1942  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfoNumFp);
1943  armnn::ScopedTensorHandle cellToForgetWeightsTensor(tensorInfoNum);
1944  armnn::ScopedTensorHandle cellToOutputWeightsTensor(tensorInfoNum);
1945  armnn::ScopedTensorHandle projectionWeightsTensor(tensorInfoOutNum);
1946  armnn::ScopedTensorHandle projectionBiasTensor(tensorInfoOut);
1947 
1948  armnn::ScopedTensorHandle inputLayerNormWeightsTensor(tensorInfoNumFp);
1949  armnn::ScopedTensorHandle forgetLayerNormWeightsTensor(tensorInfoNumFp);
1950  armnn::ScopedTensorHandle cellLayerNormWeightsTensor(tensorInfoNumFp);
1951  armnn::ScopedTensorHandle outputLayerNormWeightsTensor(tensorInfoNumFp);
1952 
1953  AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data());
1954  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
1955  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
1956  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
1957  AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data());
1958  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
1959  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
1960  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
1961  AllocateAndCopyDataToITensorHandle(&cellToInputWeightsTensor, cellToInputWeights.data());
1962  AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data());
1963  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
1964  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
1965  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
1966  AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, cellToForgetWeights.data());
1967  AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, cellToOutputWeights.data());
1968  AllocateAndCopyDataToITensorHandle(&projectionWeightsTensor, projectionWeights.data());
1969  AllocateAndCopyDataToITensorHandle(&projectionBiasTensor, projectionBiasVector.data());
1970 
1971  AllocateAndCopyDataToITensorHandle(&inputLayerNormWeightsTensor, inputLayerNormWeights.data());
1972  AllocateAndCopyDataToITensorHandle(&forgetLayerNormWeightsTensor, forgetLayerNormWeights.data());
1973  AllocateAndCopyDataToITensorHandle(&cellLayerNormWeightsTensor, cellLayerNormWeights.data());
1974  AllocateAndCopyDataToITensorHandle(&outputLayerNormWeightsTensor, outputLayerNormWeights.data());
1975 
1976  data.m_InputToInputWeights = &inputToInputWeightsTensor;
1977  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
1978  data.m_InputToCellWeights = &inputToCellWeightsTensor;
1979  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
1980  data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
1981  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
1982  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
1983  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
1984  data.m_CellToInputWeights = &cellToInputWeightsTensor;
1985  data.m_InputGateBias = &inputGateBiasTensor;
1986  data.m_ForgetGateBias = &forgetGateBiasTensor;
1987  data.m_CellBias = &cellBiasTensor;
1988  data.m_OutputGateBias = &outputGateBiasTensor;
1989  data.m_CellToForgetWeights = &cellToForgetWeightsTensor;
1990  data.m_CellToOutputWeights = &cellToOutputWeightsTensor;
1991  data.m_ProjectionWeights = &projectionWeightsTensor;
1992  data.m_ProjectionBias = &projectionBiasTensor;
1993 
1994  data.m_InputLayerNormWeights = &inputLayerNormWeightsTensor;
1995  data.m_ForgetLayerNormWeights = &forgetLayerNormWeightsTensor;
1996  data.m_CellLayerNormWeights = &cellLayerNormWeightsTensor;
1997  data.m_OutputLayerNormWeights = &outputLayerNormWeightsTensor;
1998 
1999  // Flags to set test configuration
2000  data.m_Parameters.m_ActivationFunc = 4;
2001  data.m_Parameters.m_CifgEnabled = false;
2002  data.m_Parameters.m_PeepholeEnabled = true;
2003  data.m_Parameters.m_ProjectionEnabled = true;
2004  data.m_Parameters.m_LayerNormEnabled = true;
2005  data.m_Parameters.m_TimeMajor = false;
2006  data.m_Parameters.m_ClippingThresCell = 10.0f;
2007 
2008  std::unique_ptr<armnn::IWorkload> workload
2009  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
2010  inputHandle->Allocate();
2011  outputStateInHandle->Allocate();
2012  cellStateInHandle->Allocate();
2013 
2014  outputStateOutHandle->Allocate();
2015  cellStateOutHandle->Allocate();
2016  outputHandle->Allocate();
2017 
2018  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
2019  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
2020  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
2021 
2022  workload->Execute();
2023 
2024  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
2025  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
2026  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
2027 
2028  return LayerTestResult<float, 3>(actualOutput,
2029  expectedOutput,
2030  outputHandle->GetShape(),
2031  outputTensorInfo.GetShape());
2032 }
2033 
2035  armnn::IWorkloadFactory& workloadFactory,
2037  const armnn::ITensorHandleFactory& tensorHandleFactory)
2038 {
2039  IgnoreUnused(memoryManager);
2040  unsigned int batchSize = 3;
2041  unsigned int timeSize = 2;
2042  unsigned int inputSize = 3;
2043  unsigned int outputSize = 4;
2044  unsigned numUnits = outputSize;
2045 
2046  armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32);
2047  armnn::TensorInfo cellStateInTensorInfo({batchSize, numUnits}, armnn::DataType::Float32);
2048  armnn::TensorInfo outputStateInTensorInfo({batchSize, outputSize}, armnn::DataType::Float32);
2049  armnn::TensorInfo outputStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
2050  armnn::TensorInfo cellStateOutTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
2051  armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32);
2052 
2053  const std::vector<float> inputVector = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f,
2054  0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f,
2055  0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f };
2056 
2057  std::vector<float> cellStateInVector(batchSize * numUnits, 0.f);
2058  std::vector<float> outputStateInVector(batchSize * outputSize, 0.f);
2059 
2060  std::vector<float> actualOutputStateOut(outputStateOutTensorInfo.GetNumElements());
2061  std::vector<float> actualCellStateOut(cellStateOutTensorInfo.GetNumElements());
2062  std::vector<float> actualOutput(outputTensorInfo.GetNumElements());
2063 
2064  const std::vector<float> outputVector = { -0.0072104f, -0.00991171f, -0.00650478f, -0.00713055f,
2065  -0.0191782f, -0.0161269f, -0.0233683f, -0.054299f,
2066  -0.00783725f, 0.00635271f, -0.0126718f, -0.022613f,
2067  -0.0161351f, -0.00775868f, -0.021054f, -0.0339778f,
2068  -0.0146392f, 0.00330261f, -0.0258733f, -0.0407797f,
2069  -0.0174297f, 0.0050105f, -0.0266275f, -0.0362564f };
2070 
2071  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
2072  std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
2073  tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo);
2074  std::unique_ptr<armnn::ITensorHandle> outputStateInHandle =
2075  tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo);
2076 
2077  std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle =
2078  tensorHandleFactory.CreateTensorHandle(outputStateOutTensorInfo);
2079  std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle =
2080  tensorHandleFactory.CreateTensorHandle(cellStateOutTensorInfo);
2081  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
2082 
2084  armnn::WorkloadInfo info;
2085 
2086  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
2087  AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get());
2088  AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get());
2089 
2090  AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get());
2091  AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get());
2092  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
2093 
2094  armnn::TensorInfo tensorInfoNumFp({numUnits}, armnn::DataType::Float32);
2095  armnn::TensorInfo tensorInfoNum({numUnits}, armnn::DataType::QAsymmS8, 0.1f, 0);
2096  armnn::TensorInfo tensorInfoNumInput({numUnits, inputSize}, armnn::DataType::QAsymmS8, 0.1f, 0);
2097  armnn::TensorInfo tensorInfoNumOutput({numUnits, outputSize}, armnn::DataType::QAsymmS8, 0.1f, 0);
2098 
2099  std::vector<int8_t> inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 };
2100  std::vector<int8_t> inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 };
2101  std::vector<int8_t> inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 };
2102 
2103  std::vector<int8_t> recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 };
2104  std::vector<int8_t> recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 };
2105  std::vector<int8_t> recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 };
2106 
2107  std::vector<int8_t> cellToForgetWeights = { 47, -52, -24, 31 };
2108  std::vector<int8_t> cellToOutputWeights = { -17, 82, 85, -77 };
2109 
2110  std::vector<float> forgetGateBias = { 1., 1., 1., 1. };
2111  std::vector<float> cellBias = { 0., 0., 0., 0. };
2112  std::vector<float> outputGateBias = { 0., 0., 0., 0. };
2113 
2114  armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfoNumInput);
2115  armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfoNumInput);
2116  armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfoNumInput);
2117  armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfoNumOutput);
2118  armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfoNumOutput);
2119  armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfoNumOutput);
2120  armnn::ScopedTensorHandle cellToForgetWeightsTensor(tensorInfoNum);
2121  armnn::ScopedTensorHandle cellToOutputWeightsTensor(tensorInfoNum);
2122  armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfoNumFp);
2123  armnn::ScopedTensorHandle cellBiasTensor(tensorInfoNumFp);
2124  armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfoNumFp);
2125 
2126  AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data());
2127  AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data());
2128  AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data());
2129  AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data());
2130  AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data());
2131  AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data());
2132  AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, cellToForgetWeights.data());
2133  AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, cellToOutputWeights.data());
2134  AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data());
2135  AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data());
2136  AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data());
2137 
2138  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
2139  data.m_InputToCellWeights = &inputToCellWeightsTensor;
2140  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
2141  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
2142  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
2143  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
2144  data.m_CellToForgetWeights = &cellToForgetWeightsTensor;
2145  data.m_CellToOutputWeights = &cellToOutputWeightsTensor;
2146  data.m_ForgetGateBias = &forgetGateBiasTensor;
2147  data.m_CellBias = &cellBiasTensor;
2148  data.m_OutputGateBias = &outputGateBiasTensor;
2149 
2150  // Flags to set test configuration
2153  data.m_Parameters.m_ActivationFunc = 4;
2154  data.m_Parameters.m_CifgEnabled = true;
2155  data.m_Parameters.m_PeepholeEnabled = true;
2156  data.m_Parameters.m_ProjectionEnabled = false;
2157  data.m_Parameters.m_TimeMajor = false;
2158 
2159  std::unique_ptr<armnn::IWorkload> workload
2160  = workloadFactory.CreateWorkload(armnn::LayerType::UnidirectionalSequenceLstm, data, info);
2161  inputHandle->Allocate();
2162  outputStateInHandle->Allocate();
2163  cellStateInHandle->Allocate();
2164 
2165  outputStateOutHandle->Allocate();
2166  cellStateOutHandle->Allocate();
2167  outputHandle->Allocate();
2168 
2169  CopyDataToITensorHandle(inputHandle.get(), inputVector.data());
2170  CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data());
2171  CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data());
2172 
2173  workload->Execute();
2174 
2175  CopyDataFromITensorHandle(actualOutputStateOut.data(), outputStateOutHandle.get());
2176  CopyDataFromITensorHandle(actualCellStateOut.data(), cellStateOutHandle.get());
2177  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
2178 
2179  return LayerTestResult<float, 3>(actualOutput,
2180  outputVector,
2181  outputHandle->GetShape(),
2182  outputTensorInfo.GetShape());
2183 }
bool m_ProjectionEnabled
Enable/disable the projection layer.
float m_ClippingThresProj
Clipping threshold value for the projection.
LayerTestResult< float, 3 > UnidirectionalSequenceLstmLayerInt8Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
LayerTestResult< float, 3 > UnidirectionalSequenceLstmInt8WithCifgWithPeepholeNoProjectionTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
bool m_TimeMajor
Enable/disable time major.
void IgnoreUnused(Ts &&...)
LayerTestResult< float, 3 > UnidirectionalSequenceLstmLayerFloat32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
void AllocateAndCopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
LayerTestResult< float, 3 > UnidirectionalSequenceLstmLayerInt8TimeMajorTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
LayerTestResult< float, 3 > UnidirectionalSequenceLstmLayerFloat32TimeMajorSingleBatchTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
LayerTestResult< float, 3 > UnidirectionalSequenceLstmLayerNoCifgWithPeepholeWithProjectionTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
DataType
Definition: Types.hpp:48
LayerTestResult< float, 3 > UnidirectionalSequenceLstmLayerNoCifgWithPeepholeWithProjectionWithLayerNormTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
LayerTestResult< float, 3 > UnidirectionalSequenceLstmWithCifgWithPeepholeNoProjectionTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
bool m_PeepholeEnabled
Enable/disable peephole.
void CopyDataFromITensorHandle(void *mem, const armnn::ITensorHandle *tensorHandle)
LayerTestResult< float, 3 > UnidirectionalSequenceLstmLayerInt8NoCifgWithPeepholeWithProjectionTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
uint32_t m_ActivationFunc
The activation function to use.
float m_ClippingThresCell
Clipping threshold value for the cell state.
LayerTestResult< float, 3 > UnidirectionalSequenceLstmLayerFloat32BatchMajorSingleBatchTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
LayerTestResult< float, 3 > UnidirectionalSequenceLstmLayerFloat32TimeMajorTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
bool m_LayerNormEnabled
Enable/disable layer normalization.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
LayerTestResult< float, 3 > UnidirectionalSequenceLstmLayerInt8NoCifgWithPeepholeWithProjectionWithLayerNormTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
Contains information about TensorInfos of a layer.
const ConstTensorHandle * m_RecurrentToOutputWeights
virtual std::unique_ptr< IWorkload > CreateWorkload(LayerType type, const QueueDescriptor &descriptor, const WorkloadInfo &info) const
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const =0
const ConstTensorHandle * m_RecurrentToForgetWeights