blob: 3669281d488d3b9e45b5e48e81b9aab5cb7a322b [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
8#include "LayerTestResult.hpp"
9
10#include <ResolveType.hpp>
11
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010012
Matteo Martincighe5b8eb92019-11-28 15:45:42 +000013#include <armnn/backends/IBackendInternal.hpp>
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010014#include <backendsCommon/WorkloadFactory.hpp>
15
16#include <backendsCommon/test/DataTypeUtils.hpp>
17#include <backendsCommon/test/TensorCopyUtils.hpp>
18#include <backendsCommon/test/WorkloadTestUtils.hpp>
19
20#include <test/TensorHelpers.hpp>
21
22namespace
23{
24
25template<armnn::DataType ArmnnType,
26 std::size_t InputDim,
27 std::size_t OutputDim,
28 typename T = armnn::ResolveType<ArmnnType>>
29LayerTestResult<T, OutputDim> BatchToSpaceNdHelper(
30 armnn::IWorkloadFactory &workloadFactory,
31 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Keith Davis33a626f2020-08-27 15:38:12 +010032 const armnn::ITensorHandleFactory& tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010033 const armnn::DataLayout& dataLayout,
34 const unsigned int *inputShape,
35 const std::vector<float> &inputData,
36 const std::vector<unsigned int> &blockShape,
37 const std::vector<std::pair<unsigned int, unsigned int>> &crops,
38 const unsigned int *outputShape,
39 const std::vector<float> &outputData,
40 float scale = 1.0f,
41 int32_t offset = 0)
42{
Jan Eilers8eb25602020-03-09 12:13:48 +000043 IgnoreUnused(memoryManager);
Derek Lambertic374ff02019-12-10 21:57:35 +000044
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010045 armnn::TensorInfo inputTensorInfo(InputDim, inputShape, ArmnnType);
46 armnn::TensorInfo outputTensorInfo(OutputDim, outputShape, ArmnnType);
47
48 inputTensorInfo.SetQuantizationScale(scale);
49 inputTensorInfo.SetQuantizationOffset(offset);
50
51 outputTensorInfo.SetQuantizationScale(scale);
52 outputTensorInfo.SetQuantizationOffset(offset);
53
Sadik Armagan483c8112021-06-01 09:24:52 +010054 std::vector<T> input = ConvertToDataType<ArmnnType>(inputData, inputTensorInfo);
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010055
Sadik Armagan483c8112021-06-01 09:24:52 +010056 std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
57 std::vector<T> expectedOutput = ConvertToDataType<ArmnnType>(outputData, outputTensorInfo);
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010058
Keith Davis33a626f2020-08-27 15:38:12 +010059 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
60 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010061
62 armnn::BatchToSpaceNdQueueDescriptor data;
63 data.m_Parameters.m_DataLayout = dataLayout;
64 data.m_Parameters.m_BlockShape = blockShape;
65 data.m_Parameters.m_Crops = crops;
66 armnn::WorkloadInfo info;
67 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
68 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
69
70 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchToSpaceNd(data, info);
71
72 inputHandle->Allocate();
73 outputHandle->Allocate();
74
Sadik Armagan483c8112021-06-01 09:24:52 +010075 CopyDataToITensorHandle(inputHandle.get(), input.data());
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010076
77 workload->PostAllocationConfigure();
78 workload->Execute();
79
Sadik Armagan483c8112021-06-01 09:24:52 +010080 CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010081
Sadik Armagan483c8112021-06-01 09:24:52 +010082 return LayerTestResult<T, OutputDim>(actualOutput,
83 expectedOutput,
84 outputHandle->GetShape(),
85 outputTensorInfo.GetShape());
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010086}
87
88} // anonymous namespace
89
90template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
91LayerTestResult<T, 4> BatchToSpaceNdNhwcTest1(
92 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +010093 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
94 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +010095{
96 const unsigned int inputShape[] = {4, 2, 2, 1};
97 const unsigned int outputShape[] = {1, 4, 4, 1};
98
99 std::vector<float> input({
100 // Batch 0, Height 0, Width (2) x Channel (1)
101 1.0f, 3.0f,
102 // Batch 0, Height 1, Width (2) x Channel (1)
103 9.0f, 11.0f,
104
105
106 // Batch 1, Height 0, Width (2) x Channel (1)
107 2.0f, 4.0f,
108 // Batch 1, Height 1, Width (2) x Channel (1)
109 10.0f, 12.0f,
110
111
112 // Batch 2, Height 0, Width (2) x Channel (1)
113 5.0f, 7.0f,
114 // Batch 2, Height 1, Width (2) x Channel (1)
115 13.0f, 15.0f,
116
117 // Batch 3, Height 0, Width (2) x Channel (3)
118 6.0f, 8.0f,
119 // Batch 3, Height 1, Width (2) x Channel (1)
120 14.0f, 16.0f
121 });
122
123 std::vector<float> expectedOutput({
124 1.0f, 2.0f, 3.0f, 4.0f,
125 5.0f, 6.0f, 7.0f, 8.0f,
126 9.0f, 10.0f, 11.0f, 12.0f,
127 13.0f, 14.0f, 15.0f, 16.0f
128 });
129
130 std::vector<unsigned int> blockShape {2, 2};
131 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
132
Keith Davis33a626f2020-08-27 15:38:12 +0100133 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100134 armnn::DataLayout::NHWC, inputShape, input, blockShape,
135 crops, outputShape, expectedOutput);
136}
137
138template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
139LayerTestResult<T, 4> BatchToSpaceNdNhwcTest2(
140 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100141 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
142 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100143{
144 const unsigned int inputShape[] = {4, 1, 1, 1};
145 const unsigned int outputShape[] = {1, 2, 2, 1};
146
147 std::vector<float> input({
148 // Batch 0, Height 0, Width (2) x Channel (1)
149 1.0f, 2.0f, 3.0f, 4.0f
150 });
151
152 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f});
153
154 std::vector<unsigned int> blockShape({2, 2});
155 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
156
Keith Davis33a626f2020-08-27 15:38:12 +0100157 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100158 armnn::DataLayout::NHWC, inputShape, input, blockShape,
159 crops, outputShape, expectedOutput);
160}
161
162template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
163LayerTestResult<T, 4> BatchToSpaceNdNhwcTest3(
164 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100165 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
166 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100167{
168 const unsigned int inputShape[] = {4, 1, 1, 3};
169 const unsigned int outputShape[] = {1, 2, 2, 3};
170
171 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});
172
173 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});
174
175 std::vector<unsigned int> blockShape({2, 2});
176 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
177
Keith Davis33a626f2020-08-27 15:38:12 +0100178 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100179 armnn::DataLayout::NHWC, inputShape, input, blockShape,
180 crops, outputShape, expectedOutput);
181}
182
183template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
184LayerTestResult<T, 4> BatchToSpaceNdNhwcTest4(
185 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100186 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
187 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100188{
189 const unsigned int inputShape[] = {8, 1, 3, 1};
190 const unsigned int outputShape[] = {2, 2, 4, 1};
191
192 std::vector<float> input({
193 0.0f, 1.0f, 3.0f,
194 0.0f, 9.0f, 11.0f,
195 0.0f, 2.0f, 4.0f,
196 0.0f, 10.0f, 12.0f,
197 0.0f, 5.0f, 7.0f,
198 0.0f, 13.0f, 15.0f,
199 0.0f, 6.0f, 8.0f,
200 0.0f, 14.0f, 16.0f
201 });
202
203 std::vector<float> expectedOutput({
204 1.0f, 2.0f, 3.0f, 4.0f,
205 5.0f, 6.0f, 7.0f, 8.0f,
206 9.0f, 10.0f, 11.0f, 12.0f,
207 13.0f, 14.0f, 15.0f, 16.0f
208 });
209
210 std::vector<unsigned int> blockShape({2, 2});
211 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {2, 0}};
212
Keith Davis33a626f2020-08-27 15:38:12 +0100213 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100214 armnn::DataLayout::NHWC, inputShape, input, blockShape,
215 crops, outputShape, expectedOutput);
216}
217
218template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
219LayerTestResult<T, 4> BatchToSpaceNdNhwcTest5(
220 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100221 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
222 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100223{
224 const unsigned int inputShape[] = {4, 2, 2, 1};
225 const unsigned int outputShape[] = {1, 4, 4, 1};
226
227 std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
228 std::vector<float> expectedOutput({1, 5, 2, 6, 9, 13, 10, 14, 3, 7, 4, 8, 11, 15, 12, 16});
229
230 std::vector<unsigned int> blockShape({2, 2});
231 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
232
Keith Davis33a626f2020-08-27 15:38:12 +0100233 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
234 armnn::DataLayout::NHWC, inputShape,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100235 input, blockShape, crops, outputShape, expectedOutput);
236}
237
238template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
239LayerTestResult<T, 4> BatchToSpaceNdNhwcTest6(
240 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100241 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
242 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100243{
244 const unsigned int inputShape[] = {4, 1, 1, 1};
245 const unsigned int outputShape[] = {1, 2, 2, 1};
246
247 std::vector<float> input({
248 // Batch 0, Height 0, Width (2) x Channel (1)
249 1, 2, 3, 4
250 });
251
252 std::vector<float> expectedOutput({1, 2, 3, 4});
253
254 std::vector<unsigned int> blockShape({2, 2});
255 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
256
Keith Davis33a626f2020-08-27 15:38:12 +0100257 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100258 armnn::DataLayout::NHWC, inputShape, input, blockShape,
259 crops, outputShape, expectedOutput);
260}
261
262template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
263LayerTestResult<T, 4> BatchToSpaceNdNhwcTest7(
264 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100265 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
266 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100267{
268 const unsigned int inputShape[] = {4, 1, 1, 3};
269 const unsigned int outputShape[] = {1, 2, 2, 3};
270
271 std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
272
273 std::vector<float> expectedOutput({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
274
275 std::vector<unsigned int> blockShape({2, 2});
276 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
277
Keith Davis33a626f2020-08-27 15:38:12 +0100278 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100279 armnn::DataLayout::NHWC, inputShape, input, blockShape,
280 crops, outputShape, expectedOutput);
281}
282
283template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
284LayerTestResult<T, 4> BatchToSpaceNdNchwTest1(
285 armnn::IWorkloadFactory &workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100286 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
287 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100288{
289 const unsigned int inputShape[] = {4, 3, 1, 1};
290 const unsigned int outputShape[] = {1, 3, 2, 2};
291
292 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});
293
294 std::vector<float> expectedOutput({
295 // Batch 0, Channel 0, Height (2) x Width (2)
296 1.0f, 4.0f,
297 7.0f, 10.0f,
298
299 // Batch 0, Channel 1, Height (2) x Width (2)
300 2.0f, 5.0f,
301 8.0f, 11.0f,
302
303 // Batch 0, Channel 2, Height (2) x Width (2)
304 3.0f, 6.0f,
305 9.0f, 12.0f,
306 });
307
308 std::vector<unsigned int> blockShape({2, 2});
309 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
310
Keith Davis33a626f2020-08-27 15:38:12 +0100311 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100312 armnn::DataLayout::NCHW, inputShape, input, blockShape,
313 crops, outputShape, expectedOutput);
314}
315
316template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
317LayerTestResult<T, 4> BatchToSpaceNdNchwTest2(
318 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100319 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
320 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100321{
322 const unsigned int inputShape[] = {4, 1, 1, 1};
323 const unsigned int outputShape[] = {1, 1, 2, 2};
324
325 std::vector<float> input({
326 // Batch 0, Height 0, Width (2) x Channel (1)
327 1.0f, 2.0f, 3.0f, 4.0f
328 });
329
330 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f});
331
332 std::vector<unsigned int> blockShape({2, 2});
333 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
334
Keith Davis33a626f2020-08-27 15:38:12 +0100335 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100336 armnn::DataLayout::NCHW, inputShape, input, blockShape,
337 crops, outputShape, expectedOutput);
338}
339
340template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
341LayerTestResult<T, 4> BatchToSpaceNdNchwTest3(
342 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100343 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
344 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100345{
346 const unsigned int inputShape[] = {4, 3, 1, 1};
347 const unsigned int outputShape[] = {1, 3, 2, 2};
348
349 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});
350
351 std::vector<float> expectedOutput({
352 // Batch 0, Channel 0, Height (2) x Width (2)
353 1.0f, 7.0f,
354 2.0f, 8.0f,
355
356 // Batch 0, Channel 1, Height (2) x Width (2)
357 3.0f, 9.0f,
358 4.0f, 10.0f,
359
360 // Batch 0, Channel 2, Height (2) x Width (2)
361 5.0f, 11.0f,
362 6.0f, 12.0f,
363 });
364
365 std::vector<unsigned int> blockShape({2, 2});
366 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
367
Keith Davis33a626f2020-08-27 15:38:12 +0100368 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100369 armnn::DataLayout::NCHW, inputShape, input, blockShape,
370 crops, outputShape, expectedOutput);
371}
372
373template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
374LayerTestResult<T, 4> BatchToSpaceNdNchwTest4(
375 armnn::IWorkloadFactory &workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100376 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
377 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100378{
379 const unsigned int inputShape[] = {4, 3, 1, 1};
380 const unsigned int outputShape[] = {1, 3, 2, 2};
381
382 std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
383
384 std::vector<float> expectedOutput({
385 // Batch 0, Channel 0, Height (2) x Width (2)
386 1, 4,
387 7, 10,
388
389 // Batch 0, Channel 1, Height (2) x Width (2)
390 2, 5,
391 8, 11,
392
393 // Batch 0, Channel 2, Height (2) x Width (2)
394 3, 6,
395 9, 12,
396 });
397
398 std::vector<unsigned int> blockShape({2, 2});
399 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
400
Keith Davis33a626f2020-08-27 15:38:12 +0100401 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100402 armnn::DataLayout::NCHW, inputShape, input, blockShape,
403 crops, outputShape, expectedOutput);
404}
405
406template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
407LayerTestResult<T, 4> BatchToSpaceNdNchwTest5(
408 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100409 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
410 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100411{
412 const unsigned int inputShape[] = {4, 1, 1, 1};
413 const unsigned int outputShape[] = {1, 1, 2, 2};
414
415 std::vector<float> input({
416 // Batch 0, Height 0, Width (2) x Channel (1)
417 1, 2, 3, 4
418 });
419
420 std::vector<float> expectedOutput({1, 2, 3, 4});
421
422 std::vector<unsigned int> blockShape({2, 2});
423 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
424
Keith Davis33a626f2020-08-27 15:38:12 +0100425 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100426 armnn::DataLayout::NCHW, inputShape, input, blockShape,
427 crops, outputShape, expectedOutput);
428}
429
430template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
431LayerTestResult<T, 4> BatchToSpaceNdNchwTest6(
432 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100433 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
434 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100435{
436 const unsigned int inputShape[] = {4, 3, 1, 1};
437 const unsigned int outputShape[] = {1, 3, 2, 2};
438
439 std::vector<float> input({1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12});
440
441 std::vector<float> expectedOutput({
442 // Batch 0, Channel 0, Height (2) x Width (2)
443 1, 7,
444 2, 8,
445
446 // Batch 0, Channel 1, Height (2) x Width (2)
447 3, 9,
448 4, 10,
449
450 // Batch 0, Channel 2, Height (2) x Width (2)
451 5, 11,
452 6, 12,
453 });
454
455 std::vector<unsigned int> blockShape({2, 2});
456 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
457
Keith Davis33a626f2020-08-27 15:38:12 +0100458 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100459 armnn::DataLayout::NCHW, inputShape, input, blockShape,
460 crops, outputShape, expectedOutput);
461}
462
463template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
464LayerTestResult<T, 4> BatchToSpaceNdNchwTest7(
465 armnn::IWorkloadFactory& workloadFactory,
Keith Davis33a626f2020-08-27 15:38:12 +0100466 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
467 const armnn::ITensorHandleFactory& tensorHandleFactory)
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100468{
469 const unsigned int inputShape[] = {8, 1, 1, 3};
470 const unsigned int outputShape[] = {2, 1, 2, 4};
471
472 std::vector<float> input({
473 0, 1, 3, 0, 9, 11,
474 0, 2, 4, 0, 10, 12,
475 0, 5, 7, 0, 13, 15,
476 0, 6, 8, 0, 14, 16
477 });
478
479 std::vector<float> expectedOutput({
480 1, 2, 3, 4,
481 5, 6, 7, 8,
482 9, 10, 11, 12,
483 13, 14, 15, 16
484 });
485
486 std::vector<unsigned int> blockShape({2, 2});
487 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {2, 0}};
488
Keith Davis33a626f2020-08-27 15:38:12 +0100489 return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory,
Aron Virginas-Tar00d306e2019-08-28 18:08:46 +0100490 armnn::DataLayout::NCHW, inputShape, input, blockShape,
491 crops, outputShape, expectedOutput);
492}