ArmNN
 22.05
CastTestImpl.hpp File Reference

Go to the source code of this file.

Functions

template<armnn::DataType inputDataType, armnn::DataType outputDataType, typename TInput = armnn::ResolveType<inputDataType>, typename TOutput = armnn::ResolveType<outputDataType>>
LayerTestResult< TOutput, 4 > CastTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, const std::vector< TInput > &inputTensor, const std::vector< TOutput > &outputTensor)
 
LayerTestResult< float, 4 > CastInt32ToFloat2dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< float, 4 > CastInt16ToFloat2dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< float, 4 > CastInt8ToFloat2dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< float, 4 > CastInt8AsymmToFloat2dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< float, 4 > CastUInt8ToFloat2dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< uint8_t, 4 > CastInt8ToUInt82dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< uint8_t, 4 > CastInt8AsymmToUInt82dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< float, 4 > CastFloat16ToFloat322dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< float, 4 > CastBFloat16ToFloat322dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< armnn::Half, 4 > CastFloat32ToFloat162dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< int8_t, 4 > CastFloat32ToInt82dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
LayerTestResult< uint8_t, 4 > CastFloat32ToUInt82dTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 

Function Documentation

◆ CastBFloat16ToFloat322dTest()

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

Definition at line 166 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

169 {
170 
171  std::vector<armnn::BFloat16> inputValues = armnnUtils::QuantizedVector<armnn::BFloat16>(
172  {
173  -37.5f, -15.2f, -8.76f, -2.0f, -1.5f, -1.3f, -0.5f, -0.4f, 0.0f,
174  1.0f, 0.4f, 0.5f, 1.3f, 1.5f, 2.0f, 8.76f, 15.2f, 37.5f
175  },
176  1.0f, 0);
177 
178 
179  std::vector<float> outputValues = { -37.5f, -15.2f, -8.76f, -2.0f, -1.5f, -1.3f, -0.5f, -0.4f, 0.0f,
180  1.0f, 0.4f, 0.5f, 1.3f, 1.5f, 2.0f, 8.76f, 15.2f, 37.5f };
181 
182  return CastTest<armnn::DataType::BFloat16, armnn::DataType::Float32>(workloadFactory, memoryManager,
183  tensorHandleFactory, inputValues, outputValues);
184 }

◆ CastFloat16ToFloat322dTest()

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

Definition at line 151 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

154 {
155  using namespace half_float::literal;
156 
157  std::vector<armnn::Half> inputValues = { -1.10_h, -3._h, -1.30_h, -3._h, -1._h, -3._h, -1._h, -3._h, 1._h,
158  3.10_h, 1._h, 3.30_h, 1._h, 2._h, 1._h, 3._h, 1._h, 3._h };
159  std::vector<float> outputValues = { -1.1f, -3.0f, -1.3f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, 1.0f,
160  3.1f, 1.0f, 3.3f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f };
161  return CastTest<armnn::DataType::Float16, armnn::DataType::Float32>(workloadFactory, memoryManager,
162  tensorHandleFactory, inputValues,
163  outputValues);
164 }

◆ CastFloat32ToFloat162dTest()

LayerTestResult<armnn::Half, 4> CastFloat32ToFloat162dTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
const armnn::ITensorHandleFactory tensorHandleFactory 
)

Definition at line 186 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

190 {
191  using namespace half_float::literal;
192 
193  std::vector<float> inputValues = { -37.5f, -15.2f, -8.76f, -2.0f, -1.5f, -1.3f, -0.5f, -0.4f,
194  0.00000004f, 3.4E38f, 300.0f, 0.5f, 1.3f, 1.5f, 2.1E4f, 8.76f, 15.2f, 37.5f };
195  std::vector<armnn::Half> outputValues = {-37.50_h, -15.20_h, -8.76_h, -2._h, -1.50_h, -1.30_h, -0.50_h, -0.40_h,
196  0._h, 6.55E4_h, 300._h, 0.50_h, 1.30_h, 1.50_h, 2.1E4_h, 8.76_h, 15.20_h, 37.50_h};
197 
198  return CastTest<armnn::DataType::Float32, armnn::DataType::Float16>(workloadFactory, memoryManager,
199  tensorHandleFactory, inputValues,
200  outputValues);
201 }

