ArmNN
 20.08
ActivationTestImpl.cpp File Reference
#include "ActivationTestImpl.hpp"
#include <QuantizeHelper.hpp>
#include <ResolveType.hpp>
#include <backendsCommon/test/ActivationFixture.hpp>
#include <backendsCommon/test/TensorCopyUtils.hpp>
#include <backendsCommon/test/WorkloadTestUtils.hpp>
#include <test/TensorHelpers.hpp>
#include <boost/multi_array.hpp>
#include <algorithm>

Go to the source code of this file.

Functions

template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > BoundedReLuTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float upperBound, float lowerBound, float inputScale, int32_t inputOffset, float outputScale, int32_t outputOffset, const std::vector< T > &inputData, const std::vector< T > &outputExpectedData, unsigned int inputWidth, unsigned int inputHeight, unsigned int inputChannels, unsigned int inputBatchSize)
 
LayerTestResult< float, 4 > BoundedReLuUpperAndLowerBoundTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< float, 4 > BoundedReLuUpperBoundOnlyTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > BoundedReLuUint8UpperBoundOnlyTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > BoundedReLuUint8UpperAndLowerBoundTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< float, 4 > CompareBoundedReLuTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory, float upperBound, float lowerBound)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > ConstantLinearActivationTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale=0.0f, int32_t qOffset=0)
 
LayerTestResult< float, 4 > ConstantLinearActivationTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > ConstantLinearActivationUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< int16_t, 4 > ConstantLinearActivationInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > SimpleActivationTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::ActivationFunction activationFunction, float activationParameterA, float activationParameterB, float scale, int32_t offset, const std::vector< float > &inputData, float outScale, int32_t outOffset, const std::vector< float > &outputExpectedData)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > SimpleSigmoidTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< float, 4 > SimpleSigmoidTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > SimpleSigmoidUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< int16_t, 4 > SimpleSigmoidInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > ReLuTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< int16_t, 4 > ReLuInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > ReLuUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< float, 4 > ReLuTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > BoundedReLuTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< int16_t, 4 > BoundedReLuInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > SoftReLuTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< float, 4 > SoftReLuTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > SoftReLuUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< int16_t, 4 > SoftReLuInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > LeakyReLuTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< float, 4 > LeakyReLuTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > LeakyReLuUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< int16_t, 4 > LeakyReLuInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > AbsTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< float, 4 > AbsTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > AbsUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< int16_t, 4 > AbsInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< float, 5 > SqrtNNTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > SqrtTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< float, 4 > SqrtTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > SqrtUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< int16_t, 4 > SqrtInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > SquareTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< float, 4 > SquareTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > SquareUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< int16_t, 4 > SquareInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > TanhTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< float, 4 > TanhTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > TanhUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< int16_t, 4 > TanhInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > EluTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< float, 4 > EluTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > EluUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< int16_t, 4 > EluInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > HardSwishTestCommon (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, float qScale, int32_t qOffset)
 
LayerTestResult< float, 4 > HardSwishTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< uint8_t, 4 > HardSwishUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
LayerTestResult< int16_t, 4 > HardSwishInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > CompareActivationTestImpl (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory, armnn::ActivationFunction f, unsigned int batchSize=5, float qScale=0.0f, int32_t qOffset=0)
 
LayerTestResult< float, 4 > CompareActivationTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory, armnn::ActivationFunction f, unsigned int batchSize)
 
LayerTestResult< uint8_t, 4 > CompareActivationUint8Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory, armnn::ActivationFunction f)
 
LayerTestResult< int16_t, 4 > CompareActivationInt16Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory, armnn::ActivationFunction f)
 

Function Documentation

◆ AbsInt16Test()

LayerTestResult<int16_t, 4> AbsInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 792 of file ActivationTestImpl.cpp.

795 {
796  return AbsTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
797 }

◆ AbsTest()

LayerTestResult<float, 4> AbsTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 778 of file ActivationTestImpl.cpp.

781 {
782  return AbsTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.1f, 0);
783 }

◆ AbsTestCommon()

LayerTestResult<T, 4> AbsTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 744 of file ActivationTestImpl.cpp.

References armnn::Abs.

749 {
750  std::vector<float> inputData = {
751  -0.1f, -0.2f, -0.3f, -0.4f,
752  0.1f, 0.2f, 0.3f, 0.4f,
753  -1.0f, -2.0f, -3.0f, -4.0f,
754  1.0f, 2.0f, 3.0f, 4.0f
755  };
756 
757  // Calculate output values for input.
758  auto f = [](float value)
759  {
760  return std::abs(value);
761  };
762  std::vector<float> outputExpectedData(inputData.size());
763  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
764 
765  return SimpleActivationTest<ArmnnType>(workloadFactory,
766  memoryManager,
768  0.f,
769  0.f,
770  qScale,
771  qOffset,
772  inputData,
773  qScale,
774  qOffset,
775  outputExpectedData);
776 }

◆ AbsUint8Test()

LayerTestResult<uint8_t, 4> AbsUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 785 of file ActivationTestImpl.cpp.

788 {
789  return AbsTestCommon<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, 0.0625f, 64);
790 }

◆ BoundedReLuInt16Test()

LayerTestResult<int16_t, 4> BoundedReLuInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 621 of file ActivationTestImpl.cpp.

624 {
625  return ReLuTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
626 }

◆ BoundedReLuTestCommon() [1/2]

LayerTestResult<T, 4> BoundedReLuTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  upperBound,
float  lowerBound,
float  inputScale,
int32_t  inputOffset,
float  outputScale,
int32_t  outputOffset,
const std::vector< T > &  inputData,
const std::vector< T > &  outputExpectedData,
unsigned int  inputWidth,
unsigned int  inputHeight,
unsigned int  inputChannels,
unsigned int  inputBatchSize 
)

Definition at line 23 of file ActivationTestImpl.cpp.

