blob: 4f8b7d019310b54ed19da174e65cdf0cb294b6a5 [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
Colm Donelanc42a9872022-02-02 16:35:09 +000013#include <DataTypeUtils.hpp>
Sadik Armagana097d2a2021-11-24 15:47:28 +000014#include <armnnTestUtils/LayerTestResult.hpp>
15#include <armnnTestUtils/TensorCopyUtils.hpp>
Colm Donelanc42a9872022-02-02 16:35:09 +000016#include <armnnTestUtils/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
Teresa Charlin611c7fb2022-01-07 09:47:29 +000067 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateWorkload(armnn::LayerType::BatchToSpaceNd,
68 data, info);
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010069
70 inputHandle->Allocate();
71 outputHandle->Allocate();
72
Sadik Armagan483c8112021-06-01 09:24:52 +010073 CopyDataToITensorHandle(inputHandle.get(), input.data());
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010074
75 workload->PostAllocationConfigure();
76 workload->Execute();
77
Sadik Armagan483c8112021-06-01 09:24:52 +010078 CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010079
Sadik Armagan483c8112021-06-01 09:24:52 +010080 return LayerTestResult<T, OutputDim>(actualOutput,
81 expectedOutput,
82 outputHandle->GetShape(),
83 outputTensorInfo.GetShape());
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010084}
85
86} // anonymous namespace
87
88template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
89LayerTestResult<T, 4> BatchToSpaceNdNhwcTest1(
90 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +010091 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
92 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010093{
94 const unsigned int inputShape[] = {4, 2, 2, 1};
95 const unsigned int outputShape[] = {1, 4, 4, 1};
96
97 std::vector<float> input({
98 // Batch 0, Height 0, Width (2) x Channel (1)
99 1.0f, 3.0f,
100 // Batch 0, Height 1, Width (2) x Channel (1)
101 9.0f, 11.0f,
102
103
104 // Batch 1, Height 0, Width (2) x Channel (1)
105 2.0f, 4.0f,
106 // Batch 1, Height 1, Width (2) x Channel (1)
107 10.0f, 12.0f,
108
109
110 // Batch 2, Height 0, Width (2) x Channel (1)
111 5.0f, 7.0f,
112 // Batch 2, Height 1, Width (2) x Channel (1)
113 13.0f, 15.0f,
114
115 // Batch 3, Height 0, Width (2) x Channel (3)
116 6.0f, 8.0f,
117 // Batch 3, Height 1, Width (2) x Channel (1)
118 14.0f, 16.0f
119 });
120
121 std::vector<float> expectedOutput({
122 1.0f, 2.0f, 3.0f, 4.0f,
123 5.0f, 6.0f, 7.0f, 8.0f,
124 9.0f, 10.0f, 11.0f, 12.0f,
125 13.0f, 14.0f, 15.0f, 16.0f
126 });
127
128 std::vector<unsigned int> blockShape {2, 2};
129 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
130
Keith Davis33a626f2020-08-27 15:38:12 +0100131 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100132 armnn::DataLayout::NHWC, inputShape, input, blockShape,
133 crops, outputShape, expectedOutput);
134}
135
136template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
137LayerTestResult<T, 4> BatchToSpaceNdNhwcTest2(
138 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100139 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
140 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100141{
142 const unsigned int inputShape[] = {4, 1, 1, 1};
143 const unsigned int outputShape[] = {1, 2, 2, 1};
144
145 std::vector<float> input({
146 // Batch 0, Height 0, Width (2) x Channel (1)
147 1.0f, 2.0f, 3.0f, 4.0f
148 });
149
150 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f});
151
152 std::vector<unsigned int> blockShape({2, 2});
153 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
154
Keith Davis33a626f2020-08-27 15:38:12 +0100155 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100156 armnn::DataLayout::NHWC, inputShape, input, blockShape,
157 crops, outputShape, expectedOutput);
158}
159
160template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
161LayerTestResult<T, 4> BatchToSpaceNdNhwcTest3(
162 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100163 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
164 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100165{
166 const unsigned int inputShape[] = {4, 1, 1, 3};
167 const unsigned int outputShape[] = {1, 2, 2, 3};
168
169 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});
170
171 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});
172
173 std::vector<unsigned int> blockShape({2, 2});
174 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
175
Keith Davis33a626f2020-08-27 15:38:12 +0100176 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100177 armnn::DataLayout::NHWC, inputShape, input, blockShape,
178 crops, outputShape, expectedOutput);
179}
180
181template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
182LayerTestResult<T, 4> BatchToSpaceNdNhwcTest4(
183 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100184 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
185 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100186{
187 const unsigned int inputShape[] = {8, 1, 3, 1};
188 const unsigned int outputShape[] = {2, 2, 4, 1};
189
190 std::vector<float> input({
191 0.0f, 1.0f, 3.0f,
192 0.0f, 9.0f, 11.0f,
193 0.0f, 2.0f, 4.0f,
194 0.0f, 10.0f, 12.0f,
195 0.0f, 5.0f, 7.0f,
196 0.0f, 13.0f, 15.0f,
197 0.0f, 6.0f, 8.0f,
198 0.0f, 14.0f, 16.0f
199 });
200
201 std::vector<float> expectedOutput({
202 1.0f, 2.0f, 3.0f, 4.0f,
203 5.0f, 6.0f, 7.0f, 8.0f,
204 9.0f, 10.0f, 11.0f, 12.0f,
205 13.0f, 14.0f, 15.0f, 16.0f
206 });
207
208 std::vector<unsigned int> blockShape({2, 2});
209 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {2, 0}};
210
Keith Davis33a626f2020-08-27 15:38:12 +0100211 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100212 armnn::DataLayout::NHWC, inputShape, input, blockShape,
213 crops, outputShape, expectedOutput);
214}
215
216template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
217LayerTestResult<T, 4> BatchToSpaceNdNhwcTest5(
218 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100219 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
220 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100221{
222 const unsigned int inputShape[] = {4, 2, 2, 1};
223 const unsigned int outputShape[] = {1, 4, 4, 1};
224
225 std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
226 std::vector<float> expectedOutput({1, 5, 2, 6, 9, 13, 10, 14, 3, 7, 4, 8, 11, 15, 12, 16});
227
228 std::vector<unsigned int> blockShape({2, 2});
229 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
230
Keith Davis33a626f2020-08-27 15:38:12 +0100231 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
232 armnn::DataLayout::NHWC, inputShape,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100233 input, blockShape, crops, outputShape, expectedOutput);
234}
235
236template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
237LayerTestResult<T, 4> BatchToSpaceNdNhwcTest6(
238 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100239 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
240 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100241{
242 const unsigned int inputShape[] = {4, 1, 1, 1};
243 const unsigned int outputShape[] = {1, 2, 2, 1};
244
245 std::vector<float> input({
246 // Batch 0, Height 0, Width (2) x Channel (1)
247 1, 2, 3, 4
248 });
249
250 std::vector<float> expectedOutput({1, 2, 3, 4});
251
252 std::vector<unsigned int> blockShape({2, 2});
253 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
254
Keith Davis33a626f2020-08-27 15:38:12 +0100255 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100256 armnn::DataLayout::NHWC, inputShape, input, blockShape,
257 crops, outputShape, expectedOutput);
258}
259
260template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
261LayerTestResult<T, 4> BatchToSpaceNdNhwcTest7(
262 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100263 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
264 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100265{
266 const unsigned int inputShape[] = {4, 1, 1, 3};
267 const unsigned int outputShape[] = {1, 2, 2, 3};
268
269 std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
270
271 std::vector<float> expectedOutput({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
272
273 std::vector<unsigned int> blockShape({2, 2});
274 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
275
Keith Davis33a626f2020-08-27 15:38:12 +0100276 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100277 armnn::DataLayout::NHWC, inputShape, input, blockShape,
278 crops, outputShape, expectedOutput);
279}
280
281template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
Teresa Charlinf77cab52023-06-01 16:15:13 +0100282LayerTestResult<T, 3> BatchToSpaceNdNhwcTest8(
283 armnn::IWorkloadFactory& workloadFactory,
284 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
285 const armnn::ITensorHandleFactory& tensorHandleFactory)
286{
287 const unsigned int inputShape[] = {4, 2, 1};
288 const unsigned int outputShape[] = {1, 8, 1};
289
290 std::vector<float> input({
291 1.0f, 2.0f, 3.0f, 4.0f,
292 5.0f, 6.0f, 7.0f, 8.0f
293 });
294
295 std::vector<float> expectedOutput({
296 1.0f, 3.0f, 5.0f, 7.0f,
297 2.0f, 4.0f, 6.0f, 8.0f
298 });
299
300 std::vector<unsigned int> blockShape {4};
301 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}};
302
303 return BatchToSpaceNdHelper<ArmnnType, 3, 3>(workloadFactory, memoryManager, tensorHandleFactory,
304 armnn::DataLayout::NHWC, inputShape, input, blockShape,
305 crops, outputShape, expectedOutput);
306}
307
308template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100309LayerTestResult<T, 4> BatchToSpaceNdNchwTest1(
310 armnn::IWorkloadFactory &workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100311 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
312 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100313{
314 const unsigned int inputShape[] = {4, 3, 1, 1};
315 const unsigned int outputShape[] = {1, 3, 2, 2};
316
317 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});
318
319 std::vector<float> expectedOutput({
320 // Batch 0, Channel 0, Height (2) x Width (2)
321 1.0f, 4.0f,
322 7.0f, 10.0f,
323
324 // Batch 0, Channel 1, Height (2) x Width (2)
325 2.0f, 5.0f,
326 8.0f, 11.0f,
327
328 // Batch 0, Channel 2, Height (2) x Width (2)
329 3.0f, 6.0f,
330 9.0f, 12.0f,
331 });
332
333 std::vector<unsigned int> blockShape({2, 2});
334 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
335
Keith Davis33a626f2020-08-27 15:38:12 +0100336 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100337 armnn::DataLayout::NCHW, inputShape, input, blockShape,
338 crops, outputShape, expectedOutput);
339}
340
341template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
342LayerTestResult<T, 4> BatchToSpaceNdNchwTest2(
343 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100344 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
345 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100346{
347 const unsigned int inputShape[] = {4, 1, 1, 1};
348 const unsigned int outputShape[] = {1, 1, 2, 2};
349
350 std::vector<float> input({
351 // Batch 0, Height 0, Width (2) x Channel (1)
352 1.0f, 2.0f, 3.0f, 4.0f
353 });
354
355 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f});
356
357 std::vector<unsigned int> blockShape({2, 2});
358 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
359
Keith Davis33a626f2020-08-27 15:38:12 +0100360 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100361 armnn::DataLayout::NCHW, inputShape, input, blockShape,
362 crops, outputShape, expectedOutput);
363}
364
365template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
366LayerTestResult<T, 4> BatchToSpaceNdNchwTest3(
367 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100368 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
369 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100370{
371 const unsigned int inputShape[] = {4, 3, 1, 1};
372 const unsigned int outputShape[] = {1, 3, 2, 2};
373
374 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});
375
376 std::vector<float> expectedOutput({
377 // Batch 0, Channel 0, Height (2) x Width (2)
378 1.0f, 7.0f,
379 2.0f, 8.0f,
380
381 // Batch 0, Channel 1, Height (2) x Width (2)
382 3.0f, 9.0f,
383 4.0f, 10.0f,
384
385 // Batch 0, Channel 2, Height (2) x Width (2)
386 5.0f, 11.0f,
387 6.0f, 12.0f,
388 });
389
390 std::vector<unsigned int> blockShape({2, 2});
391 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
392
Keith Davis33a626f2020-08-27 15:38:12 +0100393 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100394 armnn::DataLayout::NCHW, inputShape, input, blockShape,
395 crops, outputShape, expectedOutput);
396}
397
398template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
399LayerTestResult<T, 4> BatchToSpaceNdNchwTest4(
400 armnn::IWorkloadFactory &workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100401 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
402 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100403{
404 const unsigned int inputShape[] = {4, 3, 1, 1};
405 const unsigned int outputShape[] = {1, 3, 2, 2};
406
407 std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
408
409 std::vector<float> expectedOutput({
410 // Batch 0, Channel 0, Height (2) x Width (2)
411 1, 4,
412 7, 10,
413
414 // Batch 0, Channel 1, Height (2) x Width (2)
415 2, 5,
416 8, 11,
417
418 // Batch 0, Channel 2, Height (2) x Width (2)
419 3, 6,
420 9, 12,
421 });
422
423 std::vector<unsigned int> blockShape({2, 2});
424 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
425
Keith Davis33a626f2020-08-27 15:38:12 +0100426 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100427 armnn::DataLayout::NCHW, inputShape, input, blockShape,
428 crops, outputShape, expectedOutput);
429}
430
431template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
432LayerTestResult<T, 4> BatchToSpaceNdNchwTest5(
433 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100434 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
435 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100436{
437 const unsigned int inputShape[] = {4, 1, 1, 1};
438 const unsigned int outputShape[] = {1, 1, 2, 2};
439
440 std::vector<float> input({
441 // Batch 0, Height 0, Width (2) x Channel (1)
442 1, 2, 3, 4
443 });
444
445 std::vector<float> expectedOutput({1, 2, 3, 4});
446
447 std::vector<unsigned int> blockShape({2, 2});
448 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
449
Keith Davis33a626f2020-08-27 15:38:12 +0100450 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100451 armnn::DataLayout::NCHW, inputShape, input, blockShape,
452 crops, outputShape, expectedOutput);
453}
454
455template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
456LayerTestResult<T, 4> BatchToSpaceNdNchwTest6(
457 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100458 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
459 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100460{
461 const unsigned int inputShape[] = {4, 3, 1, 1};
462 const unsigned int outputShape[] = {1, 3, 2, 2};
463
464 std::vector<float> input({1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12});
465
466 std::vector<float> expectedOutput({
467 // Batch 0, Channel 0, Height (2) x Width (2)
468 1, 7,
469 2, 8,
470
471 // Batch 0, Channel 1, Height (2) x Width (2)
472 3, 9,
473 4, 10,
474
475 // Batch 0, Channel 2, Height (2) x Width (2)
476 5, 11,
477 6, 12,
478 });
479
480 std::vector<unsigned int> blockShape({2, 2});
481 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
482
Keith Davis33a626f2020-08-27 15:38:12 +0100483 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100484 armnn::DataLayout::NCHW, inputShape, input, blockShape,
485 crops, outputShape, expectedOutput);
486}
487
488template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
489LayerTestResult<T, 4> BatchToSpaceNdNchwTest7(
490 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100491 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
492 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100493{
494 const unsigned int inputShape[] = {8, 1, 1, 3};
495 const unsigned int outputShape[] = {2, 1, 2, 4};
496
497 std::vector<float> input({
498 0, 1, 3, 0, 9, 11,
499 0, 2, 4, 0, 10, 12,
500 0, 5, 7, 0, 13, 15,
501 0, 6, 8, 0, 14, 16
502 });
503
504 std::vector<float> expectedOutput({
505 1, 2, 3, 4,
506 5, 6, 7, 8,
507 9, 10, 11, 12,
508 13, 14, 15, 16
509 });
510
511 std::vector<unsigned int> blockShape({2, 2});
512 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {2, 0}};
513
Keith Davis33a626f2020-08-27 15:38:12 +0100514 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100515 armnn::DataLayout::NCHW, inputShape, input, blockShape,
516 crops, outputShape, expectedOutput);
517}