blob: ee5a4d97d21ed720c86b1d0ad77d3c89d4032957 [file] [log] [blame]
Matthew Sloyan2e5d0b22021-10-21 14:05:31 +01001//
2// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "MirrorPadTestImpl.hpp"
7
Colm Donelanc42a9872022-02-02 16:35:09 +00008#include <armnnUtils/QuantizeHelper.hpp>
Matthew Sloyan2e5d0b22021-10-21 14:05:31 +01009
Sadik Armagana097d2a2021-11-24 15:47:28 +000010#include <armnnTestUtils/TensorCopyUtils.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +000011#include <armnnTestUtils/WorkloadTestUtils.hpp>
Matthew Sloyan2e5d0b22021-10-21 14:05:31 +010012
Colm Donelanc42a9872022-02-02 16:35:09 +000013#include <armnnTestUtils/TensorHelpers.hpp>
Matthew Sloyan2e5d0b22021-10-21 14:05:31 +010014
15//
16// Implementation templates
17//
18
19template<typename T>
20LayerTestResult<T, 2> MirrorPad2dTestCommon(
21 armnn::IWorkloadFactory& workloadFactory,
22 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
23 const armnn::ITensorHandleFactory& tensorHandleFactory,
24 const armnn::TensorInfo& inputTensorInfo,
25 const armnn::TensorInfo& outputTensorInfo,
26 const std::vector<T>& inputValues,
27 const std::vector<T>& expectedOutputValues,
28 const std::vector<std::pair<unsigned int, unsigned int>>& padList,
29 const armnn::PaddingMode paddingMode)
30{
31 IgnoreUnused(memoryManager);
32 std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
33
34 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
35 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
36
37 armnn::PadQueueDescriptor descriptor;
38
39 descriptor.m_Parameters.m_PadList = padList;
40 descriptor.m_Parameters.m_PaddingMode = paddingMode;
41 armnn::WorkloadInfo info;
42
43 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
44 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
45
Teresa Charlin611c7fb2022-01-07 09:47:29 +000046 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateWorkload(armnn::LayerType::Pad,
47 descriptor,
48 info);
Matthew Sloyan2e5d0b22021-10-21 14:05:31 +010049
50 inputHandle->Allocate();
51 outputHandle->Allocate();
52
53 CopyDataToITensorHandle(inputHandle.get(), inputValues.data());
54
55 ExecuteWorkload(*workload, memoryManager);
56
57 CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
58
59 return LayerTestResult<T, 2>(actualOutput,
60 expectedOutputValues,
61 outputHandle->GetShape(),
62 outputTensorInfo.GetShape());
63}
64
65template<typename T>
66LayerTestResult<T, 3> MirrorPad3dTestCommon(
67 armnn::IWorkloadFactory& workloadFactory,
68 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
69 const armnn::ITensorHandleFactory& tensorHandleFactory,
70 const armnn::TensorInfo& inputTensorInfo,
71 const armnn::TensorInfo& outputTensorInfo,
72 const std::vector<T>& inputValues,
73 const std::vector<T>& expectedOutputValues,
74 const std::vector<std::pair<unsigned int, unsigned int>>& padList,
75 const armnn::PaddingMode paddingMode)
76{
77 IgnoreUnused(memoryManager);
78 std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
79
80 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
81 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
82
83 armnn::PadQueueDescriptor descriptor;
84 descriptor.m_Parameters.m_PadList = padList;
85 descriptor.m_Parameters.m_PaddingMode = paddingMode;
86
87 armnn::WorkloadInfo info;
88 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
89 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
90
Teresa Charlin611c7fb2022-01-07 09:47:29 +000091 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateWorkload(armnn::LayerType::Pad,
92 descriptor,
93 info);
Matthew Sloyan2e5d0b22021-10-21 14:05:31 +010094
95 inputHandle->Allocate();
96 outputHandle->Allocate();
97
98 CopyDataToITensorHandle(inputHandle.get(), inputValues.data());
99
100 ExecuteWorkload(*workload, memoryManager);
101
102 CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
103
104 return LayerTestResult<T, 3>(actualOutput,
105 expectedOutputValues,
106 outputHandle->GetShape(),
107 outputTensorInfo.GetShape());
108}
109
110template<typename T>
111LayerTestResult<T, 4> MirrorPad4dTestCommon(
112 armnn::IWorkloadFactory& workloadFactory,
113 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
114 const armnn::ITensorHandleFactory& tensorHandleFactory,
115 const armnn::TensorInfo& inputTensorInfo,
116 const armnn::TensorInfo& outputTensorInfo,
117 const std::vector<T>& inputValues,
118 const std::vector<T>& expectedOutputValues,
119 const std::vector<std::pair<unsigned int, unsigned int>>& padList,
120 const armnn::PaddingMode paddingMode)
121{
122 IgnoreUnused(memoryManager);
123 std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
124
125 std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
126 std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
127
128 armnn::PadQueueDescriptor descriptor;
129 descriptor.m_Parameters.m_PadList = padList;
130 descriptor.m_Parameters.m_PaddingMode = paddingMode;
131
132 armnn::WorkloadInfo info;
133 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
134 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
135
Teresa Charlin611c7fb2022-01-07 09:47:29 +0000136 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateWorkload(armnn::LayerType::Pad,
137 descriptor,
138 info);
Matthew Sloyan2e5d0b22021-10-21 14:05:31 +0100139
140 inputHandle->Allocate();
141 outputHandle->Allocate();
142
143 CopyDataToITensorHandle(inputHandle.get(), inputValues.data());
144
145 ExecuteWorkload(*workload, memoryManager);
146
147 CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
148
149 return LayerTestResult<T, 4>(actualOutput,
150 expectedOutputValues,
151 outputHandle->GetShape(),
152 outputTensorInfo.GetShape());
153}
154
155template<armnn::DataType ArmnnType,
156 typename T = armnn::ResolveType<ArmnnType>>
157LayerTestResult<T, 2> PadSymmetric2dTest(
158 armnn::IWorkloadFactory& workloadFactory,
159 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
160 const armnn::ITensorHandleFactory& tensorHandleFactory,
161 float qScale,
162 int32_t qOffset)
163{
164 const armnn::TensorShape inputShape{ 3, 3 };
165 const armnn::TensorShape outputShape{ 7, 7 };
166
167 const armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType, qScale, qOffset);
168 const armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType, qScale, qOffset);
169
170 std::vector<T> inputValues = armnnUtils::QuantizedVector<T>(
171 {
172 // Height (3) x Width (3)
173 1, 2, 3,
174 4, 5, 6,
175 7, 8, 9
176 },
177 qScale, qOffset);
178
179 std::vector<T> expectedOutputValues = armnnUtils::QuantizedVector<T>(
180 {
181 5, 4, 4, 5, 6, 6, 5,
182 2, 1, 1, 2, 3, 3, 2,
183 2, 1, 1, 2, 3, 3, 2,
184 5, 4, 4, 5, 6, 6, 5,
185 8, 7, 7, 8, 9, 9, 8,
186 8, 7, 7, 8, 9, 9, 8,
187 5, 4, 4, 5, 6, 6, 5
188 },
189 qScale, qOffset);
190
191 std::vector<std::pair<unsigned int, unsigned int>> padList;
192 padList.push_back(std::pair<unsigned int, unsigned int>(2,2));
193 padList.push_back(std::pair<unsigned int, unsigned int>(2,2));
194
195 return MirrorPad2dTestCommon<T>(workloadFactory,
196 memoryManager,
197 tensorHandleFactory,
198 inputTensorInfo,
199 outputTensorInfo,
200 inputValues,
201 expectedOutputValues,
202 padList,
203 armnn::PaddingMode::Symmetric);
204}
205
206template<armnn::DataType ArmnnType,
207 typename T = armnn::ResolveType<ArmnnType>>
208LayerTestResult<T, 2> PadReflect2dTest(
209 armnn::IWorkloadFactory& workloadFactory,
210 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
211 const armnn::ITensorHandleFactory& tensorHandleFactory,
212 float qScale,
213 int32_t qOffset)
214{
215 const armnn::TensorShape inputShape{ 3, 3 };
216 const armnn::TensorShape outputShape{ 7, 7 };
217
218 const armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType, qScale, qOffset);
219 const armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType, qScale, qOffset);
220
221 std::vector<T> inputValues = armnnUtils::QuantizedVector<T>(
222 {
223 // Height (3) x Width (3)
224 1, 2, 3,
225 4, 5, 6,
226 7, 8, 9
227 },
228 qScale, qOffset);
229
230 std::vector<T> expectedOutputValues = armnnUtils::QuantizedVector<T>(
231 {
232 9, 8, 7, 8, 9, 8, 7,
233 6, 5, 4, 5, 6, 5, 4,
234 3, 2, 1, 2, 3, 2, 1,
235 6, 5, 4, 5, 6, 5, 4,
236 9, 8, 7, 8, 9, 8, 7,
237 6, 5, 4, 5, 6, 5, 4,
238 3, 2, 1, 2, 3, 2, 1
239 },
240 qScale, qOffset);
241
242 std::vector<std::pair<unsigned int, unsigned int>> padList;
243 padList.push_back(std::pair<unsigned int, unsigned int>(2,2));
244 padList.push_back(std::pair<unsigned int, unsigned int>(2,2));
245
246 return MirrorPad2dTestCommon<T>(workloadFactory,
247 memoryManager,
248 tensorHandleFactory,
249 inputTensorInfo,
250 outputTensorInfo,
251 inputValues,
252 expectedOutputValues,
253 padList,
254 armnn::PaddingMode::Reflect);
255}
256
257template<armnn::DataType ArmnnType,
258 typename T = armnn::ResolveType<ArmnnType>>
259LayerTestResult<T, 3> PadSymmetric3dTest(
260 armnn::IWorkloadFactory& workloadFactory,
261 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
262 const armnn::ITensorHandleFactory& tensorHandleFactory,
263 float qScale,
264 int32_t qOffset)
265{
266 const armnn::TensorShape inputShape{ 2, 2, 2 };
267 const armnn::TensorShape outputShape{ 4, 4, 4 };
268
269 const armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType, qScale, qOffset);
270 const armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType, qScale, qOffset);
271
272 std::vector<T> inputValues = armnnUtils::QuantizedVector<T>(
273 {
274 // Channel 0, Height (2) x Width (2)
275 1, 2,
276 3, 4,
277
278 // Channel 1, Height (2) x Width (2)
279 5, 6,
280 7, 8
281 },
282 qScale, qOffset);
283
284 std::vector<T> expectedOutputValues = armnnUtils::QuantizedVector<T>(
285 {
286 1, 1, 2, 2,
287 1, 1, 2, 2,
288 3, 3, 4, 4,
289 3, 3, 4, 4,
290
291 1, 1, 2, 2,
292 1, 1, 2, 2,
293 3, 3, 4, 4,
294 3, 3, 4, 4,
295
296 5, 5, 6, 6,
297 5, 5, 6, 6,
298 7, 7, 8, 8,
299 7, 7, 8, 8,
300
301 5, 5, 6, 6,
302 5, 5, 6, 6,
303 7, 7, 8, 8,
304 7, 7, 8, 8
305 },
306 qScale, qOffset);
307
308 std::vector<std::pair<unsigned int, unsigned int>> padList;
309 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
310 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
311 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
312
313 return MirrorPad3dTestCommon<T>(workloadFactory,
314 memoryManager,
315 tensorHandleFactory,
316 inputTensorInfo,
317 outputTensorInfo,
318 inputValues,
319 expectedOutputValues,
320 padList,
321 armnn::PaddingMode::Symmetric);
322}
323
324template<armnn::DataType ArmnnType,
325 typename T = armnn::ResolveType<ArmnnType>>
326LayerTestResult<T, 3> PadReflect3dTest(
327 armnn::IWorkloadFactory& workloadFactory,
328 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
329 const armnn::ITensorHandleFactory& tensorHandleFactory,
330 float qScale,
331 int32_t qOffset)
332{
333 const armnn::TensorShape inputShape{ 2, 2, 2 };
334 const armnn::TensorShape outputShape{ 4, 4, 4 };
335
336 const armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType, qScale, qOffset);
337 const armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType, qScale, qOffset);
338
339 std::vector<T> inputValues = armnnUtils::QuantizedVector<T>(
340 {
341 // Channel 0, Height (2) x Width (2)
342 1, 2,
343 3, 4,
344
345 // Channel 1, Height (2) x Width (2)
346 5, 6,
347 7, 8
348 },
349 qScale, qOffset);
350
351 std::vector<T> expectedOutputValues = armnnUtils::QuantizedVector<T>(
352 {
353 8, 7, 8, 7,
354 6, 5, 6, 5,
355 8, 7, 8, 7,
356 6, 5, 6, 5,
357
358 4, 3, 4, 3,
359 2, 1, 2, 1,
360 4, 3, 4, 3,
361 2, 1, 2, 1,
362
363 8, 7, 8, 7,
364 6, 5, 6, 5,
365 8, 7, 8, 7,
366 6, 5, 6, 5,
367
368 4, 3, 4, 3,
369 2, 1, 2, 1,
370 4, 3, 4, 3,
371 2, 1, 2, 1
372 },
373 qScale, qOffset);
374
375 std::vector<std::pair<unsigned int, unsigned int>> padList;
376 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
377 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
378 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
379
380 return MirrorPad3dTestCommon<T>(workloadFactory,
381 memoryManager,
382 tensorHandleFactory,
383 inputTensorInfo,
384 outputTensorInfo,
385 inputValues,
386 expectedOutputValues,
387 padList,
388 armnn::PaddingMode::Reflect);
389}
390
391template<armnn::DataType ArmnnType,
392 typename T = armnn::ResolveType<ArmnnType>>
393LayerTestResult<T, 4> PadSymmetric4dTest(
394 armnn::IWorkloadFactory& workloadFactory,
395 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
396 const armnn::ITensorHandleFactory& tensorHandleFactory,
397 float qScale,
398 int32_t qOffset)
399{
400 const armnn::TensorShape inputShape{ 2, 2, 2, 2 };
401 const armnn::TensorShape outputShape{ 6, 6, 6, 6 };
402
403 const armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType, qScale, qOffset);
404 const armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType, qScale, qOffset);
405
406 std::vector<T> inputValues = armnnUtils::QuantizedVector<T>(
407 {
408 // Batch 0, Channel 0, Height (2) x Width (2)
409 1, 2,
410 3, 4,
411
412 // Batch 0, Channel 1, Height (2) x Width (2)
413 5, 6,
414 7, 8,
415
416 // Batch 1, Channel 0, Height (2) x Width (2)
417 9, 10,
418 11, 12,
419
420 // Batch 1, Channel 1, Height (2) x Width (2)
421 13, 14,
422 15, 16,
423 },
424 qScale, qOffset);
425
426 std::vector<T> expectedOutputValues = armnnUtils::QuantizedVector<T>(
427 {
428 16, 15, 15, 16, 16, 15,
429 14, 13, 13, 14, 14, 13,
430 14, 13, 13, 14, 14, 13,
431 16, 15, 15, 16, 16, 15,
432 16, 15, 15, 16, 16, 15,
433 14, 13, 13, 14, 14, 13,
434
435 12, 11, 11, 12, 12, 11,
436 10, 9, 9, 10, 10, 9,
437 10, 9, 9, 10, 10, 9,
438 12, 11, 11, 12, 12, 11,
439 12, 11, 11, 12, 12, 11,
440 10, 9, 9, 10, 10, 9,
441
442 12, 11, 11, 12, 12, 11,
443 10, 9, 9, 10, 10, 9,
444 10, 9, 9, 10, 10, 9,
445 12, 11, 11, 12, 12, 11,
446 12, 11, 11, 12, 12, 11,
447 10, 9, 9, 10, 10, 9,
448
449 16, 15, 15, 16, 16, 15,
450 14, 13, 13, 14, 14, 13,
451 14, 13, 13, 14, 14, 13,
452 16, 15, 15, 16, 16, 15,
453 16, 15, 15, 16, 16, 15,
454 14, 13, 13, 14, 14, 13,
455
456 16, 15, 15, 16, 16, 15,
457 14, 13, 13, 14, 14, 13,
458 14, 13, 13, 14, 14, 13,
459 16, 15, 15, 16, 16, 15,
460 16, 15, 15, 16, 16, 15,
461 14, 13, 13, 14, 14, 13,
462
463 12, 11, 11, 12, 12, 11,
464 10, 9, 9, 10, 10, 9,
465 10, 9, 9, 10, 10, 9,
466 12, 11, 11, 12, 12, 11,
467 12, 11, 11, 12, 12, 11,
468 10, 9, 9, 10, 10, 9,
469
470
471 8, 7, 7, 8, 8, 7,
472 6, 5, 5, 6, 6, 5,
473 6, 5, 5, 6, 6, 5,
474 8, 7, 7, 8, 8, 7,
475 8, 7, 7, 8, 8, 7,
476 6, 5, 5, 6, 6, 5,
477
478 4, 3, 3, 4, 4, 3,
479 2, 1, 1, 2, 2, 1,
480 2, 1, 1, 2, 2, 1,
481 4, 3, 3, 4, 4, 3,
482 4, 3, 3, 4, 4, 3,
483 2, 1, 1, 2, 2, 1,
484
485 4, 3, 3, 4, 4, 3,
486 2, 1, 1, 2, 2, 1,
487 2, 1, 1, 2, 2, 1,
488 4, 3, 3, 4, 4, 3,
489 4, 3, 3, 4, 4, 3,
490 2, 1, 1, 2, 2, 1,
491
492 8, 7, 7, 8, 8, 7,
493 6, 5, 5, 6, 6, 5,
494 6, 5, 5, 6, 6, 5,
495 8, 7, 7, 8, 8, 7,
496 8, 7, 7, 8, 8, 7,
497 6, 5, 5, 6, 6, 5,
498
499 8, 7, 7, 8, 8, 7,
500 6, 5, 5, 6, 6, 5,
501 6, 5, 5, 6, 6, 5,
502 8, 7, 7, 8, 8, 7,
503 8, 7, 7, 8, 8, 7,
504 6, 5, 5, 6, 6, 5,
505
506 4, 3, 3, 4, 4, 3,
507 2, 1, 1, 2, 2, 1,
508 2, 1, 1, 2, 2, 1,
509 4, 3, 3, 4, 4, 3,
510 4, 3, 3, 4, 4, 3,
511 2, 1, 1, 2, 2, 1,
512
513
514 8, 7, 7, 8, 8, 7,
515 6, 5, 5, 6, 6, 5,
516 6, 5, 5, 6, 6, 5,
517 8, 7, 7, 8, 8, 7,
518 8, 7, 7, 8, 8, 7,
519 6, 5, 5, 6, 6, 5,
520
521 4, 3, 3, 4, 4, 3,
522 2, 1, 1, 2, 2, 1,
523 2, 1, 1, 2, 2, 1,
524 4, 3, 3, 4, 4, 3,
525 4, 3, 3, 4, 4, 3,
526 2, 1, 1, 2, 2, 1,
527
528 4, 3, 3, 4, 4, 3,
529 2, 1, 1, 2, 2, 1,
530 2, 1, 1, 2, 2, 1,
531 4, 3, 3, 4, 4, 3,
532 4, 3, 3, 4, 4, 3,
533 2, 1, 1, 2, 2, 1,
534
535 8, 7, 7, 8, 8, 7,
536 6, 5, 5, 6, 6, 5,
537 6, 5, 5, 6, 6, 5,
538 8, 7, 7, 8, 8, 7,
539 8, 7, 7, 8, 8, 7,
540 6, 5, 5, 6, 6, 5,
541
542 8, 7, 7, 8, 8, 7,
543 6, 5, 5, 6, 6, 5,
544 6, 5, 5, 6, 6, 5,
545 8, 7, 7, 8, 8, 7,
546 8, 7, 7, 8, 8, 7,
547 6, 5, 5, 6, 6, 5,
548
549 4, 3, 3, 4, 4, 3,
550 2, 1, 1, 2, 2, 1,
551 2, 1, 1, 2, 2, 1,
552 4, 3, 3, 4, 4, 3,
553 4, 3, 3, 4, 4, 3,
554 2, 1, 1, 2, 2, 1,
555
556
557 16, 15, 15, 16, 16, 15,
558 14, 13, 13, 14, 14, 13,
559 14, 13, 13, 14, 14, 13,
560 16, 15, 15, 16, 16, 15,
561 16, 15, 15, 16, 16, 15,
562 14, 13, 13, 14, 14, 13,
563
564 12, 11, 11, 12, 12, 11,
565 10, 9, 9, 10, 10, 9,
566 10, 9, 9, 10, 10, 9,
567 12, 11, 11, 12, 12, 11,
568 12, 11, 11, 12, 12, 11,
569 10, 9, 9, 10, 10, 9,
570
571 12, 11, 11, 12, 12, 11,
572 10, 9, 9, 10, 10, 9,
573 10, 9, 9, 10, 10, 9,
574 12, 11, 11, 12, 12, 11,
575 12, 11, 11, 12, 12, 11,
576 10, 9, 9, 10, 10, 9,
577
578 16, 15, 15, 16, 16, 15,
579 14, 13, 13, 14, 14, 13,
580 14, 13, 13, 14, 14, 13,
581 16, 15, 15, 16, 16, 15,
582 16, 15, 15, 16, 16, 15,
583 14, 13, 13, 14, 14, 13,
584
585 16, 15, 15, 16, 16, 15,
586 14, 13, 13, 14, 14, 13,
587 14, 13, 13, 14, 14, 13,
588 16, 15, 15, 16, 16, 15,
589 16, 15, 15, 16, 16, 15,
590 14, 13, 13, 14, 14, 13,
591
592 12, 11, 11, 12, 12, 11,
593 10, 9, 9, 10, 10, 9,
594 10, 9, 9, 10, 10, 9,
595 12, 11, 11, 12, 12, 11,
596 12, 11, 11, 12, 12, 11,
597 10, 9, 9, 10, 10, 9,
598
599
600 16, 15, 15, 16, 16, 15,
601 14, 13, 13, 14, 14, 13,
602 14, 13, 13, 14, 14, 13,
603 16, 15, 15, 16, 16, 15,
604 16, 15, 15, 16, 16, 15,
605 14, 13, 13, 14, 14, 13,
606
607 12, 11, 11, 12, 12, 11,
608 10, 9, 9, 10, 10, 9,
609 10, 9, 9, 10, 10, 9,
610 12, 11, 11, 12, 12, 11,
611 12, 11, 11, 12, 12, 11,
612 10, 9, 9, 10, 10, 9,
613
614 12, 11, 11, 12, 12, 11,
615 10, 9, 9, 10, 10, 9,
616 10, 9, 9, 10, 10, 9,
617 12, 11, 11, 12, 12, 11,
618 12, 11, 11, 12, 12, 11,
619 10, 9, 9, 10, 10, 9,
620
621 16, 15, 15, 16, 16, 15,
622 14, 13, 13, 14, 14, 13,
623 14, 13, 13, 14, 14, 13,
624 16, 15, 15, 16, 16, 15,
625 16, 15, 15, 16, 16, 15,
626 14, 13, 13, 14, 14, 13,
627
628 16, 15, 15, 16, 16, 15,
629 14, 13, 13, 14, 14, 13,
630 14, 13, 13, 14, 14, 13,
631 16, 15, 15, 16, 16, 15,
632 16, 15, 15, 16, 16, 15,
633 14, 13, 13, 14, 14, 13,
634
635 12, 11, 11, 12, 12, 11,
636 10, 9, 9, 10, 10, 9,
637 10, 9, 9, 10, 10, 9,
638 12, 11, 11, 12, 12, 11,
639 12, 11, 11, 12, 12, 11,
640 10, 9, 9, 10, 10, 9,
641
642
643 8, 7, 7, 8, 8, 7,
644 6, 5, 5, 6, 6, 5,
645 6, 5, 5, 6, 6, 5,
646 8, 7, 7, 8, 8, 7,
647 8, 7, 7, 8, 8, 7,
648 6, 5, 5, 6, 6, 5,
649
650 4, 3, 3, 4, 4, 3,
651 2, 1, 1, 2, 2, 1,
652 2, 1, 1, 2, 2, 1,
653 4, 3, 3, 4, 4, 3,
654 4, 3, 3, 4, 4, 3,
655 2, 1, 1, 2, 2, 1,
656
657 4, 3, 3, 4, 4, 3,
658 2, 1, 1, 2, 2, 1,
659 2, 1, 1, 2, 2, 1,
660 4, 3, 3, 4, 4, 3,
661 4, 3, 3, 4, 4, 3,
662 2, 1, 1, 2, 2, 1,
663
664 8, 7, 7, 8, 8, 7,
665 6, 5, 5, 6, 6, 5,
666 6, 5, 5, 6, 6, 5,
667 8, 7, 7, 8, 8, 7,
668 8, 7, 7, 8, 8, 7,
669 6, 5, 5, 6, 6, 5,
670
671 8, 7, 7, 8, 8, 7,
672 6, 5, 5, 6, 6, 5,
673 6, 5, 5, 6, 6, 5,
674 8, 7, 7, 8, 8, 7,
675 8, 7, 7, 8, 8, 7,
676 6, 5, 5, 6, 6, 5,
677
678 4, 3, 3, 4, 4, 3,
679 2, 1, 1, 2, 2, 1,
680 2, 1, 1, 2, 2, 1,
681 4, 3, 3, 4, 4, 3,
682 4, 3, 3, 4, 4, 3,
683 2, 1, 1, 2, 2, 1
684 },
685 qScale, qOffset);
686
687 std::vector<std::pair<unsigned int, unsigned int>> padList;
688 padList.push_back(std::pair<unsigned int, unsigned int>(2,2));
689 padList.push_back(std::pair<unsigned int, unsigned int>(2,2));
690 padList.push_back(std::pair<unsigned int, unsigned int>(2,2));
691 padList.push_back(std::pair<unsigned int, unsigned int>(2,2));
692
693 return MirrorPad4dTestCommon<T>(workloadFactory,
694 memoryManager,
695 tensorHandleFactory,
696 inputTensorInfo,
697 outputTensorInfo,
698 inputValues,
699 expectedOutputValues,
700 padList,
701 armnn::PaddingMode::Symmetric);
702}
703
704template<armnn::DataType ArmnnType,
705 typename T = armnn::ResolveType<ArmnnType>>
706LayerTestResult<T, 4> PadReflect4dTest(
707 armnn::IWorkloadFactory& workloadFactory,
708 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
709 const armnn::ITensorHandleFactory& tensorHandleFactory,
710 float qScale,
711 int32_t qOffset)
712{
713 const armnn::TensorShape inputShape{ 2, 2, 2, 2 };
714 const armnn::TensorShape outputShape{ 4, 4, 4, 4 };
715
716 const armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType, qScale, qOffset);
717 const armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType, qScale, qOffset);
718
719 std::vector<T> inputValues = armnnUtils::QuantizedVector<T>(
720 {
721 // Batch 0, Channel 0, Height (2) x Width (2)
722 1, 2,
723 3, 4,
724
725 // Batch 0, Channel 1, Height (2) x Width (2)
726 5, 6,
727 7, 8,
728
729 // Batch 1, Channel 0, Height (2) x Width (2)
730 9, 10,
731 11, 12,
732
733 // Batch 1, Channel 1, Height (2) x Width (2)
734 13, 14,
735 15, 16,
736 },
737 qScale, qOffset);
738
739 std::vector<T> expectedOutputValues = armnnUtils::QuantizedVector<T>(
740 {
741 16, 15, 16, 15,
742 14, 13, 14, 13,
743 16, 15, 16, 15,
744 14, 13, 14, 13,
745
746 12, 11, 12, 11,
747 10, 9, 10, 9,
748 12, 11, 12, 11,
749 10, 9, 10, 9,
750
751 16, 15, 16, 15,
752 14, 13, 14, 13,
753 16, 15, 16, 15,
754 14, 13, 14, 13,
755
756 12, 11, 12, 11,
757 10, 9, 10, 9,
758 12, 11, 12, 11,
759 10, 9, 10, 9,
760
761
762 8, 7, 8, 7,
763 6, 5, 6, 5,
764 8, 7, 8, 7,
765 6, 5, 6, 5,
766
767 4, 3, 4, 3,
768 2, 1, 2, 1,
769 4, 3, 4, 3,
770 2, 1, 2, 1,
771
772 8, 7, 8, 7,
773 6, 5, 6, 5,
774 8, 7, 8, 7,
775 6, 5, 6, 5,
776
777 4, 3, 4, 3,
778 2, 1, 2, 1,
779 4, 3, 4, 3,
780 2, 1, 2, 1,
781
782
783 16, 15, 16, 15,
784 14, 13, 14, 13,
785 16, 15, 16, 15,
786 14, 13, 14, 13,
787
788 12, 11, 12, 11,
789 10, 9, 10, 9,
790 12, 11, 12, 11,
791 10, 9, 10, 9,
792
793 16, 15, 16, 15,
794 14, 13, 14, 13,
795 16, 15, 16, 15,
796 14, 13, 14, 13,
797
798 12, 11, 12, 11,
799 10, 9, 10, 9,
800 12, 11, 12, 11,
801 10, 9, 10, 9,
802
803
804 8, 7, 8, 7,
805 6, 5, 6, 5,
806 8, 7, 8, 7,
807 6, 5, 6, 5,
808
809 4, 3, 4, 3,
810 2, 1, 2, 1,
811 4, 3, 4, 3,
812 2, 1, 2, 1,
813
814 8, 7, 8, 7,
815 6, 5, 6, 5,
816 8, 7, 8, 7,
817 6, 5, 6, 5,
818
819 4, 3, 4, 3,
820 2, 1, 2, 1,
821 4, 3, 4, 3,
822 2, 1, 2, 1
823 },
824 qScale, qOffset);
825
826 std::vector<std::pair<unsigned int, unsigned int>> padList;
827 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
828 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
829 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
830 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
831
832 return MirrorPad4dTestCommon<T>(workloadFactory,
833 memoryManager,
834 tensorHandleFactory,
835 inputTensorInfo,
836 outputTensorInfo,
837 inputValues,
838 expectedOutputValues,
839 padList,
840 armnn::PaddingMode::Reflect);
841}
842
843LayerTestResult<armnn::Half, 2> PadSymmetricFloat16(
844 armnn::IWorkloadFactory& workloadFactory,
845 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
846 const armnn::ITensorHandleFactory& tensorHandleFactory)
847{
848 using namespace half_float::literal;
849
850 const armnn::TensorShape inputShape{ 3, 3 };
851 const armnn::TensorShape outputShape{ 5, 7 };
852
853 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::DataType::Float16);
854 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::DataType::Float16);
855
856 const std::vector<armnn::Half> inputValues =
857 {
858 1._h, 2._h, 3._h,
859 4._h, 5._h, 6._h,
860 7._h, 8._h, 9._h
861 };
862
863 std::vector<armnn::Half> expectedOutputValues =
864 {
865 2._h, 1._h, 1._h, 2._h, 3._h, 3._h, 2._h,
866 2._h, 1._h, 1._h, 2._h, 3._h, 3._h, 2._h,
867 5._h, 4._h, 4._h, 5._h, 6._h, 6._h, 5._h,
868 8._h, 7._h, 7._h, 8._h, 9._h, 9._h, 8._h,
869 8._h, 7._h, 7._h, 8._h, 9._h, 9._h, 8._h,
870 };
871
872 std::vector<std::pair<unsigned int, unsigned int>> padList;
873 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
874 padList.push_back(std::pair<unsigned int, unsigned int>(2,2));
875
876 return MirrorPad2dTestCommon<armnn::Half>(workloadFactory,
877 memoryManager,
878 tensorHandleFactory,
879 inputTensorInfo,
880 outputTensorInfo,
881 inputValues,
882 expectedOutputValues,
883 padList,
884 armnn::PaddingMode::Symmetric);
885}
886
887LayerTestResult<armnn::Half, 2> PadReflectFloat16(
888 armnn::IWorkloadFactory& workloadFactory,
889 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
890 const armnn::ITensorHandleFactory& tensorHandleFactory)
891{
892 using namespace half_float::literal;
893
894 const armnn::TensorShape inputShape{ 3, 3 };
895 const armnn::TensorShape outputShape{ 7, 5 };
896
897 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::DataType::Float16);
898 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::DataType::Float16);
899
900 const std::vector<armnn::Half> inputValues =
901 {
902 1._h, 2._h, 3._h,
903 4._h, 5._h, 6._h,
904 7._h, 8._h, 9._h
905 };
906
907 std::vector<armnn::Half> expectedOutputValues =
908 {
909 8._h, 7._h, 8._h, 9._h, 8._h,
910 5._h, 4._h, 5._h, 6._h, 5._h,
911 2._h, 1._h, 2._h, 3._h, 2._h,
912 5._h, 4._h, 5._h, 6._h, 5._h,
913 8._h, 7._h, 8._h, 9._h, 8._h,
914 5._h, 4._h, 5._h, 6._h, 5._h,
915 2._h, 1._h, 2._h, 3._h, 2._h,
916 };
917
918 std::vector<std::pair<unsigned int, unsigned int>> padList;
919 padList.push_back(std::pair<unsigned int, unsigned int>(2,2));
920 padList.push_back(std::pair<unsigned int, unsigned int>(1,1));
921
922 return MirrorPad2dTestCommon<armnn::Half>(workloadFactory,
923 memoryManager,
924 tensorHandleFactory,
925 inputTensorInfo,
926 outputTensorInfo,
927 inputValues,
928 expectedOutputValues,
929 padList,
930 armnn::PaddingMode::Reflect);
931}
932
933//
934// Implementation functions
935//
936
937LayerTestResult<float, 2> PadSymmetric2dFloat32Test(
938 armnn::IWorkloadFactory& workloadFactory,
939 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
940 const armnn::ITensorHandleFactory& tensorHandleFactory)
941{
942 return PadSymmetric2dTest<armnn::DataType::Float32>(workloadFactory, memoryManager, tensorHandleFactory, 0.0f, 0);
943}
944
945LayerTestResult<float, 2> PadReflect2dFloat32Test(
946 armnn::IWorkloadFactory& workloadFactory,
947 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
948 const armnn::ITensorHandleFactory& tensorHandleFactory)
949{
950 return PadReflect2dTest<armnn::DataType::Float32>(workloadFactory, memoryManager, tensorHandleFactory, 0.0f, 0);
951}
952
953LayerTestResult<float, 3> PadSymmetric3dFloat32Test(
954 armnn::IWorkloadFactory& workloadFactory,
955 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
956 const armnn::ITensorHandleFactory& tensorHandleFactory)
957{
958 return PadSymmetric3dTest<armnn::DataType::Float32>(workloadFactory, memoryManager, tensorHandleFactory, 0.0f, 0);
959}
960
961LayerTestResult<float, 3> PadReflect3dFloat32Test(
962 armnn::IWorkloadFactory& workloadFactory,
963 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
964 const armnn::ITensorHandleFactory& tensorHandleFactory)
965{
966 return PadReflect3dTest<armnn::DataType::Float32>(workloadFactory, memoryManager, tensorHandleFactory, 0.0f, 0);
967}
968
969LayerTestResult<uint8_t, 3> PadSymmetric3dUint8Test(
970 armnn::IWorkloadFactory& workloadFactory,
971 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
972 const armnn::ITensorHandleFactory& tensorHandleFactory)
973{
974 return PadSymmetric3dTest<armnn::DataType::QAsymmU8>(
975 workloadFactory, memoryManager, tensorHandleFactory, 0.1f, 128);
976}
977
978LayerTestResult<uint8_t, 3> PadReflect3dUint8Test(
979 armnn::IWorkloadFactory& workloadFactory,
980 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
981 const armnn::ITensorHandleFactory& tensorHandleFactory)
982{
983 return PadReflect3dTest<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, tensorHandleFactory, 0.1f, 128);
984}
985
986LayerTestResult<int8_t, 3> PadSymmetric3dInt8Test(
987 armnn::IWorkloadFactory& workloadFactory,
988 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
989 const armnn::ITensorHandleFactory& tensorHandleFactory)
990{
991 return PadSymmetric3dTest<armnn::DataType::QAsymmS8>(workloadFactory, memoryManager, tensorHandleFactory, 0.1f, 64);
992}
993
994LayerTestResult<int8_t, 3> PadReflect3dInt8Test(
995 armnn::IWorkloadFactory& workloadFactory,
996 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
997 const armnn::ITensorHandleFactory& tensorHandleFactory)
998{
999 return PadReflect3dTest<armnn::DataType::QAsymmS8>(workloadFactory, memoryManager, tensorHandleFactory, 0.1f, 64);
1000}
1001
1002LayerTestResult<float, 4> PadSymmetric4dFloat32Test(
1003 armnn::IWorkloadFactory& workloadFactory,
1004 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1005 const armnn::ITensorHandleFactory& tensorHandleFactory)
1006{
1007 return PadSymmetric4dTest<armnn::DataType::Float32>(workloadFactory, memoryManager, tensorHandleFactory, 0.0f, 0);
1008}
1009
1010LayerTestResult<float, 4> PadReflect4dFloat32Test(
1011 armnn::IWorkloadFactory& workloadFactory,
1012 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1013 const armnn::ITensorHandleFactory& tensorHandleFactory)
1014{
1015 return PadReflect4dTest<armnn::DataType::Float32>(workloadFactory, memoryManager, tensorHandleFactory, 0.0f, 0);
1016}
1017
1018LayerTestResult<armnn::BFloat16, 4> PadSymmetric4dBFloat16Test(
1019 armnn::IWorkloadFactory& workloadFactory,
1020 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1021 const armnn::ITensorHandleFactory& tensorHandleFactory)
1022{
1023 return PadSymmetric4dTest<armnn::DataType::BFloat16>(workloadFactory, memoryManager, tensorHandleFactory, 0.0f, 0);
1024}
1025
1026LayerTestResult<armnn::BFloat16, 4> PadReflect4dBFloat16Test(
1027 armnn::IWorkloadFactory& workloadFactory,
1028 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1029 const armnn::ITensorHandleFactory& tensorHandleFactory)
1030{
1031 return PadReflect4dTest<armnn::DataType::BFloat16>(workloadFactory, memoryManager, tensorHandleFactory, 0.0f, 0);
1032}
1033
1034LayerTestResult<uint8_t, 4> PadSymmetric4dUint8Test(
1035 armnn::IWorkloadFactory& workloadFactory,
1036 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1037 const armnn::ITensorHandleFactory& tensorHandleFactory)
1038{
1039 return PadSymmetric4dTest<armnn::DataType::QAsymmU8>(
1040 workloadFactory, memoryManager, tensorHandleFactory, 0.1f, 128);
1041}
1042
1043LayerTestResult<uint8_t, 4> PadReflect4dUint8Test(
1044 armnn::IWorkloadFactory& workloadFactory,
1045 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1046 const armnn::ITensorHandleFactory& tensorHandleFactory)
1047{
1048 return PadReflect4dTest<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, tensorHandleFactory, 0.1f, 128);
1049}
1050
1051LayerTestResult<int8_t, 4> PadSymmetric4dInt8Test(
1052 armnn::IWorkloadFactory& workloadFactory,
1053 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1054 const armnn::ITensorHandleFactory& tensorHandleFactory)
1055{
1056 return PadSymmetric4dTest<armnn::DataType::QAsymmS8>(workloadFactory, memoryManager, tensorHandleFactory, 0.1f, 64);
1057}
1058
1059LayerTestResult<int8_t, 4> PadReflect4dInt8Test(
1060 armnn::IWorkloadFactory& workloadFactory,
1061 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1062 const armnn::ITensorHandleFactory& tensorHandleFactory)
1063{
1064 return PadReflect4dTest<armnn::DataType::QAsymmS8>(workloadFactory, memoryManager, tensorHandleFactory, 0.1f, 64);
1065}
1066
1067LayerTestResult<int16_t, 4> PadSymmetric4dInt16Test(
1068 armnn::IWorkloadFactory& workloadFactory,
1069 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1070 const armnn::ITensorHandleFactory& tensorHandleFactory)
1071{
1072 return PadSymmetric4dTest<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, tensorHandleFactory, 2.0f, 0);
1073}
1074
1075LayerTestResult<int16_t, 4> PadReflect4dInt16Test(
1076 armnn::IWorkloadFactory& workloadFactory,
1077 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1078 const armnn::ITensorHandleFactory& tensorHandleFactory)
1079{
1080 return PadReflect4dTest<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, tensorHandleFactory, 2.0f, 0);
1081}
1082
1083LayerTestResult<armnn::Half, 2> PadSymmetricFloat16Test(
1084 armnn::IWorkloadFactory& workloadFactory,
1085 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1086 const armnn::ITensorHandleFactory& tensorHandleFactory)
1087{
1088 return PadSymmetricFloat16(workloadFactory, memoryManager, tensorHandleFactory);
1089}
1090
1091LayerTestResult<armnn::Half, 2> PadReflectFloat16Test(
1092 armnn::IWorkloadFactory& workloadFactory,
1093 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1094 const armnn::ITensorHandleFactory& tensorHandleFactory)
1095{
1096 return PadReflectFloat16(workloadFactory, memoryManager, tensorHandleFactory);
1097}