References ARMNN_NO_DEPRECATE_WARN_BEGIN, ARMNN_NO_DEPRECATE_WARN_END, armnn::BoundedReLu, CopyDataFromITensorHandle(), CopyDataToITensorHandle(), IWorkloadFactory::CreateActivation(), IWorkloadFactory::CreateTensorHandle(), armnn::IgnoreUnused(), LayerTestResult< T, n >::output, LayerTestResult< T, n >::outputExpected, and TensorInfo::SetQuantizationScale().

38 {
39  IgnoreUnused(memoryManager);
40  unsigned int outputWidth = inputWidth;
41  unsigned int outputHeight = inputHeight;
42  unsigned int outputChannels = inputChannels;
43  unsigned int outputBatchSize = inputBatchSize;
44 
45  armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth }, ArmnnType);
46 
47  armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth }, ArmnnType);
48 
49  if(armnn::IsQuantizedType<T>())
50  {
51  inputTensorInfo.SetQuantizationScale(inputScale);
52  inputTensorInfo.SetQuantizationOffset(inputOffset);
53 
54  outputTensorInfo.SetQuantizationScale(outputScale);
55  outputTensorInfo.SetQuantizationOffset(outputOffset);
56  }
57 
58  LayerTestResult<T, 4> result(inputTensorInfo);
59 
60  auto input = MakeTensor<T, 4>(inputTensorInfo, inputData);
61 
63  std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
64  std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
66 
67  // Setup bounded ReLu.
69  armnn::WorkloadInfo workloadInfo;
70  AddInputToWorkload(descriptor, workloadInfo, inputTensorInfo, inputHandle.get());
71  AddOutputToWorkload(descriptor, workloadInfo, outputTensorInfo, outputHandle.get());
72 
73  descriptor.m_Parameters.m_Function = armnn::ActivationFunction::BoundedReLu;
74  descriptor.m_Parameters.m_A = upperBound;
75  descriptor.m_Parameters.m_B = lowerBound;
76 
77  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateActivation(descriptor, workloadInfo);
78 
79  inputHandle->Allocate();
80  outputHandle->Allocate();
81 
82  CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
83 
84  workload->Execute();
85 
86  CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
87 
88  result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, outputExpectedData);
89 
90  return result;
91 }
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
Definition: Deprecated.hpp:33
void IgnoreUnused(Ts &&...)
virtual std::unique_ptr< IWorkload > CreateActivation(const ActivationQueueDescriptor &descriptor, const WorkloadInfo &info) const
#define ARMNN_NO_DEPRECATE_WARN_END
Definition: Deprecated.hpp:34
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:465
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
min(a, max(b, input)) ReLu1 & ReLu6.
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, const bool IsMemoryManaged=true) const =0
Contains information about inputs and outputs to a layer.
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)

◆ BoundedReLuTestCommon() [2/2]

LayerTestResult<T, 4> BoundedReLuTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 586 of file ActivationTestImpl.cpp.

References armnn::BoundedReLu.

591 {
592  std::vector<float> inputData = {
593  -0.1f, -0.2f, -0.3f, -0.4f,
594  0.1f, 0.2f, 0.3f, 0.4f,
595  -1.0f, -2.0f, -3.0f, -4.0f,
596  1.0f, 2.0f, 3.0f, 4.0f
597  };
598  const float a = 1.0f;
599  const float b = -1.0f;
600  // Calculate output values for input.
601  auto f = [a, b](float value)
602  {
603  return std::min(a, std::max(b, value));
604  };
605  std::vector<float> outputExpectedData(inputData.size());
606  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
607 
608  return SimpleActivationTest<ArmnnType>(workloadFactory,
609  memoryManager,
611  a,
612  b,
613  qScale,
614  qOffset,
615  inputData,
616  qScale,
617  qOffset,
618  outputExpectedData);
619 }
min(a, max(b, input)) ReLu1 & ReLu6.

◆ BoundedReLuUint8UpperAndLowerBoundTest()

LayerTestResult<uint8_t, 4> BoundedReLuUint8UpperAndLowerBoundTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 186 of file ActivationTestImpl.cpp.

References ARMNN_NO_DEPRECATE_WARN_BEGIN, ARMNN_NO_DEPRECATE_WARN_END, CopyDataFromITensorHandle(), CopyDataToITensorHandle(), IWorkloadFactory::CreateActivation(), IWorkloadFactory::CreateTensorHandle(), armnn::Float32, armnn::GetInputTensorInfo(), and armnn::IgnoreUnused().

189 {
190  unsigned int inputWidth = 3u;
191  unsigned int inputHeight = 2u;
192  unsigned int inputChannels = 1u;
193  unsigned int inputBatchSize = 1;
194 
195  std::vector<uint8_t> input = std::vector<uint8_t>{
196  51, 230, 28,
197  251, 8, 92
198  };
199 
200  // Calculated manually.
201  std::vector<uint8_t> output = std::vector<uint8_t>{
202  51, 192, 32,
203  192, 32, 92
204  };
205 
206  int32_t inputOffset = 112;
207  float inputScale = 0.0125f;
208 
209  return BoundedReLuTestCommon<armnn::DataType::QAsymmU8>(
210  workloadFactory, memoryManager, 1.0f, -1.0f,
211  inputScale, inputOffset, inputScale, inputOffset, // Input/output scale & offset same.
212  input, output, inputWidth, inputHeight, inputChannels, inputBatchSize);
213 }

◆ BoundedReLuUint8UpperBoundOnlyTest()

LayerTestResult<uint8_t, 4> BoundedReLuUint8UpperBoundOnlyTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 155 of file ActivationTestImpl.cpp.

158 {
159  unsigned int inputWidth = 3u;
160  unsigned int inputHeight = 2u;
161  unsigned int inputChannels = 1u;
162  unsigned int inputBatchSize = 1;
163 
164  std::vector<uint8_t> input = std::vector<uint8_t>{
165  51, 124, 28,
166  251, 8, 92
167  };
168 
169  // Calculated manually.
170  std::vector<uint8_t> output = std::vector<uint8_t>{
171  0, 122, 0,
172  255, 0, 58
173  };
174 
175  float inputScale = 12.0f / 255.0f;
176  int32_t inputOffset = 63;
177  float outputScale = 6.0f / 255.0f;
178  int32_t outputOffset = 0;
179 
180  return BoundedReLuTestCommon<armnn::DataType::QAsymmU8>(
181  workloadFactory, memoryManager, 6.0f, 0.0f,
182  inputScale, inputOffset, outputScale, outputOffset,
183  input, output, inputWidth, inputHeight, inputChannels, inputBatchSize);
184 }

