ArmNN
 20.08
TransposeTestImpl.hpp File Reference

Go to the source code of this file.

Functions

template<typename FactoryType , typename T >
LayerTestResult< T, 4 > SimpleTransposeTestImpl (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::TransposeDescriptor descriptor, armnn::TensorInfo inputTensorInfo, armnn::TensorInfo outputTensorInfo, const std::vector< T > &inputData, const std::vector< T > &outputExpectedData)
 
template<typename FactoryType , armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > SimpleTransposeTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<typename FactoryType , armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > TransposeValueSet1Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<typename FactoryType , armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > TransposeValueSet2Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<typename FactoryType , armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > TransposeValueSet3Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 

Function Documentation

◆ SimpleTransposeTest()

LayerTestResult<T, 4> SimpleTransposeTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 59 of file TransposeTestImpl.hpp.

References TransposeDescriptor::m_DimMappings, TensorInfo::SetQuantizationOffset(), and TensorInfo::SetQuantizationScale().

62 {
63  armnn::TensorInfo inputTensorInfo;
64  armnn::TensorInfo outputTensorInfo;
65 
66  unsigned int inputShape[] = { 1, 2, 2, 2 };
67  unsigned int outputShape[] = { 1, 2, 2, 2 };
68 
69  armnn::TransposeDescriptor descriptor;
70  descriptor.m_DimMappings = {0U, 2U, 3U, 1U};
71 
72  inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
73  outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
74 
75  // Set quantization parameters if the requested type is a quantized type.
76  float qScale = 0.5f;
77  int32_t qOffset = 5;
78  if(armnn::IsQuantizedType<T>())
79  {
80  inputTensorInfo.SetQuantizationScale(qScale);
81  inputTensorInfo.SetQuantizationOffset(qOffset);
82  outputTensorInfo.SetQuantizationScale(qScale);
83  outputTensorInfo.SetQuantizationOffset(qOffset);
84  }
85 
86  std::vector<T> input = armnnUtils::QuantizedVector<T>(
87  {
88  1, 2,
89  3, 4,
90  5, 6,
91  7, 8
92  },
93  qScale, qOffset);
94 
95  std::vector<T> outputExpected = armnnUtils::QuantizedVector<T>(
96  {
97  1, 5, 2, 6,
98  3, 7, 4, 8
99  },
100  qScale, qOffset);
101 
102  return SimpleTransposeTestImpl<FactoryType, T>(workloadFactory, memoryManager,
103  descriptor, inputTensorInfo,
104  outputTensorInfo, input, outputExpected);
105 }
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:465
A TransposeDescriptor for the TransposeLayer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:481
PermutationVector m_DimMappings
Indicates how to translate tensor elements from a given source into the target destination, when source and target potentially have different memory layouts e.g.

◆ SimpleTransposeTestImpl()

LayerTestResult<T, 4> SimpleTransposeTestImpl ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
armnn::TransposeDescriptor  descriptor,
armnn::TensorInfo  inputTensorInfo,
armnn::TensorInfo  outputTensorInfo,
const std::vector< T > &  inputData,
const std::vector< T > &  outputExpectedData 
)

Definition at line 20 of file TransposeTestImpl.hpp.

References CopyDataFromITensorHandle(), CopyDataToITensorHandle(), IWorkloadFactory::CreateTranspose(), and QueueDescriptorWithParameters< LayerDescriptor >::m_Parameters.

28 {
29  auto input = MakeTensor<T, 4>(inputTensorInfo, inputData);
30 
31  LayerTestResult<T, 4> ret(outputTensorInfo);
32  ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo, outputExpectedData);
33 
34  auto tensorHandleFactory = WorkloadFactoryHelper<FactoryType>::GetTensorHandleFactory(memoryManager);
35  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
36  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
37 
39  data.m_Parameters = descriptor;
41  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
42  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
43 
44  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateTranspose(data, info);
45 
46  inputHandle->Allocate();
47  outputHandle->Allocate();
48 
49  CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
50 
51  workload->Execute();
52 
53  CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
54 
55  return ret;
56 }
virtual std::unique_ptr< IWorkload > CreateTranspose(const TransposeQueueDescriptor &descriptor, const WorkloadInfo &info) const
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
Contains information about inputs and outputs to a layer.
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)

◆ TransposeValueSet1Test()

LayerTestResult<T, 4> TransposeValueSet1Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 108 of file TransposeTestImpl.hpp.

References TransposeDescriptor::m_DimMappings, TensorInfo::SetQuantizationOffset(), and TensorInfo::SetQuantizationScale().

