ArmNN
 20.08
StackTestImpl.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "StackTestImpl.hpp"
7 #include "LayerTestResult.hpp"
8 
9 #include <ResolveType.hpp>
10 
11 
14 
17 
18 #include <test/TensorHelpers.hpp>
19 
20 namespace
21 {
22 
23 template<armnn::DataType ArmnnType, typename T, std::size_t outputDimLength>
25  armnn::IWorkloadFactory& workloadFactory,
27  const armnn::TensorInfo& inputTensorInfo,
28  const armnn::TensorInfo& outputTensorInfo,
29  unsigned int axis,
30  const std::vector<std::vector<T>>& inputData,
31  const std::vector<T>& outputExpectedData)
32 {
33  IgnoreUnused(memoryManager);
34  unsigned int numInputs = static_cast<unsigned int>(inputData.size());
35  std::vector<boost::multi_array<T, outputDimLength-1>> inputs;
36  for (unsigned int i = 0; i < numInputs; ++i)
37  {
38  inputs.push_back(MakeTensor<T, outputDimLength-1>(inputTensorInfo, inputData[i]));
39  }
40 
41  LayerTestResult<T, outputDimLength> result(outputTensorInfo);
42  result.outputExpected = MakeTensor<T, outputDimLength>(outputTensorInfo, outputExpectedData);
43 
44  std::vector<std::unique_ptr<armnn::ITensorHandle>> inputHandles;
46  for (unsigned int i = 0; i < numInputs; ++i)
47  {
48  inputHandles.push_back(workloadFactory.CreateTensorHandle(inputTensorInfo));
49  }
50  std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
52 
53  armnn::StackQueueDescriptor descriptor;
54  descriptor.m_Parameters.m_Axis = axis;
55  descriptor.m_Parameters.m_InputShape = inputTensorInfo.GetShape();
56  descriptor.m_Parameters.m_NumInputs = numInputs;
57 
59  for (unsigned int i = 0; i < numInputs; ++i)
60  {
61  std::unique_ptr<armnn::ITensorHandle>& inputHandle = inputHandles[i];
62  AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
63  inputHandle->Allocate();
64  CopyDataToITensorHandle(inputHandle.get(), inputs[i].origin());
65  }
66 
67  AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
68  outputHandle->Allocate();
69 
70  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateStack(descriptor, info);
71 
72  workload->Execute();
73 
74  CopyDataFromITensorHandle(result.output.origin(), outputHandle.get());
75 
76  return result;
77 }
78 
79 } // anonymous namespace
80 
81 //
82 // Implementation templates
83 //
84 
85 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
87  armnn::IWorkloadFactory& workloadFactory,
89 {
90  armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType);
91  armnn::TensorInfo outputTensorInfo({ 2, 3, 2, 3 }, ArmnnType);
92 
93  std::vector<std::vector<T>> inputData;
94 
95  inputData.push_back(
96  {
97  1, 2, 3,
98  4, 5, 6,
99 
100  7, 8, 9,
101  10, 11, 12,
102 
103  13, 14, 15,
104  16, 17, 18
105  });
106 
107  inputData.push_back(
108  {
109  19, 20, 21,
110  22, 23, 24,
111 
112  25, 26, 27,
113  28, 29, 30,
114 
115  31, 32, 33,
116  34, 35, 36
117  });
118 
119  std::vector<T> outputExpectedData =
120  {
121  1, 2, 3,
122  4, 5, 6,
123 
124  7, 8, 9,
125  10, 11, 12,
126 
127  13, 14, 15,
128  16, 17, 18,
129 
130 
131  19, 20, 21,
132  22, 23, 24,
133 
134  25, 26, 27,
135  28, 29, 30,
136 
137  31, 32, 33,
138  34, 35, 36
139  };
140 
141  return StackTestHelper<ArmnnType, T, 4>(
142  workloadFactory,
143  memoryManager,
144  inputTensorInfo,
145  outputTensorInfo,
146  0U,
147  inputData,
148  outputExpectedData
149  );
150 }
151 
152 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
154  armnn::IWorkloadFactory& workloadFactory,
156 {
157  armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType);
158  armnn::TensorInfo outputTensorInfo({ 3, 2, 2, 3 }, ArmnnType);
159 
160  std::vector<std::vector<T>> inputData;
161 
162  inputData.push_back(
163  {
164  1, 2, 3,
165  4, 5, 6,
166 
167  7, 8, 9,
168  10, 11, 12,
169 
170  13, 14, 15,
171  16, 17, 18
172  });
173 
174  inputData.push_back(
175  {
176  19, 20, 21,
177  22, 23, 24,
178 
179  25, 26, 27,
180  28, 29, 30,
181 
182  31, 32, 33,
183  34, 35, 36
184  });
185 
186  std::vector<T> outputExpectedData =
187  {
188  1, 2, 3,
189  4, 5, 6,
190 
191  19, 20, 21,
192  22, 23, 24,
193 
194 
195  7, 8, 9,
196  10, 11, 12,
197 
198  25, 26, 27,
199  28, 29, 30,
200 
201 
202  13, 14, 15,
203  16, 17, 18,
204 
205  31, 32, 33,
206  34, 35, 36
207  };
208 
209  return StackTestHelper<ArmnnType, T, 4>(
210  workloadFactory,
211  memoryManager,
212  inputTensorInfo,
213  outputTensorInfo,
214  1U,
215  inputData,
216  outputExpectedData
217  );
218 }
219 
220 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
222  armnn::IWorkloadFactory& workloadFactory,
224 {
225  armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType);
226  armnn::TensorInfo outputTensorInfo({ 3, 2, 2, 3 }, ArmnnType);
227 
228  std::vector<std::vector<T>> inputData;
229 
230  inputData.push_back(
231  {
232  1, 2, 3,
233  4, 5, 6,
234 
235  7, 8, 9,
236  10, 11, 12,
237 
238  13, 14, 15,
239  16, 17, 18
240  });
241 
242  inputData.push_back(
243  {
244  19, 20, 21,
245  22, 23, 24,
246 
247  25, 26, 27,
248  28, 29, 30,
249 
250  31, 32, 33,
251  34, 35, 36
252  });
253 
254  std::vector<T> outputExpectedData =
255  {
256  1, 2, 3,
257  19, 20, 21,
258 
259  4, 5, 6,
260  22, 23, 24,
261 
262  7, 8, 9,
263  25, 26, 27,
264 
265  10, 11, 12,
266  28, 29, 30,
267 
268  13, 14, 15,
269  31, 32, 33,
270 
271  16, 17, 18,
272  34, 35, 36
273  };
274 
275  return StackTestHelper<ArmnnType, T, 4>(
276  workloadFactory,
277  memoryManager,
278  inputTensorInfo,
279  outputTensorInfo,
280  2U,
281  inputData,
282  outputExpectedData
283  );
284 }
285 
286 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
288  armnn::IWorkloadFactory& workloadFactory,
290 {
291  armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType);
292  armnn::TensorInfo outputTensorInfo({ 3, 2, 3, 2 }, ArmnnType);
293 
294  std::vector<std::vector<T>> inputData;
295 
296  inputData.push_back(
297  {
298  1, 2, 3,
299  4, 5, 6,
300 
301  7, 8, 9,
302  10, 11, 12,
303 
304  13, 14, 15,
305  16, 17, 18
306  });
307 
308  inputData.push_back(
309  {
310  19, 20, 21,
311  22, 23, 24,
312 
313  25, 26, 27,
314  28, 29, 30,
315 
316  31, 32, 33,
317  34, 35, 36
318  });
319 
320  std::vector<T> outputExpectedData =
321  {
322  1, 19,
323  2, 20,
324  3, 21,
325 
326  4, 22,
327  5, 23,
328  6, 24,
329 
330 
331  7, 25,
332  8, 26,
333  9, 27,
334 
335  10, 28,
336  11, 29,
337  12, 30,
338 
339 
340  13, 31,
341  14, 32,
342  15, 33,
343 
344  16, 34,
345  17, 35,
346  18, 36
347  };
348 
349  return StackTestHelper<ArmnnType, T, 4>(
350  workloadFactory,
351  memoryManager,
352  inputTensorInfo,
353  outputTensorInfo,
354  3U,
355  inputData,
356  outputExpectedData
357  );
358 }
359 
360 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
362  armnn::IWorkloadFactory& workloadFactory,
364 {
365  armnn::TensorInfo inputTensorInfo ({ 3, 3 }, ArmnnType);
366  armnn::TensorInfo outputTensorInfo({ 3, 3, 3 }, ArmnnType);
367 
368  std::vector<std::vector<T>> inputData;
369 
370  inputData.push_back(
371  {
372  1, 2, 3,
373  4, 5, 6,
374  7, 8, 9
375  });
376 
377  inputData.push_back(
378  {
379  10, 11, 12,
380  13, 14, 15,
381  16, 17, 18
382  });
383 
384  inputData.push_back(
385  {
386  19, 20, 21,
387  22, 23, 24,
388  25, 26, 27
389  });
390 
391  std::vector<T> outputExpectedData =
392  {
393  1, 2, 3,
394  10, 11, 12,
395  19, 20, 21,
396 
397  4, 5, 6,
398  13, 14, 15,
399  22, 23, 24,
400 
401  7, 8, 9,
402  16, 17, 18,
403  25, 26, 27
404  };
405 
406  return StackTestHelper<ArmnnType, T, 3>(
407  workloadFactory,
408  memoryManager,
409  inputTensorInfo,
410  outputTensorInfo,
411  1U,
412  inputData,
413  outputExpectedData
414  );
415 }
416 
417 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
419  armnn::IWorkloadFactory& workloadFactory,
421 {
422  armnn::TensorInfo inputTensorInfo ({ 2, 2, 2, 3 }, ArmnnType);
423  armnn::TensorInfo outputTensorInfo({ 2, 2, 2, 2, 3 }, ArmnnType);
424 
425  std::vector<std::vector<T>> inputData;
426 
427  inputData.push_back(
428  {
429  1, 2, 3,
430  4, 5, 6,
431 
432  7, 8, 9,
433  10, 11, 12,
434 
435 
436  13, 14, 15,
437  16, 17, 18,
438 
439  19, 20, 21,
440  22, 23, 24
441  });
442 
443  inputData.push_back(
444  {
445  25, 26, 27,
446  28, 29, 30,
447 
448  31, 32, 33,
449  34, 35, 36,
450 
451 
452  37, 38, 39,
453  40, 41, 42,
454 
455  43, 44, 45,
456  46, 47, 48
457  });
458 
459  std::vector<T> outputExpectedData =
460  {
461  1, 2, 3,
462  4, 5, 6,
463 
464  7, 8, 9,
465  10, 11, 12,
466 
467 
468  25, 26, 27,
469  28, 29, 30,
470 
471  31, 32, 33,
472  34, 35, 36,
473 
474 
475 
476  13, 14, 15,
477  16, 17, 18,
478 
479  19, 20, 21,
480  22, 23, 24,
481 
482 
483  37, 38, 39,
484  40, 41, 42,
485 
486  43, 44, 45,
487  46, 47, 48
488 
489  };
490 
491  return StackTestHelper<ArmnnType, T, 5>(
492  workloadFactory,
493  memoryManager,
494  inputTensorInfo,
495  outputTensorInfo,
496  1U,
497  inputData,
498  outputExpectedData
499  );
500 }
501 
502 //
503 // Implementation functions
504 //
505 
507  armnn::IWorkloadFactory& workloadFactory,
509 {
510  return StackAxis0TestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager);
511 }
512 
514  armnn::IWorkloadFactory& workloadFactory,
516 {
517  return StackOutput4DAxis1TestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager);
518 }
519 
521  armnn::IWorkloadFactory& workloadFactory,
523 {
524  return StackOutput4DAxis2TestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager);
525 }
526 
528  armnn::IWorkloadFactory& workloadFactory,
530 {
531  return StackOutput4DAxis3TestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager);
532 }
533 
535  armnn::IWorkloadFactory& workloadFactory,
537 {
538  return StackOutput3DInputs3TestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager);
539 }
540 
542  armnn::IWorkloadFactory& workloadFactory,
544 {
545  return StackOutput5DTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager);
546 }
547 
549  armnn::IWorkloadFactory& workloadFactory,
551 {
552  using namespace half_float::literal;
553 
554  armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, armnn::DataType::Float16);
555  armnn::TensorInfo outputTensorInfo({ 3, 2, 2, 3 }, armnn::DataType::Float16);
556 
557  std::vector<std::vector<armnn::Half>> inputData;
558 
559  inputData.push_back(
560  {
561  1.0_h, 2.0_h, 3.0_h,
562  4.0_h, 5.0_h, 6.0_h,
563 
564  7.0_h, 8.0_h, 9.0_h,
565  10.0_h, 11.0_h, 12.0_h,
566 
567  13.0_h, 14.0_h, 15.0_h,
568  16.0_h, 17.0_h, 18.0_h
569  });
570 
571  inputData.push_back(
572  {
573  19.0_h, 20.0_h, 21.0_h,
574  22.0_h, 23.0_h, 24.0_h,
575 
576  25.0_h, 26.0_h, 27.0_h,
577  28.0_h, 29.0_h, 30.0_h,
578 
579  31.0_h, 32.0_h, 33.0_h,
580  34.0_h, 35.0_h, 36.0_h
581  });
582 
583  std::vector<armnn::Half> outputExpectedData =
584  {
585  1.0_h, 2.0_h, 3.0_h,
586  19.0_h, 20.0_h, 21.0_h,
587 
588  4.0_h, 5.0_h, 6.0_h,
589  22.0_h, 23.0_h, 24.0_h,
590 
591  7.0_h, 8.0_h, 9.0_h,
592  25.0_h, 26.0_h, 27.0_h,
593 
594  10.0_h, 11.0_h, 12.0_h,
595  28.0_h, 29.0_h, 30.0_h,
596 
597  13.0_h, 14.0_h, 15.0_h,
598  31.0_h, 32.0_h, 33.0_h,
599 
600  16.0_h, 17.0_h, 18.0_h,
601  34.0_h, 35.0_h, 36.0_h
602  };
603 
604  return StackTestHelper<armnn::DataType::Float16, armnn::Half, 4>(
605  workloadFactory,
606  memoryManager,
607  inputTensorInfo,
608  outputTensorInfo,
609  2U,
610  inputData,
611  outputExpectedData
612  );
613 }
LayerTestResult< float, 3 > StackOutput3DInputs3Float32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
uint32_t m_Axis
0-based axis along which to stack the input tensors.
const TensorShape & GetShape() const
Definition: Tensor.hpp:187
LayerTestResult< T, 4 > StackOutput4DAxis1TestImpl(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
LayerTestResult< float, 4 > StackAxis0Float32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
Definition: Deprecated.hpp:33
LayerTestResult< float, 4 > StackOutput4DAxis1Float32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
virtual std::unique_ptr< IWorkload > CreateStack(const StackQueueDescriptor &descriptor, const WorkloadInfo &info) const
LayerTestResult< float, 4 > StackOutput4DAxis2Float32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
void IgnoreUnused(Ts &&...)
LayerTestResult< T, 4 > StackOutput4DAxis3TestImpl(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
LayerTestResult< float, 4 > StackOutput4DAxis3Float32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
#define ARMNN_NO_DEPRECATE_WARN_END
Definition: Deprecated.hpp:34
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
LayerTestResult< T, 4 > StackOutput4DAxis2TestImpl(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, const bool IsMemoryManaged=true) const =0
LayerTestResult< armnn::Half, 4 > StackFloat16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
LayerTestResult< float, 5 > StackOutput5DFloat32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
LayerTestResult< T, 5 > StackOutput5DTestImpl(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
Contains information about inputs and outputs to a layer.
LayerTestResult< T, 4 > StackAxis0TestImpl(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
LayerTestResult< T, 3 > StackOutput3DInputs3TestImpl(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)