ArmNN
 21.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, const armnn::ITensorHandleFactory &tensorHandleFactory, 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, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > TransposeValueSet1Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > TransposeValueSet2Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 4 > TransposeValueSet3Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory)
 

Function Documentation

◆ SimpleTransposeTest()

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

Definition at line 60 of file TransposeTestImpl.hpp.

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

64 {
65  armnn::TensorInfo inputTensorInfo;
66  armnn::TensorInfo outputTensorInfo;
67 
68  unsigned int inputShape[] = { 1, 2, 2, 2 };
69  unsigned int outputShape[] = { 1, 2, 2, 2 };
70 
71  armnn::TransposeDescriptor descriptor;
72  descriptor.m_DimMappings = {0U, 2U, 3U, 1U};
73 
74  inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
75  outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
76 
77  // Set quantization parameters if the requested type is a quantized type.
78  float qScale = 0.5f;
79  int32_t qOffset = 5;
80  if(armnn::IsQuantizedType<T>())
81  {
82  inputTensorInfo.SetQuantizationScale(qScale);
83  inputTensorInfo.SetQuantizationOffset(qOffset);
84  outputTensorInfo.SetQuantizationScale(qScale);
85  outputTensorInfo.SetQuantizationOffset(qOffset);
86  }
87 
88  std::vector<T> input = armnnUtils::QuantizedVector<T>(
89  {
90  1, 2,
91  3, 4,
92  5, 6,
93  7, 8
94  },
95  qScale, qOffset);
96 
97  std::vector<T> outputExpected = armnnUtils::QuantizedVector<T>(
98  {
99  1, 5, 2, 6,
100  3, 7, 4, 8
101  },
102  qScale, qOffset);
103 
104  return SimpleTransposeTestImpl(workloadFactory, memoryManager, tensorHandleFactory,
105  descriptor, inputTensorInfo,
106  outputTensorInfo, input, outputExpected);
107 }
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:464
A TransposeDescriptor for the TransposeLayer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:480
LayerTestResult< T, 4 > SimpleTransposeTestImpl(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, armnn::TransposeDescriptor descriptor, armnn::TensorInfo inputTensorInfo, armnn::TensorInfo outputTensorInfo, const std::vector< T > &inputData, const std::vector< T > &outputExpectedData)
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,
const armnn::ITensorHandleFactory tensorHandleFactory,
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(), ITensorHandleFactory::CreateTensorHandle(), IWorkloadFactory::CreateTranspose(), armnn::IgnoreUnused(), and QueueDescriptorWithParameters< LayerDescriptor >::m_Parameters.

Referenced by SimpleTransposeTest().

29 {
30  IgnoreUnused(memoryManager);
31  auto input = MakeTensor<T, 4>(inputTensorInfo, inputData);
32 
33  LayerTestResult<T, 4> ret(outputTensorInfo);
34  ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo, outputExpectedData);
35 
36  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
37  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
38 
40  data.m_Parameters = descriptor;
42  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
43  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
44 
45  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateTranspose(data, info);
46 
47  inputHandle->Allocate();
48  outputHandle->Allocate();
49 
50  CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
51 
52  workload->Execute();
53 
54  CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
55 
56  return ret;
57 }
void IgnoreUnused(Ts &&...)
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.
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const =0
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)

◆ TransposeValueSet1Test()

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

Definition at line 110 of file TransposeTestImpl.hpp.

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

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

Definition at line 161 of file TransposeTestImpl.hpp.

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

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

Definition at line 212 of file TransposeTestImpl.hpp.

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

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