ArmNN
 21.11
BatchNormalizationTestImpl.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 #include <QuantizeHelper.hpp>
9 #include <ResolveType.hpp>
10 
13 
18 
21 
22 #include <test/TensorHelpers.hpp>
23 
24 namespace
25 {
26 
27 using namespace armnnUtils;
28 
29 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
30 LayerTestResult<T, 4> BatchNormTestImpl(
31  armnn::IWorkloadFactory& workloadFactory,
33  const armnn::ITensorHandleFactory& tensorHandleFactory,
34  const armnn::TensorShape& inputOutputTensorShape,
35  const std::vector<float>& inputValues,
36  const std::vector<float>& expectedOutputValues,
37  float qScale,
38  int32_t qOffset,
39  armnn::DataLayout dataLayout)
40 {
41  IgnoreUnused(memoryManager);
42  armnn::TensorInfo inputTensorInfo(inputOutputTensorShape, ArmnnType);
43  armnn::TensorInfo outputTensorInfo(inputOutputTensorShape, ArmnnType);
44 
45  armnnUtils::DataLayoutIndexed dataLayoutIndexed(dataLayout);
46 
47  armnn::TensorInfo tensorInfo({ inputOutputTensorShape[dataLayoutIndexed.GetChannelsIndex()] },
48  ArmnnType);
49 
50  // Set quantization parameters if the requested type is a quantized type.
51  if (armnn::IsQuantizedType<T>())
52  {
53  inputTensorInfo.SetQuantizationScale(qScale);
54  inputTensorInfo.SetQuantizationOffset(qOffset);
55  outputTensorInfo.SetQuantizationScale(qScale);
56  outputTensorInfo.SetQuantizationOffset(qOffset);
57  tensorInfo.SetQuantizationScale(qScale);
58  tensorInfo.SetQuantizationOffset(qOffset);
59  }
60 
61  auto inputTensor = QuantizedVector<T>(inputValues, qScale, qOffset);
62 
63  // These values are per-channel of the input.
64  auto mean = QuantizedVector<T>({ 3, -2 }, qScale, qOffset);
65  auto variance = QuantizedVector<T>({ 4, 9 }, qScale, qOffset);
66  auto beta = QuantizedVector<T>({ 3, 2 }, qScale, qOffset);
67  auto gamma = QuantizedVector<T>({ 2, 1 }, qScale, qOffset);
68 
69  std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
70  std::vector<T> expectedOutput = QuantizedVector<T>(expectedOutputValues, qScale, qOffset);
71 
72  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
73  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
74 
75  armnn::ScopedTensorHandle meanTensor(tensorInfo);
76  armnn::ScopedTensorHandle varianceTensor(tensorInfo);
77  armnn::ScopedTensorHandle betaTensor(tensorInfo);
78  armnn::ScopedTensorHandle gammaTensor(tensorInfo);
79 
81  descriptor.m_Mean = &meanTensor;
82  descriptor.m_Variance = &varianceTensor;
83  descriptor.m_Beta = &betaTensor;
84  descriptor.m_Gamma = &gammaTensor;
85  descriptor.m_Parameters.m_Eps = 0.0f;
86  descriptor.m_Parameters.m_DataLayout = dataLayout;
88 
89  AllocateAndCopyDataToITensorHandle(&meanTensor, mean.data());
90  AllocateAndCopyDataToITensorHandle(&varianceTensor, variance.data());
91  AllocateAndCopyDataToITensorHandle(&betaTensor, beta.data());
92  AllocateAndCopyDataToITensorHandle(&gammaTensor, gamma.data());
93 
94  AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
95  AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
96 
97  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchNormalization(descriptor, info);
98 
99  inputHandle->Allocate();
100  outputHandle->Allocate();
101 
102  CopyDataToITensorHandle(inputHandle.get(), inputTensor.data());
103 
104  workload->Execute();
105 
106  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
107 
108  return LayerTestResult<T, 4>(actualOutput,
109  expectedOutput,
110  outputHandle->GetShape(),
111  outputTensorInfo.GetShape());
112 }
113 
114 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
115 LayerTestResult<T,4> BatchNormTestNhwcImpl(
116  armnn::IWorkloadFactory& workloadFactory,
118  const armnn::ITensorHandleFactory& tensorHandleFactory,
119  float qScale,
120  int32_t qOffset)
121 {
122  IgnoreUnused(memoryManager);
123 
124  const unsigned int width = 2;
125  const unsigned int height = 3;
126  const unsigned int channels = 2;
127  const unsigned int num = 1;
128 
129  armnn::TensorInfo inputTensorInfo({num, height, width, channels}, ArmnnType);
130  armnn::TensorInfo outputTensorInfo({num, height, width, channels}, ArmnnType);
131  armnn::TensorInfo tensorInfo({channels}, ArmnnType);
132 
133  // Set quantization parameters if the requested type is a quantized type.
134  if(armnn::IsQuantizedType<T>())
135  {
136  inputTensorInfo.SetQuantizationScale(qScale);
137  inputTensorInfo.SetQuantizationOffset(qOffset);
138  outputTensorInfo.SetQuantizationScale(qScale);
139  outputTensorInfo.SetQuantizationOffset(qOffset);
140  tensorInfo.SetQuantizationScale(qScale);
141  tensorInfo.SetQuantizationOffset(qOffset);
142  }
143 
144  auto input = QuantizedVector<T>(
145  {
146  1.f, 1.f, 4.f, 1.f,
147  4.f, 4.f, 2.f, 1.f,
148  1.f, -2.f, 6.f, 4.f
149  },
150  qScale, qOffset);
151 
152  // These values are per-channel of the input.
153  auto mean = QuantizedVector<T>({ 3, -2 }, qScale, qOffset);
154  auto variance = QuantizedVector<T>({ 4, 9 }, qScale, qOffset);
155  auto beta = QuantizedVector<T>({ 3, 2 }, qScale, qOffset);
156  auto gamma = QuantizedVector<T>({ 2, 1 }, qScale, qOffset);
157 
158  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
159  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
160 
162  armnn::WorkloadInfo info;
163  armnn::ScopedTensorHandle meanTensor(tensorInfo);
164  armnn::ScopedTensorHandle varianceTensor(tensorInfo);
165  armnn::ScopedTensorHandle betaTensor(tensorInfo);
166  armnn::ScopedTensorHandle gammaTensor(tensorInfo);
167 
168  AllocateAndCopyDataToITensorHandle(&meanTensor, &mean[0]);
169  AllocateAndCopyDataToITensorHandle(&varianceTensor, &variance[0]);
170  AllocateAndCopyDataToITensorHandle(&betaTensor, &beta[0]);
171  AllocateAndCopyDataToITensorHandle(&gammaTensor, &gamma[0]);
172 
173  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
174  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
175  data.m_Mean = &meanTensor;
176  data.m_Variance = &varianceTensor;
177  data.m_Beta = &betaTensor;
178  data.m_Gamma = &gammaTensor;
179  data.m_Parameters.m_Eps = 0.0f;
181 
182  std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
183 
184  // For each channel:
185  // substract mean, divide by standard deviation (with an epsilon to avoid div by 0),
186  // multiply by gamma and add beta
187  std::vector<T> expectedOutput = QuantizedVector<T>(
188  {
189  1.f, 3.f, 4.f, 3.f,
190  4.f, 4.f, 2.f, 3.f,
191  1.f, 2.f, 6.f, 4.f
192  },
193  qScale, qOffset);
194 
195  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchNormalization(data, info);
196 
197  inputHandle->Allocate();
198  outputHandle->Allocate();
199 
200  CopyDataToITensorHandle(inputHandle.get(), input.data());
201 
202  workload->Execute();
203 
204  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
205 
206  return LayerTestResult<T, 4>(actualOutput,
207  expectedOutput,
208  outputHandle->GetShape(),
209  outputTensorInfo.GetShape());
210 }
211 
212 } // anonymous namespace
213 
215  armnn::IWorkloadFactory& workloadFactory,
217  const armnn::ITensorHandleFactory& tensorHandleFactory)
218 {
219  // BatchSize: 1
220  // Channels: 2
221  // Height: 3
222  // Width: 2
223 
224  const armnn::TensorShape inputOutputShape{ 1, 2, 3, 2 };
225  std::vector<float> inputValues
226  {
227  // Batch 0, Channel 0, Height (3) x Width (2)
228  1.f, 4.f,
229  4.f, 2.f,
230  1.f, 6.f,
231 
232  // Batch 0, Channel 1, Height (3) x Width (2)
233  1.f, 1.f,
234  4.f, 1.f,
235  -2.f, 4.f
236  };
237  std::vector<float> expectedOutputValues
238  {
239  // Batch 0, Channel 0, Height (3) x Width (2)
240  1.f, 4.f,
241  4.f, 2.f,
242  1.f, 6.f,
243 
244  // Batch 0, Channel 1, Height (3) x Width (2)
245  3.f, 3.f,
246  4.f, 3.f,
247  2.f, 4.f
248  };
249 
250  return BatchNormTestImpl<armnn::DataType::Float32>(
251  workloadFactory,
252  memoryManager,
253  tensorHandleFactory,
254  inputOutputShape,
255  inputValues,
256  expectedOutputValues,
257  0.f,
258  0,
260 }
261 
263  armnn::IWorkloadFactory& workloadFactory,
265  const armnn::ITensorHandleFactory& tensorHandleFactory)
266 {
267  // BatchSize: 1
268  // Height: 3
269  // Width: 2
270  // Channels: 2
271 
272  const armnn::TensorShape inputOutputShape{ 1, 3, 2, 2 };
273  std::vector<float> inputValues
274  {
275  // Batch 0, Height 0, Width (2) x Channel (2)
276  1.f, 1.f,
277  4.f, 1.f,
278 
279  // Batch 0, Height 1, Width (2) x Channel (2)
280  4.f, 4.f,
281  2.f, 1.f,
282 
283  // Batch 0, Height 2, Width (2) x Channel (2)
284  1.f, -2.f,
285  6.f, 4.f
286  };
287  std::vector<float> expectedOutputValues
288  {
289  // Batch 0, Height 0, Width (2) x Channel (2)
290  1.f, 3.f,
291  4.f, 3.f,
292 
293  // Batch 0, Height 1, Width (2) x Channel (2)
294  4.f, 4.f,
295  2.f, 3.f,
296 
297  // Batch 0, Height 2, Width (2) x Channel (2)
298  1.f, 2.f,
299  6.f, 4.f
300  };
301 
302  return BatchNormTestImpl<armnn::DataType::Float32>(
303  workloadFactory,
304  memoryManager,
305  tensorHandleFactory,
306  inputOutputShape,
307  inputValues,
308  expectedOutputValues,
309  0.f,
310  0,
312 }
313 
315  armnn::IWorkloadFactory& workloadFactory,
317  const armnn::ITensorHandleFactory& tensorHandleFactory)
318 {
319  // BatchSize: 1
320  // Channels: 2
321  // Height: 3
322  // Width: 2
323 
324  const armnn::TensorShape inputOutputShape{ 1, 2, 3, 2 };
325  std::vector<float> inputValues
326  {
327  // Batch 0, Channel 0, Height (3) x Width (2)
328  1.f, 4.f,
329  4.f, 2.f,
330  1.f, 6.f,
331 
332  // Batch 0, Channel 1, Height (3) x Width (2)
333  1.f, 1.f,
334  4.f, 1.f,
335  -2.f, 4.f
336  };
337  std::vector<float> expectedOutputValues
338  {
339  // Batch 0, Channel 0, Height (3) x Width (2)
340  1.f, 4.f,
341  4.f, 2.f,
342  1.f, 6.f,
343 
344  // Batch 0, Channel 1, Height (3) x Width (2)
345  3.f, 3.f,
346  4.f, 3.f,
347  2.f, 4.f
348  };
349 
350  return BatchNormTestImpl<armnn::DataType::Float16>(
351  workloadFactory,
352  memoryManager,
353  tensorHandleFactory,
354  inputOutputShape,
355  inputValues,
356  expectedOutputValues,
357  0.f,
358  0,
360 }
361 
363  armnn::IWorkloadFactory& workloadFactory,
365  const armnn::ITensorHandleFactory& tensorHandleFactory)
366 {
367  // BatchSize: 1
368  // Height: 3
369  // Width: 2
370  // Channels: 2
371 
372  const armnn::TensorShape inputOutputShape{ 1, 3, 2, 2 };
373  std::vector<float> inputValues
374  {
375  // Batch 0, Height 0, Width (2) x Channel (2)
376  1.f, 1.f,
377  4.f, 1.f,
378 
379  // Batch 0, Height 1, Width (2) x Channel (2)
380  4.f, 4.f,
381  2.f, 1.f,
382 
383  // Batch 0, Height 2, Width (2) x Channel (2)
384  1.f, -2.f,
385  6.f, 4.f
386  };
387  std::vector<float> expectedOutputValues
388  {
389  // Batch 0, Height 0, Width (2) x Channel (2)
390  1.f, 3.f,
391  4.f, 3.f,
392 
393  // Batch 0, Height 1, Width (2) x Channel (2)
394  4.f, 4.f,
395  2.f, 3.f,
396 
397  // Batch 0, Height 2, Width (2) x Channel (2)
398  1.f, 2.f,
399  6.f, 4.f
400  };
401 
402  return BatchNormTestImpl<armnn::DataType::Float16>(
403  workloadFactory,
404  memoryManager,
405  tensorHandleFactory,
406  inputOutputShape,
407  inputValues,
408  expectedOutputValues,
409  0.f,
410  0,
412 }
413 
415  armnn::IWorkloadFactory& workloadFactory,
417  const armnn::ITensorHandleFactory& tensorHandleFactory)
418 {
419  // BatchSize: 1
420  // Channels: 2
421  // Height: 3
422  // Width: 2
423 
424  const armnn::TensorShape inputOutputShape{ 1, 2, 3, 2 };
425  std::vector<float> inputValues
426  {
427  // Batch 0, Channel 0, Height (3) x Width (2)
428  1.f, 4.f,
429  4.f, 2.f,
430  1.f, 6.f,
431 
432  // Batch 0, Channel 1, Height (3) x Width (2)
433  1.f, 1.f,
434  4.f, 1.f,
435  -2.f, 4.f
436  };
437  std::vector<float> expectedOutputValues
438  {
439  // Batch 0, Channel 0, Height (3) x Width (2)
440  1.f, 4.f,
441  4.f, 2.f,
442  1.f, 6.f,
443 
444  // Batch 0, Channel 1, Height (3) x Width (2)
445  3.f, 3.f,
446  4.f, 3.f,
447  2.f, 4.f
448  };
449 
450  return BatchNormTestImpl<armnn::DataType::QAsymmU8>(
451  workloadFactory,
452  memoryManager,
453  tensorHandleFactory,
454  inputOutputShape,
455  inputValues,
456  expectedOutputValues,
457  1.f / 20.f,
458  50,
460 }
461 
463  armnn::IWorkloadFactory& workloadFactory,
465  const armnn::ITensorHandleFactory& tensorHandleFactory)
466 {
467  // BatchSize: 1
468  // Height: 3
469  // Width: 2
470  // Channels: 2
471 
472  const armnn::TensorShape inputOutputShape{ 1, 3, 2, 2 };
473  std::vector<float> inputValues
474  {
475  // Batch 0, Height 0, Width (2) x Channel (2)
476  1.f, 1.f,
477  4.f, 1.f,
478 
479  // Batch 0, Height 1, Width (2) x Channel (2)
480  4.f, 4.f,
481  2.f, 1.f,
482 
483  // Batch 0, Height 2, Width (2) x Channel (2)
484  1.f, -2.f,
485  6.f, 4.f
486  };
487  std::vector<float> expectedOutputValues
488  {
489  // Batch 0, Height 0, Width (2) x Channel (2)
490  1.f, 3.f,
491  4.f, 3.f,
492 
493  // Batch 0, Height 1, Width (2) x Channel (2)
494  4.f, 4.f,
495  2.f, 3.f,
496 
497  // Batch 0, Height 2, Width (2) x Channel (2)
498  1.f, 2.f,
499  6.f, 4.f
500  };
501 
502  return BatchNormTestImpl<armnn::DataType::QAsymmU8>(
503  workloadFactory,
504  memoryManager,
505  tensorHandleFactory,
506  inputOutputShape, inputValues, expectedOutputValues,
507  1.f/20.f, 50, armnn::DataLayout::NHWC);
508 }
509 
511  armnn::IWorkloadFactory& workloadFactory,
513  const armnn::ITensorHandleFactory& tensorHandleFactory)
514 {
515  // BatchSize: 1
516  // Channels: 2
517  // Height: 3
518  // Width: 2
519 
520  const armnn::TensorShape inputOutputShape{ 1, 2, 3, 2 };
521  std::vector<float> inputValues
522  {
523  // Batch 0, Channel 0, Height (3) x Width (2)
524  1.f, 4.f,
525  4.f, 2.f,
526  1.f, 6.f,
527 
528  // Batch 0, Channel 1, Height (3) x Width (2)
529  1.f, 1.f,
530  4.f, 1.f,
531  -2.f, 4.f
532  };
533  std::vector<float> expectedOutputValues
534  {
535  // Batch 0, Channel 0, Height (3) x Width (2)
536  1.f, 4.f,
537  4.f, 2.f,
538  1.f, 6.f,
539 
540  // Batch 0, Channel 1, Height (3) x Width (2)
541  3.f, 3.f,
542  4.f, 3.f,
543  2.f, 4.f
544  };
545 
546  return BatchNormTestImpl<armnn::DataType::QSymmS16>(
547  workloadFactory,
548  memoryManager,
549  tensorHandleFactory,
550  inputOutputShape,
551  inputValues,
552  expectedOutputValues,
553  1.f / 20.f,
554  50,
556 }
557 
559  armnn::IWorkloadFactory& workloadFactory,
561  const armnn::ITensorHandleFactory& tensorHandleFactory)
562 {
563  // BatchSize: 1
564  // Height: 3
565  // Width: 2
566  // Channels: 2
567 
568  const armnn::TensorShape inputOutputShape{ 1, 3, 2, 2 };
569  std::vector<float> inputValues
570  {
571  // Batch 0, Height 0, Width (2) x Channel (2)
572  1.f, 1.f,
573  4.f, 1.f,
574 
575  // Batch 0, Height 1, Width (2) x Channel (2)
576  4.f, 4.f,
577  2.f, 1.f,
578 
579  // Batch 0, Height 2, Width (2) x Channel (2)
580  1.f, -2.f,
581  6.f, 4.f
582  };
583  std::vector<float> expectedOutputValues
584  {
585  // Batch 0, Height 0, Width (2) x Channel (2)
586  1.f, 3.f,
587  4.f, 3.f,
588 
589  // Batch 0, Height 1, Width (2) x Channel (2)
590  4.f, 4.f,
591  2.f, 3.f,
592 
593  // Batch 0, Height 2, Width (2) x Channel (2)
594  1.f, 2.f,
595  6.f, 4.f
596  };
597 
598  return BatchNormTestImpl<armnn::DataType::QSymmS16>(
599  workloadFactory,
600  memoryManager,
601  tensorHandleFactory,
602  inputOutputShape,
603  inputValues,
604  expectedOutputValues,
605  1.f / 20.f,
606  50,
608 }
609 
611  armnn::IWorkloadFactory& workloadFactory,
613  armnn::IWorkloadFactory& refWorkloadFactory,
614  const armnn::ITensorHandleFactory& tensorHandleFactory,
615  const armnn::ITensorHandleFactory& refTensorHandleFactory)
616 {
617  IgnoreUnused(memoryManager);
618  const unsigned int width = 2;
619  const unsigned int height = 3;
620  const unsigned int channels = 5;
621  const unsigned int batchSize = 3;
622 
623  armnn::TensorInfo inputTensorInfo;
624  armnn::TensorInfo outputTensorInfo;
625  armnn::TensorInfo tensorInfo;
626 
627  constexpr unsigned int shape[] = {batchSize, channels, height, width};
628  constexpr unsigned int tensorShape[] = {channels};
629 
630  inputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
631  outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
632  tensorInfo = armnn::TensorInfo(1, tensorShape, armnn::DataType::Float32);
633 
634  auto input = MakeRandomTensor<float>(inputTensorInfo, 21312);
635 
636  auto mean = MakeRandomTensor<float>(tensorInfo, 123);
637  auto variance = MakeRandomTensor<float>(tensorInfo, 234, 0.0f);
638  auto beta = MakeRandomTensor<float>(tensorInfo, 123);
639  auto gamma = MakeRandomTensor<float>(tensorInfo, 345);
640 
641  std::vector<float> actualOutput(outputTensorInfo.GetNumElements());
642  std::vector<float> expectedOutput(outputTensorInfo.GetNumElements());
643 
644  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
645  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
646 
647  std::unique_ptr<armnn::ITensorHandle> inputHandleRef = refTensorHandleFactory.CreateTensorHandle(inputTensorInfo);
648  std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refTensorHandleFactory.CreateTensorHandle(outputTensorInfo);
649 
651  armnn::WorkloadInfo info;
652  armnn::ScopedTensorHandle meanTensor(tensorInfo);
653  armnn::ScopedTensorHandle varianceTensor(tensorInfo);
654  armnn::ScopedTensorHandle betaTensor(tensorInfo);
655  armnn::ScopedTensorHandle gammaTensor(tensorInfo);
656 
657  AllocateAndCopyDataToITensorHandle(&meanTensor, &mean[0]);
658  AllocateAndCopyDataToITensorHandle(&varianceTensor, &variance[0]);
659  AllocateAndCopyDataToITensorHandle(&betaTensor, &beta[0]);
660  AllocateAndCopyDataToITensorHandle(&gammaTensor, &gamma[0]);
661 
662  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
663  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
664  data.m_Mean = &meanTensor;
665  data.m_Variance = &varianceTensor;
666  data.m_Beta = &betaTensor;
667  data.m_Gamma = &gammaTensor;
668  data.m_Parameters.m_Eps = 0.01f;
669 
671  armnn::WorkloadInfo refInfo = info;
672  SetWorkloadInput(refData, refInfo, 0, inputTensorInfo, inputHandleRef.get());
673  SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
674 
675  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchNormalization(data, info);
676  std::unique_ptr<armnn::IWorkload> workloadRef = refWorkloadFactory.CreateBatchNormalization(refData, refInfo);
677 
678  inputHandle->Allocate();
679  outputHandle->Allocate();
680  inputHandleRef->Allocate();
681  outputHandleRef->Allocate();
682 
683  CopyDataToITensorHandle(inputHandle.get(), input.data());
684  CopyDataToITensorHandle(inputHandleRef.get(), input.data());
685 
686  workload->PostAllocationConfigure();
687  workload->Execute();
688  workloadRef->PostAllocationConfigure();
689  workloadRef->Execute();
690 
691  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
692  CopyDataFromITensorHandle(expectedOutput.data(), outputHandleRef.get());
693 
694  return LayerTestResult<float, 4>(actualOutput,
695  expectedOutput,
696  outputHandle->GetShape(),
697  outputTensorInfo.GetShape());
698 }
virtual std::unique_ptr< IWorkload > CreateBatchNormalization(const BatchNormalizationQueueDescriptor &descriptor, const WorkloadInfo &info) const
LayerTestResult< float, 4 > CompareBatchNormTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory, const armnn::ITensorHandleFactory &tensorHandleFactory, const armnn::ITensorHandleFactory &refTensorHandleFactory)
DataLayout
Definition: Types.hpp:49
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
LayerTestResult< uint8_t, 4 > BatchNormUint8Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
LayerTestResult< uint8_t, 4 > BatchNormUint8NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
LayerTestResult< int16_t, 4 > BatchNormInt16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
const ConstTensorHandle * m_Variance
float m_Eps
Value to add to the variance. Used to avoid dividing by zero.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
void IgnoreUnused(Ts &&...)
LayerTestResult< int16_t, 4 > BatchNormInt16NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
LayerTestResult< float, 4 > BatchNormFloat32NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:475
void AllocateAndCopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
LayerTestResult< float, 4 > BatchNormFloat32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
LayerTestResult< armnn::Half, 4 > BatchNormFloat16NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
LayerTestResult< armnn::Half, 4 > BatchNormFloat16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
Contains information about TensorInfos of a layer.
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const =0
unsigned int GetNumElements() const
Definition: Tensor.hpp:196
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)