Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/core/perf/opencl/perf_arithm.cpp
16358 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of the copyright holders may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the OpenCV Foundation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
#include "../perf_precomp.hpp"
43
#include "opencv2/ts/ocl_perf.hpp"
44
45
#ifdef HAVE_OPENCL
46
47
namespace opencv_test {
48
namespace ocl {
49
50
///////////// Lut ////////////////////////
51
52
typedef Size_MatType LUTFixture;
53
54
OCL_PERF_TEST_P(LUTFixture, LUT,
55
::testing::Combine(OCL_TEST_SIZES,
56
OCL_TEST_TYPES))
57
{
58
const Size_MatType_t params = GetParam();
59
const Size srcSize = get<0>(params);
60
const int type = get<1>(params), cn = CV_MAT_CN(type);
61
62
checkDeviceMaxMemoryAllocSize(srcSize, type);
63
64
UMat src(srcSize, CV_8UC(cn)), lut(1, 256, type);
65
int dstType = CV_MAKETYPE(lut.depth(), src.channels());
66
UMat dst(srcSize, dstType);
67
68
declare.in(src, lut, WARMUP_RNG).out(dst);
69
70
OCL_TEST_CYCLE() cv::LUT(src, lut, dst);
71
72
SANITY_CHECK(dst);
73
}
74
75
///////////// Exp ////////////////////////
76
77
typedef Size_MatType ExpFixture;
78
79
OCL_PERF_TEST_P(ExpFixture, Exp, ::testing::Combine(
80
OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
81
{
82
const Size_MatType_t params = GetParam();
83
const Size srcSize = get<0>(params);
84
const int type = get<1>(params);
85
86
checkDeviceMaxMemoryAllocSize(srcSize, type);
87
88
UMat src(srcSize, type), dst(srcSize, type);
89
declare.in(src).out(dst);
90
randu(src, 5, 16);
91
92
OCL_TEST_CYCLE() cv::exp(src, dst);
93
94
if (CV_MAT_DEPTH(type) >= CV_32F)
95
SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);
96
else
97
SANITY_CHECK(dst, 1);
98
}
99
100
///////////// Log ////////////////////////
101
102
typedef Size_MatType LogFixture;
103
104
OCL_PERF_TEST_P(LogFixture, Log, ::testing::Combine(
105
OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
106
{
107
const Size_MatType_t params = GetParam();
108
const Size srcSize = get<0>(params);
109
const int type = get<1>(params);
110
111
checkDeviceMaxMemoryAllocSize(srcSize, type);
112
113
UMat src(srcSize, type), dst(srcSize, type);
114
randu(src, 1, 10000);
115
declare.in(src).out(dst);
116
117
OCL_TEST_CYCLE() cv::log(src, dst);
118
119
if (CV_MAT_DEPTH(type) >= CV_32F)
120
SANITY_CHECK(dst, 2e-4, ERROR_RELATIVE);
121
else
122
SANITY_CHECK(dst, 1);
123
}
124
125
///////////// Add ////////////////////////
126
127
typedef Size_MatType AddFixture;
128
129
OCL_PERF_TEST_P(AddFixture, Add,
130
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
131
{
132
const Size srcSize = GET_PARAM(0);
133
const int type = GET_PARAM(1);
134
135
checkDeviceMaxMemoryAllocSize(srcSize, type);
136
137
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
138
declare.in(src1, src2, WARMUP_RNG).out(dst);
139
140
OCL_TEST_CYCLE() cv::add(src1, src2, dst);
141
142
SANITY_CHECK(dst);
143
}
144
145
///////////// Subtract ////////////////////////
146
147
typedef Size_MatType SubtractFixture;
148
149
OCL_PERF_TEST_P(SubtractFixture, Subtract,
150
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
151
{
152
const Size_MatType_t params = GetParam();
153
const Size srcSize = get<0>(params);
154
const int type = get<1>(params);
155
156
checkDeviceMaxMemoryAllocSize(srcSize, type);
157
158
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
159
declare.in(src1, src2, WARMUP_RNG).out(dst);
160
161
OCL_TEST_CYCLE() cv::subtract(src1, src2, dst);
162
163
SANITY_CHECK(dst);
164
}
165
166
///////////// Mul ////////////////////////
167
168
typedef Size_MatType MulFixture;
169
170
OCL_PERF_TEST_P(MulFixture, Multiply, ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
171
{
172
const Size_MatType_t params = GetParam();
173
const Size srcSize = get<0>(params);
174
const int type = get<1>(params);
175
176
checkDeviceMaxMemoryAllocSize(srcSize, type);
177
178
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
179
declare.in(src1, src2, WARMUP_RNG).out(dst);
180
181
OCL_TEST_CYCLE() cv::multiply(src1, src2, dst);
182
183
SANITY_CHECK(dst);
184
}
185
186
///////////// Div ////////////////////////
187
188
typedef Size_MatType DivFixture;
189
190
OCL_PERF_TEST_P(DivFixture, Divide,
191
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
192
{
193
const Size_MatType_t params = GetParam();
194
const Size srcSize = get<0>(params);
195
const int type = get<1>(params);
196
197
checkDeviceMaxMemoryAllocSize(srcSize, type);
198
199
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
200
declare.in(src1, src2, WARMUP_RNG).out(dst);
201
202
// remove zeros from src2
203
{
204
Mat m2 = src2.getMat(ACCESS_RW);
205
Mat zero_mask = m2 == 0;
206
Mat fix;
207
zero_mask.convertTo(fix, type); // 0 or 255
208
cv::add(m2, fix, m2);
209
}
210
211
OCL_TEST_CYCLE() cv::divide(src1, src2, dst);
212
213
if (CV_MAT_DEPTH(type) >= CV_32F)
214
SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
215
else
216
SANITY_CHECK(dst, 1);
217
}
218
219
///////////// Absdiff ////////////////////////
220
221
typedef Size_MatType AbsDiffFixture;
222
223
OCL_PERF_TEST_P(AbsDiffFixture, Absdiff,
224
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
225
{
226
const Size_MatType_t params = GetParam();
227
const Size srcSize = get<0>(params);
228
const int type = get<1>(params);
229
230
checkDeviceMaxMemoryAllocSize(srcSize, type);
231
232
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
233
declare.in(src1, src2, WARMUP_RNG).in(dst);
234
235
OCL_TEST_CYCLE() cv::absdiff(src1, src2, dst);
236
237
SANITY_CHECK(dst);
238
}
239
240
///////////// CartToPolar ////////////////////////
241
242
typedef Size_MatType CartToPolarFixture;
243
244
OCL_PERF_TEST_P(CartToPolarFixture, CartToPolar, ::testing::Combine(
245
OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
246
{
247
const Size_MatType_t params = GetParam();
248
const Size srcSize = get<0>(params);
249
const int type = get<1>(params);
250
251
checkDeviceMaxMemoryAllocSize(srcSize, type);
252
253
UMat src1(srcSize, type), src2(srcSize, type),
254
dst1(srcSize, type), dst2(srcSize, type);
255
declare.in(src1, src2, WARMUP_RNG).out(dst1, dst2);
256
257
OCL_TEST_CYCLE() cv::cartToPolar(src1, src2, dst1, dst2);
258
259
SANITY_CHECK(dst1, 8e-3);
260
SANITY_CHECK(dst2, 8e-3);
261
}
262
263
///////////// PolarToCart ////////////////////////
264
265
typedef Size_MatType PolarToCartFixture;
266
267
OCL_PERF_TEST_P(PolarToCartFixture, PolarToCart, ::testing::Combine(
268
OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
269
{
270
const Size_MatType_t params = GetParam();
271
const Size srcSize = get<0>(params);
272
const int type = get<1>(params);
273
274
checkDeviceMaxMemoryAllocSize(srcSize, type);
275
276
UMat src1(srcSize, type), src2(srcSize, type),
277
dst1(srcSize, type), dst2(srcSize, type);
278
declare.in(src1, src2, WARMUP_RNG).out(dst1, dst2);
279
280
OCL_TEST_CYCLE() cv::polarToCart(src1, src2, dst1, dst2);
281
282
SANITY_CHECK(dst1, 5e-5);
283
SANITY_CHECK(dst2, 5e-5);
284
}
285
286
///////////// Magnitude ////////////////////////
287
288
typedef Size_MatType MagnitudeFixture;
289
290
OCL_PERF_TEST_P(MagnitudeFixture, Magnitude, ::testing::Combine(
291
OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
292
{
293
const Size_MatType_t params = GetParam();
294
const Size srcSize = get<0>(params);
295
const int type = get<1>(params);
296
297
checkDeviceMaxMemoryAllocSize(srcSize, type);
298
299
UMat src1(srcSize, type), src2(srcSize, type),
300
dst(srcSize, type);
301
declare.in(src1, src2, WARMUP_RNG).out(dst);
302
303
OCL_TEST_CYCLE() cv::magnitude(src1, src2, dst);
304
305
SANITY_CHECK(dst, 1e-6);
306
}
307
308
///////////// Transpose ////////////////////////
309
310
typedef Size_MatType TransposeFixture;
311
312
OCL_PERF_TEST_P(TransposeFixture, Transpose, ::testing::Combine(
313
OCL_TEST_SIZES, OCL_TEST_TYPES_134))
314
{
315
const Size_MatType_t params = GetParam();
316
const Size srcSize = get<0>(params);
317
const int type = get<1>(params);
318
319
checkDeviceMaxMemoryAllocSize(srcSize, type);
320
321
UMat src(srcSize, type), dst(srcSize, type);
322
declare.in(src, WARMUP_RNG).out(dst);
323
324
OCL_TEST_CYCLE() cv::transpose(src, dst);
325
326
SANITY_CHECK(dst);
327
}
328
329
OCL_PERF_TEST_P(TransposeFixture, TransposeInplace, ::testing::Combine(
330
OCL_PERF_ENUM(Size(640, 640), Size(1280, 1280), Size(2160, 2160)), OCL_TEST_TYPES_134))
331
{
332
const Size_MatType_t params = GetParam();
333
const Size srcSize = get<0>(params);
334
const int type = get<1>(params);
335
336
checkDeviceMaxMemoryAllocSize(srcSize, type);
337
338
UMat src(srcSize, type);
339
declare.in(src, WARMUP_RNG).out(src, WARMUP_NONE);
340
341
OCL_TEST_CYCLE() cv::transpose(src, src);
342
343
SANITY_CHECK_NOTHING();
344
}
345
346
///////////// Flip ////////////////////////
347
348
enum
349
{
350
FLIP_BOTH = 0, FLIP_ROWS, FLIP_COLS
351
};
352
353
CV_ENUM(FlipType, FLIP_BOTH, FLIP_ROWS, FLIP_COLS)
354
355
typedef tuple<Size, MatType, FlipType> FlipParams;
356
typedef TestBaseWithParam<FlipParams> FlipFixture;
357
358
OCL_PERF_TEST_P(FlipFixture, Flip,
359
::testing::Combine(OCL_TEST_SIZES,
360
OCL_TEST_TYPES, FlipType::all()))
361
{
362
const FlipParams params = GetParam();
363
const Size srcSize = get<0>(params);
364
const int type = get<1>(params);
365
const int flipType = get<2>(params);
366
367
checkDeviceMaxMemoryAllocSize(srcSize, type);
368
369
UMat src(srcSize, type), dst(srcSize, type);
370
declare.in(src, WARMUP_RNG).out(dst);
371
372
OCL_TEST_CYCLE() cv::flip(src, dst, flipType - 1);
373
374
SANITY_CHECK(dst);
375
}
376
377
///////////// minMaxLoc ////////////////////////
378
379
typedef Size_MatType MinMaxLocFixture;
380
381
OCL_PERF_TEST_P(MinMaxLocFixture, MinMaxLoc,
382
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
383
{
384
const Size_MatType_t params = GetParam();
385
const Size srcSize = get<0>(params);
386
const int type = get<1>(params);
387
bool onecn = CV_MAT_CN(type) == 1;
388
389
checkDeviceMaxMemoryAllocSize(srcSize, type);
390
391
UMat src(srcSize, type);;
392
declare.in(src, WARMUP_RNG);
393
394
double min_val = 0.0, max_val = 0.0;
395
Point min_loc, max_loc;
396
397
OCL_TEST_CYCLE() cv::minMaxLoc(src, &min_val, &max_val, onecn ? &min_loc : NULL,
398
onecn ? &max_loc : NULL);
399
400
ASSERT_GE(max_val, min_val);
401
SANITY_CHECK(min_val);
402
SANITY_CHECK(max_val);
403
404
int min_loc_x = min_loc.x, min_loc_y = min_loc.y, max_loc_x = max_loc.x,
405
max_loc_y = max_loc.y;
406
SANITY_CHECK(min_loc_x);
407
SANITY_CHECK(min_loc_y);
408
SANITY_CHECK(max_loc_x);
409
SANITY_CHECK(max_loc_y);
410
}
411
412
///////////// Sum ////////////////////////
413
414
typedef Size_MatType SumFixture;
415
416
OCL_PERF_TEST_P(SumFixture, Sum,
417
::testing::Combine(OCL_TEST_SIZES,
418
OCL_TEST_TYPES_134))
419
{
420
const Size_MatType_t params = GetParam();
421
const Size srcSize = get<0>(params);
422
const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
423
424
checkDeviceMaxMemoryAllocSize(srcSize, type);
425
426
UMat src(srcSize, type);
427
Scalar result;
428
randu(src, 0, 60);
429
declare.in(src);
430
431
OCL_TEST_CYCLE() result = cv::sum(src);
432
433
if (depth >= CV_32F)
434
SANITY_CHECK(result, 1e-6, ERROR_RELATIVE);
435
else
436
SANITY_CHECK(result);
437
}
438
439
///////////// countNonZero ////////////////////////
440
441
typedef Size_MatType CountNonZeroFixture;
442
443
OCL_PERF_TEST_P(CountNonZeroFixture, CountNonZero,
444
::testing::Combine(OCL_TEST_SIZES,
445
OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
446
{
447
const Size_MatType_t params = GetParam();
448
const Size srcSize = get<0>(params);
449
const int type = get<1>(params);
450
451
checkDeviceMaxMemoryAllocSize(srcSize, type);
452
453
UMat src(srcSize, type);
454
int result = 0;
455
randu(src, 0, 10);
456
declare.in(src);
457
458
OCL_TEST_CYCLE() result = cv::countNonZero(src);
459
460
SANITY_CHECK(result);
461
}
462
463
///////////// Phase ////////////////////////
464
465
typedef Size_MatType PhaseFixture;
466
467
OCL_PERF_TEST_P(PhaseFixture, Phase, ::testing::Combine(
468
OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
469
{
470
const Size_MatType_t params = GetParam();
471
const Size srcSize = get<0>(params);
472
const int type = get<1>(params);
473
474
checkDeviceMaxMemoryAllocSize(srcSize, type);
475
476
UMat src1(srcSize, type), src2(srcSize, type),
477
dst(srcSize, type);
478
declare.in(src1, src2, WARMUP_RNG).out(dst);
479
480
OCL_TEST_CYCLE() cv::phase(src1, src2, dst, 1);
481
482
SANITY_CHECK(dst, 1e-2);
483
}
484
485
///////////// bitwise_and ////////////////////////
486
487
typedef Size_MatType BitwiseAndFixture;
488
489
OCL_PERF_TEST_P(BitwiseAndFixture, Bitwise_and,
490
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
491
{
492
const Size_MatType_t params = GetParam();
493
const Size srcSize = get<0>(params);
494
const int type = get<1>(params);
495
496
checkDeviceMaxMemoryAllocSize(srcSize, type);
497
498
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
499
declare.in(src1, src2, WARMUP_RNG).out(dst);
500
501
OCL_TEST_CYCLE() cv::bitwise_and(src1, src2, dst);
502
503
SANITY_CHECK(dst);
504
}
505
506
///////////// bitwise_xor ////////////////////////
507
508
typedef Size_MatType BitwiseXorFixture;
509
510
OCL_PERF_TEST_P(BitwiseXorFixture, Bitwise_xor,
511
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
512
{
513
const Size_MatType_t params = GetParam();
514
const Size srcSize = get<0>(params);
515
const int type = get<1>(params);
516
517
checkDeviceMaxMemoryAllocSize(srcSize, type);
518
519
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
520
declare.in(src1, src2, WARMUP_RNG).out(dst);
521
522
OCL_TEST_CYCLE() cv::bitwise_xor(src1, src2, dst);
523
524
SANITY_CHECK(dst);
525
}
526
527
///////////// bitwise_or ////////////////////////
528
529
typedef Size_MatType BitwiseOrFixture;
530
531
OCL_PERF_TEST_P(BitwiseOrFixture, Bitwise_or,
532
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
533
{
534
const Size_MatType_t params = GetParam();
535
const Size srcSize = get<0>(params);
536
const int type = get<1>(params);
537
538
checkDeviceMaxMemoryAllocSize(srcSize, type);
539
540
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
541
declare.in(src1, src2, WARMUP_RNG).out(dst);
542
543
OCL_TEST_CYCLE() cv::bitwise_or(src1, src2, dst);
544
545
SANITY_CHECK(dst);
546
}
547
548
///////////// bitwise_not ////////////////////////
549
550
typedef Size_MatType BitwiseNotFixture;
551
552
OCL_PERF_TEST_P(BitwiseNotFixture, Bitwise_not,
553
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
554
{
555
const Size_MatType_t params = GetParam();
556
const Size srcSize = get<0>(params);
557
const int type = get<1>(params);
558
559
checkDeviceMaxMemoryAllocSize(srcSize, type);
560
561
UMat src(srcSize, type), dst(srcSize, type);
562
declare.in(src, WARMUP_RNG).out(dst);
563
564
OCL_TEST_CYCLE() cv::bitwise_not(src, dst);
565
566
SANITY_CHECK(dst);
567
}
568
569
///////////// compare ////////////////////////
570
571
CV_ENUM(CmpCode, CMP_LT, CMP_LE, CMP_EQ, CMP_NE, CMP_GE, CMP_GT)
572
573
typedef tuple<Size, MatType, CmpCode> CompareParams;
574
typedef TestBaseWithParam<CompareParams> CompareFixture;
575
576
OCL_PERF_TEST_P(CompareFixture, Compare,
577
::testing::Combine(OCL_TEST_SIZES,
578
OCL_TEST_TYPES_134, CmpCode::all()))
579
{
580
const CompareParams params = GetParam();
581
const Size srcSize = get<0>(params);
582
const int type = get<1>(params);
583
const int cmpCode = get<2>(params);
584
585
checkDeviceMaxMemoryAllocSize(srcSize, type);
586
587
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, CV_8UC(CV_MAT_CN(type)));
588
declare.in(src1, src2, WARMUP_RNG).out(dst);
589
590
OCL_TEST_CYCLE() cv::compare(src1, src2, dst, cmpCode);
591
592
SANITY_CHECK(dst);
593
}
594
595
OCL_PERF_TEST_P(CompareFixture, CompareScalar,
596
::testing::Combine(OCL_TEST_SIZES,
597
OCL_PERF_ENUM((MatType)CV_32FC1), // TODO: OCL_TEST_TYPES_134
598
CmpCode::all()))
599
{
600
const CompareParams params = GetParam();
601
const Size srcSize = get<0>(params);
602
const int type = get<1>(params);
603
const int cmpCode = get<2>(params);
604
605
checkDeviceMaxMemoryAllocSize(srcSize, type);
606
607
UMat src1(srcSize, type), dst(srcSize, CV_8UC(CV_MAT_CN(type)));
608
declare.in(src1, WARMUP_RNG).out(dst);
609
610
OCL_TEST_CYCLE() cv::compare(src1, 32, dst, cmpCode);
611
612
SANITY_CHECK(dst);
613
}
614
615
///////////// pow ////////////////////////
616
617
typedef Size_MatType PowFixture;
618
619
OCL_PERF_TEST_P(PowFixture, Pow, ::testing::Combine(
620
OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
621
{
622
const Size_MatType_t params = GetParam();
623
const Size srcSize = get<0>(params);
624
const int type = get<1>(params);
625
626
checkDeviceMaxMemoryAllocSize(srcSize, type);
627
628
UMat src(srcSize, type), dst(srcSize, type);
629
randu(src, 0, 100);
630
declare.in(src).out(dst);
631
632
OCL_TEST_CYCLE() cv::pow(src, 2.17, dst);
633
634
SANITY_CHECK(dst, 1.5e-6, ERROR_RELATIVE);
635
}
636
637
///////////// AddWeighted////////////////////////
638
639
typedef Size_MatType AddWeightedFixture;
640
641
OCL_PERF_TEST_P(AddWeightedFixture, AddWeighted,
642
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
643
{
644
const Size_MatType_t params = GetParam();
645
const Size srcSize = get<0>(params);
646
const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
647
648
checkDeviceMaxMemoryAllocSize(srcSize, type);
649
650
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
651
declare.in(src1, src2, WARMUP_RNG).out(dst);
652
double alpha = 2.0, beta = 1.0, gama = 3.0;
653
654
OCL_TEST_CYCLE() cv::addWeighted(src1, alpha, src2, beta, gama, dst);
655
656
if (depth >= CV_32F)
657
SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
658
else
659
SANITY_CHECK(dst);
660
}
661
662
///////////// Sqrt ///////////////////////
663
664
typedef Size_MatType SqrtFixture;
665
666
OCL_PERF_TEST_P(SqrtFixture, Sqrt, ::testing::Combine(
667
OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
668
{
669
const Size_MatType_t params = GetParam();
670
const Size srcSize = get<0>(params);
671
const int type = get<1>(params);
672
673
checkDeviceMaxMemoryAllocSize(srcSize, type);
674
675
UMat src(srcSize, type), dst(srcSize, type);
676
randu(src, 0, 1000);
677
declare.in(src).out(dst);
678
679
OCL_TEST_CYCLE() cv::sqrt(src, dst);
680
681
if (CV_MAT_DEPTH(type) >= CV_32F)
682
SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);
683
else
684
SANITY_CHECK(dst, 1);
685
}
686
687
///////////// SetIdentity ////////////////////////
688
689
typedef Size_MatType SetIdentityFixture;
690
691
OCL_PERF_TEST_P(SetIdentityFixture, SetIdentity,
692
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
693
{
694
const Size_MatType_t params = GetParam();
695
const Size srcSize = get<0>(params);
696
const int type = get<1>(params);
697
698
checkDeviceMaxMemoryAllocSize(srcSize, type);
699
700
UMat dst(srcSize, type);
701
declare.out(dst);
702
703
OCL_TEST_CYCLE() cv::setIdentity(dst, cv::Scalar::all(181));
704
705
SANITY_CHECK(dst);
706
}
707
708
///////////// MeanStdDev ////////////////////////
709
710
typedef Size_MatType MeanStdDevFixture;
711
712
OCL_PERF_TEST_P(MeanStdDevFixture, MeanStdDev,
713
::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
714
OCL_TEST_TYPES_134))
715
{
716
const Size_MatType_t params = GetParam();
717
const Size srcSize = get<0>(params);
718
const int type = get<1>(params);
719
const double eps = 2e-5;
720
721
checkDeviceMaxMemoryAllocSize(srcSize, type);
722
723
UMat src(srcSize, type);
724
Scalar mean, stddev;
725
declare.in(src, WARMUP_RNG);
726
727
OCL_TEST_CYCLE() cv::meanStdDev(src, mean, stddev);
728
729
double mean0 = mean[0], mean1 = mean[1], mean2 = mean[2], mean3 = mean[3];
730
double stddev0 = stddev[0], stddev1 = stddev[1], stddev2 = stddev[2], stddev3 = stddev[3];
731
732
SANITY_CHECK(mean0, eps, ERROR_RELATIVE);
733
SANITY_CHECK(mean1, eps, ERROR_RELATIVE);
734
SANITY_CHECK(mean2, eps, ERROR_RELATIVE);
735
SANITY_CHECK(mean3, eps, ERROR_RELATIVE);
736
SANITY_CHECK(stddev0, eps, ERROR_RELATIVE);
737
SANITY_CHECK(stddev1, eps, ERROR_RELATIVE);
738
SANITY_CHECK(stddev2, eps, ERROR_RELATIVE);
739
SANITY_CHECK(stddev3, eps, ERROR_RELATIVE);
740
}
741
742
OCL_PERF_TEST_P(MeanStdDevFixture, MeanStdDevWithMask,
743
::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
744
OCL_TEST_TYPES_134))
745
{
746
const Size_MatType_t params = GetParam();
747
const Size srcSize = get<0>(params);
748
const int type = get<1>(params);
749
const double eps = 2e-5;
750
751
checkDeviceMaxMemoryAllocSize(srcSize, type);
752
753
UMat src(srcSize, type), mask(srcSize, CV_8UC1);
754
Scalar mean, stddev;
755
declare.in(src, mask, WARMUP_RNG);
756
757
OCL_TEST_CYCLE() cv::meanStdDev(src, mean, stddev, mask);
758
759
double mean0 = mean[0], mean1 = mean[1], mean2 = mean[2], mean3 = mean[3];
760
double stddev0 = stddev[0], stddev1 = stddev[1], stddev2 = stddev[2], stddev3 = stddev[3];
761
762
SANITY_CHECK(mean0, eps, ERROR_RELATIVE);
763
SANITY_CHECK(mean1, eps, ERROR_RELATIVE);
764
SANITY_CHECK(mean2, eps, ERROR_RELATIVE);
765
SANITY_CHECK(mean3, eps, ERROR_RELATIVE);
766
SANITY_CHECK(stddev0, eps, ERROR_RELATIVE);
767
SANITY_CHECK(stddev1, eps, ERROR_RELATIVE);
768
SANITY_CHECK(stddev2, eps, ERROR_RELATIVE);
769
SANITY_CHECK(stddev3, eps, ERROR_RELATIVE);
770
}
771
772
///////////// Norm ////////////////////////
773
774
CV_ENUM(NormType, NORM_INF, NORM_L1, NORM_L2)
775
776
typedef tuple<Size, MatType, NormType> NormParams;
777
typedef TestBaseWithParam<NormParams> NormFixture;
778
779
OCL_PERF_TEST_P(NormFixture, Norm1Arg,
780
::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
781
OCL_TEST_TYPES_134, NormType::all()))
782
{
783
const NormParams params = GetParam();
784
const Size srcSize = get<0>(params);
785
const int type = get<1>(params);
786
const int normType = get<2>(params);
787
788
checkDeviceMaxMemoryAllocSize(srcSize, type);
789
790
UMat src1(srcSize, type);
791
double res;
792
declare.in(src1, WARMUP_RNG);
793
794
OCL_TEST_CYCLE() res = cv::norm(src1, normType);
795
796
SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);
797
}
798
799
OCL_PERF_TEST_P(NormFixture, Norm,
800
::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
801
OCL_TEST_TYPES_134, NormType::all()))
802
{
803
const NormParams params = GetParam();
804
const Size srcSize = get<0>(params);
805
const int type = get<1>(params);
806
const int normType = get<2>(params);
807
808
checkDeviceMaxMemoryAllocSize(srcSize, type);
809
810
UMat src1(srcSize, type), src2(srcSize, type);
811
double res;
812
declare.in(src1, src2, WARMUP_RNG);
813
814
OCL_TEST_CYCLE() res = cv::norm(src1, src2, normType);
815
816
SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);
817
}
818
819
OCL_PERF_TEST_P(NormFixture, NormRel,
820
::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
821
OCL_TEST_TYPES_134, NormType::all()))
822
{
823
const NormParams params = GetParam();
824
const Size srcSize = get<0>(params);
825
const int type = get<1>(params);
826
const int normType = get<2>(params);
827
828
checkDeviceMaxMemoryAllocSize(srcSize, type);
829
830
UMat src1(srcSize, type), src2(srcSize, type);
831
double res;
832
declare.in(src1, src2, WARMUP_RNG);
833
834
OCL_TEST_CYCLE() res = cv::norm(src1, src2, normType | cv::NORM_RELATIVE);
835
836
SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);
837
}
838
839
///////////// UMat::dot ////////////////////////
840
841
typedef Size_MatType UMatDotFixture;
842
843
OCL_PERF_TEST_P(UMatDotFixture, UMatDot,
844
::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
845
OCL_TEST_TYPES_134))
846
{
847
const Size_MatType_t params = GetParam();
848
const Size srcSize = get<0>(params);
849
const int type = get<1>(params);
850
double r = 0.0;
851
852
checkDeviceMaxMemoryAllocSize(srcSize, type);
853
854
UMat src1(srcSize, type), src2(srcSize, type);
855
declare.in(src1, src2, WARMUP_RNG);
856
857
OCL_TEST_CYCLE() r = src1.dot(src2);
858
859
SANITY_CHECK(r, 1e-5, ERROR_RELATIVE);
860
}
861
862
///////////// Repeat ////////////////////////
863
864
typedef Size_MatType RepeatFixture;
865
866
OCL_PERF_TEST_P(RepeatFixture, Repeat,
867
::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), OCL_TEST_TYPES))
868
{
869
const Size_MatType_t params = GetParam();
870
const Size srcSize = get<0>(params);
871
const int type = get<1>(params), nx = 2, ny = 2;
872
873
checkDeviceMaxMemoryAllocSize(srcSize, type);
874
875
UMat src(srcSize, type), dst(Size(srcSize.width * nx, srcSize.height * ny), type);
876
declare.in(src, WARMUP_RNG).out(dst);
877
878
OCL_TEST_CYCLE() cv::repeat(src, nx, ny, dst);
879
880
SANITY_CHECK(dst);
881
}
882
883
///////////// Min ////////////////////////
884
885
typedef Size_MatType MinFixture;
886
887
OCL_PERF_TEST_P(MinFixture, Min,
888
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
889
{
890
const Size_MatType_t params = GetParam();
891
const Size srcSize = get<0>(params);
892
const int type = get<1>(params);
893
894
checkDeviceMaxMemoryAllocSize(srcSize, type);
895
896
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
897
declare.in(src1, src2, WARMUP_RNG).out(dst);
898
899
OCL_TEST_CYCLE() cv::min(src1, src2, dst);
900
901
SANITY_CHECK(dst);
902
}
903
904
///////////// Max ////////////////////////
905
906
typedef Size_MatType MaxFixture;
907
908
OCL_PERF_TEST_P(MaxFixture, Max,
909
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
910
{
911
const Size_MatType_t params = GetParam();
912
const Size srcSize = get<0>(params);
913
const int type = get<1>(params);
914
915
checkDeviceMaxMemoryAllocSize(srcSize, type);
916
917
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
918
declare.in(src1, src2, WARMUP_RNG).out(dst);
919
920
OCL_TEST_CYCLE() cv::max(src1, src2, dst);
921
922
SANITY_CHECK(dst);
923
}
924
925
///////////// InRange ////////////////////////
926
927
typedef Size_MatType InRangeFixture;
928
929
OCL_PERF_TEST_P(InRangeFixture, InRange,
930
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
931
{
932
const Size_MatType_t params = GetParam();
933
const Size srcSize = get<0>(params);
934
const int type = get<1>(params);
935
936
checkDeviceMaxMemoryAllocSize(srcSize, type);
937
938
UMat src(srcSize, type), lb(srcSize, type), ub(srcSize, type), dst(srcSize, CV_8UC1);
939
declare.in(src, lb, ub, WARMUP_RNG).out(dst);
940
941
OCL_TEST_CYCLE() cv::inRange(src, lb, ub, dst);
942
943
SANITY_CHECK(dst);
944
}
945
946
///////////// Normalize ////////////////////////
947
948
CV_ENUM(NormalizeModes, CV_MINMAX, CV_L2, CV_L1, CV_C)
949
950
typedef tuple<Size, MatType, NormalizeModes> NormalizeParams;
951
typedef TestBaseWithParam<NormalizeParams> NormalizeFixture;
952
953
OCL_PERF_TEST_P(NormalizeFixture, Normalize,
954
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
955
NormalizeModes::all()))
956
{
957
const NormalizeParams params = GetParam();
958
const Size srcSize = get<0>(params);
959
const int type = get<1>(params), mode = get<2>(params);
960
961
checkDeviceMaxMemoryAllocSize(srcSize, type);
962
963
UMat src(srcSize, type), dst(srcSize, type);
964
declare.in(src, WARMUP_RNG).out(dst);
965
966
OCL_TEST_CYCLE() cv::normalize(src, dst, 10, 110, mode);
967
968
SANITY_CHECK(dst, 5e-2);
969
}
970
971
OCL_PERF_TEST_P(NormalizeFixture, NormalizeWithMask,
972
::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1),
973
NormalizeModes::all()))
974
{
975
const NormalizeParams params = GetParam();
976
const Size srcSize = get<0>(params);
977
const int type = get<1>(params), mode = get<2>(params);
978
979
checkDeviceMaxMemoryAllocSize(srcSize, type);
980
981
UMat src(srcSize, type), mask(srcSize, CV_8UC1), dst(srcSize, type);
982
declare.in(src, mask, WARMUP_RNG).out(dst);
983
984
OCL_TEST_CYCLE() cv::normalize(src, dst, 10, 110, mode, -1, mask);
985
986
SANITY_CHECK(dst, 5e-2);
987
}
988
989
///////////// ConvertScaleAbs ////////////////////////
990
991
typedef Size_MatType ConvertScaleAbsFixture;
992
993
OCL_PERF_TEST_P(ConvertScaleAbsFixture, ConvertScaleAbs,
994
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
995
{
996
const Size_MatType_t params = GetParam();
997
const Size srcSize = get<0>(params);
998
const int type = get<1>(params), cn = CV_MAT_CN(type);
999
1000
checkDeviceMaxMemoryAllocSize(srcSize, type);
1001
1002
UMat src(srcSize, type), dst(srcSize, CV_8UC(cn));
1003
declare.in(src, WARMUP_RNG).out(dst);
1004
1005
OCL_TEST_CYCLE() cv::convertScaleAbs(src, dst, 0.5, 2);
1006
1007
SANITY_CHECK(dst, 1); // CV_8U
1008
}
1009
1010
///////////// PatchNaNs ////////////////////////
1011
1012
typedef Size_MatType PatchNaNsFixture;
1013
1014
OCL_PERF_TEST_P(PatchNaNsFixture, PatchNaNs,
1015
::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
1016
{
1017
const Size_MatType_t params = GetParam();
1018
Size srcSize = get<0>(params);
1019
const int type = get<1>(params), cn = CV_MAT_CN(type);
1020
1021
checkDeviceMaxMemoryAllocSize(srcSize, type);
1022
1023
UMat src(srcSize, type);
1024
declare.in(src, WARMUP_RNG).out(src);
1025
1026
// generating NaNs
1027
{
1028
Mat src_ = src.getMat(ACCESS_RW);
1029
srcSize.width *= cn;
1030
for (int y = 0; y < srcSize.height; ++y)
1031
{
1032
float * const ptr = src_.ptr<float>(y);
1033
for (int x = 0; x < srcSize.width; ++x)
1034
ptr[x] = (x + y) % 2 == 0 ? std::numeric_limits<float>::quiet_NaN() : ptr[x];
1035
}
1036
}
1037
1038
OCL_TEST_CYCLE() cv::patchNaNs(src, 17.7);
1039
1040
SANITY_CHECK(src);
1041
}
1042
1043
1044
///////////// ScaleAdd ////////////////////////
1045
1046
typedef Size_MatType ScaleAddFixture;
1047
1048
OCL_PERF_TEST_P(ScaleAddFixture, ScaleAdd,
1049
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
1050
{
1051
const Size_MatType_t params = GetParam();
1052
const Size srcSize = get<0>(params);
1053
const int type = get<1>(params);
1054
1055
checkDeviceMaxMemoryAllocSize(srcSize, type);
1056
1057
UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
1058
declare.in(src1, src2, WARMUP_RNG).out(dst);
1059
1060
OCL_TEST_CYCLE() cv::scaleAdd(src1, 0.6, src2, dst);
1061
1062
SANITY_CHECK(dst, 1e-6);
1063
}
1064
1065
///////////// Transform ////////////////////////
1066
1067
typedef Size_MatType TransformFixture;
1068
1069
OCL_PERF_TEST_P(TransformFixture, Transform,
1070
::testing::Combine(OCL_TEST_SIZES,
1071
::testing::Values(CV_8UC3, CV_8SC3, CV_16UC3, CV_16SC3, CV_32SC3, CV_32FC3, CV_64FC3)))
1072
{
1073
const Size_MatType_t params = GetParam();
1074
const Size srcSize = get<0>(params);
1075
const int type = get<1>(params);
1076
1077
checkDeviceMaxMemoryAllocSize(srcSize, type);
1078
1079
const float transform[] = { 0.5f, 0.f, 0.86602540378f, 128,
1080
0.f, 1.f, 0.f, -64,
1081
0.86602540378f, 0.f, 0.5f, 32,};
1082
Mat mtx(Size(4, 3), CV_32FC1, (void*)transform);
1083
1084
UMat src(srcSize, type), dst(srcSize, type);
1085
randu(src, 0, 30);
1086
declare.in(src).out(dst);
1087
1088
OCL_TEST_CYCLE() cv::transform(src, dst, mtx);
1089
1090
SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
1091
}
1092
1093
///////////// PSNR ////////////////////////
1094
1095
typedef Size_MatType PSNRFixture;
1096
1097
OCL_PERF_TEST_P(PSNRFixture, PSNR,
1098
::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_8UC4)))
1099
{
1100
const Size_MatType_t params = GetParam();
1101
const Size srcSize = get<0>(params);
1102
const int type = get<1>(params);
1103
1104
checkDeviceMaxMemoryAllocSize(srcSize, type);
1105
1106
double psnr = 0;
1107
UMat src1(srcSize, type), src2(srcSize, type);
1108
declare.in(src1, src2, WARMUP_RNG);
1109
1110
OCL_TEST_CYCLE() psnr = cv::PSNR(src1, src2);
1111
1112
SANITY_CHECK(psnr, 1e-4, ERROR_RELATIVE);
1113
}
1114
1115
///////////// Reduce ////////////////////////
1116
1117
CV_ENUM(ReduceMinMaxOp, CV_REDUCE_MIN, CV_REDUCE_MAX)
1118
1119
typedef tuple<Size, std::pair<MatType, MatType>, int, ReduceMinMaxOp> ReduceMinMaxParams;
1120
typedef TestBaseWithParam<ReduceMinMaxParams> ReduceMinMaxFixture;
1121
1122
OCL_PERF_TEST_P(ReduceMinMaxFixture, Reduce,
1123
::testing::Combine(OCL_TEST_SIZES,
1124
OCL_PERF_ENUM(std::make_pair<MatType, MatType>(CV_8UC1, CV_8UC1),
1125
std::make_pair<MatType, MatType>(CV_32FC4, CV_32FC4)),
1126
OCL_PERF_ENUM(0, 1),
1127
ReduceMinMaxOp::all()))
1128
{
1129
const ReduceMinMaxParams params = GetParam();
1130
const std::pair<MatType, MatType> types = get<1>(params);
1131
const int stype = types.first, dtype = types.second,
1132
dim = get<2>(params), op = get<3>(params);
1133
const Size srcSize = get<0>(params),
1134
dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height);
1135
const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 1e-5;
1136
1137
checkDeviceMaxMemoryAllocSize(srcSize, stype);
1138
checkDeviceMaxMemoryAllocSize(srcSize, dtype);
1139
1140
UMat src(srcSize, stype), dst(dstSize, dtype);
1141
declare.in(src, WARMUP_RNG).out(dst);
1142
1143
OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype);
1144
1145
SANITY_CHECK(dst, eps);
1146
}
1147
1148
CV_ENUM(ReduceAccOp, CV_REDUCE_SUM, CV_REDUCE_AVG)
1149
1150
typedef tuple<Size, std::pair<MatType, MatType>, int, ReduceAccOp> ReduceAccParams;
1151
typedef TestBaseWithParam<ReduceAccParams> ReduceAccFixture;
1152
1153
OCL_PERF_TEST_P(ReduceAccFixture, Reduce,
1154
::testing::Combine(OCL_TEST_SIZES,
1155
OCL_PERF_ENUM(std::make_pair<MatType, MatType>(CV_8UC4, CV_32SC4),
1156
std::make_pair<MatType, MatType>(CV_32FC1, CV_32FC1)),
1157
OCL_PERF_ENUM(0, 1),
1158
ReduceAccOp::all()))
1159
{
1160
const ReduceAccParams params = GetParam();
1161
const std::pair<MatType, MatType> types = get<1>(params);
1162
const int stype = types.first, dtype = types.second,
1163
dim = get<2>(params), op = get<3>(params);
1164
const Size srcSize = get<0>(params),
1165
dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height);
1166
const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 3e-4;
1167
1168
checkDeviceMaxMemoryAllocSize(srcSize, stype);
1169
checkDeviceMaxMemoryAllocSize(srcSize, dtype);
1170
1171
UMat src(srcSize, stype), dst(dstSize, dtype);
1172
declare.in(src, WARMUP_RNG).out(dst);
1173
1174
OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype);
1175
1176
SANITY_CHECK(dst, eps);
1177
}
1178
1179
} } // namespace opencv_test::ocl
1180
1181
#endif // HAVE_OPENCL
1182
1183