◆ BoundedReLuUpperAndLowerBoundTest()

LayerTestResult<float, 4> BoundedReLuUpperAndLowerBoundTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 93 of file ActivationTestImpl.cpp.

96 {
97  unsigned int inputWidth = 4u;
98  unsigned int inputHeight = 5u;
99  unsigned int inputChannels = 1u;
100  unsigned int inputBatchSize = 1;
101 
102  std::vector<float> input = std::vector<float>{
103  -2.0f, 0.1f, 0.5f, 1.25f,
104  0.786f, 0.9875f, -1.5f, 0.384f,
105  1.0001f, 3.5f, 7.5f, 0.896f,
106  2.126f, 2.0f, 0.3f, 0.15f,
107  0.999f, 1.2f, 0.89f, 6.1f,
108  };
109 
110  // Calculated manually.
111  std::vector<float> output = std::vector<float>{
112  -1.0f, 0.1f, 0.5f, 1.0f,
113  0.786f, 0.9875f, -1.0f, 0.384f,
114  1.0f, 1.0f, 1.0f, 0.896f,
115  1.0f, 1.0f, 0.3f, 0.15f,
116  0.999f, 1.0f, 0.89f, 1.0f,
117  };
118 
119  return BoundedReLuTestCommon<armnn::DataType::Float32>(
120  workloadFactory, memoryManager, 1.0f, -1.0f, 1.0f, 0, 1.0f, 0, input, output,
121  inputWidth, inputHeight, inputChannels, inputBatchSize);
122 }

◆ BoundedReLuUpperBoundOnlyTest()

LayerTestResult<float, 4> BoundedReLuUpperBoundOnlyTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 124 of file ActivationTestImpl.cpp.

127 {
128  unsigned int inputWidth = 4u;
129  unsigned int inputHeight = 5u;
130  unsigned int inputChannels = 1u;
131  unsigned int inputBatchSize = 1;
132 
133  std::vector<float> input = std::vector<float>{
134  -1.0f, 0.1f, 0.5f, 6.25f,
135  0.786f, 5.9875f, -0.5f, 0.384f,
136  6.0001f, 3.5f, 7.5f, 0.896f,
137  2.126f, 12.0f, 0.3f, 0.15f,
138  0.999f, 1.2f, 0.89f, 6.1f,
139  };
140 
141  // Calculated manually.
142  std::vector<float> output = std::vector<float>{
143  0.0f, 0.1f, 0.5f, 6.0f,
144  0.786f, 5.9875f, 0.0f, 0.384f,
145  6.0f, 3.5f, 6.0f, 0.896f,
146  2.126f, 6.0f, 0.3f, 0.15f,
147  0.999f, 1.2f, 0.89f, 6.0f,
148  };
149 
150  return BoundedReLuTestCommon<armnn::DataType::Float32>(
151  workloadFactory, memoryManager, 6.0f, 0.0f, 1.0f, 0, 1.0f, 0, input, output,
152  inputWidth, inputHeight, inputChannels, inputBatchSize);
153 }

◆ CompareActivationInt16Test()

LayerTestResult<int16_t,4> CompareActivationInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
armnn::IWorkloadFactory refWorkloadFactory,
armnn::ActivationFunction  f 
)

Definition at line 1267 of file ActivationTestImpl.cpp.

1272 {
1273  return CompareActivationTestImpl<armnn::DataType::QSymmS16>(
1274  workloadFactory, memoryManager, refWorkloadFactory, f, 5, 0.1f, 0);
1275 }

◆ CompareActivationTest()

LayerTestResult<float,4> CompareActivationTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
armnn::IWorkloadFactory refWorkloadFactory,
armnn::ActivationFunction  f,
unsigned int  batchSize 
)

Definition at line 1246 of file ActivationTestImpl.cpp.

1252 {
1253  return CompareActivationTestImpl<armnn::DataType::Float32>(
1254  workloadFactory, memoryManager, refWorkloadFactory, f, batchSize);
1255 }

◆ CompareActivationTestImpl()

LayerTestResult<T,4> CompareActivationTestImpl ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
armnn::IWorkloadFactory refWorkloadFactory,
armnn::ActivationFunction  f,
unsigned int  batchSize = 5,
float  qScale = 0.0f,
int32_t  qOffset = 0 
)

Definition at line 1151 of file ActivationTestImpl.cpp.

References ARMNN_ASSERT, ARMNN_NO_DEPRECATE_WARN_BEGIN, ARMNN_NO_DEPRECATE_WARN_END, CopyDataFromITensorHandle(), CopyDataToITensorHandle(), IWorkloadFactory::CreateActivation(), IWorkloadFactory::CreateTensorHandle(), armnn::IgnoreUnused(), armnn::numeric_cast(), TensorInfo::SetQuantizationOffset(), TensorInfo::SetQuantizationScale(), and armnn::Sqrt.

