blob: 08a68cc04cbf57565e0fcd3ee795d9f63bed9de3 [file] [log] [blame]
Simon Obute51f67772021-09-03 15:50:13 +01001//
2// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ChannelShuffleTestImpl.hpp"
7
Sadik Armagana097d2a2021-11-24 15:47:28 +00008#include <DataTypeUtils.hpp>
9#include <armnnTestUtils/TensorCopyUtils.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +000010#include <armnnTestUtils/WorkloadTestUtils.hpp>
Simon Obute51f67772021-09-03 15:50:13 +010011
12namespace
13{
14
15template<typename T, size_t NumDims>
16LayerTestResult<T, NumDims> ChannelShuffleTestImpl(
17 armnn::IWorkloadFactory& workloadFactory,
18 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
19 const armnn::ITensorHandleFactory& tensorHandleFactory,
20 armnn::ChannelShuffleDescriptor descriptor,
21 armnn::TensorInfo inputTensorInfo,
22 armnn::TensorInfo outputTensorInfo,
23 const std::vector<T>& inputData,
24 const std::vector<T>& outputExpectedData)
25{
26 IgnoreUnused(memoryManager);
27 std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
28
29 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
30 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
31
32 armnn::ChannelShuffleQueueDescriptor data;
33 data.m_Parameters = descriptor;
34 armnn::WorkloadInfo info;
35 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
36 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
37
38 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateChannelShuffle(data, info);
39
40 inputHandle->Allocate();
41 outputHandle->Allocate();
42
43 CopyDataToITensorHandle(inputHandle.get(), inputData.data());
44
45 workload->Execute();
46
47 CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
48
49 return LayerTestResult<T, NumDims>(actualOutput,
50 outputExpectedData,
51 outputHandle->GetShape(),
52 outputTensorInfo.GetShape());
53}
54} // anonymous namespace
55
56template<armnn::DataType ArmnnType, typename T>
57LayerTestResult<T, 4> SimpleChannelShuffleTest(
58 armnn::IWorkloadFactory& workloadFactory,
59 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
60 const armnn::ITensorHandleFactory& tensorHandleFactory)
61{
62 armnn::TensorInfo inputTensorInfo;
63 armnn::TensorInfo outputTensorInfo;
64
65 unsigned int inputShape[] = { 1,9,1,1 };
66 unsigned int outputShape[] = { 1,9,1,1 };
67
68 armnn::ChannelShuffleDescriptor descriptor;
69 descriptor.m_Axis = 1;
70 descriptor.m_NumGroups = 3;
71
72 inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
73 inputTensorInfo.SetQuantizationScale(1.0f);
74 outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
75 outputTensorInfo.SetQuantizationScale(1.0f);
76
77 auto input = ConvertToDataType<ArmnnType>(
78 {
79 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f
80 },
81 inputTensorInfo);
82 auto outputExpected = ConvertToDataType<ArmnnType>(
83 {
84 0.0f, 3.0f, 6.0f, 1.0f, 4.0f, 7.0f, 2.0f, 5.0f, 8.0f
85 },
86 outputTensorInfo);
87
88 return ChannelShuffleTestImpl<T, 4>(
89 workloadFactory,
90 memoryManager,
91 tensorHandleFactory,
92 descriptor,
93 inputTensorInfo,
94 outputTensorInfo,
95 input,
96 outputExpected);
97}
98
99template<armnn::DataType ArmnnType, typename T>
100LayerTestResult<T, 2> ChannelShuffle2DTest(
101 armnn::IWorkloadFactory& workloadFactory,
102 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
103 const armnn::ITensorHandleFactory& tensorHandleFactory)
104{
105 armnn::TensorInfo inputTensorInfo;
106 armnn::TensorInfo outputTensorInfo;
107
108 unsigned int inputShape[] = { 3, 12 };
109 unsigned int outputShape[] = { 3, 12 };
110
111 armnn::ChannelShuffleDescriptor descriptor;
112 descriptor.m_Axis = 1;
113 descriptor.m_NumGroups = 3;
114
115 inputTensorInfo = armnn::TensorInfo(2, inputShape, ArmnnType);
116 inputTensorInfo.SetQuantizationScale(1.0f);
117 outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType);
118 outputTensorInfo.SetQuantizationScale(1.0f);
119
120 auto input = ConvertToDataType<ArmnnType>(
121 {
122 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
123 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
124 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35
125 },
126 inputTensorInfo);
127
128 auto outputExpected = ConvertToDataType<ArmnnType>(
129 {
130 0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11,
131 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19, 23,
132 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35
133 },
134 outputTensorInfo);
135
136 return ChannelShuffleTestImpl<T, 2>(
137 workloadFactory,
138 memoryManager,
139 tensorHandleFactory,
140 descriptor,
141 inputTensorInfo,
142 outputTensorInfo,
143 input,
144 outputExpected);
145}
146
147template<armnn::DataType ArmnnType, typename T>
148LayerTestResult<T, 4> ChannelShuffle4DTest(
149 armnn::IWorkloadFactory& workloadFactory,
150 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
151 const armnn::ITensorHandleFactory& tensorHandleFactory)
152{
153 armnn::TensorInfo inputTensorInfo;
154 armnn::TensorInfo outputTensorInfo;
155
156 unsigned int inputShape[] = { 2, 9, 1, 2 };
157 unsigned int outputShape[] = { 2, 9, 1, 2 };
158
159 armnn::ChannelShuffleDescriptor descriptor;
160 descriptor.m_Axis = 1;
161 descriptor.m_NumGroups = 3;
162
163 inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
164 inputTensorInfo.SetQuantizationScale(1.0f);
165 outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
166 outputTensorInfo.SetQuantizationScale(1.0f);
167
168 auto input = ConvertToDataType<ArmnnType>(
169 {
170 0.0f, 1.0f,
171 2.0f, 3.0f,
172 4.0f, 5.0f,
173
174 6.0f, 7.0f,
175 8.0f, 9.0f,
176 10.0f, 11.0f,
177
178 12.0f, 13.0f,
179 14.0f, 15.0f,
180 16.0f, 17.0f,
181
182 18.0f, 19.0f,
183 20.0f, 21.0f,
184 22.0f, 23.0f,
185
186 24.0f, 25.0f,
187 26.0f, 27.0f,
188 28.0f, 29.0f,
189
190 30.0f, 31.0f,
191 32.0f, 33.0f,
192 34.0f, 35.0f
193 },
194 inputTensorInfo);
195
196 auto outputExpected = ConvertToDataType<ArmnnType>(
197 {
198 0.0f, 1.0f,
199 6.0f, 7.0f,
200 12.0f, 13.0f,
201 2.0f, 3.0f,
202 8.0f, 9.0f,
203 14.0f, 15.0f,
204 4.0f, 5.0f,
205 10.0f, 11.0f,
206 16.0f, 17.0f,
207
208 18.0f, 19.0f,
209 24.0f, 25.0f,
210 30.0f, 31.0f,
211 20.0f, 21.0f,
212 26.0f, 27.0f,
213 32.0f, 33.0f,
214 22.0f, 23.0f,
215 28.0f, 29.0f,
216 34.0f, 35.0f
217 },
218 outputTensorInfo);
219
220 return ChannelShuffleTestImpl<T, 4>(
221 workloadFactory,
222 memoryManager,
223 tensorHandleFactory,
224 descriptor,
225 inputTensorInfo,
226 outputTensorInfo,
227 input,
228 outputExpected);
229}
230
231//
232// Explicit template specializations
233//
234
235template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4>
236SimpleChannelShuffleTest<armnn::DataType::Float32>(
237 armnn::IWorkloadFactory& workloadFactory,
238 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
239 const armnn::ITensorHandleFactory& tensorHandleFactory);
240
241template LayerTestResult<armnn::ResolveType<armnn::DataType::QAsymmU8>, 4>
242SimpleChannelShuffleTest<armnn::DataType::QAsymmU8>(
243 armnn::IWorkloadFactory& workloadFactory,
244 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
245 const armnn::ITensorHandleFactory& tensorHandleFactory);
246
Teresa Charlineb852bb2021-09-30 12:44:33 +0100247template LayerTestResult<armnn::ResolveType<armnn::DataType::QAsymmS8>, 4>
248SimpleChannelShuffleTest<armnn::DataType::QAsymmS8>(
249 armnn::IWorkloadFactory& workloadFactory,
250 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
251 const armnn::ITensorHandleFactory& tensorHandleFactory);
252
Simon Obute51f67772021-09-03 15:50:13 +0100253template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 2>
254ChannelShuffle2DTest<armnn::DataType::Float32>(
255 armnn::IWorkloadFactory& workloadFactory,
256 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
257 const armnn::ITensorHandleFactory& tensorHandleFactory);
258
259template LayerTestResult<armnn::ResolveType<armnn::DataType::QAsymmU8>, 2>
260ChannelShuffle2DTest<armnn::DataType::QAsymmU8>(
261 armnn::IWorkloadFactory& workloadFactory,
262 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
263 const armnn::ITensorHandleFactory& tensorHandleFactory);
264
Teresa Charlineb852bb2021-09-30 12:44:33 +0100265template LayerTestResult<armnn::ResolveType<armnn::DataType::QAsymmS8>, 2>
266ChannelShuffle2DTest<armnn::DataType::QAsymmS8>(
267 armnn::IWorkloadFactory& workloadFactory,
268 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
269 const armnn::ITensorHandleFactory& tensorHandleFactory);
270
Simon Obute51f67772021-09-03 15:50:13 +0100271template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4>
272ChannelShuffle4DTest<armnn::DataType::Float32>(
273 armnn::IWorkloadFactory& workloadFactory,
274 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
275 const armnn::ITensorHandleFactory& tensorHandleFactory);
276
277template LayerTestResult<armnn::ResolveType<armnn::DataType::QAsymmU8>, 4>
278ChannelShuffle4DTest<armnn::DataType::QAsymmU8>(
279 armnn::IWorkloadFactory& workloadFactory,
280 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Teresa Charlineb852bb2021-09-30 12:44:33 +0100281 const armnn::ITensorHandleFactory& tensorHandleFactory);
282
283template LayerTestResult<armnn::ResolveType<armnn::DataType::QAsymmS8>, 4>
284ChannelShuffle4DTest<armnn::DataType::QAsymmS8>(
285 armnn::IWorkloadFactory& workloadFactory,
286 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
287 const armnn::ITensorHandleFactory& tensorHandleFactory);