29 template<armnn::DataType ArmnnType,
typename T = armnn::ResolveType<ArmnnType>>
35 const std::vector<float>& inputValues,
36 const std::vector<float>& expectedOutputValues,
47 armnn::TensorInfo tensorInfo({ inputOutputTensorShape[dataLayoutIndexed.GetChannelsIndex()] },
51 if (armnn::IsQuantizedType<T>())
54 inputTensorInfo.SetQuantizationOffset(qOffset);
55 outputTensorInfo.SetQuantizationScale(qScale);
56 outputTensorInfo.SetQuantizationOffset(qOffset);
57 tensorInfo.SetQuantizationScale(qScale);
58 tensorInfo.SetQuantizationOffset(qOffset);
61 auto inputTensor = QuantizedVector<T>(inputValues, qScale, qOffset);
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);
69 std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
70 std::vector<T> expectedOutput = QuantizedVector<T>(expectedOutputValues, qScale, qOffset);
72 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
73 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.
CreateTensorHandle(outputTensorInfo);
81 descriptor.
m_Mean = &meanTensor;
83 descriptor.
m_Beta = &betaTensor;
84 descriptor.
m_Gamma = &gammaTensor;
94 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
95 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
97 std::unique_ptr<armnn::IWorkload> workload
100 inputHandle->Allocate();
101 outputHandle->Allocate();
111 outputHandle->GetShape(),
112 outputTensorInfo.GetShape());
115 template<armnn::DataType ArmnnType,
typename T = armnn::ResolveType<ArmnnType>>
125 const unsigned int width = 2;
126 const unsigned int height = 3;
127 const unsigned int channels = 2;
128 const unsigned int num = 1;
135 if(armnn::IsQuantizedType<T>())
138 inputTensorInfo.SetQuantizationOffset(qOffset);
139 outputTensorInfo.SetQuantizationScale(qScale);
140 outputTensorInfo.SetQuantizationOffset(qOffset);
141 tensorInfo.SetQuantizationScale(qScale);
142 tensorInfo.SetQuantizationOffset(qOffset);
145 auto input = QuantizedVector<T>(
154 auto mean = QuantizedVector<T>({ 3, -2 }, qScale, qOffset);
155 auto variance = QuantizedVector<T>({ 4, 9 }, qScale, qOffset);
156 auto beta = QuantizedVector<T>({ 3, 2 }, qScale, qOffset);
157 auto gamma = QuantizedVector<T>({ 2, 1 }, qScale, qOffset);
159 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
160 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.
CreateTensorHandle(outputTensorInfo);
174 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
175 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
176 data.
m_Mean = &meanTensor;
178 data.
m_Beta = &betaTensor;
183 std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
188 std::vector<T> expectedOutput = QuantizedVector<T>(
196 std::unique_ptr<armnn::IWorkload> workload
199 inputHandle->Allocate();
200 outputHandle->Allocate();
210 outputHandle->GetShape(),
211 outputTensorInfo.GetShape());
227 std::vector<float> inputValues
239 std::vector<float> expectedOutputValues
252 return BatchNormTestImpl<armnn::DataType::Float32>(
258 expectedOutputValues,
275 std::vector<float> inputValues
289 std::vector<float> expectedOutputValues
304 return BatchNormTestImpl<armnn::DataType::Float32>(
310 expectedOutputValues,
327 std::vector<float> inputValues
339 std::vector<float> expectedOutputValues
352 return BatchNormTestImpl<armnn::DataType::Float16>(
358 expectedOutputValues,
375 std::vector<float> inputValues
389 std::vector<float> expectedOutputValues
404 return BatchNormTestImpl<armnn::DataType::Float16>(
410 expectedOutputValues,
427 std::vector<float> inputValues
439 std::vector<float> expectedOutputValues
452 return BatchNormTestImpl<armnn::DataType::QAsymmU8>(
458 expectedOutputValues,
475 std::vector<float> inputValues
489 std::vector<float> expectedOutputValues
504 return BatchNormTestImpl<armnn::DataType::QAsymmU8>(
508 inputOutputShape, inputValues, expectedOutputValues,
523 std::vector<float> inputValues
535 std::vector<float> expectedOutputValues
548 return BatchNormTestImpl<armnn::DataType::QSymmS16>(
554 expectedOutputValues,
571 std::vector<float> inputValues
585 std::vector<float> expectedOutputValues
600 return BatchNormTestImpl<armnn::DataType::QSymmS16>(
606 expectedOutputValues,
620 const unsigned int width = 2;
621 const unsigned int height = 3;
622 const unsigned int channels = 5;
623 const unsigned int batchSize = 3;
629 constexpr
unsigned int shape[] = {batchSize, channels, height, width};
630 constexpr
unsigned int tensorShape[] = {channels};
636 auto input = MakeRandomTensor<float>(inputTensorInfo, 21312);
638 auto mean = MakeRandomTensor<float>(tensorInfo, 123);
639 auto variance = MakeRandomTensor<float>(tensorInfo, 234, 0.0f);
640 auto beta = MakeRandomTensor<float>(tensorInfo, 123);
641 auto gamma = MakeRandomTensor<float>(tensorInfo, 345);
643 std::vector<float> actualOutput(outputTensorInfo.
GetNumElements());
644 std::vector<float> expectedOutput(outputTensorInfo.
GetNumElements());
646 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
647 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.
CreateTensorHandle(outputTensorInfo);
649 std::unique_ptr<armnn::ITensorHandle> inputHandleRef = refTensorHandleFactory.
CreateTensorHandle(inputTensorInfo);
650 std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refTensorHandleFactory.
CreateTensorHandle(outputTensorInfo);
664 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
665 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
666 data.
m_Mean = &meanTensor;
668 data.
m_Beta = &betaTensor;
674 SetWorkloadInput(refData, refInfo, 0, inputTensorInfo, inputHandleRef.get());
675 SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
677 std::unique_ptr<armnn::IWorkload> workload
679 std::unique_ptr<armnn::IWorkload> workloadRef
682 inputHandle->Allocate();
683 outputHandle->Allocate();
684 inputHandleRef->Allocate();
685 outputHandleRef->Allocate();
690 workload->PostAllocationConfigure();
692 workloadRef->PostAllocationConfigure();
693 workloadRef->Execute();
700 outputHandle->GetShape(),
LayerTestResult< float, 4 > CompareBatchNormTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory, const armnn::ITensorHandleFactory &tensorHandleFactory, const armnn::ITensorHandleFactory &refTensorHandleFactory)
const TensorShape & GetShape() const
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 &&...)
LayerDescriptor m_Parameters
void AllocateAndCopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
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 CopyDataFromITensorHandle(void *mem, const armnn::ITensorHandle *tensorHandle)
void SetQuantizationScale(float scale)
LayerTestResult< float, 4 > BatchNormFloat32Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
LayerTestResult< armnn::Half, 4 > BatchNormFloat16NhwcTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
const ConstTensorHandle * m_Gamma
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
LayerTestResult< armnn::Half, 4 > BatchNormFloat16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
Contains information about TensorInfos of a layer.
const ConstTensorHandle * m_Mean
virtual std::unique_ptr< IWorkload > CreateWorkload(LayerType type, const QueueDescriptor &descriptor, const WorkloadInfo &info) const
const ConstTensorHandle * m_Beta
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const =0
unsigned int GetNumElements() const