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
OCL_PERF_TEST_P(LUTFixture,LUT,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES))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
OCL_PERF_TEST_P(ExpFixture,Exp,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32FC1,CV_32FC4)))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
OCL_PERF_TEST_P(LogFixture,Log,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32FC1,CV_32FC4)))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
OCL_PERF_TEST_P(AddFixture,Add,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(SubtractFixture,Subtract,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(MulFixture,Multiply,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(DivFixture,Divide,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(AbsDiffFixture,Absdiff,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(CartToPolarFixture,CartToPolar,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32FC1,CV_32FC4)))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
OCL_PERF_TEST_P(PolarToCartFixture,PolarToCart,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32FC1,CV_32FC4)))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
OCL_PERF_TEST_P(MagnitudeFixture,Magnitude,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32FC1,CV_32FC4)))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
OCL_PERF_TEST_P(TransposeFixture,Transpose,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(FlipFixture,Flip,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES,FlipType::all ()))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
OCL_PERF_TEST_P(MinMaxLocFixture,MinMaxLoc,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(SumFixture,Sum,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(CountNonZeroFixture,CountNonZero,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_8UC1,CV_32FC1)))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
OCL_PERF_TEST_P(PhaseFixture,Phase,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32FC1,CV_32FC4)))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
OCL_PERF_TEST_P(BitwiseAndFixture,Bitwise_and,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(BitwiseXorFixture,Bitwise_xor,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(BitwiseOrFixture,Bitwise_or,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(BitwiseNotFixture,Bitwise_not,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(CompareFixture,Compare,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134,CmpCode::all ()))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
OCL_PERF_TEST_P(PowFixture,Pow,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32FC1,CV_32FC4)))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
OCL_PERF_TEST_P(AddWeightedFixture,AddWeighted,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134))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
OCL_PERF_TEST_P(SqrtFixture,Sqrt,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32FC1,CV_32FC4)))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 // To square root 32 bit floats we use native_sqrt, which has implementation
682 // defined accuracy. We know intel devices have accurate native_sqrt, but
683 // otherwise stick to a relaxed sanity check. For types larger than 32 bits
684 // we can do the accuracy check for all devices as normal.
685 if (CV_MAT_DEPTH(type) > CV_32F || !ocl::useOpenCL() ||
686 ocl::Device::getDefault().isIntel())
687 SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);
688 else
689 SANITY_CHECK(dst, 1);
690 }
691
692 ///////////// SetIdentity ////////////////////////
693
694 typedef Size_MatType SetIdentityFixture;
695
OCL_PERF_TEST_P(SetIdentityFixture,SetIdentity,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES))696 OCL_PERF_TEST_P(SetIdentityFixture, SetIdentity,
697 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
698 {
699 const Size_MatType_t params = GetParam();
700 const Size srcSize = get<0>(params);
701 const int type = get<1>(params);
702
703 checkDeviceMaxMemoryAllocSize(srcSize, type);
704
705 UMat dst(srcSize, type);
706 declare.out(dst);
707
708 OCL_TEST_CYCLE() cv::setIdentity(dst, cv::Scalar::all(181));
709
710 SANITY_CHECK(dst);
711 }
712
713 ///////////// MeanStdDev ////////////////////////
714
715 typedef Size_MatType MeanStdDevFixture;
716
OCL_PERF_TEST_P(MeanStdDevFixture,MeanStdDev,::testing::Combine (OCL_PERF_ENUM (OCL_SIZE_1,OCL_SIZE_2,OCL_SIZE_3),OCL_TEST_TYPES_134))717 OCL_PERF_TEST_P(MeanStdDevFixture, MeanStdDev,
718 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
719 OCL_TEST_TYPES_134))
720 {
721 const Size_MatType_t params = GetParam();
722 const Size srcSize = get<0>(params);
723 const int type = get<1>(params);
724 const double eps = 2e-5;
725
726 checkDeviceMaxMemoryAllocSize(srcSize, type);
727
728 UMat src(srcSize, type);
729 Scalar mean, stddev;
730 declare.in(src, WARMUP_RNG);
731
732 OCL_TEST_CYCLE() cv::meanStdDev(src, mean, stddev);
733
734 double mean0 = mean[0], mean1 = mean[1], mean2 = mean[2], mean3 = mean[3];
735 double stddev0 = stddev[0], stddev1 = stddev[1], stddev2 = stddev[2], stddev3 = stddev[3];
736
737 SANITY_CHECK(mean0, eps, ERROR_RELATIVE);
738 SANITY_CHECK(mean1, eps, ERROR_RELATIVE);
739 SANITY_CHECK(mean2, eps, ERROR_RELATIVE);
740 SANITY_CHECK(mean3, eps, ERROR_RELATIVE);
741 SANITY_CHECK(stddev0, eps, ERROR_RELATIVE);
742 SANITY_CHECK(stddev1, eps, ERROR_RELATIVE);
743 SANITY_CHECK(stddev2, eps, ERROR_RELATIVE);
744 SANITY_CHECK(stddev3, eps, ERROR_RELATIVE);
745 }
746
OCL_PERF_TEST_P(MeanStdDevFixture,MeanStdDevWithMask,::testing::Combine (OCL_PERF_ENUM (OCL_SIZE_1,OCL_SIZE_2,OCL_SIZE_3),OCL_TEST_TYPES_134))747 OCL_PERF_TEST_P(MeanStdDevFixture, MeanStdDevWithMask,
748 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
749 OCL_TEST_TYPES_134))
750 {
751 const Size_MatType_t params = GetParam();
752 const Size srcSize = get<0>(params);
753 const int type = get<1>(params);
754 const double eps = 2e-5;
755
756 checkDeviceMaxMemoryAllocSize(srcSize, type);
757
758 UMat src(srcSize, type), mask(srcSize, CV_8UC1);
759 Scalar mean, stddev;
760 declare.in(src, mask, WARMUP_RNG);
761
762 OCL_TEST_CYCLE() cv::meanStdDev(src, mean, stddev, mask);
763
764 double mean0 = mean[0], mean1 = mean[1], mean2 = mean[2], mean3 = mean[3];
765 double stddev0 = stddev[0], stddev1 = stddev[1], stddev2 = stddev[2], stddev3 = stddev[3];
766
767 SANITY_CHECK(mean0, eps, ERROR_RELATIVE);
768 SANITY_CHECK(mean1, eps, ERROR_RELATIVE);
769 SANITY_CHECK(mean2, eps, ERROR_RELATIVE);
770 SANITY_CHECK(mean3, eps, ERROR_RELATIVE);
771 SANITY_CHECK(stddev0, eps, ERROR_RELATIVE);
772 SANITY_CHECK(stddev1, eps, ERROR_RELATIVE);
773 SANITY_CHECK(stddev2, eps, ERROR_RELATIVE);
774 SANITY_CHECK(stddev3, eps, ERROR_RELATIVE);
775 }
776
777 ///////////// Norm ////////////////////////
778
779 CV_ENUM(NormType, NORM_INF, NORM_L1, NORM_L2)
780
781 typedef tuple<Size, MatType, NormType> NormParams;
782 typedef TestBaseWithParam<NormParams> NormFixture;
783
OCL_PERF_TEST_P(NormFixture,Norm1Arg,::testing::Combine (OCL_PERF_ENUM (OCL_SIZE_1,OCL_SIZE_2,OCL_SIZE_3),OCL_TEST_TYPES_134,NormType::all ()))784 OCL_PERF_TEST_P(NormFixture, Norm1Arg,
785 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
786 OCL_TEST_TYPES_134, NormType::all()))
787 {
788 const NormParams params = GetParam();
789 const Size srcSize = get<0>(params);
790 const int type = get<1>(params);
791 const int normType = get<2>(params);
792
793 checkDeviceMaxMemoryAllocSize(srcSize, type);
794
795 UMat src1(srcSize, type);
796 double res;
797 declare.in(src1, WARMUP_RNG);
798
799 OCL_TEST_CYCLE() res = cv::norm(src1, normType);
800
801 SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);
802 }
803
OCL_PERF_TEST_P(NormFixture,Norm,::testing::Combine (OCL_PERF_ENUM (OCL_SIZE_1,OCL_SIZE_2,OCL_SIZE_3),OCL_TEST_TYPES_134,NormType::all ()))804 OCL_PERF_TEST_P(NormFixture, Norm,
805 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
806 OCL_TEST_TYPES_134, NormType::all()))
807 {
808 const NormParams params = GetParam();
809 const Size srcSize = get<0>(params);
810 const int type = get<1>(params);
811 const int normType = get<2>(params);
812
813 checkDeviceMaxMemoryAllocSize(srcSize, type);
814
815 UMat src1(srcSize, type), src2(srcSize, type);
816 double res;
817 declare.in(src1, src2, WARMUP_RNG);
818
819 OCL_TEST_CYCLE() res = cv::norm(src1, src2, normType);
820
821 SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);
822 }
823
OCL_PERF_TEST_P(NormFixture,NormRel,::testing::Combine (OCL_PERF_ENUM (OCL_SIZE_1,OCL_SIZE_2,OCL_SIZE_3),OCL_TEST_TYPES_134,NormType::all ()))824 OCL_PERF_TEST_P(NormFixture, NormRel,
825 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
826 OCL_TEST_TYPES_134, NormType::all()))
827 {
828 const NormParams params = GetParam();
829 const Size srcSize = get<0>(params);
830 const int type = get<1>(params);
831 const int normType = get<2>(params);
832
833 checkDeviceMaxMemoryAllocSize(srcSize, type);
834
835 UMat src1(srcSize, type), src2(srcSize, type);
836 double res;
837 declare.in(src1, src2, WARMUP_RNG);
838
839 OCL_TEST_CYCLE() res = cv::norm(src1, src2, normType | cv::NORM_RELATIVE);
840
841 SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);
842 }
843
844 ///////////// UMat::dot ////////////////////////
845
846 typedef Size_MatType UMatDotFixture;
847
OCL_PERF_TEST_P(UMatDotFixture,UMatDot,::testing::Combine (OCL_PERF_ENUM (OCL_SIZE_1,OCL_SIZE_2,OCL_SIZE_3),OCL_TEST_TYPES_134))848 OCL_PERF_TEST_P(UMatDotFixture, UMatDot,
849 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
850 OCL_TEST_TYPES_134))
851 {
852 const Size_MatType_t params = GetParam();
853 const Size srcSize = get<0>(params);
854 const int type = get<1>(params);
855 double r = 0.0;
856
857 checkDeviceMaxMemoryAllocSize(srcSize, type);
858
859 UMat src1(srcSize, type), src2(srcSize, type);
860 declare.in(src1, src2, WARMUP_RNG);
861
862 OCL_TEST_CYCLE() r = src1.dot(src2);
863
864 SANITY_CHECK(r, 1e-5, ERROR_RELATIVE);
865 }
866
867 ///////////// Repeat ////////////////////////
868
869 typedef Size_MatType RepeatFixture;
870
OCL_PERF_TEST_P(RepeatFixture,Repeat,::testing::Combine (OCL_PERF_ENUM (OCL_SIZE_1,OCL_SIZE_2,OCL_SIZE_3),OCL_TEST_TYPES))871 OCL_PERF_TEST_P(RepeatFixture, Repeat,
872 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), OCL_TEST_TYPES))
873 {
874 const Size_MatType_t params = GetParam();
875 const Size srcSize = get<0>(params);
876 const int type = get<1>(params), nx = 2, ny = 2;
877
878 checkDeviceMaxMemoryAllocSize(srcSize, type);
879
880 UMat src(srcSize, type), dst(Size(srcSize.width * nx, srcSize.height * ny), type);
881 declare.in(src, WARMUP_RNG).out(dst);
882
883 OCL_TEST_CYCLE() cv::repeat(src, nx, ny, dst);
884
885 SANITY_CHECK(dst);
886 }
887
888 ///////////// Min ////////////////////////
889
890 typedef Size_MatType MinFixture;
891
OCL_PERF_TEST_P(MinFixture,Min,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES))892 OCL_PERF_TEST_P(MinFixture, Min,
893 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
894 {
895 const Size_MatType_t params = GetParam();
896 const Size srcSize = get<0>(params);
897 const int type = get<1>(params);
898
899 checkDeviceMaxMemoryAllocSize(srcSize, type);
900
901 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
902 declare.in(src1, src2, WARMUP_RNG).out(dst);
903
904 OCL_TEST_CYCLE() cv::min(src1, src2, dst);
905
906 SANITY_CHECK(dst);
907 }
908
909 ///////////// Max ////////////////////////
910
911 typedef Size_MatType MaxFixture;
912
OCL_PERF_TEST_P(MaxFixture,Max,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES))913 OCL_PERF_TEST_P(MaxFixture, Max,
914 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
915 {
916 const Size_MatType_t params = GetParam();
917 const Size srcSize = get<0>(params);
918 const int type = get<1>(params);
919
920 checkDeviceMaxMemoryAllocSize(srcSize, type);
921
922 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
923 declare.in(src1, src2, WARMUP_RNG).out(dst);
924
925 OCL_TEST_CYCLE() cv::max(src1, src2, dst);
926
927 SANITY_CHECK(dst);
928 }
929
930 ///////////// InRange ////////////////////////
931
932 typedef Size_MatType InRangeFixture;
933
OCL_PERF_TEST_P(InRangeFixture,InRange,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES))934 OCL_PERF_TEST_P(InRangeFixture, InRange,
935 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
936 {
937 const Size_MatType_t params = GetParam();
938 const Size srcSize = get<0>(params);
939 const int type = get<1>(params);
940
941 checkDeviceMaxMemoryAllocSize(srcSize, type);
942
943 UMat src(srcSize, type), lb(srcSize, type), ub(srcSize, type), dst(srcSize, CV_8UC1);
944 declare.in(src, lb, ub, WARMUP_RNG).out(dst);
945
946 OCL_TEST_CYCLE() cv::inRange(src, lb, ub, dst);
947
948 SANITY_CHECK(dst);
949 }
950
951 ///////////// Normalize ////////////////////////
952
953 CV_ENUM(NormalizeModes, CV_MINMAX, CV_L2, CV_L1, CV_C)
954
955 typedef tuple<Size, MatType, NormalizeModes> NormalizeParams;
956 typedef TestBaseWithParam<NormalizeParams> NormalizeFixture;
957
OCL_PERF_TEST_P(NormalizeFixture,Normalize,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134,NormalizeModes::all ()))958 OCL_PERF_TEST_P(NormalizeFixture, Normalize,
959 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
960 NormalizeModes::all()))
961 {
962 const NormalizeParams params = GetParam();
963 const Size srcSize = get<0>(params);
964 const int type = get<1>(params), mode = get<2>(params);
965
966 checkDeviceMaxMemoryAllocSize(srcSize, type);
967
968 UMat src(srcSize, type), dst(srcSize, type);
969 declare.in(src, WARMUP_RNG).out(dst);
970
971 OCL_TEST_CYCLE() cv::normalize(src, dst, 10, 110, mode);
972
973 SANITY_CHECK(dst, 5e-2);
974 }
975
OCL_PERF_TEST_P(NormalizeFixture,NormalizeWithMask,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_8UC1,CV_32FC1),NormalizeModes::all ()))976 OCL_PERF_TEST_P(NormalizeFixture, NormalizeWithMask,
977 ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1),
978 NormalizeModes::all()))
979 {
980 const NormalizeParams params = GetParam();
981 const Size srcSize = get<0>(params);
982 const int type = get<1>(params), mode = get<2>(params);
983
984 checkDeviceMaxMemoryAllocSize(srcSize, type);
985
986 UMat src(srcSize, type), mask(srcSize, CV_8UC1), dst(srcSize, type);
987 declare.in(src, mask, WARMUP_RNG).out(dst);
988
989 OCL_TEST_CYCLE() cv::normalize(src, dst, 10, 110, mode, -1, mask);
990
991 SANITY_CHECK(dst, 5e-2);
992 }
993
994 ///////////// ConvertScaleAbs ////////////////////////
995
996 typedef Size_MatType ConvertScaleAbsFixture;
997
OCL_PERF_TEST_P(ConvertScaleAbsFixture,ConvertScaleAbs,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES))998 OCL_PERF_TEST_P(ConvertScaleAbsFixture, ConvertScaleAbs,
999 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
1000 {
1001 const Size_MatType_t params = GetParam();
1002 const Size srcSize = get<0>(params);
1003 const int type = get<1>(params), cn = CV_MAT_CN(type);
1004
1005 checkDeviceMaxMemoryAllocSize(srcSize, type);
1006
1007 UMat src(srcSize, type), dst(srcSize, CV_8UC(cn));
1008 declare.in(src, WARMUP_RNG).out(dst);
1009
1010 OCL_TEST_CYCLE() cv::convertScaleAbs(src, dst, 0.5, 2);
1011
1012 SANITY_CHECK(dst, 1); // CV_8U
1013 }
1014
1015 ///////////// PatchNaNs ////////////////////////
1016
1017 typedef Size_MatType PatchNaNsFixture;
1018
OCL_PERF_TEST_P(PatchNaNsFixture,PatchNaNs,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32FC1,CV_32FC4)))1019 OCL_PERF_TEST_P(PatchNaNsFixture, PatchNaNs,
1020 ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
1021 {
1022 const Size_MatType_t params = GetParam();
1023 Size srcSize = get<0>(params);
1024 const int type = get<1>(params), cn = CV_MAT_CN(type);
1025
1026 checkDeviceMaxMemoryAllocSize(srcSize, type);
1027
1028 UMat src(srcSize, type);
1029 declare.in(src, WARMUP_RNG).out(src);
1030
1031 // generating NaNs
1032 {
1033 Mat src_ = src.getMat(ACCESS_RW);
1034 srcSize.width *= cn;
1035 for (int y = 0; y < srcSize.height; ++y)
1036 {
1037 float * const ptr = src_.ptr<float>(y);
1038 for (int x = 0; x < srcSize.width; ++x)
1039 ptr[x] = (x + y) % 2 == 0 ? std::numeric_limits<float>::quiet_NaN() : ptr[x];
1040 }
1041 }
1042
1043 OCL_TEST_CYCLE() cv::patchNaNs(src, 17.7);
1044
1045 SANITY_CHECK(src);
1046 }
1047
1048
1049 ///////////// ScaleAdd ////////////////////////
1050
1051 typedef Size_MatType ScaleAddFixture;
1052
OCL_PERF_TEST_P(ScaleAddFixture,ScaleAdd,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES))1053 OCL_PERF_TEST_P(ScaleAddFixture, ScaleAdd,
1054 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
1055 {
1056 const Size_MatType_t params = GetParam();
1057 const Size srcSize = get<0>(params);
1058 const int type = get<1>(params);
1059
1060 checkDeviceMaxMemoryAllocSize(srcSize, type);
1061
1062 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
1063 declare.in(src1, src2, WARMUP_RNG).out(dst);
1064
1065 OCL_TEST_CYCLE() cv::scaleAdd(src1, 0.6, src2, dst);
1066
1067 SANITY_CHECK(dst, 1e-6);
1068 }
1069
1070 ///////////// Transform ////////////////////////
1071
1072 typedef Size_MatType TransformFixture;
1073
OCL_PERF_TEST_P(TransformFixture,Transform,::testing::Combine (OCL_TEST_SIZES,::testing::Values (CV_8UC3,CV_8SC3,CV_16UC3,CV_16SC3,CV_32SC3,CV_32FC3,CV_64FC3)))1074 OCL_PERF_TEST_P(TransformFixture, Transform,
1075 ::testing::Combine(OCL_TEST_SIZES,
1076 ::testing::Values(CV_8UC3, CV_8SC3, CV_16UC3, CV_16SC3, CV_32SC3, CV_32FC3, CV_64FC3)))
1077 {
1078 const Size_MatType_t params = GetParam();
1079 const Size srcSize = get<0>(params);
1080 const int type = get<1>(params);
1081
1082 checkDeviceMaxMemoryAllocSize(srcSize, type);
1083
1084 const float transform[] = { 0.5f, 0.f, 0.86602540378f, 128,
1085 0.f, 1.f, 0.f, -64,
1086 0.86602540378f, 0.f, 0.5f, 32,};
1087 Mat mtx(Size(4, 3), CV_32FC1, (void*)transform);
1088
1089 UMat src(srcSize, type), dst(srcSize, type);
1090 randu(src, 0, 30);
1091 declare.in(src).out(dst);
1092
1093 OCL_TEST_CYCLE() cv::transform(src, dst, mtx);
1094
1095 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
1096 }
1097
1098 ///////////// PSNR ////////////////////////
1099
1100 typedef Size_MatType PSNRFixture;
1101
OCL_PERF_TEST_P(PSNRFixture,PSNR,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_8UC1,CV_8UC4)))1102 OCL_PERF_TEST_P(PSNRFixture, PSNR,
1103 ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_8UC4)))
1104 {
1105 const Size_MatType_t params = GetParam();
1106 const Size srcSize = get<0>(params);
1107 const int type = get<1>(params);
1108
1109 checkDeviceMaxMemoryAllocSize(srcSize, type);
1110
1111 double psnr = 0;
1112 UMat src1(srcSize, type), src2(srcSize, type);
1113 declare.in(src1, src2, WARMUP_RNG);
1114
1115 OCL_TEST_CYCLE() psnr = cv::PSNR(src1, src2);
1116
1117 SANITY_CHECK(psnr, 1e-4, ERROR_RELATIVE);
1118 }
1119
1120 ///////////// Reduce ////////////////////////
1121
1122 CV_ENUM(ReduceMinMaxOp, CV_REDUCE_MIN, CV_REDUCE_MAX)
1123
1124 typedef tuple<Size, std::pair<MatType, MatType>, int, ReduceMinMaxOp> ReduceMinMaxParams;
1125 typedef TestBaseWithParam<ReduceMinMaxParams> ReduceMinMaxFixture;
1126
1127 OCL_PERF_TEST_P(ReduceMinMaxFixture, Reduce,
1128 ::testing::Combine(OCL_TEST_SIZES,
1129 OCL_PERF_ENUM(std::make_pair<MatType, MatType>(CV_8UC1, CV_8UC1),
1130 std::make_pair<MatType, MatType>(CV_32FC4, CV_32FC4)),
1131 OCL_PERF_ENUM(0, 1),
1132 ReduceMinMaxOp::all()))
1133 {
1134 const ReduceMinMaxParams params = GetParam();
1135 const std::pair<MatType, MatType> types = get<1>(params);
1136 const int stype = types.first, dtype = types.second,
1137 dim = get<2>(params), op = get<3>(params);
1138 const Size srcSize = get<0>(params),
1139 dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height);
1140 const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 1e-5;
1141
1142 checkDeviceMaxMemoryAllocSize(srcSize, stype);
1143 checkDeviceMaxMemoryAllocSize(srcSize, dtype);
1144
1145 UMat src(srcSize, stype), dst(dstSize, dtype);
1146 declare.in(src, WARMUP_RNG).out(dst);
1147
1148 OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype);
1149
1150 SANITY_CHECK(dst, eps);
1151 }
1152
1153 CV_ENUM(ReduceAccOp, CV_REDUCE_SUM, CV_REDUCE_AVG)
1154
1155 typedef tuple<Size, std::pair<MatType, MatType>, int, ReduceAccOp> ReduceAccParams;
1156 typedef TestBaseWithParam<ReduceAccParams> ReduceAccFixture;
1157
1158 OCL_PERF_TEST_P(ReduceAccFixture, Reduce,
1159 ::testing::Combine(OCL_TEST_SIZES,
1160 OCL_PERF_ENUM(std::make_pair<MatType, MatType>(CV_8UC4, CV_32SC4),
1161 std::make_pair<MatType, MatType>(CV_32FC1, CV_32FC1)),
1162 OCL_PERF_ENUM(0, 1),
1163 ReduceAccOp::all()))
1164 {
1165 const ReduceAccParams params = GetParam();
1166 const std::pair<MatType, MatType> types = get<1>(params);
1167 const int stype = types.first, dtype = types.second,
1168 dim = get<2>(params), op = get<3>(params);
1169 const Size srcSize = get<0>(params),
1170 dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height);
1171 const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 3e-4;
1172
1173 checkDeviceMaxMemoryAllocSize(srcSize, stype);
1174 checkDeviceMaxMemoryAllocSize(srcSize, dtype);
1175
1176 UMat src(srcSize, stype), dst(dstSize, dtype);
1177 declare.in(src, WARMUP_RNG).out(dst);
1178
1179 OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype);
1180
1181 SANITY_CHECK(dst, eps);
1182 }
1183
1184 } } // namespace opencv_test::ocl
1185
1186 #endif // HAVE_OPENCL
1187