1159 {
1160  IgnoreUnused(memoryManager);
1161  unsigned int width = 17;
1162  unsigned int height = 29;
1163  unsigned int channels = 2;
1164 
1165  float a = 0.234f;
1166  float b = -12.345f;
1167 
1168  armnn::TensorInfo inputTensorInfo;
1169  armnn::TensorInfo outputTensorInfo;
1170 
1171  unsigned int shape[] = {batchSize, channels, height, width};
1172 
1173  inputTensorInfo = armnn::TensorInfo(4, shape, ArmnnType);
1174  outputTensorInfo = armnn::TensorInfo(4, shape, ArmnnType);
1175 
1176  // Set quantization parameters if the requested type is a quantized type.
1177  if(armnn::IsQuantizedType<T>())
1178  {
1179  inputTensorInfo.SetQuantizationScale(qScale);
1180  inputTensorInfo.SetQuantizationOffset(qOffset);
1181  outputTensorInfo.SetQuantizationScale(qScale);
1182  outputTensorInfo.SetQuantizationOffset(qOffset);
1183  }
1184 
1185  float minVal = -10.f;
1187  {
1188  minVal = 0.f;
1189  }
1190 
1191  boost::multi_array<T, 4> input = MakeRandomTensor<T, 4>(inputTensorInfo, 21453, minVal, 10.f);
1192 
1193 
1194  LayerTestResult<T,4> ret(outputTensorInfo);
1195  auto boostArrayExtents = boost::extents
1196  [boost::numeric_cast<boost::multi_array_types::extent_gen::index>(batchSize)]
1197  [boost::numeric_cast<boost::multi_array_types::extent_gen::index>(channels)]
1198  [boost::numeric_cast<boost::multi_array_types::extent_gen::index>(height)]
1199  [boost::numeric_cast<boost::multi_array_types::extent_gen::index>(width)];
1200  ret.output.resize(boostArrayExtents);
1201  ret.outputExpected.resize(boostArrayExtents);
1202 
1204  std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
1205  std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1206 
1207  std::unique_ptr<armnn::ITensorHandle> inputHandleRef = refWorkloadFactory.CreateTensorHandle(inputTensorInfo);
1208  std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refWorkloadFactory.CreateTensorHandle(outputTensorInfo);
1210 
1213  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
1214  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1215  data.m_Parameters.m_A = a;
1216  data.m_Parameters.m_B = b;
1217  data.m_Parameters.m_Function = f;
1218 
1219  armnn::ActivationQueueDescriptor refData = data;
1220  armnn::WorkloadInfo refInfo = info;
1221  SetWorkloadInput(refData, refInfo, 0, inputTensorInfo, inputHandleRef.get());
1222  SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
1223 
1224  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateActivation(data, info);
1225  ARMNN_ASSERT(workload != nullptr);
1226  std::unique_ptr<armnn::IWorkload> workloadRef = refWorkloadFactory.CreateActivation(refData, refInfo);
1227  ARMNN_ASSERT(workloadRef != nullptr);
1228 
1229  inputHandle->Allocate();
1230  outputHandle->Allocate();
1231  inputHandleRef->Allocate();
1232  outputHandleRef->Allocate();
1233 
1234  CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
1235  CopyDataToITensorHandle(inputHandleRef.get(), &input[0][0][0][0]);
1236 
1237  workload->Execute();
1238  workloadRef->Execute();
1239 
1240  CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1241  CopyDataFromITensorHandle(&ret.outputExpected[0][0][0][0], outputHandleRef.get());
1242 
1243  return ret;
1244 }
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
Definition: Deprecated.hpp:33
void IgnoreUnused(Ts &&...)
virtual std::unique_ptr< IWorkload > CreateActivation(const ActivationQueueDescriptor &descriptor, const WorkloadInfo &info) const
#define ARMNN_NO_DEPRECATE_WARN_END
Definition: Deprecated.hpp:34
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:465
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, const bool IsMemoryManaged=true) const =0
Contains information about inputs and outputs to a layer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:481
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)

◆ CompareActivationUint8Test()

LayerTestResult<uint8_t,4> CompareActivationUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
armnn::IWorkloadFactory refWorkloadFactory,
armnn::ActivationFunction  f 
)

Definition at line 1257 of file ActivationTestImpl.cpp.

1262 {
1263  return CompareActivationTestImpl<armnn::DataType::QAsymmU8>(
1264  workloadFactory, memoryManager, refWorkloadFactory, f, 5, 0.1f, 50);
1265 }

◆ CompareBoundedReLuTest()

LayerTestResult<float, 4> CompareBoundedReLuTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
armnn::IWorkloadFactory refWorkloadFactory,
float  upperBound,
float  lowerBound 
)

Definition at line 288 of file ActivationTestImpl.cpp.

References armnn::BoundedReLu, ActivationDescriptor::m_A, ActivationDescriptor::m_B, ActivationDescriptor::m_Function, LayerTestResult< T, n >::output, and LayerTestResult< T, n >::outputExpected.

294 {
295  LayerTestResult<float, 4> result(BoundedReLuRandomInputTestTraits::GetOutputTensorInfo());
296 
297  armnn::ActivationDescriptor activationDescriptor;
298  activationDescriptor.m_Function = armnn::ActivationFunction::BoundedReLu;
299  activationDescriptor.m_A = upperBound;
300  activationDescriptor.m_B = lowerBound;
301 
302  result.output = BoundedReLuRandomInputTest(
303  workloadFactory, memoryManager, 0.0f, upperBound, activationDescriptor);
304  result.outputExpected = BoundedReLuRandomInputTest(
305  refWorkloadFactory, nullptr, 0.0f, upperBound, activationDescriptor);
306 
307  return result;
308 }
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:20
min(a, max(b, input)) ReLu1 & ReLu6.
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH, Elu).
Definition: Descriptors.hpp:45
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
Definition: Descriptors.hpp:47
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
Definition: Descriptors.hpp:43

◆ ConstantLinearActivationInt16Test()

LayerTestResult<int16_t, 4> ConstantLinearActivationInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 388 of file ActivationTestImpl.cpp.

391 {
392  return ConstantLinearActivationTestCommon<armnn::DataType::QSymmS16>(
393  workloadFactory, memoryManager, 0.1f, 0);
394 }

◆ ConstantLinearActivationTest()

LayerTestResult<float, 4> ConstantLinearActivationTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 373 of file ActivationTestImpl.cpp.

376 {
377  return ConstantLinearActivationTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager);
378 }

◆ ConstantLinearActivationTestCommon()

LayerTestResult<T,4> ConstantLinearActivationTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale = 0.0f,
int32_t  qOffset = 0 
)

Definition at line 311 of file ActivationTestImpl.cpp.

References ARMNN_NO_DEPRECATE_WARN_BEGIN, ARMNN_NO_DEPRECATE_WARN_END, CopyDataFromITensorHandle(), CopyDataToITensorHandle(), IWorkloadFactory::CreateActivation(), IWorkloadFactory::CreateTensorHandle(), armnn::IgnoreUnused(), armnn::Linear, LayerTestResult< T, n >::output, LayerTestResult< T, n >::outputExpected, TensorInfo::SetQuantizationOffset(), and TensorInfo::SetQuantizationScale().

