xref: /aosp_15_r20/external/armnn/delegate/test/ElementwiseBinaryTest.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2020-2021, 2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ElementwiseBinaryTestHelper.hpp"
7 
8 #include <armnn_delegate.hpp>
9 
10 #include <flatbuffers/flatbuffers.h>
11 #include <tensorflow/lite/interpreter.h>
12 #include <tensorflow/lite/kernels/register.h>
13 #include <tensorflow/lite/model.h>
14 #include <schema_generated.h>
15 #include <tensorflow/lite/version.h>
16 
17 #include <doctest/doctest.h>
18 
19 namespace armnnDelegate
20 {
21 
AddFP32Test(std::vector<armnn::BackendId> & backends)22 void AddFP32Test(std::vector<armnn::BackendId>& backends)
23 {
24     std::vector<int32_t> input0Shape { 2, 2, 2, 3 };
25     std::vector<int32_t> input1Shape { 2, 2, 2, 3 };
26     std::vector<int32_t> expectedOutputShape { 2, 2, 2, 3 };
27 
28     std::vector<float> input0Values =
29     {
30         0.0f, 2.0f, 1.0f,
31         0.2f, 1.0f, 2.0f,
32 
33         1.0f, 2.0f, 1.0f,
34         0.2f, 1.0f, 2.0f,
35 
36         0.0f, 2.0f, 1.0f,
37         4.2f, 1.0f, 2.0f,
38 
39         0.0f, 0.0f, 1.0f,
40         0.2f, 1.0f, 2.0f,
41     };
42 
43     std::vector<float> input1Values =
44     {
45         1.0f, 2.0f,  1.0f,
46         0.0f, 1.0f,  2.0f,
47 
48         1.0f, 2.0f, -2.0f,
49         0.2f, 1.0f,  2.0f,
50 
51         0.0f, 2.0f,  1.0f,
52         4.2f, 0.0f, -3.0f,
53 
54         0.0f, 0.0f,  1.0f,
55         0.7f, 1.0f,  5.0f,
56     };
57 
58     std::vector<float> expectedOutputValues =
59     {
60         1.0f, 4.0f,  2.0f,
61         0.2f, 2.0f,  4.0f,
62 
63         2.0f, 4.0f, -1.0f,
64         0.4f, 2.0f,  4.0f,
65 
66         0.0f, 4.0f,  2.0f,
67         8.4f, 1.0f, -1.0f,
68 
69         0.0f, 0.0f,  2.0f,
70         0.9f, 2.0f,  7.0f,
71     };
72 
73     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_ADD,
74                                  tflite::ActivationFunctionType_NONE,
75                                  ::tflite::TensorType_FLOAT32,
76                                  backends,
77                                  input0Shape,
78                                  input1Shape,
79                                  expectedOutputShape,
80                                  input0Values,
81                                  input1Values,
82                                  expectedOutputValues);
83 }
84 
AddBroadcastTest(std::vector<armnn::BackendId> & backends)85 void AddBroadcastTest(std::vector<armnn::BackendId>& backends)
86 {
87     std::vector<int32_t> input0Shape { 1, 3, 2, 1 };
88     std::vector<int32_t> input1Shape { 1, 1, 2, 3 };
89     std::vector<int32_t> expectedOutputShape { 1, 3, 2, 3 };
90 
91     std::vector<float> input0Values
92     {
93         0.0f,
94         1.0f,
95 
96         2.0f,
97         3.0f,
98 
99         4.0f,
100         5.0f,
101     };
102     std::vector<float> input1Values
103     {
104         0.5f, 1.5f, 2.5f,
105         3.5f, 4.5f, 5.5f,
106     };
107     // Set output data
108     std::vector<float> expectedOutputValues
109     {
110         0.5f, 1.5f, 2.5f,
111         4.5f, 5.5f, 6.5f,
112 
113         2.5f, 3.5f, 4.5f,
114         6.5f, 7.5f, 8.5f,
115 
116         4.5f, 5.5f, 6.5f,
117         8.5f, 9.5f, 10.5f,
118     };
119 
120     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_ADD,
121                                  tflite::ActivationFunctionType_NONE,
122                                  ::tflite::TensorType_FLOAT32,
123                                  backends,
124                                  input0Shape,
125                                  input1Shape,
126                                  expectedOutputShape,
127                                  input0Values,
128                                  input1Values,
129                                  expectedOutputValues);
130 }
131 
AddConstInputTest(std::vector<armnn::BackendId> & backends)132 void AddConstInputTest(std::vector<armnn::BackendId>& backends)
133 {
134     std::vector<int32_t> input0Shape { 1, 3, 2, 1 };
135     std::vector<int32_t> input1Shape { 1 };
136     std::vector<int32_t> expectedOutputShape { 1, 3, 2, 1 };
137 
138     std::vector<float> input0Values
139         {
140             0.0f,
141             1.0f,
142 
143             2.0f,
144             3.0f,
145 
146             4.0f,
147             5.0f,
148         };
149     std::vector<float> input1Values
150         {
151             0.5f
152         };
153     // Set output data
154     std::vector<float> expectedOutputValues
155         {
156             0.5f,
157             1.5f,
158 
159             2.5f,
160             3.5f,
161 
162             4.5f,
163             5.5f,
164         };
165 
166     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_ADD,
167                                  tflite::ActivationFunctionType_NONE,
168                                  ::tflite::TensorType_FLOAT32,
169                                  backends,
170                                  input0Shape,
171                                  input1Shape,
172                                  expectedOutputShape,
173                                  input0Values,
174                                  input1Values,
175                                  expectedOutputValues,
176                                  1.0f,
177                                  0,
178                                  true);
179 }
180 
AddActivationTest(std::vector<armnn::BackendId> & backends)181 void AddActivationTest(std::vector<armnn::BackendId>& backends)
182 {
183     std::vector<int32_t> input0Shape { 1, 2, 2, 1 };
184     std::vector<int32_t> input1Shape { 1, 2, 2, 1 };
185     std::vector<int32_t> expectedOutputShape { 1, 2, 2, 1 };
186 
187     std::vector<float> input0Values { 4.0f, 0.8f, 0.7f, -0.8f };
188     std::vector<float> input1Values { 0.7f, -1.2f, 0.8f, 0.5f };
189     std::vector<float> expectedOutputValues { 4.7f, 0.0f, 1.5f, 0.0f };
190 
191     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_ADD,
192                                  tflite::ActivationFunctionType_RELU,
193                                  ::tflite::TensorType_FLOAT32,
194                                  backends,
195                                  input0Shape,
196                                  input1Shape,
197                                  expectedOutputShape,
198                                  input0Values,
199                                  input1Values,
200                                  expectedOutputValues);
201 }
202 
AddUint8Test(std::vector<armnn::BackendId> & backends)203 void AddUint8Test(std::vector<armnn::BackendId>& backends)
204 {
205     std::vector<int32_t> input0Shape { 1, 2, 2, 3 };
206     std::vector<int32_t> input1Shape { 1, 2, 2, 3 };
207     std::vector<int32_t> expectedOutputShape { 1, 2, 2, 3 };
208 
209     std::vector<uint8_t> input0Values =
210     {
211         63,  35,  77,  70,  56, 112,
212         203,  28, 252, 168, 245,  91
213     };
214 
215     std::vector<uint8_t> input1Values =
216     {
217         21,   7, 175, 231, 175, 210,
218         126, 161,  63,  21, 105, 126
219     };
220 
221     std::vector<uint8_t> expectedOutputValues =
222     {
223         81,  39, 249, 255, 228, 255,
224         255, 186, 255, 186, 255, 214,
225     };
226 
227     ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_ADD,
228                                    tflite::ActivationFunctionType_NONE,
229                                    ::tflite::TensorType_UINT8,
230                                    backends,
231                                    input0Shape,
232                                    input1Shape,
233                                    expectedOutputShape,
234                                    input0Values,
235                                    input1Values,
236                                    expectedOutputValues, 7.0f, 3);
237 }
238 
DivFP32Test(std::vector<armnn::BackendId> & backends)239 void DivFP32Test(std::vector<armnn::BackendId>& backends)
240 {
241     std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
242     std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
243     std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
244 
245     std::vector<float> input0Values =
246     {
247         2.f, 2.f, 2.f, 2.f, 3.f, 3.f, 3.f, 3.f,
248         4.f, 4.f, 4.f, 4.f, 5.f, 5.f, 5.f, 5.f
249 
250     };
251 
252     std::vector<float> input1Values =
253     {
254         1.f, 1.f, 1.f, 1.f, 2.f, 2.f, 2.f, 2.f,
255         4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f
256     };
257 
258     std::vector<float> expectedOutputValues =
259     {
260         2.f, 2.f, 2.f, 2.f, 1.50f, 1.50f, 1.50f, 1.50f,
261         1.f, 1.f, 1.f, 1.f, 1.25f, 1.25f, 1.25f, 1.25f
262     };
263 
264     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_DIV,
265                                  tflite::ActivationFunctionType_NONE,
266                                  ::tflite::TensorType_FLOAT32,
267                                  backends,
268                                  input0Shape,
269                                  input1Shape,
270                                  expectedOutputShape,
271                                  input0Values,
272                                  input1Values,
273                                  expectedOutputValues);
274 }
275 
DivBroadcastTest(std::vector<armnn::BackendId> & backends)276 void DivBroadcastTest(std::vector<armnn::BackendId>& backends)
277 {
278     std::vector<int32_t> input0Shape { 1, 2, 2, 2 };
279     std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
280     std::vector<int32_t> expectedOutputShape { 1, 2, 2, 2 };
281 
282     std::vector<float> input0Values = { 2, 4, 6, 8, 10, 12, 14, 16 };
283     std::vector<float> input1Values = { 2 };
284     std::vector<float> expectedOutputValues = { 1, 2, 3, 4, 5, 6, 7, 8 };
285 
286     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_DIV,
287                                  tflite::ActivationFunctionType_NONE,
288                                  ::tflite::TensorType_FLOAT32,
289                                  backends,
290                                  input0Shape,
291                                  input1Shape,
292                                  expectedOutputShape,
293                                  input0Values,
294                                  input1Values,
295                                  expectedOutputValues);
296 }
297 
DivUint8Test(std::vector<armnn::BackendId> & backends)298 void DivUint8Test(std::vector<armnn::BackendId>& backends)
299 {
300     std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
301     std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
302     std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
303 
304     std::vector<uint8_t> input0Values =
305     {
306         2, 2, 2, 2,  3, 3, 3, 3,
307         4, 4, 4, 4,  5, 5, 5, 5
308 
309     };
310 
311     std::vector<uint8_t> input1Values =
312     {
313         1, 1, 1, 1,  2, 2, 2, 2,
314         4, 4, 4, 4,  4, 4, 4, 4
315     };
316 
317     std::vector<uint8_t> expectedOutputValues =
318     {
319         8, 8, 8, 8,  6, 6, 6, 6,
320         4, 4, 4, 4,  5, 5, 5, 5
321     };
322 
323     ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_DIV,
324                                    tflite::ActivationFunctionType_NONE,
325                                    ::tflite::TensorType_UINT8,
326                                    backends,
327                                    input0Shape,
328                                    input1Shape,
329                                    expectedOutputShape,
330                                    input0Values,
331                                    input1Values,
332                                    expectedOutputValues, 0.25f, 0);
333 }
334 
FloorDivFP32Test(std::vector<armnn::BackendId> & backends)335 void FloorDivFP32Test(std::vector<armnn::BackendId>& backends)
336 {
337     std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
338     std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
339     std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
340 
341     std::vector<float> input0Values =
342     {
343         -37.5f, -15.2f, -8.76f, -2.0f,  -2.6f, -1.0f,  -0.8f,   0.0f,
344           4.0f,   1.6f,  2.0f,   5.2f,   6.0f, 35.04f, 60.8f, 150.0f
345     };
346 
347     std::vector<float> input1Values =
348     {
349         1.f, 1.f, 1.f, 1.f, 2.f, 2.f, 2.f, 2.f,
350         4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f
351     };
352 
353     std::vector<float> expectedOutputValues =
354     {
355         -38.0f, -16.0f, -9.0f,  -2.0f, -2.0f, -1.0f,  -1.0f,  0.0f,
356           1.0f,   0.0f,  0.0f,   1.0f,  1.0f,  8.0f,  15.0f, 37.0f
357     };
358 
359     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_FLOOR_DIV,
360                                  tflite::ActivationFunctionType_NONE,
361                                  ::tflite::TensorType_FLOAT32,
362                                  backends,
363                                  input0Shape,
364                                  input1Shape,
365                                  expectedOutputShape,
366                                  input0Values,
367                                  input1Values,
368                                  expectedOutputValues);
369 
370 }
371 
MaxFP32Test(std::vector<armnn::BackendId> & backends)372 void MaxFP32Test(std::vector<armnn::BackendId>& backends)
373 {
374     std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
375     std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
376     std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
377 
378     std::vector<float> input0Values =
379     {
380         1.f, 1.f, 5.f, 1.f,  2.f, 2.f, 7.f, 2.f,
381         3.f, 3.f, 3.f, 3.f,  4.f, 4.f, 4.f, 4.f
382 
383     };
384 
385     std::vector<float> input1Values =
386     {
387         2.f, 2.f, 2.f, 2.f,  3.f, 3.f, 3.f, 3.f,
388         4.f, 4.f, 4.f, 4.f,  5.f, 5.f, 5.f, 5.f
389     };
390 
391     std::vector<float> expectedOutputValues =
392     {
393         2.f,  2.f, 5.f,  2.f,   3.f,  3.f,  7.f,  3.f,
394         4.f, 4.f, 4.f, 4.f,  5.f, 5.f, 5.f, 5.f
395     };
396 
397     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MAXIMUM,
398                                  tflite::ActivationFunctionType_NONE,
399                                  ::tflite::TensorType_FLOAT32,
400                                  backends,
401                                  input0Shape,
402                                  input1Shape,
403                                  expectedOutputShape,
404                                  input0Values,
405                                  input1Values,
406                                  expectedOutputValues);
407 }
408 
MaxBroadcastTest(std::vector<armnn::BackendId> & backends)409 void MaxBroadcastTest(std::vector<armnn::BackendId>& backends)
410 {
411     std::vector<int32_t> input0Shape { 1, 2, 2, 2 };
412     std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
413     std::vector<int32_t> expectedOutputShape { 1, 2, 2, 2 };
414 
415     std::vector<float> input0Values = { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f };
416     std::vector<float> input1Values = { 4.f };
417     std::vector<float> expectedOutputValues = { 4.f, 4.f, 4.f, 4.f, 5.f, 6.f, 7.f, 8.f };
418 
419     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MAXIMUM,
420                                  tflite::ActivationFunctionType_NONE,
421                                  ::tflite::TensorType_FLOAT32,
422                                  backends,
423                                  input0Shape,
424                                  input1Shape,
425                                  expectedOutputShape,
426                                  input0Values,
427                                  input1Values,
428                                  expectedOutputValues);
429 }
430 
MaxUint8Test(std::vector<armnn::BackendId> & backends)431 void MaxUint8Test(std::vector<armnn::BackendId>& backends)
432 {
433     std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
434     std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
435     std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
436 
437     std::vector<uint8_t> input0Values =
438     {
439         1, 1, 1, 1, 7, 8, 9, 9,
440         3, 3, 3, 3, 4, 4, 4, 4
441 
442     };
443 
444     std::vector<uint8_t> input1Values =
445     {
446         2, 2, 2, 2, 3, 3, 3, 3,
447         4, 4, 4, 4, 5, 5, 5, 5
448     };
449 
450     std::vector<uint8_t> expectedOutputValues =
451     {
452         2, 2, 2, 2, 7, 8, 9, 9,
453         4, 4, 4, 4, 5, 5, 5, 5
454     };
455 
456     ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_MAXIMUM,
457                                    tflite::ActivationFunctionType_NONE,
458                                    ::tflite::TensorType_UINT8,
459                                    backends,
460                                    input0Shape,
461                                    input1Shape,
462                                    expectedOutputShape,
463                                    input0Values,
464                                    input1Values,
465                                    expectedOutputValues, 1.0f, 0);
466 }
467 
MinFP32Test(std::vector<armnn::BackendId> & backends)468 void MinFP32Test(std::vector<armnn::BackendId>& backends)
469 {
470     std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
471     std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
472     std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
473 
474     std::vector<float> input0Values =
475     {
476         1.f, 1.f, 5.f, 1.f,  2.f, 2.f, 7.f, 2.f,
477         3.f, 3.f, 3.f, 3.f,  4.f, 4.f, 4.f, 4.f
478 
479     };
480 
481     std::vector<float> input1Values =
482     {
483         2.f, 2.f, 2.f, 2.f,  3.f, 3.f, 3.f, 3.f,
484         1.f, 1.f, 1.f, 1.f,  5.f, 5.f, 5.f, 5.f
485     };
486 
487     std::vector<float> expectedOutputValues =
488     {
489         1.f,  1.f, 2.f,  1.f,   2.f,  2.f,  3.f,  2.f,
490         1.f, 1.f, 1.f, 1.f,  4.f, 4.f, 4.f, 4.f
491     };
492 
493     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MINIMUM,
494                                  tflite::ActivationFunctionType_NONE,
495                                  ::tflite::TensorType_FLOAT32,
496                                  backends,
497                                  input0Shape,
498                                  input1Shape,
499                                  expectedOutputShape,
500                                  input0Values,
501                                  input1Values,
502                                  expectedOutputValues);
503 }
504 
MinBroadcastTest(std::vector<armnn::BackendId> & backends)505 void MinBroadcastTest(std::vector<armnn::BackendId>& backends)
506 {
507     std::vector<int32_t> input0Shape { 1, 2, 2, 2 };
508     std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
509     std::vector<int32_t> expectedOutputShape { 1, 2, 2, 2 };
510 
511     std::vector<float> input0Values = { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f };
512 
513     std::vector<float> input1Values = { 4.f };
514 
515     std::vector<float> expectedOutputValues = { 1.f, 2.f, 3.f, 4.f, 4.f, 4.f, 4.f, 4.f };
516 
517     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MINIMUM,
518                                  tflite::ActivationFunctionType_NONE,
519                                  ::tflite::TensorType_FLOAT32,
520                                  backends,
521                                  input0Shape,
522                                  input1Shape,
523                                  expectedOutputShape,
524                                  input0Values,
525                                  input1Values,
526                                  expectedOutputValues);
527 }
528 
MinUint8Test(std::vector<armnn::BackendId> & backends)529 void MinUint8Test(std::vector<armnn::BackendId>& backends)
530 {
531     std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
532     std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
533     std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
534 
535     std::vector<uint8_t> input0Values =
536     {
537         1, 1, 1, 1, 7, 8, 9, 9,
538         3, 3, 3, 3, 4, 4, 4, 4
539 
540     };
541 
542     std::vector<uint8_t> input1Values =
543     {
544         2, 2, 2, 2, 3, 3, 3, 3,
545         4, 4, 4, 4, 5, 5, 5, 5
546     };
547 
548     std::vector<uint8_t> expectedOutputValues =
549     {
550         1, 1, 1, 1, 3, 3, 3, 3,
551         3, 3, 3, 3, 4, 4, 4, 4
552     };
553 
554     ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_MINIMUM,
555                                    tflite::ActivationFunctionType_NONE,
556                                    ::tflite::TensorType_UINT8,
557                                    backends,
558                                    input0Shape,
559                                    input1Shape,
560                                    expectedOutputShape,
561                                    input0Values,
562                                    input1Values,
563                                    expectedOutputValues, 1.0f, 0);
564 }
565 
MulFP32Test(std::vector<armnn::BackendId> & backends)566 void MulFP32Test(std::vector<armnn::BackendId>& backends)
567 {
568     std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
569     std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
570     std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
571 
572     std::vector<float> input0Values =
573     {
574         1.f, 1.f, 1.f, 1.f,  2.f, 2.f, 2.f, 2.f,
575         3.f, 3.f, 3.f, 3.f,  4.f, 4.f, 4.f, 4.f
576 
577     };
578 
579     std::vector<float> input1Values =
580     {
581         2.f, 2.f, 2.f, 2.f,  3.f, 3.f, 3.f, 3.f,
582         4.f, 4.f, 4.f, 4.f,  5.f, 5.f, 5.f, 5.f
583     };
584 
585     std::vector<float> expectedOutputValues =
586     {
587         2.f,  2.f,  2.f,  2.f,   6.f,  6.f,  6.f,  6.f,
588         12.f, 12.f, 12.f, 12.f,  20.f, 20.f, 20.f, 20.f
589     };
590 
591     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MUL,
592                                  tflite::ActivationFunctionType_NONE,
593                                  ::tflite::TensorType_FLOAT32,
594                                  backends,
595                                  input0Shape,
596                                  input1Shape,
597                                  expectedOutputShape,
598                                  input0Values,
599                                  input1Values,
600                                  expectedOutputValues);
601 }
602 
MulBroadcastTest(std::vector<armnn::BackendId> & backends)603 void MulBroadcastTest(std::vector<armnn::BackendId>& backends)
604 {
605     std::vector<int32_t> input0Shape { 1, 2, 2, 2 };
606     std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
607     std::vector<int32_t> expectedOutputShape { 1, 2, 2, 2 };
608 
609     std::vector<float> input0Values = { 2, 4, 6, 8, 10, 12, 14, 16 };
610     std::vector<float> input1Values = { 2 };
611     std::vector<float> expectedOutputValues = { 4, 8, 12, 16, 20, 24, 28, 32 };
612 
613     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MUL,
614                                  tflite::ActivationFunctionType_NONE,
615                                  ::tflite::TensorType_FLOAT32,
616                                  backends,
617                                  input0Shape,
618                                  input1Shape,
619                                  expectedOutputShape,
620                                  input0Values,
621                                  input1Values,
622                                  expectedOutputValues);
623 }
624 
MulUint8Test(std::vector<armnn::BackendId> & backends)625 void MulUint8Test(std::vector<armnn::BackendId>& backends)
626 {
627     std::vector<int32_t> input0Shape { 1, 2, 2, 3 };
628     std::vector<int32_t> input1Shape { 1, 1, 1, 3 };
629     std::vector<int32_t> expectedOutputShape { 1, 2, 2, 3 };
630 
631     std::vector<uint8_t> input0Values =
632     {
633         1, 2, 3,    4,  5,  6,
634         7, 8, 9,   10, 11, 12
635 
636     };
637 
638     std::vector<uint8_t> input1Values = { 1, 2, 3 };
639 
640     std::vector<uint8_t> expectedOutputValues =
641     {
642         1,  4,   9,     4, 10, 18,
643         7, 16,  27,    10, 22, 36
644     };
645 
646     ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_MUL,
647                                    tflite::ActivationFunctionType_NONE,
648                                    ::tflite::TensorType_UINT8,
649                                    backends,
650                                    input0Shape,
651                                    input1Shape,
652                                    expectedOutputShape,
653                                    input0Values,
654                                    input1Values,
655                                    expectedOutputValues, 1.0f, 0);
656 }
657 
MulActivationTest(std::vector<armnn::BackendId> & backends)658 void MulActivationTest(std::vector<armnn::BackendId>& backends)
659 {
660     std::vector<int32_t> input0Shape { 1, 2, 2, 1 };
661     std::vector<int32_t> input1Shape { 1, 2, 2, 1 };
662     std::vector<int32_t> expectedOutputShape { 1, 2, 2, 1 };
663 
664     std::vector<float> input0Values { 4.0f, 0.0f, 1.0f, 0.5f };
665     std::vector<float> input1Values { -2.0f, -1.2f, 2.5f, 2.0f };
666     std::vector<float> expectedOutputValues { 0.0f, 0.0f, 2.5f, 1.0f };
667 
668     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MUL,
669                                  tflite::ActivationFunctionType_RELU,
670                                  ::tflite::TensorType_FLOAT32,
671                                  backends,
672                                  input0Shape,
673                                  input1Shape,
674                                  expectedOutputShape,
675                                  input0Values,
676                                  input1Values,
677                                  expectedOutputValues);
678 }
679 
SubFP32Test(std::vector<armnn::BackendId> & backends)680 void SubFP32Test(std::vector<armnn::BackendId>& backends)
681 {
682     std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
683     std::vector<int32_t> input1Shape { 1, 1, 2, 2 };
684     std::vector<int32_t> expectedOutputShape { 1, 1, 2, 2 };
685 
686     std::vector<float> input0Values = { 1, 3, 3, -7 };
687     std::vector<float> input1Values = { 1, -1, 0, -2 };
688     std::vector<float> expectedOutputValues = { 0, 4, 3, -5 };
689 
690     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_SUB,
691                                  tflite::ActivationFunctionType_NONE,
692                                  ::tflite::TensorType_FLOAT32,
693                                  backends,
694                                  input0Shape,
695                                  input1Shape,
696                                  expectedOutputShape,
697                                  input0Values,
698                                  input1Values,
699                                  expectedOutputValues);
700 }
701 
SubBroadcastTest(std::vector<armnn::BackendId> & backends)702 void SubBroadcastTest(std::vector<armnn::BackendId>& backends)
703 {
704     std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
705     std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
706     std::vector<int32_t> expectedOutputShape { 1, 1, 2, 2 };
707 
708     std::vector<float> input0Values = { 2, 3, 4, 5};
709     std::vector<float> input1Values = { 10 };
710     std::vector<float> expectedOutputValues = { -8, -7, -6, -5 };
711 
712     ElementwiseBinaryTest<float>(tflite::BuiltinOperator_SUB,
713                                  tflite::ActivationFunctionType_NONE,
714                                  ::tflite::TensorType_FLOAT32,
715                                  backends,
716                                  input0Shape,
717                                  input1Shape,
718                                  expectedOutputShape,
719                                  input0Values,
720                                  input1Values,
721                                  expectedOutputValues);
722 }
723 
SubUint8Test(std::vector<armnn::BackendId> & backends)724 void SubUint8Test(std::vector<armnn::BackendId>& backends)
725 {
726     std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
727     std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
728     std::vector<int32_t> expectedOutputShape { 1, 1, 2, 2 };
729 
730     std::vector<uint8_t> input0Values = { 10, 12, 14, 16 };
731     std::vector<uint8_t> input1Values = { 2 };
732     std::vector<uint8_t> expectedOutputValues = { 8, 10, 12, 14 };
733 
734     ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_SUB,
735                                    tflite::ActivationFunctionType_NONE,
736                                    ::tflite::TensorType_UINT8,
737                                    backends,
738                                    input0Shape,
739                                    input1Shape,
740                                    expectedOutputShape,
741                                    input0Values,
742                                    input1Values,
743                                    expectedOutputValues, 1.0f, 0);
744 }
745 
746 TEST_SUITE("ElementwiseBinary_GpuAccTests")
747 {
748 
749 TEST_CASE ("ADD_FP32_GpuAcc_Test")
750 {
751     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
752     AddFP32Test(backends);
753 }
754 
755 TEST_CASE ("ADD_Broadcast_GpuAcc_Test")
756 {
757     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
758     AddBroadcastTest(backends);
759 }
760 
761 TEST_CASE ("ADD_Activation_GpuAcc_Test")
762 {
763     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
764     AddActivationTest(backends);
765 }
766 
767 TEST_CASE ("ADD_UINT8_GpuAcc_Test")
768 {
769     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
770     AddUint8Test(backends);
771 }
772 
773 TEST_CASE ("DIV_FP32_GpuAcc_Test")
774 {
775     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
776     DivFP32Test(backends);
777 }
778 
779 TEST_CASE ("DIV_Broadcast_GpuAcc_Test")
780 {
781     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
782     DivBroadcastTest(backends);
783 }
784 
785 TEST_CASE ("FLOORDIV_FP32_GpuAcc_Test")
786 {
787     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
788     FloorDivFP32Test(backends);
789 }
790 
791 TEST_CASE ("MAX_FP32_GpuAcc_Test")
792 {
793     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
794     MaxFP32Test(backends);
795 }
796 
797 TEST_CASE ("MAX_Broadcast_GpuAcc_Test")
798 {
799     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
800     MaxBroadcastTest(backends);
801 }
802 
803 TEST_CASE ("MAX_UINT8_GpuAcc_Test")
804 {
805     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
806     MaxUint8Test(backends);
807 }
808 
809 TEST_CASE ("MIN_FP32_GpuAcc_Test")
810 {
811     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
812     MinFP32Test(backends);
813 }
814 
815 TEST_CASE ("MIN_Broadcast_GpuAcc_Test")
816 {
817     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
818     MinBroadcastTest(backends);
819 }
820 
821 TEST_CASE ("MIN_UINT8_GpuAcc_Test")
822 {
823     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
824     MinUint8Test(backends);
825 }
826 
827 TEST_CASE ("MUL_FP32_GpuAcc_Test")
828 {
829     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
830     MulFP32Test(backends);
831 }
832 
833 TEST_CASE ("MUL_Broadcast_GpuAcc_Test")
834 {
835     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
836     MulBroadcastTest(backends);
837 }
838 
839 TEST_CASE ("MUL_Activation_GpuAcc_Test")
840 {
841     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
842     MulActivationTest(backends);
843 }
844 
845 TEST_CASE ("MUL_UINT8_GpuAcc_Test")
846 {
847     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
848     MulUint8Test(backends);
849 }
850 
851 TEST_CASE ("SUB_FP32_GpuAcc_Test")
852 {
853     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
854     SubFP32Test(backends);
855 }
856 
857 TEST_CASE ("SUB_Broadcast_GpuAcc_Test")
858 {
859     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
860     SubBroadcastTest(backends);
861 }
862 
863 TEST_CASE ("SUB_UINT8_GpuAcc_Test")
864 {
865     std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
866     SubUint8Test(backends);
867 }
868 
869 } //TEST_SUITE("ElementwiseBinary_GpuAccTests")
870 
871 
872 
873 TEST_SUITE("ElementwiseBinary_CpuAccTests")
874 {
875 
876 TEST_CASE ("ADD_FP32_CpuAcc_Test")
877 {
878     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
879     AddFP32Test(backends);
880 }
881 
882 TEST_CASE ("ADD_Broadcast_CpuAcc_Test")
883 {
884     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
885     AddBroadcastTest(backends);
886 }
887 
888 TEST_CASE ("ADD_Activation_CpuAcc_Test")
889 {
890     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
891     AddActivationTest(backends);
892 }
893 
894 TEST_CASE ("ADD_UINT8_CpuAcc_Test")
895 {
896     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
897     AddUint8Test(backends);
898 }
899 
900 TEST_CASE ("DIV_FP32_CpuAcc_Test")
901 {
902     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
903     DivFP32Test(backends);
904 }
905 
906 TEST_CASE ("DIV_Broadcast_CpuAcc_Test")
907 {
908     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
909     DivBroadcastTest(backends);
910 }
911 
912 TEST_CASE ("FLOORDIV_FP32_CpuAcc_Test")
913 {
914     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
915     FloorDivFP32Test(backends);
916 }
917 
918 TEST_CASE ("MAX_FP32_CpuAcc_Test")
919 {
920     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
921     MaxFP32Test(backends);
922 }
923 
924 TEST_CASE ("MAX_Broadcast_CpuAcc_Test")
925 {
926     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
927     MaxBroadcastTest(backends);
928 }
929 
930 TEST_CASE ("MAX_UINT8_CpuAcc_Test")
931 {
932     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
933     MaxUint8Test(backends);
934 }
935 
936 TEST_CASE ("MIN_FP32_CpuAcc_Test")
937 {
938     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
939     MinFP32Test(backends);
940 }
941 
942 TEST_CASE ("MIN_Broadcast_CpuAcc_Test")
943 {
944     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
945     MinBroadcastTest(backends);
946 }
947 
948 TEST_CASE ("MIN_UINT8_CpuAcc_Test")
949 {
950     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
951     MinUint8Test(backends);
952 }
953 
954 TEST_CASE ("MUL_FP32_CpuAcc_Test")
955 {
956     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
957     MulFP32Test(backends);
958 }
959 
960 TEST_CASE ("MUL_Broadcast_CpuAcc_Test")
961 {
962     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
963     MulBroadcastTest(backends);
964 }
965 
966 TEST_CASE ("MUL_Actiation_CpuAcc_Test")
967 {
968     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
969     MulActivationTest(backends);
970 }
971 
972 TEST_CASE ("MUL_UINT8_CpuAcc_Test")
973 {
974     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
975     MulUint8Test(backends);
976 }
977 
978 TEST_CASE ("SUB_FP32_CpuAcc_Test")
979 {
980     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
981     SubFP32Test(backends);
982 }
983 
984 TEST_CASE ("SUB_Broadcast_CpuAcc_Test")
985 {
986     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
987     SubBroadcastTest(backends);
988 }
989 
990 TEST_CASE ("SUB_UINT8_CpuAcc_Test")
991 {
992     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
993     SubUint8Test(backends);
994 }
995 
996 } // TEST_SUITE("ElementwiseBinary_CpuAccTests")
997 
998 
999 TEST_SUITE("ElementwiseBinary_CpuRefTests")
1000 {
1001 
1002 TEST_CASE ("ADD_FP32_CpuRef_Test")
1003 {
1004     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1005     AddFP32Test(backends);
1006 }
1007 
1008 TEST_CASE ("ADD_Broadcast_CpuRef_Test")
1009 {
1010     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1011     AddBroadcastTest(backends);
1012 }
1013 
1014 TEST_CASE ("ADD_Constant_Input_CpuRef_Test")
1015 {
1016     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1017     AddConstInputTest(backends);
1018 }
1019 
1020 TEST_CASE ("ADD_Activation_CpuRef_Test")
1021 {
1022     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1023     AddActivationTest(backends);
1024 }
1025 
1026 TEST_CASE ("ADD_UINT8_CpuRef_Test")
1027 {
1028     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1029     AddUint8Test(backends);
1030 }
1031 
1032 TEST_CASE ("DIV_FP32_CpuRef_Test")
1033 {
1034     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1035     DivFP32Test(backends);
1036 }
1037 
1038 TEST_CASE ("DIV_Broadcast_CpuRef_Test")
1039 {
1040     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1041     DivBroadcastTest(backends);
1042 }
1043 
1044 TEST_CASE ("FLOORDIV_FP32_CpuRef_Test")
1045 {
1046     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1047     FloorDivFP32Test(backends);
1048 }
1049 
1050 TEST_CASE ("DIV_UINT8_CpuRef_Test")
1051 {
1052     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1053     DivUint8Test(backends);
1054 }
1055 
1056 TEST_CASE ("MAX_FP32_CpuRef_Test")
1057 {
1058     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1059     MaxFP32Test(backends);
1060 }
1061 
1062 TEST_CASE ("MAX_Broadcast_CpuRef_Test")
1063 {
1064     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1065     MaxBroadcastTest(backends);
1066 }
1067 
1068 TEST_CASE ("MAX_UINT8_CpuRef_Test")
1069 {
1070     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1071     MaxUint8Test(backends);
1072 }
1073 
1074 TEST_CASE ("MIN_FP32_CpuRef_Test")
1075 {
1076     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1077     MinFP32Test(backends);
1078 }
1079 
1080 TEST_CASE ("MIN_Broadcast_CpuRef_Test")
1081 {
1082     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1083     MinBroadcastTest(backends);
1084 }
1085 
1086 TEST_CASE ("MIN_UINT8_CpuRef_Test")
1087 {
1088     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1089     MinUint8Test(backends);
1090 }
1091 
1092 TEST_CASE ("MUL_FP32_CpuRef_Test")
1093 {
1094     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1095     MulFP32Test(backends);
1096 }
1097 
1098 TEST_CASE ("MUL_Broadcast_CpuRef_Test")
1099 {
1100     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1101     MulBroadcastTest(backends);
1102 }
1103 
1104 TEST_CASE ("MUL_Actiation_CpuRef_Test")
1105 {
1106     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1107     MulActivationTest(backends);
1108 }
1109 
1110 TEST_CASE ("MUL_UINT8_CpuRef_Test")
1111 {
1112     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1113     MulUint8Test(backends);
1114 }
1115 
1116 TEST_CASE ("SUB_FP32_CpuRef_Test")
1117 {
1118     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1119     SubFP32Test(backends);
1120 }
1121 
1122 TEST_CASE ("SUB_Broadcast_CpuRef_Test")
1123 {
1124     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1125     SubBroadcastTest(backends);
1126 }
1127 
1128 TEST_CASE ("SUB_UINT8_CpuRef_Test")
1129 {
1130     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
1131     SubUint8Test(backends);
1132 }
1133 
1134 } // TEST_SUITE("ElementwiseBinary_CpuRefTests")
1135 
1136 } // namespace armnnDelegate
1137