◆ CastFloat32ToInt82dTest()

LayerTestResult<int8_t , 4> CastFloat32ToInt82dTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
const armnn::ITensorHandleFactory tensorHandleFactory 
)

Definition at line 203 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

207 {
208  std::vector<float> inputValues = { -1.0f, -3.5f, -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, 1.0f,
209  3.1f, 1.5f, 3.9f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f };
210  std::vector<int8_t> outputValues = { -1, -3, -1, -3, -1, -3, -1, -3, 1,
211  3, 1, 3, 1, 2, 1, 3, 1, 3 };
212  return CastTest<armnn::DataType::Float32, armnn::DataType::QAsymmS8>(workloadFactory, memoryManager,
213  tensorHandleFactory, inputValues,
214  outputValues);
215 }

◆ CastFloat32ToUInt82dTest()

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

Definition at line 217 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

221 {
222  std::vector<float> inputValues = { -1.0f, -3.5f, -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, 1.0f,
223  3.1f, 1.5f, 3.9f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f };
224  std::vector<uint8_t> outputValues = { 0, 0, 0, 0, 0, 0, 0, 0, 1,
225  3, 1, 3, 1, 2, 1, 3, 1, 3 };
226  return CastTest<armnn::DataType::Float32, armnn::DataType::QAsymmU8>(workloadFactory, memoryManager,
227  tensorHandleFactory, inputValues,
228  outputValues);
229 }

◆ CastInt16ToFloat2dTest()

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

Definition at line 74 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

77 {
78  std::vector<int16_t> inputValues = { -1, -3, -1, -3, -1, -3, -1, -3, 1,
79  3, 1, 3, 1, 2, 1, 3, 1, 3 };
80  std::vector<float> outputValues = { -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, 1.0f,
81  3.0f, 1.0f, 3.0f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f };
82  return CastTest<armnn::DataType::QSymmS16, armnn::DataType::Float32>(workloadFactory, memoryManager,
83  tensorHandleFactory, inputValues,
84  outputValues);
85 }

◆ CastInt32ToFloat2dTest()

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

Definition at line 61 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

64 {
65  std::vector<int32_t> inputValues = { -1, -3, -1, -3, -1, -3, -1, -3, 1,
66  3, 1, 3, 1, 2, 1, 3, 1, 3 };
67  std::vector<float> outputValues = { -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, 1.0f,
68  3.0f, 1.0f, 3.0f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f };
69  return CastTest<armnn::DataType::Signed32, armnn::DataType::Float32>(workloadFactory, memoryManager,
70  tensorHandleFactory, inputValues,
71  outputValues);
72 }

◆ CastInt8AsymmToFloat2dTest()

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

Definition at line 100 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

103 {
104  std::vector<int8_t> inputValues = { -1, -3, -1, -3, -1, -3, -1, -3, 1,
105  3, 1, 3, 1, 2, 1, 3, 1, 3 };
106  std::vector<float> outputValues = { -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, 1.0f,
107  3.0f, 1.0f, 3.0f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f };
108  return CastTest<armnn::DataType::QAsymmS8, armnn::DataType::Float32>(workloadFactory, memoryManager,
109  tensorHandleFactory, inputValues, outputValues);
110 }

◆ CastInt8AsymmToUInt82dTest()

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

Definition at line 138 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

141 {
142  std::vector<int8_t> inputValues = { -1, -3, -1, -3, -1, -3, -1, -3, -1,
143  3, 1, 3, 1, 2, 1, 3, 1, 3 };
144  std::vector<uint8_t> outputValues = { 0, 0, 0, 0, 0, 0, 0, 0, 0,
145  3, 1, 3, 1, 2, 1, 3, 1, 3 };
146  return CastTest<armnn::DataType::QAsymmS8, armnn::DataType::QAsymmU8>(workloadFactory, memoryManager,
147  tensorHandleFactory, inputValues,
148  outputValues);
149 }

◆ CastInt8ToFloat2dTest()

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

Definition at line 87 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

