ArmNN
 20.02
TransposeTestImpl.hpp File Reference

Go to the source code of this file.

Functions

template<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<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > SimpleTransposeTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > TransposeValueSet1Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > TransposeValueSet2Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager)
 
template<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 58 of file TransposeTestImpl.hpp.

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

61 {
62  armnn::TensorInfo inputTensorInfo;
63  armnn::TensorInfo outputTensorInfo;
64 
65  unsigned int inputShape[] = { 1, 2, 2, 2 };
66  unsigned int outputShape[] = { 1, 2, 2, 2 };
67 
68  armnn::TransposeDescriptor descriptor;
69  descriptor.m_DimMappings = {0U, 2U, 3U, 1U};
70 
71  inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
72  outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
73 
74  // Set quantization parameters if the requested type is a quantized type.
75  float qScale = 0.5f;
76  int32_t qOffset = 5;
77  if(armnn::IsQuantizedType<T>())
78  {
79  inputTensorInfo.SetQuantizationScale(qScale);
80  inputTensorInfo.SetQuantizationOffset(qOffset);
81  outputTensorInfo.SetQuantizationScale(qScale);
82  outputTensorInfo.SetQuantizationOffset(qOffset);
83  }
84 
85  std::vector<T> input = armnnUtils::QuantizedVector<T>(
86  {
87  1, 2,
88  3, 4,
89  5, 6,
90  7, 8
91  },
92  qScale, qOffset);
93 
94  std::vector<T> outputExpected = armnnUtils::QuantizedVector<T>(
95  {
96  1, 5, 2, 6,
97  3, 7, 4, 8
98  },
99  qScale, qOffset);
100 
101  return SimpleTransposeTestImpl<T>(workloadFactory, memoryManager,
102  descriptor, inputTensorInfo,
103  outputTensorInfo, input, outputExpected);
104 }
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:259
A TransposeDescriptor for the TransposeLayer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:275
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 19 of file TransposeTestImpl.hpp.

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

27 {
28  IgnoreUnused(memoryManager);
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  std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
35  std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
36 
38  data.m_Parameters = descriptor;
40  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
41  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
42 
43  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateTranspose(data, info);
44 
45  inputHandle->Allocate();
46  outputHandle->Allocate();
47 
48  CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
49 
50  workload->Execute();
51 
52  CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
53 
54  return ret;
55 }
void IgnoreUnused(Ts &&...)
virtual std::unique_ptr< IWorkload > CreateTranspose(const TransposeQueueDescriptor &descriptor, const WorkloadInfo &info) const
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)

◆ TransposeValueSet1Test()

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

Definition at line 107 of file TransposeTestImpl.hpp.

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

110 {
111  armnn::TensorInfo inputTensorInfo;
112  armnn::TensorInfo outputTensorInfo;
113 
114  unsigned int inputShape[] = { 1, 2, 2, 3 };
115  unsigned int outputShape[] = { 1, 3, 2, 2 };
116 
117  armnn::TransposeDescriptor descriptor;
118  descriptor.m_DimMappings = {0U, 3U, 1U, 2U};
119 
120  inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
121  outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
122 
123  // Set quantization parameters if the requested type is a quantized type.
124  float qScale = 0.5f;
125  int32_t qOffset = 5;
126  if(armnn::IsQuantizedType<T>())
127  {
128  inputTensorInfo.SetQuantizationScale(qScale);
129  inputTensorInfo.SetQuantizationOffset(qOffset);
130  outputTensorInfo.SetQuantizationScale(qScale);
131  outputTensorInfo.SetQuantizationOffset(qOffset);
132  }
133 
134  std::vector<T> input = armnnUtils::QuantizedVector<T>(
135  {
136  1, 2, 3,
137  11, 12, 13,
138  21, 22, 23,
139  31, 32, 33
140  },
141  qScale, qOffset);
142 
143  std::vector<T> outputExpected = armnnUtils::QuantizedVector<T>(
144  {
145  1, 11, 21, 31,
146  2, 12, 22, 32,
147  3, 13, 23, 33
148  },
149  qScale, qOffset);
150 
151  return SimpleTransposeTestImpl<T>(workloadFactory, memoryManager,
152  descriptor, inputTensorInfo,
153  outputTensorInfo, input, outputExpected);
154 }
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:259
A TransposeDescriptor for the TransposeLayer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:275
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 157 of file TransposeTestImpl.hpp.

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