316 {
317  IgnoreUnused(memoryManager);
318  unsigned int inputHeight = 20;
319  unsigned int inputWidth = 17;
320  unsigned int inputChannels = 3;
321  unsigned int batchSize = 5;
322 
323  armnn::TensorInfo inputTensorInfo;
324  armnn::TensorInfo outputTensorInfo;
325 
326  unsigned int shape[] = {batchSize, inputChannels, inputHeight, inputWidth};
327 
328  inputTensorInfo = armnn::TensorInfo(4, shape, ArmnnType);
329  outputTensorInfo = armnn::TensorInfo(4, shape, ArmnnType);
330 
331  // Set quantization parameters if the requested type is a quantized type.
332  if(armnn::IsQuantizedType<T>())
333  {
334  inputTensorInfo.SetQuantizationScale(qScale);
335  inputTensorInfo.SetQuantizationOffset(qOffset);
336  outputTensorInfo.SetQuantizationScale(qScale);
337  outputTensorInfo.SetQuantizationOffset(qOffset);
338  }
339 
340  LayerTestResult<T, 4> ret(outputTensorInfo);
342  std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
343  std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
345 
346  // Do linear activation that should leave the tensor unchanged.
349  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
350  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
351  data.m_Parameters.m_A = 1.0f;
352  data.m_Parameters.m_B = 0.0f;
353  data.m_Parameters.m_Function = armnn::ActivationFunction::Linear;
354 
355  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateActivation(data, info);
356 
357  inputHandle->Allocate();
358  outputHandle->Allocate();
359 
360  boost::multi_array<T, 4> input = MakeRandomTensor<T, 4>(inputTensorInfo, 7123561);
361  CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
362 
363  workload->Execute();
364 
365  CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
366 
367  // Ensure output equals input.
368  ret.outputExpected = input;
369 
370  return ret;
371 }
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
Definition: Deprecated.hpp:33
void IgnoreUnused(Ts &&...)
virtual std::unique_ptr< IWorkload > CreateActivation(const ActivationQueueDescriptor &descriptor, const WorkloadInfo &info) const
#define ARMNN_NO_DEPRECATE_WARN_END
Definition: Deprecated.hpp:34
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:465
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, const bool IsMemoryManaged=true) const =0
Contains information about inputs and outputs to a layer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:481
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)

◆ ConstantLinearActivationUint8Test()

LayerTestResult<uint8_t, 4> ConstantLinearActivationUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 380 of file ActivationTestImpl.cpp.

383 {
384  return ConstantLinearActivationTestCommon<armnn::DataType::QAsymmU8>(
385  workloadFactory, memoryManager, 4.0f, 3);
386 }

◆ EluInt16Test()

LayerTestResult<int16_t, 4> EluInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 1079 of file ActivationTestImpl.cpp.

1082 {
1083  return EluTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
1084 }

◆ EluTest()

LayerTestResult<float, 4> EluTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 1065 of file ActivationTestImpl.cpp.

1068 {
1069  return EluTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.1f, 0);
1070 }

◆ EluTestCommon()

LayerTestResult<T, 4> EluTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 1029 of file ActivationTestImpl.cpp.

References armnn::Elu.

1034 {
1035  std::vector<float> inputData = {
1036  -0.1f, -0.2f, -0.3f, -0.4f,
1037  0.1f, 0.2f, 0.3f, 0.4f,
1038  -1.0f, -2.0f, -3.0f, -4.0f,
1039  1.0f, 2.0f, 3.0f, 4.0f
1040  };
1041 
1042 
1043  const float a = 0.01f;
1044  // Calculate output values for input.
1045  auto f = [a](float value)
1046  {
1047  return (value >= 0) ? value : a * (expf(value) - 1);
1048  };
1049  std::vector<float> outputExpectedData(inputData.size());
1050  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
1051 
1052  return SimpleActivationTest<ArmnnType>(workloadFactory,
1053  memoryManager,
1055  a,
1056  0.0f,
1057  qScale,
1058  qOffset,
1059  inputData,
1060  qScale,
1061  qOffset,
1062  outputExpectedData);
1063 }

◆ EluUint8Test()

LayerTestResult<uint8_t, 4> EluUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 1072 of file ActivationTestImpl.cpp.

1075 {
1076  return EluTestCommon<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, 0.1f, 64);
1077 }

◆ HardSwishInt16Test()

LayerTestResult<int16_t, 4> HardSwishInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 1142 of file ActivationTestImpl.cpp.

1145 {
1146  return HardSwishTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
1147 }

◆ HardSwishTest()

LayerTestResult<float, 4> HardSwishTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 1128 of file ActivationTestImpl.cpp.

1131 {
1132  return HardSwishTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.1f, 0);
1133 }

◆ HardSwishTestCommon()

LayerTestResult<T, 4> HardSwishTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 1088 of file ActivationTestImpl.cpp.

References armnn::HardSwish.

1093 {
1094  std::vector<float> inputData = {
1095  -0.1f, -0.2f, -0.3f, -0.4f,
1096  0.1f, 0.2f, 0.3f, 0.4f,
1097  -1.0f, -2.0f, -3.0f, -4.0f,
1098  1.0f, 2.0f, 3.0f, 4.0f
1099  };
1100  // Calculate output values for input.
1101  auto f = [](float x)
1102  {
1103  // Break down the calculation to help with verification.
1104  // hard_swish(x) = x * relu6(x+3) / 6
1105  // relu6(x) = min(max(x,0),6)
1106  float reLu6_step1 = std::max((x + 3),0.0f);
1107  float reLu6Complete = std::min(reLu6_step1, 6.0f);
1108  float hardSwish_step1 = x * reLu6Complete;
1109  float result = hardSwish_step1 / 6;
1110  return result;
1111  };
1112  std::vector<float> outputExpectedData(inputData.size());
1113  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
1114 
1115  return SimpleActivationTest<ArmnnType>(workloadFactory,
1116  memoryManager,
1118  0.f,
1119  0.f,
1120  qScale,
1121  qOffset,
1122  inputData,
1123  qScale,
1124  qOffset,
1125  outputExpectedData);
1126 }

