blob: 51f545ce5effb624fefc9d54c121abb039eaab15 [file] [log] [blame]
Matthew Sloyana7a12f52021-05-06 10:05:28 +01001//
Teresa Charlinad1b3d72023-03-14 12:10:28 +00002// Copyright © 2021, 2023 Arm Ltd and Contributors. All rights reserved.
Matthew Sloyana7a12f52021-05-06 10:05:28 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "PackTestHelper.hpp"
7
8#include <armnn_delegate.hpp>
9
10#include <flatbuffers/flatbuffers.h>
Matthew Sloyana7a12f52021-05-06 10:05:28 +010011
12#include <doctest/doctest.h>
13
14namespace armnnDelegate
15{
16
17template <typename T>
18void PackFp32Axis0Test(tflite::TensorType tensorType, std::vector<armnn::BackendId>& backends)
19{
20 std::vector<int32_t> inputShape { 3, 2, 3 };
21 std::vector<int32_t> expectedOutputShape { 2, 3, 2, 3 };
22
23 std::vector<std::vector<T>> inputValues;
24 inputValues.push_back(
25 {
26 1, 2, 3,
27 4, 5, 6,
28
29 7, 8, 9,
30 10, 11, 12,
31
32 13, 14, 15,
33 16, 17, 18
34 });
35
36 inputValues.push_back(
37 {
38 19, 20, 21,
39 22, 23, 24,
40
41 25, 26, 27,
42 28, 29, 30,
43
44 31, 32, 33,
45 34, 35, 36
46 });
47
48 std::vector<T> expectedOutputValues =
49 {
50 1, 2, 3,
51 4, 5, 6,
52
53 7, 8, 9,
54 10, 11, 12,
55
56 13, 14, 15,
57 16, 17, 18,
58
59
60 19, 20, 21,
61 22, 23, 24,
62
63 25, 26, 27,
64 28, 29, 30,
65
66 31, 32, 33,
67 34, 35, 36
68 };
69
70 PackTest<T>(tflite::BuiltinOperator_PACK,
71 tensorType,
72 backends,
73 inputShape,
74 expectedOutputShape,
75 inputValues,
76 expectedOutputValues,
77 0);
78}
79
80template <typename T>
81void PackFp32Axis1Test(tflite::TensorType tensorType, std::vector<armnn::BackendId>& backends)
82{
83 std::vector<int32_t> inputShape { 3, 2, 3 };
84 std::vector<int32_t> expectedOutputShape { 3, 2, 2, 3 };
85
86 std::vector<std::vector<T>> inputValues;
87 inputValues.push_back(
88 {
89 1, 2, 3,
90 4, 5, 6,
91
92 7, 8, 9,
93 10, 11, 12,
94
95 13, 14, 15,
96 16, 17, 18
97 });
98
99 inputValues.push_back(
100 {
101 19, 20, 21,
102 22, 23, 24,
103
104 25, 26, 27,
105 28, 29, 30,
106
107 31, 32, 33,
108 34, 35, 36
109 });
110
111 std::vector<T> expectedOutputValues =
112 {
113 1, 2, 3,
114 4, 5, 6,
115
116 19, 20, 21,
117 22, 23, 24,
118
119
120 7, 8, 9,
121 10, 11, 12,
122
123 25, 26, 27,
124 28, 29, 30,
125
126
127 13, 14, 15,
128 16, 17, 18,
129
130 31, 32, 33,
131 34, 35, 36
132 };
133
134 PackTest<T>(tflite::BuiltinOperator_PACK,
135 tensorType,
136 backends,
137 inputShape,
138 expectedOutputShape,
139 inputValues,
140 expectedOutputValues,
141 1);
142}
143
144template <typename T>
145void PackFp32Axis2Test(tflite::TensorType tensorType, std::vector<armnn::BackendId>& backends)
146{
147 std::vector<int32_t> inputShape { 3, 2, 3 };
148 std::vector<int32_t> expectedOutputShape { 3, 2, 2, 3 };
149
150 std::vector<std::vector<T>> inputValues;
151 inputValues.push_back(
152 {
153 1, 2, 3,
154 4, 5, 6,
155
156 7, 8, 9,
157 10, 11, 12,
158
159 13, 14, 15,
160 16, 17, 18
161 });
162
163 inputValues.push_back(
164 {
165 19, 20, 21,
166 22, 23, 24,
167
168 25, 26, 27,
169 28, 29, 30,
170
171 31, 32, 33,
172 34, 35, 36
173 });
174
175 std::vector<float> expectedOutputValues =
176 {
177 1, 2, 3,
178 19, 20, 21,
179
180 4, 5, 6,
181 22, 23, 24,
182
183 7, 8, 9,
184 25, 26, 27,
185
186 10, 11, 12,
187 28, 29, 30,
188
189 13, 14, 15,
190 31, 32, 33,
191
192 16, 17, 18,
193 34, 35, 36
194 };
195
196 PackTest<T>(tflite::BuiltinOperator_PACK,
197 tensorType,
198 backends,
199 inputShape,
200 expectedOutputShape,
201 inputValues,
202 expectedOutputValues,
203 2);
204}
205
206template <typename T>
207void PackFp32Axis3Test(tflite::TensorType tensorType, std::vector<armnn::BackendId>& backends)
208{
209 std::vector<int32_t> inputShape { 3, 2, 3 };
210 std::vector<int32_t> expectedOutputShape { 3, 2, 3, 2 };
211
212 std::vector<std::vector<T>> inputValues;
213 inputValues.push_back(
214 {
215 1, 2, 3,
216 4, 5, 6,
217
218 7, 8, 9,
219 10, 11, 12,
220
221 13, 14, 15,
222 16, 17, 18
223 });
224
225 inputValues.push_back(
226 {
227 19, 20, 21,
228 22, 23, 24,
229
230 25, 26, 27,
231 28, 29, 30,
232
233 31, 32, 33,
234 34, 35, 36
235 });
236
237 std::vector<T> expectedOutputValues =
238 {
239 1, 19,
240 2, 20,
241 3, 21,
242
243 4, 22,
244 5, 23,
245 6, 24,
246
247
248 7, 25,
249 8, 26,
250 9, 27,
251
252 10, 28,
253 11, 29,
254 12, 30,
255
256
257 13, 31,
258 14, 32,
259 15, 33,
260
261 16, 34,
262 17, 35,
263 18, 36
264 };
265
266 PackTest<T>(tflite::BuiltinOperator_PACK,
267 tflite::TensorType_FLOAT32,
268 backends,
269 inputShape,
270 expectedOutputShape,
271 inputValues,
272 expectedOutputValues,
273 3);
274}
275
276template <typename T>
277void PackFp32Inputs3Test(tflite::TensorType tensorType, std::vector<armnn::BackendId>& backends)
278{
279 std::vector<int32_t> inputShape { 3, 3 };
280 std::vector<int32_t> expectedOutputShape { 3, 3, 3 };
281
282 std::vector<std::vector<T>> inputValues;
283 inputValues.push_back(
284 {
285 1, 2, 3,
286 4, 5, 6,
287 7, 8, 9
288 });
289
290 inputValues.push_back(
291 {
292 10, 11, 12,
293 13, 14, 15,
294 16, 17, 18
295 });
296
297 inputValues.push_back(
298 {
299 19, 20, 21,
300 22, 23, 24,
301 25, 26, 27
302 });
303
304 std::vector<T> expectedOutputValues =
305 {
306 1, 2, 3,
307 10, 11, 12,
308 19, 20, 21,
309
310 4, 5, 6,
311 13, 14, 15,
312 22, 23, 24,
313
314 7, 8, 9,
315 16, 17, 18,
316 25, 26, 27
317 };
318
319 PackTest<T>(tflite::BuiltinOperator_PACK,
320 tensorType,
321 backends,
322 inputShape,
323 expectedOutputShape,
324 inputValues,
325 expectedOutputValues,
326 1);
327}
328
329TEST_SUITE("Pack_CpuAccTests")
330{
331
332// Fp32
333TEST_CASE ("Pack_Fp32_Axis0_CpuAcc_Test")
334{
335 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
336 PackFp32Axis0Test<float>(tflite::TensorType_FLOAT32, backends);
337}
338
339TEST_CASE ("Pack_Fp32_Axis1_CpuAcc_Test")
340{
341 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
342 PackFp32Axis1Test<float>(tflite::TensorType_FLOAT32, backends);
343}
344
345TEST_CASE ("Pack_Fp32_Axis2_CpuAcc_Test")
346{
347 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
348 PackFp32Axis2Test<float>(tflite::TensorType_FLOAT32, backends);
349}
350
351TEST_CASE ("Pack_Fp32_Axis3_CpuAcc_Test")
352{
353 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
354 PackFp32Axis3Test<float>(tflite::TensorType_FLOAT32, backends);
355}
356
357TEST_CASE ("Pack_Fp32_Inputs3_CpuAcc_Test")
358{
359 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
360 PackFp32Inputs3Test<float>(tflite::TensorType_FLOAT32, backends);
361}
362
363// Uint8
364TEST_CASE ("Pack_Uint8_Axis0_CpuAcc_Test")
365{
366 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
367 PackFp32Axis0Test<uint8_t>(tflite::TensorType_UINT8, backends);
368}
369
370TEST_CASE ("Pack_Uint8_Inputs3_CpuAcc_Test")
371{
372 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
373 PackFp32Inputs3Test<uint8_t>(tflite::TensorType_UINT8, backends);
374}
375
376// Uint8
377TEST_CASE ("Pack_Int8_Axis0_CpuAcc_Test")
378{
379 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
380 PackFp32Axis0Test<int8_t>(tflite::TensorType_INT8, backends);
381}
382
383TEST_CASE ("Pack_Int8_Inputs3_CpuAcc_Test")
384{
385 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
386 PackFp32Inputs3Test<int8_t>(tflite::TensorType_INT8, backends);
387}
388
389}
390
391TEST_SUITE("Pack_GpuAccTests")
392{
393
394// Fp32
395TEST_CASE ("Pack_Fp32_Axis0_GpuAcc_Test")
396{
397 std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
398 PackFp32Axis0Test<float>(tflite::TensorType_FLOAT32, backends);
399}
400
401TEST_CASE ("Pack_Fp32_Axis1_GpuAcc_Test")
402{
403 std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
404 PackFp32Axis1Test<float>(tflite::TensorType_FLOAT32, backends);
405}
406
407TEST_CASE ("Pack_Fp32_Axis2_GpuAcc_Test")
408{
409 std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
410 PackFp32Axis2Test<float>(tflite::TensorType_FLOAT32, backends);
411}
412
413TEST_CASE ("Pack_Fp32_Axis3_GpuAcc_Test")
414{
415 std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
416 PackFp32Axis3Test<float>(tflite::TensorType_FLOAT32, backends);
417}
418
419TEST_CASE ("Pack_Fp32_Inputs3_GpuAcc_Test")
420{
421 std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
422 PackFp32Inputs3Test<float>(tflite::TensorType_FLOAT32, backends);
423}
424
425// Uint8
426TEST_CASE ("Pack_Uint8_Axis0_GpuAcc_Test")
427{
428 std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
429 PackFp32Axis0Test<uint8_t>(tflite::TensorType_UINT8, backends);
430}
431
432TEST_CASE ("Pack_Uint8_Inputs3_GpuAcc_Test")
433{
434 std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
435 PackFp32Inputs3Test<uint8_t>(tflite::TensorType_UINT8, backends);
436}
437
438// Int8
439TEST_CASE ("Pack_Int8_Axis0_GpuAcc_Test")
440{
441 std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
442 PackFp32Axis0Test<int8_t>(tflite::TensorType_INT8, backends);
443}
444
445TEST_CASE ("Pack_Int8_Inputs3_GpuAcc_Test")
446{
447 std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
448 PackFp32Inputs3Test<int8_t>(tflite::TensorType_INT8, backends);
449}
450
451}
452
453TEST_SUITE("Pack_CpuRefTests")
454{
455
456// Fp32
457TEST_CASE ("Pack_Fp32_Axis0_CpuRef_Test")
458{
459 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
460 PackFp32Axis0Test<float>(tflite::TensorType_FLOAT32, backends);
461}
462
463TEST_CASE ("Pack_Fp32_Axis1_CpuRef_Test")
464{
465 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
466 PackFp32Axis1Test<float>(tflite::TensorType_FLOAT32, backends);
467}
468
469TEST_CASE ("Pack_Fp32_Axis2_CpuRef_Test")
470{
471 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
472 PackFp32Axis2Test<float>(tflite::TensorType_FLOAT32, backends);
473}
474
475TEST_CASE ("Pack_Fp32_Axis3_CpuRef_Test")
476{
477 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
478 PackFp32Axis3Test<float>(tflite::TensorType_FLOAT32, backends);
479}
480
481TEST_CASE ("Pack_Fp32_Inputs3_CpuRef_Test")
482{
483 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
484 PackFp32Inputs3Test<float>(tflite::TensorType_FLOAT32, backends);
485}
486
487// Uint8
488TEST_CASE ("Pack_Uint8_Axis0_CpuRef_Test")
489{
490 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
491 PackFp32Axis0Test<uint8_t>(tflite::TensorType_UINT8, backends);
492}
493
494TEST_CASE ("Pack_Uint8_Inputs3_CpuRef_Test")
495{
496 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
497 PackFp32Inputs3Test<uint8_t>(tflite::TensorType_UINT8, backends);
498}
499
500// Int8
501TEST_CASE ("Pack_Int8_Axis0_CpuRef_Test")
502{
503 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
504 PackFp32Axis0Test<int8_t>(tflite::TensorType_INT8, backends);
505}
506
507TEST_CASE ("Pack_Int8_Inputs3_CpuRef_Test")
508{
509 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
510 PackFp32Inputs3Test<int8_t>(tflite::TensorType_INT8, backends);
511}
512
513}
514
515} // namespace armnnDelegate