blob: 633143630871b578a50c2bdf4f2a999c22a3165b [file] [log] [blame]
Sadik Armagan0534e032020-10-27 17:30:18 +00001//
Teresa Charlinad1b3d72023-03-14 12:10:28 +00002// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
Sadik Armagan0534e032020-10-27 17:30:18 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "ElementwiseUnaryTestHelper.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>
Teresa Charlinad1b3d72023-03-14 12:10:28 +000014#include <schema_generated.h>
Sadik Armagan0534e032020-10-27 17:30:18 +000015#include <tensorflow/lite/version.h>
16
17#include <doctest/doctest.h>
18
19namespace armnnDelegate
20{
21
Jan Eilers187b3a72020-11-19 17:50:34 +000022TEST_SUITE("ElementwiseUnary_GpuAccTests")
Sadik Armagan0534e032020-10-27 17:30:18 +000023{
24
25TEST_CASE ("Abs_Float32_GpuAcc_Test")
26{
27 // Create the ArmNN Delegate
Jan Eilers187b3a72020-11-19 17:50:34 +000028 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
Sadik Armagan0534e032020-10-27 17:30:18 +000029 // Set input data
30 std::vector<float> inputValues
31 {
32 -0.1f, -0.2f, -0.3f,
33 0.1f, 0.2f, 0.3f
34 };
35 // Calculate output data
36 std::vector<float> expectedOutputValues(inputValues.size());
37 for (unsigned int i = 0; i < inputValues.size(); ++i)
38 {
39 expectedOutputValues[i] = std::abs(inputValues[i]);
40 }
41 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_ABS, backends, inputValues, expectedOutputValues);
42}
43
Sadik Armagan0534e032020-10-27 17:30:18 +000044TEST_CASE ("Exp_Float32_GpuAcc_Test")
45{
46 // Create the ArmNN Delegate
Jan Eilers187b3a72020-11-19 17:50:34 +000047 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
Sadik Armagan0534e032020-10-27 17:30:18 +000048 // Set input data
49 std::vector<float> inputValues
50 {
51 5.0f, 4.0f,
52 3.0f, 2.0f,
53 1.0f, 1.1f
54 };
55 // Set output data
56 std::vector<float> expectedOutputValues
57 {
58 148.413159102577f, 54.598150033144f,
59 20.085536923188f, 7.389056098931f,
60 2.718281828459f, 3.004166023946f
61 };
62
63 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_EXP, backends, inputValues, expectedOutputValues);
64}
65
Teresa Charlinb1f5f702022-07-12 14:16:24 +010066TEST_CASE ("Log_Float32_GpuAcc_Test")
67{
68 // Create the ArmNN Delegate
69 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
70 // Set input data
71 std::vector<float> inputValues
72 {
73 1.0f, 1.0f, 2.0f,
74 3.0f, 4.0f, 2.71828f
75 };
76 // Set output data
77 std::vector<float> expectedOutputValues
78 {
79 0.f, 0.f, 0.69314718056f,
80 1.09861228867f, 1.38629436112f, 0.99999932734f
81 };
82
83 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_LOG, backends, inputValues, expectedOutputValues);
84}
85
Sadik Armagan0534e032020-10-27 17:30:18 +000086TEST_CASE ("Neg_Float32_GpuAcc_Test")
87{
88 // Create the ArmNN Delegate
Jan Eilers187b3a72020-11-19 17:50:34 +000089 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
Sadik Armagan0534e032020-10-27 17:30:18 +000090 // Set input data
91 std::vector<float> inputValues
92 {
93 1.f, 0.f, 3.f,
94 25.f, 64.f, 100.f
95 };
96 // Set output data
97 std::vector<float> expectedOutputValues
98 {
99 -1.f, 0.f, -3.f,
100 -25.f, -64.f, -100.f
101 };
102
103 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_NEG, backends, inputValues, expectedOutputValues);
104}
105
106TEST_CASE ("Rsqrt_Float32_GpuAcc_Test")
107{
108 // Create the ArmNN Delegate
Jan Eilers187b3a72020-11-19 17:50:34 +0000109 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
Sadik Armagan0534e032020-10-27 17:30:18 +0000110 // Set input data
111 std::vector<float> inputValues
112 {
113 1.f, 4.f, 16.f,
114 25.f, 64.f, 100.f
115 };
116 // Set output data
117 std::vector<float> expectedOutputValues
118 {
119 1.f, 0.5f, 0.25f,
120 0.2f, 0.125f, 0.1f
121 };
122
123 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_RSQRT, backends, inputValues, expectedOutputValues);
124}
125
Teresa Charlinb1f5f702022-07-12 14:16:24 +0100126TEST_CASE ("Sin_Float32_GpuAcc_Test")
127{
128 // Create the ArmNN Delegate
129 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
130 // Set input data
131 std::vector<float> inputValues
132 {
133 0.0f, 1.0f, 16.0f,
134 0.5f, 36.0f, -1.f
135 };
136 // Set output data
137 std::vector<float> expectedOutputValues
138 {
139 0.0f, 0.8414709848f, -0.28790331666f,
140 0.4794255386f, -0.99177885344f, -0.8414709848f
141 };
142
143 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_SIN, backends, inputValues, expectedOutputValues);
144}
Jan Eilers187b3a72020-11-19 17:50:34 +0000145} // TEST_SUITE("ElementwiseUnary_GpuAccTests")
146
147
148
149TEST_SUITE("ElementwiseUnary_CpuAccTests")
150{
151
152TEST_CASE ("Abs_Float32_CpuAcc_Test")
153{
154 // Create the ArmNN Delegate
155 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
156 // Set input data
157 std::vector<float> inputValues
158 {
159 -0.1f, -0.2f, -0.3f,
160 0.1f, 0.2f, 0.3f
161 };
162 // Calculate output data
163 std::vector<float> expectedOutputValues(inputValues.size());
164 for (unsigned int i = 0; i < inputValues.size(); ++i)
165 {
166 expectedOutputValues[i] = std::abs(inputValues[i]);
167 }
168
169 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_ABS, backends, inputValues, expectedOutputValues);
170}
171
172TEST_CASE ("Exp_Float32_CpuAcc_Test")
173{
174 // Create the ArmNN Delegate
175 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
176 // Set input data
177 std::vector<float> inputValues
178 {
179 5.0f, 4.0f,
180 3.0f, 2.0f,
181 1.0f, 1.1f
182 };
183 // Set output data
184 std::vector<float> expectedOutputValues
185 {
186 148.413159102577f, 54.598150033144f,
187 20.085536923188f, 7.389056098931f,
188 2.718281828459f, 3.004166023946f
189 };
190
191 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_EXP, backends, inputValues, expectedOutputValues);
192}
193
Teresa Charlinb1f5f702022-07-12 14:16:24 +0100194TEST_CASE ("Log_Float32_CpuAcc_Test")
195{
196 // Create the ArmNN Delegate
197 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
198 // Set input data
199 std::vector<float> inputValues
200 {
201 1.0f, 1.0f, 2.0f,
202 3.0f, 4.0f, 2.71828f
203 };
204 // Set output data
205 std::vector<float> expectedOutputValues
206 {
207 0.f, 0.f, 0.69314718056f,
208 1.09861228867f, 1.38629436112f, 0.99999932734f
209 };
210
211 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_LOG, backends, inputValues, expectedOutputValues);
212}
213
Jan Eilers187b3a72020-11-19 17:50:34 +0000214TEST_CASE ("Neg_Float32_CpuAcc_Test")
215{
216 // Create the ArmNN Delegate
217 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
218 // Set input data
219 std::vector<float> inputValues
220 {
221 1.f, 0.f, 3.f,
222 25.f, 64.f, 100.f
223 };
224 // Set output data
225 std::vector<float> expectedOutputValues
226 {
227 -1.f, 0.f, -3.f,
228 -25.f, -64.f, -100.f
229 };
230
231 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_NEG, backends, inputValues, expectedOutputValues);
232}
233
234TEST_CASE ("Rsqrt_Float32_CpuAcc_Test")
235{
236 // Create the ArmNN Delegate
237 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
238 // Set input data
239 std::vector<float> inputValues
240 {
241 1.f, 4.f, 16.f,
242 25.f, 64.f, 100.f
243 };
244 // Set output data
245 std::vector<float> expectedOutputValues
246 {
247 1.f, 0.5f, 0.25f,
248 0.2f, 0.125f, 0.1f
249 };
250
251 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_RSQRT, backends, inputValues, expectedOutputValues);
252}
253
Teresa Charlinb1f5f702022-07-12 14:16:24 +0100254TEST_CASE ("Sin_Float32_CpuAcc_Test")
255{
256 // Create the ArmNN Delegate
257 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
258 // Set input data
259 std::vector<float> inputValues
260 {
261 0.0f, 1.0f, 16.0f,
262 0.5f, 36.0f, -1.f
263 };
264 // Set output data
265 std::vector<float> expectedOutputValues
266 {
267 0.0f, 0.8414709848f, -0.28790331666f,
268 0.4794255386f, -0.99177885344f, -0.8414709848f
269 };
270
271 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_SIN, backends, inputValues, expectedOutputValues);
272}
Jan Eilers187b3a72020-11-19 17:50:34 +0000273} // TEST_SUITE("ElementwiseUnary_CpuAccTests")
274
Jan Eilers187b3a72020-11-19 17:50:34 +0000275TEST_SUITE("ElementwiseUnary_CpuRefTests")
276{
277
278TEST_CASE ("Abs_Float32_CpuRef_Test")
279{
280 // Create the ArmNN Delegate
281 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
282 // Set input data
283 std::vector<float> inputValues
284 {
285 -0.1f, -0.2f, -0.3f,
286 0.1f, 0.2f, 0.3f
287 };
288 // Calculate output data
289 std::vector<float> expectedOutputValues(inputValues.size());
290 for (unsigned int i = 0; i < inputValues.size(); ++i)
291 {
292 expectedOutputValues[i] = std::abs(inputValues[i]);
293 }
294
295 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_ABS, backends, inputValues, expectedOutputValues);
Sadik Armagan0534e032020-10-27 17:30:18 +0000296}
297
Jan Eilers187b3a72020-11-19 17:50:34 +0000298TEST_CASE ("Exp_Float32_CpuRef_Test")
299{
300 // Create the ArmNN Delegate
301 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
302 // Set input data
303 std::vector<float> inputValues
304 {
305 5.0f, 4.0f,
306 3.0f, 2.0f,
307 1.0f, 1.1f
308 };
309 // Set output data
310 std::vector<float> expectedOutputValues
311 {
312 148.413159102577f, 54.598150033144f,
313 20.085536923188f, 7.389056098931f,
314 2.718281828459f, 3.004166023946f
315 };
316
317 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_EXP, backends, inputValues, expectedOutputValues);
318}
319
Teresa Charlinb1f5f702022-07-12 14:16:24 +0100320TEST_CASE ("Log_Float32_CpuRef_Test")
321{
322 // Create the ArmNN Delegate
323 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
324 // Set input data
325 std::vector<float> inputValues
326 {
327 1.0f, 1.0f, 2.0f,
328 3.0f, 4.0f, 2.71828f
329 };
330 // Set output data
331 std::vector<float> expectedOutputValues
332 {
333 0.f, 0.f, 0.69314718056f,
334 1.09861228867f, 1.38629436112f, 0.99999932734f
335 };
336
337 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_LOG, backends, inputValues, expectedOutputValues);
338}
339
Jan Eilers187b3a72020-11-19 17:50:34 +0000340TEST_CASE ("Neg_Float32_CpuRef_Test")
341{
342 // Create the ArmNN Delegate
343 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
344 // Set input data
345 std::vector<float> inputValues
346 {
347 1.f, 0.f, 3.f,
348 25.f, 64.f, 100.f
349 };
350 // Set output data
351 std::vector<float> expectedOutputValues
352 {
353 -1.f, 0.f, -3.f,
354 -25.f, -64.f, -100.f
355 };
356
357 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_NEG, backends, inputValues, expectedOutputValues);
358}
359
360TEST_CASE ("Rsqrt_Float32_CpuRef_Test")
361{
362 // Create the ArmNN Delegate
363 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
364 // Set input data
365 std::vector<float> inputValues
366 {
367 1.f, 4.f, 16.f,
368 25.f, 64.f, 100.f
369 };
370 // Set output data
371 std::vector<float> expectedOutputValues
372 {
373 1.f, 0.5f, 0.25f,
374 0.2f, 0.125f, 0.1f
375 };
376
377 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_RSQRT, backends, inputValues, expectedOutputValues);
378}
379
380TEST_CASE ("Sqrt_Float32_CpuRef_Test")
381{
382 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
383 // Set input data
384 std::vector<float> inputValues
385 {
386 9.0f, 4.25f, 81.9f,
387 0.1f, 0.9f, 169.0f
388 };
389 // Calculate output data
390 std::vector<float> expectedOutputValues(inputValues.size());
391 for (unsigned int i = 0; i < inputValues.size(); ++i)
392 {
393 expectedOutputValues[i] = std::sqrt(inputValues[i]);
394 }
395
396 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_SQRT, backends, inputValues, expectedOutputValues);
397}
398
Teresa Charlinb1f5f702022-07-12 14:16:24 +0100399TEST_CASE ("Sin_Float32_CpuRef_Test")
400{
401 // Create the ArmNN Delegate
402 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
403 // Set input data
404 std::vector<float> inputValues
405 {
406 0.0f, 1.0f, 16.0f,
407 0.5f, 36.0f, -1.f
408 };
409 // Set output data
410 std::vector<float> expectedOutputValues
411 {
412 0.0f, 0.8414709848f, -0.28790331666f,
413 0.4794255386f, -0.99177885344f, -0.8414709848f
414 };
415
416 ElementwiseUnaryFP32Test(tflite::BuiltinOperator_SIN, backends, inputValues, expectedOutputValues);
417}
Jan Eilers187b3a72020-11-19 17:50:34 +0000418} // TEST_SUITE("ElementwiseUnary_CpuRefTests")
419
Sadik Armagan0534e032020-10-27 17:30:18 +0000420} // namespace armnnDelegate