◆ HardSwishUint8Test()

LayerTestResult<uint8_t, 4> HardSwishUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 1135 of file ActivationTestImpl.cpp.

1138 {
1139  return HardSwishTestCommon<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, 0.1f, 64);
1140 }

◆ LeakyReLuInt16Test()

LayerTestResult<int16_t, 4> LeakyReLuInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 736 of file ActivationTestImpl.cpp.

739 {
740  return LeakyReLuTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
741 }

◆ LeakyReLuTest()

LayerTestResult<float, 4> LeakyReLuTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 722 of file ActivationTestImpl.cpp.

725 {
726  return LeakyReLuTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.1f, 0);
727 }

◆ LeakyReLuTestCommon()

LayerTestResult<T, 4> LeakyReLuTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 687 of file ActivationTestImpl.cpp.

References armnn::LeakyReLu.

692 {
693  std::vector<float> inputData = {
694  -0.1f, -0.2f, -0.3f, -0.4f,
695  0.1f, 0.2f, 0.3f, 0.4f,
696  -1.0f, -2.0f, -3.0f, -4.0f,
697  1.0f, 2.0f, 3.0f, 4.0f
698  };
699 
700  const float a = 0.01f;
701  // Calculate output values for input.
702  auto f = [a](float value)
703  {
704  return value > 0.0f ? value : (value * a);
705  };
706  std::vector<float> outputExpectedData(inputData.size());
707  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
708 
709  return SimpleActivationTest<ArmnnType>(workloadFactory,
710  memoryManager,
712  a,
713  0.f,
714  qScale,
715  qOffset,
716  inputData,
717  qScale,
718  qOffset,
719  outputExpectedData);
720 }

◆ LeakyReLuUint8Test()

LayerTestResult<uint8_t, 4> LeakyReLuUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 729 of file ActivationTestImpl.cpp.

732 {
733  return LeakyReLuTestCommon<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, 0.0625f, 64);
734 }

◆ ReLuInt16Test()

LayerTestResult<int16_t, 4> ReLuInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 562 of file ActivationTestImpl.cpp.

565 {
566  return ReLuTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
567 }

◆ ReLuTest()

LayerTestResult<float, 4> ReLuTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 577 of file ActivationTestImpl.cpp.

580 {
581  return ReLuTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.1f, 0);
582 }

◆ ReLuTestCommon()

LayerTestResult<T, 4> ReLuTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 528 of file ActivationTestImpl.cpp.

References armnn::ReLu.

533 {
534  std::vector<float> inputData = {
535  -0.1f, -0.2f, -0.3f, -0.4f,
536  0.1f, 0.2f, 0.3f, 0.4f,
537  -1.0f, -2.0f, -3.0f, -4.0f,
538  1.0f, 2.0f, 3.0f, 4.0f
539  };
540 
541  // Calculate output values for input.
542  auto f = [](float value)
543  {
544  return std::fmax(0.0f, value);
545  };
546  std::vector<float> outputExpectedData(inputData.size());
547  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
548 
549  return SimpleActivationTest<ArmnnType>(workloadFactory,
550  memoryManager,
552  0.f,
553  0.f,
554  qScale,
555  qOffset,
556  inputData,
557  qScale,
558  qOffset,
559  outputExpectedData);
560 }

◆ ReLuUint8Test()

LayerTestResult<uint8_t, 4> ReLuUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 570 of file ActivationTestImpl.cpp.

573 {
574  return ReLuTestCommon<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, 0.1f, 0);
575 }

◆ SimpleActivationTest()

LayerTestResult<T, 4> SimpleActivationTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
armnn::ActivationFunction  activationFunction,
float  activationParameterA,
float  activationParameterB,
float  scale,
int32_t  offset,
const std::vector< float > &  inputData,
float  outScale,
int32_t  outOffset,
const std::vector< float > &  outputExpectedData 
)

Definition at line 397 of file ActivationTestImpl.cpp.

References ARMNN_NO_DEPRECATE_WARN_BEGIN, ARMNN_NO_DEPRECATE_WARN_END, CopyDataFromITensorHandle(), CopyDataToITensorHandle(), IWorkloadFactory::CreateActivation(), IWorkloadFactory::CreateTensorHandle(), armnn::IgnoreUnused(), LayerTestResult< T, n >::output, LayerTestResult< T, n >::outputExpected, and TensorInfo::SetQuantizationScale().

409 {
410  IgnoreUnused(memoryManager);
411  constexpr static unsigned int inputWidth = 16u;
412  constexpr static unsigned int inputHeight = 1u;
413  constexpr static unsigned int inputChannels = 1u;
414  constexpr static unsigned int inputBatchSize = 1u;
415 
416  constexpr static unsigned int outputWidth = inputWidth;
417  constexpr static unsigned int outputHeight = inputHeight;
418  constexpr static unsigned int outputChannels = inputChannels;
419  constexpr static unsigned int outputBatchSize = inputBatchSize;
420 
421  armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth }, ArmnnType);
422  armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth }, ArmnnType);
423 
424  // Set quantization parameters if the requested type is a quantized type.
425  if(armnn::IsQuantizedType<T>())
426  {
427  inputTensorInfo.SetQuantizationScale(scale);
428  inputTensorInfo.SetQuantizationOffset(offset);
429  outputTensorInfo.SetQuantizationScale(outScale);
430  outputTensorInfo.SetQuantizationOffset(outOffset);
431  }
432 
433  LayerTestResult<T, 4> result(inputTensorInfo);
434 
435  auto input = MakeTensor<T, 4>(inputTensorInfo, armnnUtils::QuantizedVector<T>(inputData, scale, offset));
436 
438  std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
439  std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
441 
442  // Setup bounded ReLu.
444  armnn::WorkloadInfo workloadInfo;
445  AddInputToWorkload(descriptor, workloadInfo, inputTensorInfo, inputHandle.get());
446  AddOutputToWorkload(descriptor, workloadInfo, outputTensorInfo, outputHandle.get());
447 
448  descriptor.m_Parameters.m_Function = activationFunction;
449  descriptor.m_Parameters.m_A = activationParameterA;
450  descriptor.m_Parameters.m_B = activationParameterB;
451 
452  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateActivation(descriptor, workloadInfo);
453 
454  inputHandle->Allocate();
455  outputHandle->Allocate();
456 
457  CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
458 
459  workload->Execute();
460 
461  CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
462 
463  // Calculated manually.
464  result.outputExpected =
465  MakeTensor<T, 4>(outputTensorInfo, armnnUtils::QuantizedVector<T>(outputExpectedData, outScale, outOffset));
466 
467  return result;
468 }
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
Definition: Deprecated.hpp:33
void IgnoreUnused(Ts &&...)
virtual std::unique_ptr< IWorkload > CreateActivation(const ActivationQueueDescriptor &descriptor, const WorkloadInfo &info) const
#define ARMNN_NO_DEPRECATE_WARN_END
Definition: Deprecated.hpp:34
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:465
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, const bool IsMemoryManaged=true) const =0
Contains information about inputs and outputs to a layer.
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)