160 {
161  armnn::TensorInfo inputTensorInfo;
162  armnn::TensorInfo outputTensorInfo;
163 
164  unsigned int inputShape[] = { 1, 3, 2, 2 };
165  unsigned int outputShape[] = { 1, 2, 2, 3 };
166 
167  armnn::TransposeDescriptor descriptor;
168  descriptor.m_DimMappings = {0U, 2U, 3U, 1U};
169 
170  inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
171  outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
172 
173  // Set quantization parameters if the requested type is a quantized type.
174  float qScale = 0.5f;
175  int32_t qOffset = 5;
176  if(armnn::IsQuantizedType<T>())
177  {
178  inputTensorInfo.SetQuantizationScale(qScale);
179  inputTensorInfo.SetQuantizationOffset(qOffset);
180  outputTensorInfo.SetQuantizationScale(qScale);
181  outputTensorInfo.SetQuantizationOffset(qOffset);
182  }
183 
184  std::vector<T> input = armnnUtils::QuantizedVector<T>(
185  {
186  1, 11, 21, 31,
187  2, 12, 22, 32,
188  3, 13, 23, 33
189  },
190  qScale, qOffset);
191 
192  std::vector<T> outputExpected = armnnUtils::QuantizedVector<T>(
193  {
194  1, 2, 3,
195  11, 12, 13,
196  21, 22, 23,
197  31, 32, 33,
198  },
199  qScale, qOffset);
200 
201  return SimpleTransposeTestImpl<T>(workloadFactory, memoryManager,
202  descriptor, inputTensorInfo,
203  outputTensorInfo, input, outputExpected);
204 }
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:259
A TransposeDescriptor for the TransposeLayer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:275
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 207 of file TransposeTestImpl.hpp.

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

210 {
211  armnn::TensorInfo inputTensorInfo;
212  armnn::TensorInfo outputTensorInfo;
213 
214  unsigned int inputShape[] = { 1, 2, 3, 3 };
215  unsigned int outputShape[] = { 1, 3, 2, 3 };
216 
217  armnn::TransposeDescriptor descriptor;
218  descriptor.m_DimMappings = {0U, 3U, 1U, 2U};
219 
220  inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
221  outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
222 
223  // Set quantization parameters if the requested type is a quantized type.
224  float qScale = 0.5f;
225  int32_t qOffset = 5;
226  if(armnn::IsQuantizedType<T>())
227  {
228  inputTensorInfo.SetQuantizationScale(qScale);
229  inputTensorInfo.SetQuantizationOffset(qOffset);
230  outputTensorInfo.SetQuantizationScale(qScale);
231  outputTensorInfo.SetQuantizationOffset(qOffset);
232  }
233 
234  std::vector<T> input = armnnUtils::QuantizedVector<T>(
235  {
236  1, 2, 3,
237  11, 12, 13,
238  21, 22, 23,
239  31, 32, 33,
240  41, 42, 43,
241  51, 52, 53
242  },
243  qScale, qOffset);
244 
245  std::vector<T> outputExpected = armnnUtils::QuantizedVector<T>(
246  {
247  1, 11, 21, 31, 41, 51,
248  2, 12, 22, 32, 42, 52,
249  3, 13, 23, 33, 43, 53
250  },
251  qScale, qOffset);
252 
253  return SimpleTransposeTestImpl<T>(workloadFactory, memoryManager,
254  descriptor, inputTensorInfo,
255  outputTensorInfo, input, outputExpected);
256 }
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:259
A TransposeDescriptor for the TransposeLayer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:275
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.