90 {
91  std::vector<int8_t> inputValues = { -1, -3, -1, -3, -1, -3, -1, -3, 1,
92  3, 1, 3, 1, 2, 1, 3, 1, 3 };
93  std::vector<float> outputValues = { -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, 1.0f,
94  3.0f, 1.0f, 3.0f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f };
95  return CastTest<armnn::DataType::QSymmS8, armnn::DataType::Float32>(workloadFactory, memoryManager,
96  tensorHandleFactory, inputValues,
97  outputValues);
98 }

◆ CastInt8ToUInt82dTest()

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

Definition at line 125 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

128 {
129  std::vector<int8_t> inputValues = { -1, -3, -1, -3, -1, -3, -1, -3, -1,
130  3, 1, 3, 1, 2, 1, 3, 1, 3 };
131  std::vector<uint8_t> outputValues = { 0, 0, 0, 0, 0, 0, 0, 0, 0,
132  3, 1, 3, 1, 2, 1, 3, 1, 3 };
133  return CastTest<armnn::DataType::QSymmS8, armnn::DataType::QAsymmU8>(workloadFactory, memoryManager,
134  tensorHandleFactory, inputValues,
135  outputValues);
136 }

◆ CastTest()

LayerTestResult<TOutput, 4> CastTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
const armnn::ITensorHandleFactory tensorHandleFactory,
const std::vector< TInput > &  inputTensor,
const std::vector< TOutput > &  outputTensor 
)

Definition at line 11 of file CastTestImpl.cpp.

References armnn::Cast, CopyDataFromITensorHandle(), CopyDataToITensorHandle(), ITensorHandleFactory::CreateTensorHandle(), IWorkloadFactory::CreateWorkload(), armnn::IgnoreUnused(), and TensorInfo::SetQuantizationScale().

16 {
17  IgnoreUnused(memoryManager);
18  armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, inputDataType);
19  armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, outputDataType);
20  float quantizationScale = 1.0f;
21  int32_t quantizationOffset = 0;
22 
23  if(armnn::IsQuantizedType<TInput>())
24  {
25  inputTensorInfo.SetQuantizationScale(quantizationScale);
26  inputTensorInfo.SetQuantizationOffset(quantizationOffset);
27  }
28  if(armnn::IsQuantizedType<TOutput>())
29  {
30  outputTensorInfo.SetQuantizationScale(quantizationScale);
31  outputTensorInfo.SetQuantizationOffset(quantizationOffset);
32  }
33 
34  std::vector<TOutput> actualOutput(outputTensorInfo.GetNumElements());
35 
36  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
37  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
38 
41  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
42  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
43 
44  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateWorkload(armnn::LayerType::Cast, data, info);
45 
46  inputHandle->Allocate();
47  outputHandle->Allocate();
48 
49  CopyDataToITensorHandle(inputHandle.get(), inputValues.data());
50 
51  workload->Execute();
52 
53  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
54 
55  return LayerTestResult<TOutput, 4>(actualOutput,
56  outputValues,
57  outputHandle->GetShape(),
58  outputTensorInfo.GetShape());
59 }
void IgnoreUnused(Ts &&...)
void CopyDataFromITensorHandle(void *mem, const armnn::ITensorHandle *tensorHandle)
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:473
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
Contains information about TensorInfos of a layer.
virtual std::unique_ptr< IWorkload > CreateWorkload(LayerType type, const QueueDescriptor &descriptor, const WorkloadInfo &info) const
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const =0

◆ CastUInt8ToFloat2dTest()

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

Definition at line 112 of file CastTestImpl.cpp.

Referenced by TEST_SUITE().

115 {
116  std::vector<uint8_t> inputValues = { 1, 3, 1, 3, 1, 3, 1, 3, 1,
117  3, 1, 3, 1, 2, 1, 3, 1, 3 };
118  std::vector<float> outputValues = { 1.0f, 3.0f, 1.0f, 3.0f, 1.0f, 3.0f, 1.0f, 3.0f, 1.0f,
119  3.0f, 1.0f, 3.0f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f };
120  return CastTest<armnn::DataType::QAsymmU8, armnn::DataType::Float32>(workloadFactory, memoryManager,
121  tensorHandleFactory, inputValues,
122  outputValues);
123 }