◆ SimpleSigmoidInt16Test()

LayerTestResult<int16_t, 4> SimpleSigmoidInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 520 of file ActivationTestImpl.cpp.

523 {
524  return SimpleSigmoidTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
525 }

◆ SimpleSigmoidTest()

LayerTestResult<float, 4> SimpleSigmoidTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 506 of file ActivationTestImpl.cpp.

509 {
510  return SimpleSigmoidTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.0f, 0);
511 }

◆ SimpleSigmoidTestCommon()

LayerTestResult<T, 4> SimpleSigmoidTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 471 of file ActivationTestImpl.cpp.

References armnn::Sigmoid.

476 {
477  std::vector<float> inputData =
478  {
479  -0.1f, -0.2f, -0.3f, -0.4f,
480  0.1f, 0.2f, 0.3f, 0.4f,
481  -1.0f, -2.0f, -3.0f, -4.0f,
482  1.0f, 2.0f, 3.0f, 4.0f
483  };
484 
485  // Calculate output values for input.
486  auto f = [](float value)
487  {
488  return 1.0f / (1.0f + std::exp(-value));
489  };
490  std::vector<float> outputExpectedData(inputData.size());
491  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
492 
493  return SimpleActivationTest<ArmnnType>(workloadFactory,
494  memoryManager,
496  0.f,
497  0.f,
498  qScale,
499  qOffset,
500  inputData,
501  1.f / 256.f,
502  0,
503  outputExpectedData);
504 }

◆ SimpleSigmoidUint8Test()

LayerTestResult<uint8_t, 4> SimpleSigmoidUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 513 of file ActivationTestImpl.cpp.

516 {
517  return SimpleSigmoidTestCommon<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, 0.1f, 50);
518 }

◆ SoftReLuInt16Test()

LayerTestResult<int16_t, 4> SoftReLuInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 679 of file ActivationTestImpl.cpp.

682 {
683  return SoftReLuTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
684 }

◆ SoftReLuTest()

LayerTestResult<float, 4> SoftReLuTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 665 of file ActivationTestImpl.cpp.

668 {
669  return SoftReLuTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.1f, 0);
670 }

◆ SoftReLuTestCommon()

LayerTestResult<T, 4> SoftReLuTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 631 of file ActivationTestImpl.cpp.

References armnn::SoftReLu.

636 {
637  std::vector<float> inputData = {
638  -0.1f, -0.2f, -0.3f, -0.4f,
639  0.1f, 0.2f, 0.3f, 0.4f,
640  -1.0f, -2.0f, -3.0f, -4.0f,
641  1.0f, 2.0f, 3.0f, 4.0f
642  };
643 
644  // Calculate output values for input.
645  auto f = [](float value)
646  {
647  return std::log(1.0f + std::exp(value));
648  };
649  std::vector<float> outputExpectedData(inputData.size());
650  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
651 
652  return SimpleActivationTest<ArmnnType>(workloadFactory,
653  memoryManager,
655  0.f,
656  0.f,
657  qScale,
658  qOffset,
659  inputData,
660  qScale,
661  qOffset,
662  outputExpectedData);
663 }

◆ SoftReLuUint8Test()

LayerTestResult<uint8_t, 4> SoftReLuUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 672 of file ActivationTestImpl.cpp.

675 {
676  return SoftReLuTestCommon<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, 0.0625f, 64);
677 }

◆ SqrtInt16Test()

LayerTestResult<int16_t, 4> SqrtInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 906 of file ActivationTestImpl.cpp.

909 {
910  return SqrtTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
911 }

◆ SqrtNNTest()

LayerTestResult<float, 5> SqrtNNTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 799 of file ActivationTestImpl.cpp.

References ARMNN_NO_DEPRECATE_WARN_BEGIN, ARMNN_NO_DEPRECATE_WARN_END, CopyDataFromITensorHandle(), CopyDataToITensorHandle(), IWorkloadFactory::CreateActivation(), IWorkloadFactory::CreateTensorHandle(), armnn::Float32, armnn::IgnoreUnused(), and armnn::Sqrt.

