blob: dd6d56927027d1fa5e3db274a5dab0b8ade3240e [file] [log] [blame]
John Mcloughlin0ec00872023-05-15 17:03:49 +01001//
2// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "PowerTestImpl.hpp"
7
8#include "ElementwiseTestImpl.hpp"
9
10LayerTestResult<float, 4> PowerTest(
11 armnn::IWorkloadFactory& workloadFactory,
12 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
13 const armnn::ITensorHandleFactory& tensorHandleFactory)
14{
15 IgnoreUnused(memoryManager);
16 unsigned int shape[] = { 2, 2, 2, 2 };
17
18 std::vector<float> input0 =
19 {
20 7.f, 3.f, 4.f, 2.f, 6.f, 4.f, 2.f, 1.f,
21 1.f, 1.f, 0.f, 2.f, 9.f, 3.f, 5.f, 3.f
22 };
23
24 std::vector<float> input1 =
25 {
26 2.f, 3.f, 2.f, 1.f, 2.f, 3.f, 4.f, 3.f,
27 4.f, 5.f, 3.f, 5.f, 2.f, 3.f, 2.f, 0.f
28 };
29
30 std::vector<float> output
31 {
32 49.f, 27.f, 16.f, 2.f, 36.f, 64.f, 16.f, 1.f,
33 1.f, 1.f, 0.f, 32.f, 81.f, 27.f, 25.f, 1.f
34 };
35
36 return ElementwiseTestHelper<4, armnn::DataType::Float32, armnn::DataType::Float32>(
37 workloadFactory,
38 memoryManager,
39 armnn::BinaryOperation::Power,
40 shape,
41 input0,
42 shape,
43 input1,
44 shape,
45 output,
46 tensorHandleFactory);
47}
48
49LayerTestResult<float, 4> PowerBroadcast1ElementTest(
50 armnn::IWorkloadFactory& workloadFactory,
51 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
52 const armnn::ITensorHandleFactory& tensorHandleFactory)
53{
54 IgnoreUnused(memoryManager);
55 unsigned int shape0[] = { 1, 2, 2, 2 };
56 unsigned int shape1[] = { 1, 1, 1, 1 };
57
58 std::vector<float> input0 =
59 {
60 1.f, 2.f, 3.f, 4.f, 5.f, 0.f, 2.f, 1.f
61 };
62
63 std::vector<float> input1 = { 2.f };
64
65 std::vector<float> output =
66 {
67 1.f, 4.f, 9.f, 16.f, 25.f, 0.f, 4.f, 1.f
68 };
69
70 return ElementwiseTestHelper<4, armnn::DataType::Float32, armnn::DataType::Float32>(
71 workloadFactory,
72 memoryManager,
73 armnn::BinaryOperation::Power,
74 shape0,
75 input0,
76 shape1,
77 input1,
78 shape0,
79 output,
80 tensorHandleFactory);
81}
82
83LayerTestResult<float, 4> PowerBroadcastTest(
84 armnn::IWorkloadFactory & workloadFactory,
85 const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager,
86 const armnn::ITensorHandleFactory& tensorHandleFactory)
87{
88 IgnoreUnused(memoryManager);
89 const unsigned int shape0[] = { 1, 2, 2, 3 };
90 const unsigned int shape1[] = { 1, 1, 1, 3 };
91
92 std::vector<float> input0 =
93 {
94 1.f, 2.f, 3.f, 3.f, 4.f, 4.f,
95 4.f, 0.f, 2.f, 3.f, 4.f, 4.f
96 };
97
98 std::vector<float> input1 = { 1.f, 3.f, 1.f };
99
100 std::vector<float> output =
101 {
102 1.f, 8.f, 3.f, 3.f, 64.f, 4.f,
103 4.f, 0.f, 2.f, 3.f, 64.f, 4.f
104 };
105
106 return ElementwiseTestHelper<4, armnn::DataType::Float32, armnn::DataType::Float32>(
107 workloadFactory,
108 memoryManager,
109 armnn::BinaryOperation::Power,
110 shape0,
111 input0,
112 shape1,
113 input1,
114 shape0,
115 output,
116 tensorHandleFactory);
117}
118
119LayerTestResult<armnn::Half, 4> PowerFloat16Test(
120 armnn::IWorkloadFactory& workloadFactory,
121 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
122 const armnn::ITensorHandleFactory& tensorHandleFactory)
123{
124 IgnoreUnused(memoryManager);
125 using namespace half_float::literal;
126
127 unsigned int shape[] = { 2, 2, 2, 2 };
128
129 std::vector<armnn::Half> input0 =
130 {
131 1._h, 5._h, 1._h, 4._h, 6._h, 1._h, 3._h, 5._h,
132 3._h, 7._h, 6._h, 3._h, 8._h, 4._h, 4._h, 2._h
133 };
134
135 std::vector<armnn::Half> input1 =
136 {
137 2._h, 2._h, 2._h, 2._h, 2._h, 3._h, 3._h, 2._h,
138 1._h, 2._h, 2._h, 4._h, 2._h, 1._h, 3._h, 5._h
139 };
140
141 std::vector<armnn::Half> output
142 {
143 1._h, 25._h, 1._h, 16._h, 36._h, 1._h, 27._h, 25._h,
144 3._h, 49._h, 36._h, 81._h, 64._h, 4._h, 64._h, 32._h
145 };
146
147 return ElementwiseTestHelper<4, armnn::DataType::Float16, armnn::DataType::Float16>(
148 workloadFactory,
149 memoryManager,
150 armnn::BinaryOperation::Power,
151 shape,
152 input0,
153 shape,
154 input1,
155 shape,
156 output,
157 tensorHandleFactory);
158}
159
160LayerTestResult<armnn::Half, 4> PowerBroadcast1ElementFloat16Test(
161 armnn::IWorkloadFactory& workloadFactory,
162 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
163 const armnn::ITensorHandleFactory& tensorHandleFactory)
164{
165 IgnoreUnused(memoryManager);
166 using namespace half_float::literal;
167
168 const unsigned int shape0[] = { 1, 2, 2, 3 };
169 const unsigned int shape1[] = { 1, 1, 1, 1 };
170
171 std::vector<armnn::Half> input0 =
172 {
173 1._h, 2._h, 3._h, 4._h, 5._h, 4._h,
174 1._h, 5._h, 4._h, 2._h, 0._h, 1._h
175 };
176
177 std::vector<armnn::Half> input1 = { 2._h };
178
179 std::vector<armnn::Half> output =
180 {
181 1._h, 4._h, 9._h, 16._h, 25._h, 16._h,
182 1._h, 25._h, 16._h, 4._h, 0._h, 1._h
183 };
184
185 return ElementwiseTestHelper<4, armnn::DataType::Float16, armnn::DataType::Float16>(
186 workloadFactory,
187 memoryManager,
188 armnn::BinaryOperation::Power,
189 shape0,
190 input0,
191 shape1,
192 input1,
193 shape0,
194 output,
195 tensorHandleFactory);
196}
197
198LayerTestResult<armnn::Half, 4> PowerBroadcastFloat16Test(
199 armnn::IWorkloadFactory& workloadFactory,
200 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
201 const armnn::ITensorHandleFactory& tensorHandleFactory)
202{
203 IgnoreUnused(memoryManager);
204 using namespace half_float::literal;
205
206 const unsigned int shape0[] = { 1, 2, 2, 3 };
207 const unsigned int shape1[] = { 1, 1, 1, 3 };
208
209 std::vector<armnn::Half> input0 =
210 {
211 4._h, 2._h, 3._h, 4._h, 1._h, 0._h,
212 8._h, 1._h, 1._h, 1._h, 2._h, 4._h
213 };
214
215 std::vector<armnn::Half> input1 = { 1._h, 5._h, 3._h };
216
217 std::vector<armnn::Half> output =
218 {
219 4._h, 32._h, 27._h, 4._h, 1._h, 0._h,
220 8._h, 1._h, 1._h, 1._h, 32._h, 64._h
221 };
222
223 return ElementwiseTestHelper<4, armnn::DataType::Float16, armnn::DataType::Float16>(
224 workloadFactory,
225 memoryManager,
226 armnn::BinaryOperation::Power,
227 shape0,
228 input0,
229 shape1,
230 input1,
231 shape0,
232 output,
233 tensorHandleFactory);
234}
235
236LayerTestResult<uint8_t, 4> PowerUint8Test(
237 armnn::IWorkloadFactory& workloadFactory,
238 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
239 const armnn::ITensorHandleFactory& tensorHandleFactory)
240{
241 IgnoreUnused(memoryManager);
242 const unsigned int shape[] = { 1, 1, 2, 2 };
243
244 std::vector<uint8_t> input0 = { 4, 2, 4, 3 };
245
246 std::vector<uint8_t> input1 = { 1, 2, 2, 2 };
247
248 std::vector<uint8_t> output = { 4, 4, 16, 9 };
249
250 return ElementwiseTestHelper<4, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>(
251 workloadFactory,
252 memoryManager,
253 armnn::BinaryOperation::Power,
254 shape,
255 input0,
256 shape,
257 input1,
258 shape,
259 output,
260 tensorHandleFactory);
261}
262
263LayerTestResult<uint8_t, 4> PowerBroadcast1ElementUint8Test(
264 armnn::IWorkloadFactory& workloadFactory,
265 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
266 const armnn::ITensorHandleFactory& tensorHandleFactory)
267{
268 IgnoreUnused(memoryManager);
269 const unsigned int shape0[] = { 1, 1, 2, 2 };
270 const unsigned int shape1[] = { 1, 1, 1, 1 };
271
272 std::vector<uint8_t> input0 = { 4, 5, 1, 0 };
273
274 std::vector<uint8_t> input1 = { 2 };
275
276 std::vector<uint8_t> output = { 16, 25, 1, 0 };
277
278 return ElementwiseTestHelper<4, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>(
279 workloadFactory,
280 memoryManager,
281 armnn::BinaryOperation::Power,
282 shape0,
283 input0,
284 shape1,
285 input1,
286 shape0,
287 output,
288 tensorHandleFactory);
289}
290
291LayerTestResult<uint8_t, 4> PowerBroadcastUint8Test(
292 armnn::IWorkloadFactory& workloadFactory,
293 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
294 const armnn::ITensorHandleFactory& tensorHandleFactory)
295{
296 IgnoreUnused(memoryManager);
297 const unsigned int shape0[] = { 1, 1, 2, 2 };
298 const unsigned int shape1[] = { 1, 1, 1, 2 };
299
300 std::vector<uint8_t> input0 = { 4, 1, 6, 2 };
301
302 std::vector<uint8_t> input1 = { 2, 6 };
303
304 std::vector<uint8_t> output = { 16, 1, 36, 64 };
305
306 return ElementwiseTestHelper<4, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>(
307 workloadFactory,
308 memoryManager,
309 armnn::BinaryOperation::Power,
310 shape0,
311 input0,
312 shape1,
313 input1,
314 shape0,
315 output,
316 tensorHandleFactory);
317}
318
319LayerTestResult<int16_t, 4> PowerInt16Test(
320 armnn::IWorkloadFactory& workloadFactory,
321 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
322 const armnn::ITensorHandleFactory& tensorHandleFactory)
323{
324 IgnoreUnused(memoryManager);
325 unsigned int shape[] = { 2, 2, 2, 2 };
326
327 std::vector<int16_t> input0 =
328 {
329 1, 5, 1, 4, 4, 9, 3, 7,
330 3, 2, 9, 6, 1, 2, 1, 4
331 };
332
333 std::vector<int16_t> input1 =
334 {
335 2, 2, 0, 3, 2, 1, 3, 2,
336 4, 4, 2, 1, 7, 5, 4, 2
337 };
338
339 std::vector<int16_t> output
340 {
341 1, 25, 0, 64, 16, 9, 27, 49,
342 81, 16, 81, 6, 1, 32, 1, 16
343 };
344
345 return ElementwiseTestHelper<4, armnn::DataType::QSymmS16, armnn::DataType::QSymmS16>(
346 workloadFactory,
347 memoryManager,
348 armnn::BinaryOperation::Power,
349 shape,
350 input0,
351 shape,
352 input1,
353 shape,
354 output,
355 tensorHandleFactory);
356}
357
358LayerTestResult<int16_t, 4> PowerBroadcast1ElementInt16Test(
359 armnn::IWorkloadFactory& workloadFactory,
360 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
361 const armnn::ITensorHandleFactory& tensorHandleFactory)
362{
363 IgnoreUnused(memoryManager);
364 const unsigned int shape0[] = { 1, 2, 2, 3 };
365 const unsigned int shape1[] = { 1, 1, 1, 1 };
366
367 std::vector<int16_t> input0 =
368 {
369 1, 2, 3, 4, 5, 0,
370 5, 4, 1, 4, 5, 2
371 };
372
373 std::vector<int16_t> input1 = { 2 };
374
375 std::vector<int16_t> output =
376 {
377 1, 4, 9, 16, 25, 0,
378 25, 16, 1, 16, 25, 4
379 };
380
381 return ElementwiseTestHelper<4, armnn::DataType::QSymmS16, armnn::DataType::QSymmS16>(
382 workloadFactory,
383 memoryManager,
384 armnn::BinaryOperation::Power,
385 shape0,
386 input0,
387 shape1,
388 input1,
389 shape0,
390 output,
391 tensorHandleFactory);
392}
393
394LayerTestResult<int16_t, 4> PowerBroadcastInt16Test(
395 armnn::IWorkloadFactory& workloadFactory,
396 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
397 const armnn::ITensorHandleFactory& tensorHandleFactory)
398{
399 IgnoreUnused(memoryManager);
400 const unsigned int shape0[] = { 1, 2, 2, 3 };
401 const unsigned int shape1[] = { 1, 1, 1, 3 };
402
403 std::vector<int16_t> input0 =
404 {
405 4, 2, 1, 4, 5, 3,
406 7, 3, 4, 8, 1, 2
407 };
408
409 std::vector<int16_t> input1 = { 1, 2, 3 };
410
411 std::vector<int16_t> output =
412 {
413 4, 4, 1, 4, 25, 27,
414 7, 9, 64, 8, 1, 8
415 };
416
417 return ElementwiseTestHelper<4, armnn::DataType::QSymmS16, armnn::DataType::QSymmS16>(
418 workloadFactory,
419 memoryManager,
420 armnn::BinaryOperation::Power,
421 shape0,
422 input0,
423 shape1,
424 input1,
425 shape0,
426 output,
427 tensorHandleFactory);
428}
429
430LayerTestResult<int32_t, 4> PowerInt32Test(
431 armnn::IWorkloadFactory& workloadFactory,
432 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
433 const armnn::ITensorHandleFactory& tensorHandleFactory)
434{
435 IgnoreUnused(memoryManager);
436 unsigned int shape[] = { 2, 2, 2, 2 };
437
438 std::vector<int32_t> input0 =
439 {
440 1, 3, 4, 3, 1, 4, 2, 1,
441 2, 1, 2, 1, 4, 3, 4, 3
442 };
443
444 std::vector<int32_t> input1 =
445 {
446 2, 2, 2, 2, 3, 3, 4, 3,
447 4, 4, 4, 4, 1, 3, 1, 3
448 };
449
450 std::vector<int32_t> output
451 {
452 1, 9, 16, 9, 1, 64, 16, 1,
453 16, 1, 16, 1, 4, 27, 4, 27
454 };
455
456 return ElementwiseTestHelper<4, armnn::DataType::Signed32, armnn::DataType::Signed32>(
457 workloadFactory,
458 memoryManager,
459 armnn::BinaryOperation::Power,
460 shape,
461 input0,
462 shape,
463 input1,
464 shape,
465 output,
466 tensorHandleFactory);
467}
468
469LayerTestResult<int32_t, 4> PowerBroadcastInt32Test(
470 armnn::IWorkloadFactory& workloadFactory,
471 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
472 const armnn::ITensorHandleFactory& tensorHandleFactory)
473{
474 IgnoreUnused(memoryManager);
475 const unsigned int shape0[] = { 1, 2, 2, 3 };
476 const unsigned int shape1[] = { 1, 1, 1, 3 };
477
478 std::vector<int32_t> input0 =
479 {
480 4, 4, 3, 4, 5, 0,
481 5, 8, 1, 3, 9, 2
482 };
483
484 std::vector<int32_t> input1 = { 2, 1, 3 };
485
486 std::vector<int32_t> output =
487 {
488 16, 4, 27, 16, 5, 0,
489 25, 8, 1, 9, 9, 8
490 };
491
492 return ElementwiseTestHelper<4, armnn::DataType::Signed32, armnn::DataType::Signed32>(
493 workloadFactory,
494 memoryManager,
495 armnn::BinaryOperation::Power,
496 shape0,
497 input0,
498 shape1,
499 input1,
500 shape0,
501 output,
502 tensorHandleFactory);
503}
504
505LayerTestResult<int32_t, 4> PowerBroadcast1ElementInt32Test(
506 armnn::IWorkloadFactory& workloadFactory,
507 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
508 const armnn::ITensorHandleFactory& tensorHandleFactory)
509{
510 IgnoreUnused(memoryManager);
511 const unsigned int shape0[] = { 1, 2, 2, 3 };
512 const unsigned int shape1[] = { 1, 1, 1, 1 };
513
514 std::vector<int32_t> input0 =
515 {
516 1, 2, 3, 4, 5, 3,
517 3, 1, 0, 2, 1, 5
518 };
519
520 std::vector<int32_t> input1 = { 2 };
521
522 std::vector<int32_t> output =
523 {
524 1, 4, 9, 16, 25, 9,
525 9, 1, 0, 4, 1, 25
526 };
527
528 return ElementwiseTestHelper<4, armnn::DataType::Signed32, armnn::DataType::Signed32>(
529 workloadFactory,
530 memoryManager,
531 armnn::BinaryOperation::Power,
532 shape0,
533 input0,
534 shape1,
535 input1,
536 shape0,
537 output,
538 tensorHandleFactory);
539}