blob: 23e790f15aa75376ba0b333852ffc839c50970b1 [file] [log] [blame]
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +01001//
Teresa Charlinfbf0e5b2020-08-17 01:01:06 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +01003// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +01008#include <ResolveType.hpp>
9
Matteo Martincighe5b8eb92019-11-28 15:45:42 +000010#include <armnn/backends/IBackendInternal.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +000011#include <armnn/backends/WorkloadFactory.hpp>
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010012
Sadik Armagana097d2a2021-11-24 15:47:28 +000013#include <armnnTestUtils/LayerTestResult.hpp>
14#include <armnnTestUtils/TensorCopyUtils.hpp>
15#include <DataTypeUtils.hpp>
16#include <TensorHelpers.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +000017#include <armnnTestUtils/WorkloadTestUtils.hpp>
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010018
19namespace
20{
21
22template<armnn::DataType ArmnnType,
23 std::size_t InputDim,
24 std::size_t OutputDim,
25 typename T = armnn::ResolveType<ArmnnType>>
26LayerTestResult<T, OutputDim> BatchToSpaceNdHelper(
27 armnn::IWorkloadFactory &workloadFactory,
28 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Keith Davis33a626f2020-08-27 15:38:12 +010029 const armnn::ITensorHandleFactory& tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010030 const armnn::DataLayout& dataLayout,
31 const unsigned int *inputShape,
32 const std::vector<float> &inputData,
33 const std::vector<unsigned int> &blockShape,
34 const std::vector<std::pair<unsigned int, unsigned int>> &crops,
35 const unsigned int *outputShape,
36 const std::vector<float> &outputData,
37 float scale = 1.0f,
38 int32_t offset = 0)
39{
Jan Eilers8eb25602020-03-09 12:13:48 +000040 IgnoreUnused(memoryManager);
Derek Lambertic374ff02019-12-10 21:57:35 +000041
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010042 armnn::TensorInfo inputTensorInfo(InputDim, inputShape, ArmnnType);
43 armnn::TensorInfo outputTensorInfo(OutputDim, outputShape, ArmnnType);
44
45 inputTensorInfo.SetQuantizationScale(scale);
46 inputTensorInfo.SetQuantizationOffset(offset);
47
48 outputTensorInfo.SetQuantizationScale(scale);
49 outputTensorInfo.SetQuantizationOffset(offset);
50
Sadik Armagan483c8112021-06-01 09:24:52 +010051 std::vector<T> input = ConvertToDataType<ArmnnType>(inputData, inputTensorInfo);
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010052
Sadik Armagan483c8112021-06-01 09:24:52 +010053 std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
54 std::vector<T> expectedOutput = ConvertToDataType<ArmnnType>(outputData, outputTensorInfo);
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010055
Keith Davis33a626f2020-08-27 15:38:12 +010056 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
57 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010058
59 armnn::BatchToSpaceNdQueueDescriptor data;
60 data.m_Parameters.m_DataLayout = dataLayout;
61 data.m_Parameters.m_BlockShape = blockShape;
62 data.m_Parameters.m_Crops = crops;
63 armnn::WorkloadInfo info;
64 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
65 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
66
67 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchToSpaceNd(data, info);
68
69 inputHandle->Allocate();
70 outputHandle->Allocate();
71
Sadik Armagan483c8112021-06-01 09:24:52 +010072 CopyDataToITensorHandle(inputHandle.get(), input.data());
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010073
74 workload->PostAllocationConfigure();
75 workload->Execute();
76
Sadik Armagan483c8112021-06-01 09:24:52 +010077 CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010078
Sadik Armagan483c8112021-06-01 09:24:52 +010079 return LayerTestResult<T, OutputDim>(actualOutput,
80 expectedOutput,
81 outputHandle->GetShape(),
82 outputTensorInfo.GetShape());
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010083}
84
85} // anonymous namespace
86
87template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
88LayerTestResult<T, 4> BatchToSpaceNdNhwcTest1(
89 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +010090 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
91 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010092{
93 const unsigned int inputShape[] = {4, 2, 2, 1};
94 const unsigned int outputShape[] = {1, 4, 4, 1};
95
96 std::vector<float> input({
97 // Batch 0, Height 0, Width (2) x Channel (1)
98 1.0f, 3.0f,
99 // Batch 0, Height 1, Width (2) x Channel (1)
100 9.0f, 11.0f,
101
102
103 // Batch 1, Height 0, Width (2) x Channel (1)
104 2.0f, 4.0f,
105 // Batch 1, Height 1, Width (2) x Channel (1)
106 10.0f, 12.0f,
107
108
109 // Batch 2, Height 0, Width (2) x Channel (1)
110 5.0f, 7.0f,
111 // Batch 2, Height 1, Width (2) x Channel (1)
112 13.0f, 15.0f,
113
114 // Batch 3, Height 0, Width (2) x Channel (3)
115 6.0f, 8.0f,
116 // Batch 3, Height 1, Width (2) x Channel (1)
117 14.0f, 16.0f
118 });
119
120 std::vector<float> expectedOutput({
121 1.0f, 2.0f, 3.0f, 4.0f,
122 5.0f, 6.0f, 7.0f, 8.0f,
123 9.0f, 10.0f, 11.0f, 12.0f,
124 13.0f, 14.0f, 15.0f, 16.0f
125 });
126
127 std::vector<unsigned int> blockShape {2, 2};
128 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
129
Keith Davis33a626f2020-08-27 15:38:12 +0100130 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100131 armnn::DataLayout::NHWC, inputShape, input, blockShape,
132 crops, outputShape, expectedOutput);
133}
134
135template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
136LayerTestResult<T, 4> BatchToSpaceNdNhwcTest2(
137 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100138 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
139 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100140{
141 const unsigned int inputShape[] = {4, 1, 1, 1};
142 const unsigned int outputShape[] = {1, 2, 2, 1};
143
144 std::vector<float> input({
145 // Batch 0, Height 0, Width (2) x Channel (1)
146 1.0f, 2.0f, 3.0f, 4.0f
147 });
148
149 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f});
150
151 std::vector<unsigned int> blockShape({2, 2});
152 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
153
Keith Davis33a626f2020-08-27 15:38:12 +0100154 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100155 armnn::DataLayout::NHWC, inputShape, input, blockShape,
156 crops, outputShape, expectedOutput);
157}
158
159template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
160LayerTestResult<T, 4> BatchToSpaceNdNhwcTest3(
161 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100162 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
163 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100164{
165 const unsigned int inputShape[] = {4, 1, 1, 3};
166 const unsigned int outputShape[] = {1, 2, 2, 3};
167
168 std::vector<float> input({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f});
169
170 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f});
171
172 std::vector<unsigned int> blockShape({2, 2});
173 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
174
Keith Davis33a626f2020-08-27 15:38:12 +0100175 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100176 armnn::DataLayout::NHWC, inputShape, input, blockShape,
177 crops, outputShape, expectedOutput);
178}
179
180template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
181LayerTestResult<T, 4> BatchToSpaceNdNhwcTest4(
182 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100183 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
184 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100185{
186 const unsigned int inputShape[] = {8, 1, 3, 1};
187 const unsigned int outputShape[] = {2, 2, 4, 1};
188
189 std::vector<float> input({
190 0.0f, 1.0f, 3.0f,
191 0.0f, 9.0f, 11.0f,
192 0.0f, 2.0f, 4.0f,
193 0.0f, 10.0f, 12.0f,
194 0.0f, 5.0f, 7.0f,
195 0.0f, 13.0f, 15.0f,
196 0.0f, 6.0f, 8.0f,
197 0.0f, 14.0f, 16.0f
198 });
199
200 std::vector<float> expectedOutput({
201 1.0f, 2.0f, 3.0f, 4.0f,
202 5.0f, 6.0f, 7.0f, 8.0f,
203 9.0f, 10.0f, 11.0f, 12.0f,
204 13.0f, 14.0f, 15.0f, 16.0f
205 });
206
207 std::vector<unsigned int> blockShape({2, 2});
208 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {2, 0}};
209
Keith Davis33a626f2020-08-27 15:38:12 +0100210 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100211 armnn::DataLayout::NHWC, inputShape, input, blockShape,
212 crops, outputShape, expectedOutput);
213}
214
215template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
216LayerTestResult<T, 4> BatchToSpaceNdNhwcTest5(
217 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100218 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
219 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100220{
221 const unsigned int inputShape[] = {4, 2, 2, 1};
222 const unsigned int outputShape[] = {1, 4, 4, 1};
223
224 std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
225 std::vector<float> expectedOutput({1, 5, 2, 6, 9, 13, 10, 14, 3, 7, 4, 8, 11, 15, 12, 16});
226
227 std::vector<unsigned int> blockShape({2, 2});
228 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
229
Keith Davis33a626f2020-08-27 15:38:12 +0100230 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
231 armnn::DataLayout::NHWC, inputShape,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100232 input, blockShape, crops, outputShape, expectedOutput);
233}
234
235template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
236LayerTestResult<T, 4> BatchToSpaceNdNhwcTest6(
237 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100238 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
239 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100240{
241 const unsigned int inputShape[] = {4, 1, 1, 1};
242 const unsigned int outputShape[] = {1, 2, 2, 1};
243
244 std::vector<float> input({
245 // Batch 0, Height 0, Width (2) x Channel (1)
246 1, 2, 3, 4
247 });
248
249 std::vector<float> expectedOutput({1, 2, 3, 4});
250
251 std::vector<unsigned int> blockShape({2, 2});
252 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
253
Keith Davis33a626f2020-08-27 15:38:12 +0100254 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100255 armnn::DataLayout::NHWC, inputShape, input, blockShape,
256 crops, outputShape, expectedOutput);
257}
258
259template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
260LayerTestResult<T, 4> BatchToSpaceNdNhwcTest7(
261 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100262 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
263 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100264{
265 const unsigned int inputShape[] = {4, 1, 1, 3};
266 const unsigned int outputShape[] = {1, 2, 2, 3};
267
268 std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
269
270 std::vector<float> expectedOutput({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
271
272 std::vector<unsigned int> blockShape({2, 2});
273 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
274
Keith Davis33a626f2020-08-27 15:38:12 +0100275 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100276 armnn::DataLayout::NHWC, inputShape, input, blockShape,
277 crops, outputShape, expectedOutput);
278}
279
280template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
281LayerTestResult<T, 4> BatchToSpaceNdNchwTest1(
282 armnn::IWorkloadFactory &workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100283 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
284 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100285{
286 const unsigned int inputShape[] = {4, 3, 1, 1};
287 const unsigned int outputShape[] = {1, 3, 2, 2};
288
289 std::vector<float> input({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f});
290
291 std::vector<float> expectedOutput({
292 // Batch 0, Channel 0, Height (2) x Width (2)
293 1.0f, 4.0f,
294 7.0f, 10.0f,
295
296 // Batch 0, Channel 1, Height (2) x Width (2)
297 2.0f, 5.0f,
298 8.0f, 11.0f,
299
300 // Batch 0, Channel 2, Height (2) x Width (2)
301 3.0f, 6.0f,
302 9.0f, 12.0f,
303 });
304
305 std::vector<unsigned int> blockShape({2, 2});
306 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
307
Keith Davis33a626f2020-08-27 15:38:12 +0100308 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100309 armnn::DataLayout::NCHW, inputShape, input, blockShape,
310 crops, outputShape, expectedOutput);
311}
312
313template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
314LayerTestResult<T, 4> BatchToSpaceNdNchwTest2(
315 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100316 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
317 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100318{
319 const unsigned int inputShape[] = {4, 1, 1, 1};
320 const unsigned int outputShape[] = {1, 1, 2, 2};
321
322 std::vector<float> input({
323 // Batch 0, Height 0, Width (2) x Channel (1)
324 1.0f, 2.0f, 3.0f, 4.0f
325 });
326
327 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f});
328
329 std::vector<unsigned int> blockShape({2, 2});
330 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
331
Keith Davis33a626f2020-08-27 15:38:12 +0100332 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100333 armnn::DataLayout::NCHW, inputShape, input, blockShape,
334 crops, outputShape, expectedOutput);
335}
336
337template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
338LayerTestResult<T, 4> BatchToSpaceNdNchwTest3(
339 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100340 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
341 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100342{
343 const unsigned int inputShape[] = {4, 3, 1, 1};
344 const unsigned int outputShape[] = {1, 3, 2, 2};
345
346 std::vector<float> input({1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f});
347
348 std::vector<float> expectedOutput({
349 // Batch 0, Channel 0, Height (2) x Width (2)
350 1.0f, 7.0f,
351 2.0f, 8.0f,
352
353 // Batch 0, Channel 1, Height (2) x Width (2)
354 3.0f, 9.0f,
355 4.0f, 10.0f,
356
357 // Batch 0, Channel 2, Height (2) x Width (2)
358 5.0f, 11.0f,
359 6.0f, 12.0f,
360 });
361
362 std::vector<unsigned int> blockShape({2, 2});
363 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
364
Keith Davis33a626f2020-08-27 15:38:12 +0100365 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100366 armnn::DataLayout::NCHW, inputShape, input, blockShape,
367 crops, outputShape, expectedOutput);
368}
369
370template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
371LayerTestResult<T, 4> BatchToSpaceNdNchwTest4(
372 armnn::IWorkloadFactory &workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100373 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
374 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100375{
376 const unsigned int inputShape[] = {4, 3, 1, 1};
377 const unsigned int outputShape[] = {1, 3, 2, 2};
378
379 std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
380
381 std::vector<float> expectedOutput({
382 // Batch 0, Channel 0, Height (2) x Width (2)
383 1, 4,
384 7, 10,
385
386 // Batch 0, Channel 1, Height (2) x Width (2)
387 2, 5,
388 8, 11,
389
390 // Batch 0, Channel 2, Height (2) x Width (2)
391 3, 6,
392 9, 12,
393 });
394
395 std::vector<unsigned int> blockShape({2, 2});
396 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
397
Keith Davis33a626f2020-08-27 15:38:12 +0100398 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100399 armnn::DataLayout::NCHW, inputShape, input, blockShape,
400 crops, outputShape, expectedOutput);
401}
402
403template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
404LayerTestResult<T, 4> BatchToSpaceNdNchwTest5(
405 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100406 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
407 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100408{
409 const unsigned int inputShape[] = {4, 1, 1, 1};
410 const unsigned int outputShape[] = {1, 1, 2, 2};
411
412 std::vector<float> input({
413 // Batch 0, Height 0, Width (2) x Channel (1)
414 1, 2, 3, 4
415 });
416
417 std::vector<float> expectedOutput({1, 2, 3, 4});
418
419 std::vector<unsigned int> blockShape({2, 2});
420 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
421
Keith Davis33a626f2020-08-27 15:38:12 +0100422 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100423 armnn::DataLayout::NCHW, inputShape, input, blockShape,
424 crops, outputShape, expectedOutput);
425}
426
427template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
428LayerTestResult<T, 4> BatchToSpaceNdNchwTest6(
429 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100430 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
431 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100432{
433 const unsigned int inputShape[] = {4, 3, 1, 1};
434 const unsigned int outputShape[] = {1, 3, 2, 2};
435
436 std::vector<float> input({1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12});
437
438 std::vector<float> expectedOutput({
439 // Batch 0, Channel 0, Height (2) x Width (2)
440 1, 7,
441 2, 8,
442
443 // Batch 0, Channel 1, Height (2) x Width (2)
444 3, 9,
445 4, 10,
446
447 // Batch 0, Channel 2, Height (2) x Width (2)
448 5, 11,
449 6, 12,
450 });
451
452 std::vector<unsigned int> blockShape({2, 2});
453 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
454
Keith Davis33a626f2020-08-27 15:38:12 +0100455 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100456 armnn::DataLayout::NCHW, inputShape, input, blockShape,
457 crops, outputShape, expectedOutput);
458}
459
460template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
461LayerTestResult<T, 4> BatchToSpaceNdNchwTest7(
462 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100463 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
464 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100465{
466 const unsigned int inputShape[] = {8, 1, 1, 3};
467 const unsigned int outputShape[] = {2, 1, 2, 4};
468
469 std::vector<float> input({
470 0, 1, 3, 0, 9, 11,
471 0, 2, 4, 0, 10, 12,
472 0, 5, 7, 0, 13, 15,
473 0, 6, 8, 0, 14, 16
474 });
475
476 std::vector<float> expectedOutput({
477 1, 2, 3, 4,
478 5, 6, 7, 8,
479 9, 10, 11, 12,
480 13, 14, 15, 16
481 });
482
483 std::vector<unsigned int> blockShape({2, 2});
484 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {2, 0}};
485
Keith Davis33a626f2020-08-27 15:38:12 +0100486 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100487 armnn::DataLayout::NCHW, inputShape, input, blockShape,
488 crops, outputShape, expectedOutput);
489}