blob: 49d4ae41b359ca4abf1a293eb3aad0cc8ee00197 [file] [log] [blame]
Sadik Armagan67e95f22020-10-29 16:14:54 +00001//
Ryan OSheaa544f0f2023-01-25 18:10:20 +00002// Copyright © 2020-2021, 2023 Arm Ltd and Contributors. All rights reserved.
Sadik Armagan67e95f22020-10-29 16:14:54 +00003// 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>
Colm Donelan5ea6e3f2023-12-08 15:49:54 +000014
Sadik Armagan67e95f22020-10-29 16:14:54 +000015#include <tensorflow/lite/version.h>
16
17#include <doctest/doctest.h>
18
19namespace armnnDelegate
20{
21
Colm Donelaneff204a2023-11-28 15:46:09 +000022void AddFP32Test()
Sadik Armagan67e95f22020-10-29 16:14:54 +000023{
Sadik Armagan67e95f22020-10-29 16:14:54 +000024 std::vector<int32_t> input0Shape { 2, 2, 2, 3 };
25 std::vector<int32_t> input1Shape { 2, 2, 2, 3 };
Sadik Armagan21a94ff2020-11-09 08:38:30 +000026 std::vector<int32_t> expectedOutputShape { 2, 2, 2, 3 };
Sadik Armagan67e95f22020-10-29 16:14:54 +000027
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,
Sadik Armagan67e95f22020-10-29 16:14:54 +000041 };
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
Sadik Armagan21a94ff2020-11-09 08:38:30 +000073 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_ADD,
74 tflite::ActivationFunctionType_NONE,
75 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +000076 input0Shape,
77 input1Shape,
78 expectedOutputShape,
79 input0Values,
80 input1Values,
81 expectedOutputValues);
Sadik Armagan67e95f22020-10-29 16:14:54 +000082}
83
Colm Donelaneff204a2023-11-28 15:46:09 +000084void AddBroadcastTest()
Sadik Armagan67e95f22020-10-29 16:14:54 +000085{
Sadik Armagan67e95f22020-10-29 16:14:54 +000086 std::vector<int32_t> input0Shape { 1, 3, 2, 1 };
87 std::vector<int32_t> input1Shape { 1, 1, 2, 3 };
Sadik Armagan21a94ff2020-11-09 08:38:30 +000088 std::vector<int32_t> expectedOutputShape { 1, 3, 2, 3 };
Sadik Armagan67e95f22020-10-29 16:14:54 +000089
90 std::vector<float> input0Values
91 {
92 0.0f,
93 1.0f,
94
95 2.0f,
96 3.0f,
97
98 4.0f,
99 5.0f,
100 };
101 std::vector<float> input1Values
102 {
103 0.5f, 1.5f, 2.5f,
104 3.5f, 4.5f, 5.5f,
105 };
106 // Set output data
107 std::vector<float> expectedOutputValues
108 {
109 0.5f, 1.5f, 2.5f,
110 4.5f, 5.5f, 6.5f,
111
112 2.5f, 3.5f, 4.5f,
113 6.5f, 7.5f, 8.5f,
114
115 4.5f, 5.5f, 6.5f,
116 8.5f, 9.5f, 10.5f,
117 };
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000118
119 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_ADD,
120 tflite::ActivationFunctionType_NONE,
121 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000122 input0Shape,
123 input1Shape,
124 expectedOutputShape,
125 input0Values,
126 input1Values,
127 expectedOutputValues);
Sadik Armagan67e95f22020-10-29 16:14:54 +0000128}
129
Colm Donelaneff204a2023-11-28 15:46:09 +0000130void AddConstInputTest()
Sadik Armaganf7ac72c2021-05-05 15:03:50 +0100131{
132 std::vector<int32_t> input0Shape { 1, 3, 2, 1 };
133 std::vector<int32_t> input1Shape { 1 };
134 std::vector<int32_t> expectedOutputShape { 1, 3, 2, 1 };
135
136 std::vector<float> input0Values
137 {
138 0.0f,
139 1.0f,
140
141 2.0f,
142 3.0f,
143
144 4.0f,
145 5.0f,
146 };
147 std::vector<float> input1Values
148 {
149 0.5f
150 };
151 // Set output data
152 std::vector<float> expectedOutputValues
153 {
154 0.5f,
155 1.5f,
156
157 2.5f,
158 3.5f,
159
160 4.5f,
161 5.5f,
162 };
163
164 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_ADD,
165 tflite::ActivationFunctionType_NONE,
166 ::tflite::TensorType_FLOAT32,
Sadik Armaganf7ac72c2021-05-05 15:03:50 +0100167 input0Shape,
168 input1Shape,
169 expectedOutputShape,
170 input0Values,
171 input1Values,
172 expectedOutputValues,
173 1.0f,
174 0,
175 true);
176}
177
Colm Donelaneff204a2023-11-28 15:46:09 +0000178void AddActivationTest()
Sadik Armagan67e95f22020-10-29 16:14:54 +0000179{
Sadik Armagan67e95f22020-10-29 16:14:54 +0000180 std::vector<int32_t> input0Shape { 1, 2, 2, 1 };
181 std::vector<int32_t> input1Shape { 1, 2, 2, 1 };
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000182 std::vector<int32_t> expectedOutputShape { 1, 2, 2, 1 };
Sadik Armagan67e95f22020-10-29 16:14:54 +0000183
184 std::vector<float> input0Values { 4.0f, 0.8f, 0.7f, -0.8f };
185 std::vector<float> input1Values { 0.7f, -1.2f, 0.8f, 0.5f };
Sadik Armagan67e95f22020-10-29 16:14:54 +0000186 std::vector<float> expectedOutputValues { 4.7f, 0.0f, 1.5f, 0.0f };
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000187
188 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_ADD,
189 tflite::ActivationFunctionType_RELU,
190 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000191 input0Shape,
192 input1Shape,
193 expectedOutputShape,
194 input0Values,
195 input1Values,
196 expectedOutputValues);
Sadik Armagan67e95f22020-10-29 16:14:54 +0000197}
198
Colm Donelaneff204a2023-11-28 15:46:09 +0000199void AddUint8Test()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000200{
201 std::vector<int32_t> input0Shape { 1, 2, 2, 3 };
202 std::vector<int32_t> input1Shape { 1, 2, 2, 3 };
203 std::vector<int32_t> expectedOutputShape { 1, 2, 2, 3 };
204
205 std::vector<uint8_t> input0Values =
206 {
207 63, 35, 77, 70, 56, 112,
208 203, 28, 252, 168, 245, 91
209 };
210
211 std::vector<uint8_t> input1Values =
212 {
213 21, 7, 175, 231, 175, 210,
214 126, 161, 63, 21, 105, 126
215 };
216
217 std::vector<uint8_t> expectedOutputValues =
218 {
219 81, 39, 249, 255, 228, 255,
220 255, 186, 255, 186, 255, 214,
221 };
222
223 ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_ADD,
224 tflite::ActivationFunctionType_NONE,
225 ::tflite::TensorType_UINT8,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000226 input0Shape,
227 input1Shape,
228 expectedOutputShape,
229 input0Values,
230 input1Values,
231 expectedOutputValues, 7.0f, 3);
Sadik Armagan67e95f22020-10-29 16:14:54 +0000232}
233
Colm Donelaneff204a2023-11-28 15:46:09 +0000234void DivFP32Test()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000235{
236 std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
237 std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
238 std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
239
240 std::vector<float> input0Values =
241 {
242 2.f, 2.f, 2.f, 2.f, 3.f, 3.f, 3.f, 3.f,
243 4.f, 4.f, 4.f, 4.f, 5.f, 5.f, 5.f, 5.f
244
245 };
246
247 std::vector<float> input1Values =
248 {
249 1.f, 1.f, 1.f, 1.f, 2.f, 2.f, 2.f, 2.f,
250 4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f
251 };
252
253 std::vector<float> expectedOutputValues =
254 {
255 2.f, 2.f, 2.f, 2.f, 1.50f, 1.50f, 1.50f, 1.50f,
256 1.f, 1.f, 1.f, 1.f, 1.25f, 1.25f, 1.25f, 1.25f
257 };
258
259 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_DIV,
260 tflite::ActivationFunctionType_NONE,
261 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000262 input0Shape,
263 input1Shape,
264 expectedOutputShape,
265 input0Values,
266 input1Values,
267 expectedOutputValues);
268}
269
Colm Donelaneff204a2023-11-28 15:46:09 +0000270void DivBroadcastTest()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000271{
272 std::vector<int32_t> input0Shape { 1, 2, 2, 2 };
273 std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
274 std::vector<int32_t> expectedOutputShape { 1, 2, 2, 2 };
275
276 std::vector<float> input0Values = { 2, 4, 6, 8, 10, 12, 14, 16 };
277 std::vector<float> input1Values = { 2 };
278 std::vector<float> expectedOutputValues = { 1, 2, 3, 4, 5, 6, 7, 8 };
279
280 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_DIV,
281 tflite::ActivationFunctionType_NONE,
282 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000283 input0Shape,
284 input1Shape,
285 expectedOutputShape,
286 input0Values,
287 input1Values,
288 expectedOutputValues);
289}
290
291void DivUint8Test(std::vector<armnn::BackendId>& backends)
292{
293 std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
294 std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
295 std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
296
297 std::vector<uint8_t> input0Values =
298 {
299 2, 2, 2, 2, 3, 3, 3, 3,
300 4, 4, 4, 4, 5, 5, 5, 5
301
302 };
303
304 std::vector<uint8_t> input1Values =
305 {
306 1, 1, 1, 1, 2, 2, 2, 2,
307 4, 4, 4, 4, 4, 4, 4, 4
308 };
309
310 std::vector<uint8_t> expectedOutputValues =
311 {
312 8, 8, 8, 8, 6, 6, 6, 6,
313 4, 4, 4, 4, 5, 5, 5, 5
314 };
315
316 ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_DIV,
317 tflite::ActivationFunctionType_NONE,
318 ::tflite::TensorType_UINT8,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000319 input0Shape,
320 input1Shape,
321 expectedOutputShape,
322 input0Values,
323 input1Values,
Colm Donelaneff204a2023-11-28 15:46:09 +0000324 expectedOutputValues,
325 0.25f,
326 0,
327 false,
328 backends);
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000329}
330
Colm Donelaneff204a2023-11-28 15:46:09 +0000331void FloorDivFP32Test()
Jim Flynn4b2f3472021-10-13 21:20:07 +0100332{
333 std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
334 std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
335 std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
336
337 std::vector<float> input0Values =
338 {
339 -37.5f, -15.2f, -8.76f, -2.0f, -2.6f, -1.0f, -0.8f, 0.0f,
340 4.0f, 1.6f, 2.0f, 5.2f, 6.0f, 35.04f, 60.8f, 150.0f
341 };
342
343 std::vector<float> input1Values =
344 {
345 1.f, 1.f, 1.f, 1.f, 2.f, 2.f, 2.f, 2.f,
346 4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f
347 };
348
349 std::vector<float> expectedOutputValues =
350 {
351 -38.0f, -16.0f, -9.0f, -2.0f, -2.0f, -1.0f, -1.0f, 0.0f,
352 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 8.0f, 15.0f, 37.0f
353 };
354
355 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_FLOOR_DIV,
356 tflite::ActivationFunctionType_NONE,
357 ::tflite::TensorType_FLOAT32,
Jim Flynn4b2f3472021-10-13 21:20:07 +0100358 input0Shape,
359 input1Shape,
360 expectedOutputShape,
361 input0Values,
362 input1Values,
363 expectedOutputValues);
364
365}
366
Colm Donelaneff204a2023-11-28 15:46:09 +0000367void MaxFP32Test()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000368{
369 std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
370 std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
371 std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
372
373 std::vector<float> input0Values =
374 {
375 1.f, 1.f, 5.f, 1.f, 2.f, 2.f, 7.f, 2.f,
376 3.f, 3.f, 3.f, 3.f, 4.f, 4.f, 4.f, 4.f
377
378 };
379
380 std::vector<float> input1Values =
381 {
382 2.f, 2.f, 2.f, 2.f, 3.f, 3.f, 3.f, 3.f,
383 4.f, 4.f, 4.f, 4.f, 5.f, 5.f, 5.f, 5.f
384 };
385
386 std::vector<float> expectedOutputValues =
387 {
388 2.f, 2.f, 5.f, 2.f, 3.f, 3.f, 7.f, 3.f,
389 4.f, 4.f, 4.f, 4.f, 5.f, 5.f, 5.f, 5.f
390 };
391
392 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MAXIMUM,
393 tflite::ActivationFunctionType_NONE,
394 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000395 input0Shape,
396 input1Shape,
397 expectedOutputShape,
398 input0Values,
399 input1Values,
400 expectedOutputValues);
401}
402
Colm Donelaneff204a2023-11-28 15:46:09 +0000403void MaxBroadcastTest()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000404{
405 std::vector<int32_t> input0Shape { 1, 2, 2, 2 };
406 std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
407 std::vector<int32_t> expectedOutputShape { 1, 2, 2, 2 };
408
409 std::vector<float> input0Values = { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f };
410 std::vector<float> input1Values = { 4.f };
411 std::vector<float> expectedOutputValues = { 4.f, 4.f, 4.f, 4.f, 5.f, 6.f, 7.f, 8.f };
412
413 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MAXIMUM,
414 tflite::ActivationFunctionType_NONE,
415 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000416 input0Shape,
417 input1Shape,
418 expectedOutputShape,
419 input0Values,
420 input1Values,
421 expectedOutputValues);
422}
423
Colm Donelaneff204a2023-11-28 15:46:09 +0000424void MaxUint8Test()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000425{
426 std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
427 std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
428 std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
429
430 std::vector<uint8_t> input0Values =
431 {
432 1, 1, 1, 1, 7, 8, 9, 9,
433 3, 3, 3, 3, 4, 4, 4, 4
434
435 };
436
437 std::vector<uint8_t> input1Values =
438 {
439 2, 2, 2, 2, 3, 3, 3, 3,
440 4, 4, 4, 4, 5, 5, 5, 5
441 };
442
443 std::vector<uint8_t> expectedOutputValues =
444 {
445 2, 2, 2, 2, 7, 8, 9, 9,
446 4, 4, 4, 4, 5, 5, 5, 5
447 };
448
449 ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_MAXIMUM,
450 tflite::ActivationFunctionType_NONE,
451 ::tflite::TensorType_UINT8,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000452 input0Shape,
453 input1Shape,
454 expectedOutputShape,
455 input0Values,
456 input1Values,
457 expectedOutputValues, 1.0f, 0);
458}
459
Colm Donelaneff204a2023-11-28 15:46:09 +0000460void MinFP32Test()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000461{
462 std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
463 std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
464 std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
465
466 std::vector<float> input0Values =
467 {
468 1.f, 1.f, 5.f, 1.f, 2.f, 2.f, 7.f, 2.f,
469 3.f, 3.f, 3.f, 3.f, 4.f, 4.f, 4.f, 4.f
470
471 };
472
473 std::vector<float> input1Values =
474 {
475 2.f, 2.f, 2.f, 2.f, 3.f, 3.f, 3.f, 3.f,
476 1.f, 1.f, 1.f, 1.f, 5.f, 5.f, 5.f, 5.f
477 };
478
479 std::vector<float> expectedOutputValues =
480 {
481 1.f, 1.f, 2.f, 1.f, 2.f, 2.f, 3.f, 2.f,
482 1.f, 1.f, 1.f, 1.f, 4.f, 4.f, 4.f, 4.f
483 };
484
485 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MINIMUM,
486 tflite::ActivationFunctionType_NONE,
487 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000488 input0Shape,
489 input1Shape,
490 expectedOutputShape,
491 input0Values,
492 input1Values,
493 expectedOutputValues);
494}
495
Colm Donelaneff204a2023-11-28 15:46:09 +0000496void MinBroadcastTest()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000497{
498 std::vector<int32_t> input0Shape { 1, 2, 2, 2 };
499 std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
500 std::vector<int32_t> expectedOutputShape { 1, 2, 2, 2 };
501
502 std::vector<float> input0Values = { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f };
503
504 std::vector<float> input1Values = { 4.f };
505
506 std::vector<float> expectedOutputValues = { 1.f, 2.f, 3.f, 4.f, 4.f, 4.f, 4.f, 4.f };
507
508 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MINIMUM,
509 tflite::ActivationFunctionType_NONE,
510 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000511 input0Shape,
512 input1Shape,
513 expectedOutputShape,
514 input0Values,
515 input1Values,
516 expectedOutputValues);
517}
518
Colm Donelaneff204a2023-11-28 15:46:09 +0000519void MinUint8Test()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000520{
521 std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
522 std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
523 std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
524
525 std::vector<uint8_t> input0Values =
526 {
527 1, 1, 1, 1, 7, 8, 9, 9,
528 3, 3, 3, 3, 4, 4, 4, 4
529
530 };
531
532 std::vector<uint8_t> input1Values =
533 {
534 2, 2, 2, 2, 3, 3, 3, 3,
535 4, 4, 4, 4, 5, 5, 5, 5
536 };
537
538 std::vector<uint8_t> expectedOutputValues =
539 {
540 1, 1, 1, 1, 3, 3, 3, 3,
541 3, 3, 3, 3, 4, 4, 4, 4
542 };
543
544 ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_MINIMUM,
545 tflite::ActivationFunctionType_NONE,
546 ::tflite::TensorType_UINT8,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000547 input0Shape,
548 input1Shape,
549 expectedOutputShape,
550 input0Values,
551 input1Values,
552 expectedOutputValues, 1.0f, 0);
553}
554
Colm Donelaneff204a2023-11-28 15:46:09 +0000555void MulFP32Test()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000556{
557 std::vector<int32_t> input0Shape { 2, 2, 2, 2 };
558 std::vector<int32_t> input1Shape { 2, 2, 2, 2 };
559 std::vector<int32_t> expectedOutputShape { 2, 2, 2, 2 };
560
561 std::vector<float> input0Values =
562 {
563 1.f, 1.f, 1.f, 1.f, 2.f, 2.f, 2.f, 2.f,
564 3.f, 3.f, 3.f, 3.f, 4.f, 4.f, 4.f, 4.f
565
566 };
567
568 std::vector<float> input1Values =
569 {
570 2.f, 2.f, 2.f, 2.f, 3.f, 3.f, 3.f, 3.f,
571 4.f, 4.f, 4.f, 4.f, 5.f, 5.f, 5.f, 5.f
572 };
573
574 std::vector<float> expectedOutputValues =
575 {
576 2.f, 2.f, 2.f, 2.f, 6.f, 6.f, 6.f, 6.f,
577 12.f, 12.f, 12.f, 12.f, 20.f, 20.f, 20.f, 20.f
578 };
579
580 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MUL,
581 tflite::ActivationFunctionType_NONE,
582 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000583 input0Shape,
584 input1Shape,
585 expectedOutputShape,
586 input0Values,
587 input1Values,
588 expectedOutputValues);
589}
590
Colm Donelaneff204a2023-11-28 15:46:09 +0000591void MulBroadcastTest()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000592{
593 std::vector<int32_t> input0Shape { 1, 2, 2, 2 };
594 std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
595 std::vector<int32_t> expectedOutputShape { 1, 2, 2, 2 };
596
597 std::vector<float> input0Values = { 2, 4, 6, 8, 10, 12, 14, 16 };
598 std::vector<float> input1Values = { 2 };
599 std::vector<float> expectedOutputValues = { 4, 8, 12, 16, 20, 24, 28, 32 };
600
601 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MUL,
602 tflite::ActivationFunctionType_NONE,
603 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000604 input0Shape,
605 input1Shape,
606 expectedOutputShape,
607 input0Values,
608 input1Values,
609 expectedOutputValues);
610}
611
Colm Donelaneff204a2023-11-28 15:46:09 +0000612void MulUint8Test()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000613{
614 std::vector<int32_t> input0Shape { 1, 2, 2, 3 };
615 std::vector<int32_t> input1Shape { 1, 1, 1, 3 };
616 std::vector<int32_t> expectedOutputShape { 1, 2, 2, 3 };
617
618 std::vector<uint8_t> input0Values =
619 {
620 1, 2, 3, 4, 5, 6,
621 7, 8, 9, 10, 11, 12
622
623 };
624
625 std::vector<uint8_t> input1Values = { 1, 2, 3 };
626
627 std::vector<uint8_t> expectedOutputValues =
628 {
629 1, 4, 9, 4, 10, 18,
630 7, 16, 27, 10, 22, 36
631 };
632
633 ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_MUL,
634 tflite::ActivationFunctionType_NONE,
635 ::tflite::TensorType_UINT8,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000636 input0Shape,
637 input1Shape,
638 expectedOutputShape,
639 input0Values,
640 input1Values,
641 expectedOutputValues, 1.0f, 0);
642}
643
Colm Donelaneff204a2023-11-28 15:46:09 +0000644void MulActivationTest()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000645{
646 std::vector<int32_t> input0Shape { 1, 2, 2, 1 };
647 std::vector<int32_t> input1Shape { 1, 2, 2, 1 };
648 std::vector<int32_t> expectedOutputShape { 1, 2, 2, 1 };
649
650 std::vector<float> input0Values { 4.0f, 0.0f, 1.0f, 0.5f };
651 std::vector<float> input1Values { -2.0f, -1.2f, 2.5f, 2.0f };
652 std::vector<float> expectedOutputValues { 0.0f, 0.0f, 2.5f, 1.0f };
653
654 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_MUL,
655 tflite::ActivationFunctionType_RELU,
656 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000657 input0Shape,
658 input1Shape,
659 expectedOutputShape,
660 input0Values,
661 input1Values,
662 expectedOutputValues);
663}
664
Colm Donelaneff204a2023-11-28 15:46:09 +0000665void SubFP32Test()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000666{
667 std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
668 std::vector<int32_t> input1Shape { 1, 1, 2, 2 };
669 std::vector<int32_t> expectedOutputShape { 1, 1, 2, 2 };
670
671 std::vector<float> input0Values = { 1, 3, 3, -7 };
672 std::vector<float> input1Values = { 1, -1, 0, -2 };
673 std::vector<float> expectedOutputValues = { 0, 4, 3, -5 };
674
675 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_SUB,
676 tflite::ActivationFunctionType_NONE,
677 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000678 input0Shape,
679 input1Shape,
680 expectedOutputShape,
681 input0Values,
682 input1Values,
683 expectedOutputValues);
684}
685
Colm Donelaneff204a2023-11-28 15:46:09 +0000686void PowerFP32Test()
John Mcloughlin0ec00872023-05-15 17:03:49 +0100687{
688 std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
689 std::vector<int32_t> input1Shape { 1, 1, 2, 2 };
690 std::vector<int32_t> expectedOutputShape { 1, 1, 2, 2 };
691
692 std::vector<float> input0Values = { 1, 3, 3, -7 };
693 std::vector<float> input1Values = { 1, 1, 0, 2 };
694 std::vector<float> expectedOutputValues = { 1, 3, 1, 49 };
695
696 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_POW,
697 tflite::ActivationFunctionType_NONE,
698 ::tflite::TensorType_FLOAT32,
John Mcloughlin0ec00872023-05-15 17:03:49 +0100699 input0Shape,
700 input1Shape,
701 expectedOutputShape,
702 input0Values,
703 input1Values,
704 expectedOutputValues);
705}
706
Colm Donelaneff204a2023-11-28 15:46:09 +0000707void SqDiffFP32Test()
John Mcloughlin0ec00872023-05-15 17:03:49 +0100708{
709 std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
710 std::vector<int32_t> input1Shape { 1, 1, 2, 2 };
711 std::vector<int32_t> expectedOutputShape { 1, 1, 2, 2 };
712
713 std::vector<float> input0Values = { 1, 3, 3, -7 };
714 std::vector<float> input1Values = { 1, -1, 0, -2 };
715 std::vector<float> expectedOutputValues = { 0, 16, 9, 25 };
716
717 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_SQUARED_DIFFERENCE,
718 tflite::ActivationFunctionType_NONE,
719 ::tflite::TensorType_FLOAT32,
John Mcloughlin0ec00872023-05-15 17:03:49 +0100720 input0Shape,
721 input1Shape,
722 expectedOutputShape,
723 input0Values,
724 input1Values,
725 expectedOutputValues);
726}
727
Colm Donelaneff204a2023-11-28 15:46:09 +0000728void SubBroadcastTest()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000729{
730 std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
731 std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
732 std::vector<int32_t> expectedOutputShape { 1, 1, 2, 2 };
733
734 std::vector<float> input0Values = { 2, 3, 4, 5};
735 std::vector<float> input1Values = { 10 };
736 std::vector<float> expectedOutputValues = { -8, -7, -6, -5 };
737
738 ElementwiseBinaryTest<float>(tflite::BuiltinOperator_SUB,
739 tflite::ActivationFunctionType_NONE,
740 ::tflite::TensorType_FLOAT32,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000741 input0Shape,
742 input1Shape,
743 expectedOutputShape,
744 input0Values,
745 input1Values,
746 expectedOutputValues);
747}
748
Colm Donelaneff204a2023-11-28 15:46:09 +0000749void SubUint8Test()
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000750{
751 std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
752 std::vector<int32_t> input1Shape { 1, 1, 1, 1 };
753 std::vector<int32_t> expectedOutputShape { 1, 1, 2, 2 };
754
755 std::vector<uint8_t> input0Values = { 10, 12, 14, 16 };
756 std::vector<uint8_t> input1Values = { 2 };
757 std::vector<uint8_t> expectedOutputValues = { 8, 10, 12, 14 };
758
759 ElementwiseBinaryTest<uint8_t>(tflite::BuiltinOperator_SUB,
760 tflite::ActivationFunctionType_NONE,
761 ::tflite::TensorType_UINT8,
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000762 input0Shape,
763 input1Shape,
764 expectedOutputShape,
765 input0Values,
766 input1Values,
767 expectedOutputValues, 1.0f, 0);
768}
769
Colm Donelaneff204a2023-11-28 15:46:09 +0000770TEST_SUITE("ElementwiseBinary_Tests")
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000771{
772
Colm Donelaneff204a2023-11-28 15:46:09 +0000773TEST_CASE ("ADD_FP32_Test")
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000774{
Colm Donelaneff204a2023-11-28 15:46:09 +0000775 AddFP32Test();
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000776}
777
Colm Donelaneff204a2023-11-28 15:46:09 +0000778TEST_CASE ("ADD_Broadcast_Test")
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000779{
Colm Donelaneff204a2023-11-28 15:46:09 +0000780 AddBroadcastTest();
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000781}
782
Colm Donelaneff204a2023-11-28 15:46:09 +0000783TEST_CASE ("ADD_Constant_Input_Test")
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000784{
Colm Donelaneff204a2023-11-28 15:46:09 +0000785 AddConstInputTest();
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000786}
787
Colm Donelaneff204a2023-11-28 15:46:09 +0000788TEST_CASE ("ADD_Activation_Test")
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000789{
Colm Donelaneff204a2023-11-28 15:46:09 +0000790 AddActivationTest();
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000791}
792
Colm Donelaneff204a2023-11-28 15:46:09 +0000793TEST_CASE ("ADD_UINT8_Test")
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000794{
Colm Donelaneff204a2023-11-28 15:46:09 +0000795 AddUint8Test();
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000796}
797
Colm Donelaneff204a2023-11-28 15:46:09 +0000798TEST_CASE ("DIV_FP32_Test")
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000799{
Colm Donelaneff204a2023-11-28 15:46:09 +0000800 DivFP32Test();
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000801}
802
Colm Donelaneff204a2023-11-28 15:46:09 +0000803TEST_CASE ("DIV_Broadcast_Test")
Jim Flynn4b2f3472021-10-13 21:20:07 +0100804{
Colm Donelaneff204a2023-11-28 15:46:09 +0000805 DivBroadcastTest();
Jim Flynn4b2f3472021-10-13 21:20:07 +0100806}
807
Colm Donelaneff204a2023-11-28 15:46:09 +0000808TEST_CASE ("FLOORDIV_FP32_Test")
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000809{
Colm Donelaneff204a2023-11-28 15:46:09 +0000810 FloorDivFP32Test();
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000811}
812
Colm Donelaneff204a2023-11-28 15:46:09 +0000813TEST_CASE ("DIV_UINT8_Test")
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000814{
Colm Donelaneff204a2023-11-28 15:46:09 +0000815 // Only works on CpuRef.
Jan Eilers187b3a72020-11-19 17:50:34 +0000816 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
817 DivUint8Test(backends);
818}
819
Colm Donelaneff204a2023-11-28 15:46:09 +0000820TEST_CASE ("MAX_FP32_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000821{
Colm Donelaneff204a2023-11-28 15:46:09 +0000822 MaxFP32Test();
Jan Eilers187b3a72020-11-19 17:50:34 +0000823}
824
Colm Donelaneff204a2023-11-28 15:46:09 +0000825TEST_CASE ("MAX_Broadcast_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000826{
Colm Donelaneff204a2023-11-28 15:46:09 +0000827 MaxBroadcastTest();
Jan Eilers187b3a72020-11-19 17:50:34 +0000828}
829
Colm Donelaneff204a2023-11-28 15:46:09 +0000830TEST_CASE ("MAX_UINT8_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000831{
Colm Donelaneff204a2023-11-28 15:46:09 +0000832 MaxUint8Test();
Jan Eilers187b3a72020-11-19 17:50:34 +0000833}
834
Colm Donelaneff204a2023-11-28 15:46:09 +0000835TEST_CASE ("MIN_FP32_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000836{
Colm Donelaneff204a2023-11-28 15:46:09 +0000837 MinFP32Test();
Jan Eilers187b3a72020-11-19 17:50:34 +0000838}
839
Colm Donelaneff204a2023-11-28 15:46:09 +0000840TEST_CASE ("MIN_Broadcast_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000841{
Colm Donelaneff204a2023-11-28 15:46:09 +0000842 MinBroadcastTest();
Jan Eilers187b3a72020-11-19 17:50:34 +0000843}
844
Colm Donelaneff204a2023-11-28 15:46:09 +0000845TEST_CASE ("MIN_UINT8_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000846{
Colm Donelaneff204a2023-11-28 15:46:09 +0000847 MinUint8Test();
Jan Eilers187b3a72020-11-19 17:50:34 +0000848}
849
Colm Donelaneff204a2023-11-28 15:46:09 +0000850TEST_CASE ("MUL_FP32_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000851{
Colm Donelaneff204a2023-11-28 15:46:09 +0000852 MulFP32Test();
Jan Eilers187b3a72020-11-19 17:50:34 +0000853}
854
Colm Donelaneff204a2023-11-28 15:46:09 +0000855TEST_CASE ("MUL_Broadcast_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000856{
Colm Donelaneff204a2023-11-28 15:46:09 +0000857 MulBroadcastTest();
Jan Eilers187b3a72020-11-19 17:50:34 +0000858}
859
Colm Donelaneff204a2023-11-28 15:46:09 +0000860TEST_CASE ("MUL_Actiation_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000861{
Colm Donelaneff204a2023-11-28 15:46:09 +0000862 MulActivationTest();
Jan Eilers187b3a72020-11-19 17:50:34 +0000863}
864
Colm Donelaneff204a2023-11-28 15:46:09 +0000865TEST_CASE ("MUL_UINT8_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000866{
Colm Donelaneff204a2023-11-28 15:46:09 +0000867 MulUint8Test();
Jan Eilers187b3a72020-11-19 17:50:34 +0000868}
869
Colm Donelaneff204a2023-11-28 15:46:09 +0000870TEST_CASE ("SUB_FP32_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000871{
Colm Donelaneff204a2023-11-28 15:46:09 +0000872 SubFP32Test();
Jan Eilers187b3a72020-11-19 17:50:34 +0000873}
874
Colm Donelaneff204a2023-11-28 15:46:09 +0000875TEST_CASE ("SUB_Broadcast_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000876{
Colm Donelaneff204a2023-11-28 15:46:09 +0000877 SubBroadcastTest();
Jan Eilers187b3a72020-11-19 17:50:34 +0000878}
879
Colm Donelaneff204a2023-11-28 15:46:09 +0000880TEST_CASE ("SUB_UINT8_Test")
Jan Eilers187b3a72020-11-19 17:50:34 +0000881{
Colm Donelaneff204a2023-11-28 15:46:09 +0000882 SubUint8Test();
Jan Eilers187b3a72020-11-19 17:50:34 +0000883}
884
Colm Donelaneff204a2023-11-28 15:46:09 +0000885TEST_CASE ("SqDiffFP32_Test")
John Mcloughlin0ec00872023-05-15 17:03:49 +0100886{
Colm Donelaneff204a2023-11-28 15:46:09 +0000887 SqDiffFP32Test();
John Mcloughlin0ec00872023-05-15 17:03:49 +0100888}
889
Colm Donelaneff204a2023-11-28 15:46:09 +0000890TEST_CASE ("PowerFP32_Test")
John Mcloughlin0ec00872023-05-15 17:03:49 +0100891{
Colm Donelaneff204a2023-11-28 15:46:09 +0000892 PowerFP32Test();
John Mcloughlin0ec00872023-05-15 17:03:49 +0100893}
894
Jan Eilers187b3a72020-11-19 17:50:34 +0000895} // TEST_SUITE("ElementwiseBinary_CpuRefTests")
Sadik Armagan21a94ff2020-11-09 08:38:30 +0000896
Jim Flynn4b2f3472021-10-13 21:20:07 +0100897} // namespace armnnDelegate