111 {
112  armnn::TensorInfo inputTensorInfo;
113  armnn::TensorInfo outputTensorInfo;
114 
115  unsigned int inputShape[] = { 1, 2, 2, 3 };
116  unsigned int outputShape[] = { 1, 3, 2, 2 };
117 
118  armnn::TransposeDescriptor descriptor;
119  descriptor.m_DimMappings = {0U, 3U, 1U, 2U};
120 
121  inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
122  outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
123 
124  // Set quantization parameters if the requested type is a quantized type.
125  float qScale = 0.5f;
126  int32_t qOffset = 5;
127  if(armnn::IsQuantizedType<T>())
128  {
129  inputTensorInfo.SetQuantizationScale(qScale);
130  inputTensorInfo.SetQuantizationOffset(qOffset);
131  outputTensorInfo.SetQuantizationScale(qScale);
132  outputTensorInfo.SetQuantizationOffset(qOffset);
133  }
134 
135  std::vector<T> input = armnnUtils::QuantizedVector<T>(
136  {
137  1, 2, 3,
138  11, 12, 13,
139  21, 22, 23,
140  31, 32, 33
141  },
142  qScale, qOffset);
143 
144  std::vector<T> outputExpected = armnnUtils::QuantizedVector<T>(
145  {
146  1, 11, 21, 31,
147  2, 12, 22, 32,
148  3, 13, 23, 33
149  },
150  qScale, qOffset);
151 
152  return SimpleTransposeTestImpl<FactoryType, T>(workloadFactory, memoryManager,
153  descriptor, inputTensorInfo,
154  outputTensorInfo, input, outputExpected);
155 }
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:465
A TransposeDescriptor for the TransposeLayer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:481
PermutationVector m_DimMappings
Indicates how to translate tensor elements from a given source into the target destination, when source and target potentially have different memory layouts e.g.

◆ TransposeValueSet2Test()

LayerTestResult<T, 4> TransposeValueSet2Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 158 of file TransposeTestImpl.hpp.

References TransposeDescriptor::m_DimMappings, TensorInfo::SetQuantizationOffset(), and TensorInfo::SetQuantizationScale().

161 {
162  armnn::TensorInfo inputTensorInfo;
163  armnn::TensorInfo outputTensorInfo;
164 
165  unsigned int inputShape[] = { 1, 3, 2, 2 };
166  unsigned int outputShape[] = { 1, 2, 2, 3 };
167 
168  armnn::TransposeDescriptor descriptor;
169  descriptor.m_DimMappings = {0U, 2U, 3U, 1U};
170 
171  inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
172  outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
173 
174  // Set quantization parameters if the requested type is a quantized type.
175  float qScale = 0.5f;
176  int32_t qOffset = 5;
177  if(armnn::IsQuantizedType<T>())
178  {
179  inputTensorInfo.SetQuantizationScale(qScale);
180  inputTensorInfo.SetQuantizationOffset(qOffset);
181  outputTensorInfo.SetQuantizationScale(qScale);
182  outputTensorInfo.SetQuantizationOffset(qOffset);
183  }
184 
185  std::vector<T> input = armnnUtils::QuantizedVector<T>(
186  {
187  1, 11, 21, 31,
188  2, 12, 22, 32,
189  3, 13, 23, 33
190  },
191  qScale, qOffset);
192 
193  std::vector<T> outputExpected = armnnUtils::QuantizedVector<T>(
194  {
195  1, 2, 3,
196  11, 12, 13,
197  21, 22, 23,
198  31, 32, 33,
199  },
200  qScale, qOffset);
201 
202  return SimpleTransposeTestImpl<FactoryType, T>(workloadFactory, memoryManager,
203  descriptor, inputTensorInfo,
204  outputTensorInfo, input, outputExpected);
205 }
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:465
A TransposeDescriptor for the TransposeLayer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:481
PermutationVector m_DimMappings
Indicates how to translate tensor elements from a given source into the target destination, when source and target potentially have different memory layouts e.g.

◆ TransposeValueSet3Test()

LayerTestResult<T, 4> TransposeValueSet3Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager 
)

Definition at line 208 of file TransposeTestImpl.hpp.

References TransposeDescriptor::m_DimMappings, TensorInfo::SetQuantizationOffset(), and TensorInfo::SetQuantizationScale().

211 {
212  armnn::TensorInfo inputTensorInfo;
213  armnn::TensorInfo outputTensorInfo;
214 
215  unsigned int inputShape[] = { 1, 2, 3, 3 };
216  unsigned int outputShape[] = { 1, 3, 2, 3 };
217 
218  armnn::TransposeDescriptor descriptor;
219  descriptor.m_DimMappings = {0U, 3U, 1U, 2U};
220 
221  inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
222  outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
223 
224  // Set quantization parameters if the requested type is a quantized type.
225  float qScale = 0.5f;
226  int32_t qOffset = 5;
227  if(armnn::IsQuantizedType<T>())
228  {
229  inputTensorInfo.SetQuantizationScale(qScale);
230  inputTensorInfo.SetQuantizationOffset(qOffset);
231  outputTensorInfo.SetQuantizationScale(qScale);
232  outputTensorInfo.SetQuantizationOffset(qOffset);
233  }
234 
235  std::vector<T> input = armnnUtils::QuantizedVector<T>(
236  {
237  1, 2, 3,
238  11, 12, 13,
239  21, 22, 23,
240  31, 32, 33,
241  41, 42, 43,
242  51, 52, 53
243  },
244  qScale, qOffset);
245 
246  std::vector<T> outputExpected = armnnUtils::QuantizedVector<T>(
247  {
248  1, 11, 21, 31, 41, 51,
249  2, 12, 22, 32, 42, 52,
250  3, 13, 23, 33, 43, 53
251  },
252  qScale, qOffset);
253 
254  return SimpleTransposeTestImpl<FactoryType, T>(workloadFactory, memoryManager,
255  descriptor, inputTensorInfo,
256  outputTensorInfo, input, outputExpected);
257 }
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:465
A TransposeDescriptor for the TransposeLayer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:481
PermutationVector m_DimMappings
Indicates how to translate tensor elements from a given source into the target destination, when source and target potentially have different memory layouts e.g.