802 {
803  IgnoreUnused(memoryManager);
804  const int inputDataSize = 120;
805  std::vector<float> inputData(inputDataSize);
806 
807  for (unsigned int i = 0u; i < inputDataSize; ++i)
808  {
809  inputData[i] = static_cast<float>(i) / 10;
810  }
811 
812  auto f = [](float value)
813  {
814  return std::sqrt(value);
815  };
816  std::vector<float> outputExpectedData(inputDataSize);
817  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
818 
819  armnn::TensorInfo inputTensorInfo(
820  { 1u, 2u, 3u, 4u, 5u }, armnn::DataType::Float32);
821  armnn::TensorInfo outputTensorInfo(
822  { 1u, 2u, 3u, 4u, 5u }, armnn::DataType::Float32);
823 
824  LayerTestResult<float, 5> result(inputTensorInfo);
825 
826  auto input = MakeTensor<float, 5>(inputTensorInfo, inputData);
827 
829  std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
830  std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
832 
834  armnn::WorkloadInfo workloadInfo;
835  AddInputToWorkload(descriptor, workloadInfo, inputTensorInfo, inputHandle.get());
836  AddOutputToWorkload(descriptor, workloadInfo, outputTensorInfo, outputHandle.get());
837 
838  descriptor.m_Parameters.m_Function = armnn::ActivationFunction::Sqrt;
839 
840  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateActivation(descriptor, workloadInfo);
841 
842  inputHandle->Allocate();
843  outputHandle->Allocate();
844 
845  CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0][0]);
846 
847  workload->Execute();
848 
849  CopyDataFromITensorHandle(&result.output[0][0][0][0][0], outputHandle.get());
850 
851  // Calculated manually.
852  result.outputExpected = MakeTensor<float, 5>(outputTensorInfo, outputExpectedData);
853 
854  return result;
855 };
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
Definition: Deprecated.hpp:33
void IgnoreUnused(Ts &&...)
virtual std::unique_ptr< IWorkload > CreateActivation(const ActivationQueueDescriptor &descriptor, const WorkloadInfo &info) const
#define ARMNN_NO_DEPRECATE_WARN_END
Definition: Deprecated.hpp:34
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, const bool IsMemoryManaged=true) const =0
Contains information about inputs and outputs to a layer.
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)

◆ SqrtTest()

LayerTestResult<float, 4> SqrtTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 892 of file ActivationTestImpl.cpp.

895 {
896  return SqrtTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.1f, 0);
897 }

◆ SqrtTestCommon()

LayerTestResult<T, 4> SqrtTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 858 of file ActivationTestImpl.cpp.

References armnn::Sqrt.

863 {
864  std::vector<float> inputData = {
865  0.1f, 0.2f, 0.3f, 0.4f,
866  0.1f, 0.2f, 0.3f, 0.4f,
867  1.0f, 2.0f, 3.0f, 4.0f,
868  1.0f, 2.0f, 3.0f, 4.0f
869  };
870 
871  // Calculate output values for input.
872  auto f = [](float value)
873  {
874  return std::sqrt(value);
875  };
876  std::vector<float> outputExpectedData(inputData.size());
877  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
878 
879  return SimpleActivationTest<ArmnnType>(workloadFactory,
880  memoryManager,
882  0.f,
883  0.f,
884  qScale,
885  qOffset,
886  inputData,
887  qScale,
888  qOffset,
889  outputExpectedData);
890 }

◆ SqrtUint8Test()

LayerTestResult<uint8_t, 4> SqrtUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 899 of file ActivationTestImpl.cpp.

902 {
903  return SqrtTestCommon<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, 0.0625f, 64);
904 }

◆ SquareInt16Test()

LayerTestResult<int16_t, 4> SquareInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 962 of file ActivationTestImpl.cpp.

965 {
966  return SquareTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
967 }

◆ SquareTest()

LayerTestResult<float, 4> SquareTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 948 of file ActivationTestImpl.cpp.

951 {
952  return SquareTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.1f, 0);
953 }

◆ SquareTestCommon()

LayerTestResult<T, 4> SquareTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 914 of file ActivationTestImpl.cpp.

References armnn::Square.

919 {
920  std::vector<float> inputData = {
921  -0.1f, -0.2f, -0.3f, -0.4f,
922  0.1f, 0.2f, 0.3f, 0.4f,
923  -1.0f, -2.0f, -3.0f, -4.0f,
924  1.0f, 2.0f, 3.0f, 4.0f
925  };
926 
927  // Calculate output values for input.
928  auto f = [](float value)
929  {
930  return std::pow(value,2);
931  };
932  std::vector<float> outputExpectedData(inputData.size());
933  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
934 
935  return SimpleActivationTest<ArmnnType>(workloadFactory,
936  memoryManager,
938  0.f,
939  0.f,
940  qScale,
941  qOffset,
942  inputData,
943  qScale,
944  qOffset,
945  outputExpectedData);
946 }

◆ SquareUint8Test()

LayerTestResult<uint8_t, 4> SquareUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 955 of file ActivationTestImpl.cpp.

958 {
959  return SquareTestCommon<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, 0.0625f, 64);
960 }

◆ TanhInt16Test()

LayerTestResult<int16_t, 4> TanhInt16Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 1020 of file ActivationTestImpl.cpp.

1023 {
1024  return TanhTestCommon<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, 0.1f, 0);
1025 }

◆ TanhTest()

LayerTestResult<float, 4> TanhTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 1006 of file ActivationTestImpl.cpp.

1009 {
1010  return TanhTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.1f, 0);
1011 }

◆ TanhTestCommon()

LayerTestResult<T, 4> TanhTestCommon ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
float  qScale,
int32_t  qOffset 
)

Definition at line 970 of file ActivationTestImpl.cpp.

References armnn::TanH.

975 {
976  std::vector<float> inputData = {
977  -0.1f, -0.2f, -0.3f, -0.4f,
978  0.1f, 0.2f, 0.3f, 0.4f,
979  -1.0f, -2.0f, -3.0f, -4.0f,
980  1.0f, 2.0f, 3.0f, 4.0f
981  };
982 
983  const float a = 2.0f;
984  const float b = 3.0f;
985  // Calculate output values for input.
986  auto f = [a, b](float value)
987  {
988  return a * tanhf(b * value);
989  };
990  std::vector<float> outputExpectedData(inputData.size());
991  std::transform(inputData.begin(), inputData.end(), outputExpectedData.begin(), f);
992 
993  return SimpleActivationTest<ArmnnType>(workloadFactory,
994  memoryManager,
996  a,
997  b,
998  qScale,
999  qOffset,
1000  inputData,
1001  qScale,
1002  qOffset,
1003  outputExpectedData);
1004 }

◆ TanhUint8Test()

LayerTestResult<uint8_t, 4> TanhUint8Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 1013 of file ActivationTestImpl.cpp.

1016 {
1017  return TanhTestCommon<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, 0.1f, 64);
1018 }