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