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