1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
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.
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.
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.
42 #include "perf_precomp.hpp"
43 #include "opencv2/ts/ocl_perf.hpp"
50 ///////////// Lut ////////////////////////
52 typedef Size_MatType LUTFixture;
54 OCL_PERF_TEST_P(LUTFixture, LUT,
55 ::testing::Combine(OCL_TEST_SIZES,
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);
62 checkDeviceMaxMemoryAllocSize(srcSize, type);
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);
68 declare.in(src, lut, WARMUP_RNG).out(dst);
70 OCL_TEST_CYCLE() cv::LUT(src, lut, dst);
75 ///////////// Exp ////////////////////////
77 typedef Size_MatType ExpFixture;
79 OCL_PERF_TEST_P(ExpFixture, Exp, ::testing::Combine(
80 OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
82 const Size_MatType_t params = GetParam();
83 const Size srcSize = get<0>(params);
84 const int type = get<1>(params);
86 checkDeviceMaxMemoryAllocSize(srcSize, type);
88 UMat src(srcSize, type), dst(srcSize, type);
89 declare.in(src).out(dst);
92 OCL_TEST_CYCLE() cv::exp(src, dst);
94 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
97 ///////////// Log ////////////////////////
99 typedef Size_MatType LogFixture;
101 OCL_PERF_TEST_P(LogFixture, Log, ::testing::Combine(
102 OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
104 const Size_MatType_t params = GetParam();
105 const Size srcSize = get<0>(params);
106 const int type = get<1>(params);
108 checkDeviceMaxMemoryAllocSize(srcSize, type);
110 UMat src(srcSize, type), dst(srcSize, type);
111 randu(src, 1, 10000);
112 declare.in(src).out(dst);
114 OCL_TEST_CYCLE() cv::log(src, dst);
116 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
119 ///////////// Add ////////////////////////
121 typedef Size_MatType AddFixture;
123 OCL_PERF_TEST_P(AddFixture, Add,
124 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
126 const Size srcSize = GET_PARAM(0);
127 const int type = GET_PARAM(1);
129 checkDeviceMaxMemoryAllocSize(srcSize, type);
131 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
132 declare.in(src1, src2, WARMUP_RNG).out(dst);
134 OCL_TEST_CYCLE() cv::add(src1, src2, dst);
139 ///////////// Subtract ////////////////////////
141 typedef Size_MatType SubtractFixture;
143 OCL_PERF_TEST_P(SubtractFixture, Subtract,
144 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
146 const Size_MatType_t params = GetParam();
147 const Size srcSize = get<0>(params);
148 const int type = get<1>(params);
150 checkDeviceMaxMemoryAllocSize(srcSize, type);
152 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
153 declare.in(src1, src2, WARMUP_RNG).out(dst);
155 OCL_TEST_CYCLE() cv::subtract(src1, src2, dst);
160 ///////////// Mul ////////////////////////
162 typedef Size_MatType MulFixture;
164 OCL_PERF_TEST_P(MulFixture, Multiply, ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
166 const Size_MatType_t params = GetParam();
167 const Size srcSize = get<0>(params);
168 const int type = get<1>(params);
170 checkDeviceMaxMemoryAllocSize(srcSize, type);
172 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
173 declare.in(src1, src2, WARMUP_RNG).out(dst);
175 OCL_TEST_CYCLE() cv::multiply(src1, src2, dst);
180 ///////////// Div ////////////////////////
182 typedef Size_MatType DivFixture;
184 OCL_PERF_TEST_P(DivFixture, Divide,
185 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
187 const Size_MatType_t params = GetParam();
188 const Size srcSize = get<0>(params);
189 const int type = get<1>(params);
191 checkDeviceMaxMemoryAllocSize(srcSize, type);
193 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
194 declare.in(src1, src2, WARMUP_RNG).out(dst);
196 OCL_TEST_CYCLE() cv::divide(src1, src2, dst);
198 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
201 ///////////// Absdiff ////////////////////////
203 typedef Size_MatType AbsDiffFixture;
205 OCL_PERF_TEST_P(AbsDiffFixture, Absdiff,
206 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
208 const Size_MatType_t params = GetParam();
209 const Size srcSize = get<0>(params);
210 const int type = get<1>(params);
212 checkDeviceMaxMemoryAllocSize(srcSize, type);
214 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
215 declare.in(src1, src2, WARMUP_RNG).in(dst);
217 OCL_TEST_CYCLE() cv::absdiff(src1, src2, dst);
222 ///////////// CartToPolar ////////////////////////
224 typedef Size_MatType CartToPolarFixture;
226 OCL_PERF_TEST_P(CartToPolarFixture, CartToPolar, ::testing::Combine(
227 OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
229 const Size_MatType_t params = GetParam();
230 const Size srcSize = get<0>(params);
231 const int type = get<1>(params);
233 checkDeviceMaxMemoryAllocSize(srcSize, type);
235 UMat src1(srcSize, type), src2(srcSize, type),
236 dst1(srcSize, type), dst2(srcSize, type);
237 declare.in(src1, src2, WARMUP_RNG).out(dst1, dst2);
239 OCL_TEST_CYCLE() cv::cartToPolar(src1, src2, dst1, dst2);
241 SANITY_CHECK(dst1, 8e-3);
242 SANITY_CHECK(dst2, 8e-3);
245 ///////////// PolarToCart ////////////////////////
247 typedef Size_MatType PolarToCartFixture;
249 OCL_PERF_TEST_P(PolarToCartFixture, PolarToCart, ::testing::Combine(
250 OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
252 const Size_MatType_t params = GetParam();
253 const Size srcSize = get<0>(params);
254 const int type = get<1>(params);
256 checkDeviceMaxMemoryAllocSize(srcSize, type);
258 UMat src1(srcSize, type), src2(srcSize, type),
259 dst1(srcSize, type), dst2(srcSize, type);
260 declare.in(src1, src2, WARMUP_RNG).out(dst1, dst2);
262 OCL_TEST_CYCLE() cv::polarToCart(src1, src2, dst1, dst2);
264 SANITY_CHECK(dst1, 5e-5);
265 SANITY_CHECK(dst2, 5e-5);
268 ///////////// Magnitude ////////////////////////
270 typedef Size_MatType MagnitudeFixture;
272 OCL_PERF_TEST_P(MagnitudeFixture, Magnitude, ::testing::Combine(
273 OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
275 const Size_MatType_t params = GetParam();
276 const Size srcSize = get<0>(params);
277 const int type = get<1>(params);
279 checkDeviceMaxMemoryAllocSize(srcSize, type);
281 UMat src1(srcSize, type), src2(srcSize, type),
283 declare.in(src1, src2, WARMUP_RNG).out(dst);
285 OCL_TEST_CYCLE() cv::magnitude(src1, src2, dst);
287 SANITY_CHECK(dst, 1e-6);
290 ///////////// Transpose ////////////////////////
292 typedef Size_MatType TransposeFixture;
294 OCL_PERF_TEST_P(TransposeFixture, Transpose, ::testing::Combine(
295 OCL_TEST_SIZES, OCL_TEST_TYPES_134))
297 const Size_MatType_t params = GetParam();
298 const Size srcSize = get<0>(params);
299 const int type = get<1>(params);
301 checkDeviceMaxMemoryAllocSize(srcSize, type);
303 UMat src(srcSize, type), dst(srcSize, type);
304 declare.in(src, WARMUP_RNG).out(dst);
306 OCL_TEST_CYCLE() cv::transpose(src, dst);
311 ///////////// Flip ////////////////////////
315 FLIP_BOTH = 0, FLIP_ROWS, FLIP_COLS
318 CV_ENUM(FlipType, FLIP_BOTH, FLIP_ROWS, FLIP_COLS)
320 typedef std::tr1::tuple<Size, MatType, FlipType> FlipParams;
321 typedef TestBaseWithParam<FlipParams> FlipFixture;
323 OCL_PERF_TEST_P(FlipFixture, Flip,
324 ::testing::Combine(OCL_TEST_SIZES,
325 OCL_TEST_TYPES, FlipType::all()))
327 const FlipParams params = GetParam();
328 const Size srcSize = get<0>(params);
329 const int type = get<1>(params);
330 const int flipType = get<2>(params);
332 checkDeviceMaxMemoryAllocSize(srcSize, type);
334 UMat src(srcSize, type), dst(srcSize, type);
335 declare.in(src, WARMUP_RNG).out(dst);
337 OCL_TEST_CYCLE() cv::flip(src, dst, flipType - 1);
342 ///////////// minMaxLoc ////////////////////////
344 typedef Size_MatType MinMaxLocFixture;
346 OCL_PERF_TEST_P(MinMaxLocFixture, MinMaxLoc,
347 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
349 const Size_MatType_t params = GetParam();
350 const Size srcSize = get<0>(params);
351 const int type = get<1>(params);
352 bool onecn = CV_MAT_CN(type) == 1;
354 checkDeviceMaxMemoryAllocSize(srcSize, type);
356 UMat src(srcSize, type);;
357 declare.in(src, WARMUP_RNG);
359 double min_val = 0.0, max_val = 0.0;
360 Point min_loc, max_loc;
362 OCL_TEST_CYCLE() cv::minMaxLoc(src, &min_val, &max_val, onecn ? &min_loc : NULL,
363 onecn ? &max_loc : NULL);
365 ASSERT_GE(max_val, min_val);
366 SANITY_CHECK(min_val);
367 SANITY_CHECK(max_val);
369 int min_loc_x = min_loc.x, min_loc_y = min_loc.y, max_loc_x = max_loc.x,
370 max_loc_y = max_loc.y;
371 SANITY_CHECK(min_loc_x);
372 SANITY_CHECK(min_loc_y);
373 SANITY_CHECK(max_loc_x);
374 SANITY_CHECK(max_loc_y);
377 ///////////// Sum ////////////////////////
379 typedef Size_MatType SumFixture;
381 OCL_PERF_TEST_P(SumFixture, Sum,
382 ::testing::Combine(OCL_TEST_SIZES,
385 const Size_MatType_t params = GetParam();
386 const Size srcSize = get<0>(params);
387 const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
389 checkDeviceMaxMemoryAllocSize(srcSize, type);
391 UMat src(srcSize, type);
396 OCL_TEST_CYCLE() result = cv::sum(src);
399 SANITY_CHECK(result, 1e-6, ERROR_RELATIVE);
401 SANITY_CHECK(result);
404 ///////////// countNonZero ////////////////////////
406 typedef Size_MatType CountNonZeroFixture;
408 OCL_PERF_TEST_P(CountNonZeroFixture, CountNonZero,
409 ::testing::Combine(OCL_TEST_SIZES,
410 OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
412 const Size_MatType_t params = GetParam();
413 const Size srcSize = get<0>(params);
414 const int type = get<1>(params);
416 checkDeviceMaxMemoryAllocSize(srcSize, type);
418 UMat src(srcSize, type);
423 OCL_TEST_CYCLE() result = cv::countNonZero(src);
425 SANITY_CHECK(result);
428 ///////////// Phase ////////////////////////
430 typedef Size_MatType PhaseFixture;
432 OCL_PERF_TEST_P(PhaseFixture, Phase, ::testing::Combine(
433 OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
435 const Size_MatType_t params = GetParam();
436 const Size srcSize = get<0>(params);
437 const int type = get<1>(params);
439 checkDeviceMaxMemoryAllocSize(srcSize, type);
441 UMat src1(srcSize, type), src2(srcSize, type),
443 declare.in(src1, src2, WARMUP_RNG).out(dst);
445 OCL_TEST_CYCLE() cv::phase(src1, src2, dst, 1);
447 SANITY_CHECK(dst, 1e-2);
450 ///////////// bitwise_and ////////////////////////
452 typedef Size_MatType BitwiseAndFixture;
454 OCL_PERF_TEST_P(BitwiseAndFixture, Bitwise_and,
455 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
457 const Size_MatType_t params = GetParam();
458 const Size srcSize = get<0>(params);
459 const int type = get<1>(params);
461 checkDeviceMaxMemoryAllocSize(srcSize, type);
463 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
464 declare.in(src1, src2, WARMUP_RNG).out(dst);
466 OCL_TEST_CYCLE() cv::bitwise_and(src1, src2, dst);
471 ///////////// bitwise_xor ////////////////////////
473 typedef Size_MatType BitwiseXorFixture;
475 OCL_PERF_TEST_P(BitwiseXorFixture, Bitwise_xor,
476 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
478 const Size_MatType_t params = GetParam();
479 const Size srcSize = get<0>(params);
480 const int type = get<1>(params);
482 checkDeviceMaxMemoryAllocSize(srcSize, type);
484 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
485 declare.in(src1, src2, WARMUP_RNG).out(dst);
487 OCL_TEST_CYCLE() cv::bitwise_xor(src1, src2, dst);
492 ///////////// bitwise_or ////////////////////////
494 typedef Size_MatType BitwiseOrFixture;
496 OCL_PERF_TEST_P(BitwiseOrFixture, Bitwise_or,
497 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
499 const Size_MatType_t params = GetParam();
500 const Size srcSize = get<0>(params);
501 const int type = get<1>(params);
503 checkDeviceMaxMemoryAllocSize(srcSize, type);
505 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
506 declare.in(src1, src2, WARMUP_RNG).out(dst);
508 OCL_TEST_CYCLE() cv::bitwise_or(src1, src2, dst);
513 ///////////// bitwise_not ////////////////////////
515 typedef Size_MatType BitwiseNotFixture;
517 OCL_PERF_TEST_P(BitwiseNotFixture, Bitwise_not,
518 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
520 const Size_MatType_t params = GetParam();
521 const Size srcSize = get<0>(params);
522 const int type = get<1>(params);
524 checkDeviceMaxMemoryAllocSize(srcSize, type);
526 UMat src(srcSize, type), dst(srcSize, type);
527 declare.in(src, WARMUP_RNG).out(dst);
529 OCL_TEST_CYCLE() cv::bitwise_not(src, dst);
534 ///////////// compare ////////////////////////
536 CV_ENUM(CmpCode, CMP_LT, CMP_LE, CMP_EQ, CMP_NE, CMP_GE, CMP_GT)
538 typedef std::tr1::tuple<Size, MatType, CmpCode> CompareParams;
539 typedef TestBaseWithParam<CompareParams> CompareFixture;
541 OCL_PERF_TEST_P(CompareFixture, Compare,
542 ::testing::Combine(OCL_TEST_SIZES,
543 OCL_TEST_TYPES_134, CmpCode::all()))
545 const CompareParams params = GetParam();
546 const Size srcSize = get<0>(params);
547 const int type = get<1>(params);
548 const int cmpCode = get<2>(params);
550 checkDeviceMaxMemoryAllocSize(srcSize, type);
552 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, CV_8UC(CV_MAT_CN(type)));
553 declare.in(src1, src2, WARMUP_RNG).out(dst);
555 OCL_TEST_CYCLE() cv::compare(src1, src2, dst, cmpCode);
560 OCL_PERF_TEST_P(CompareFixture, CompareScalar,
561 ::testing::Combine(OCL_TEST_SIZES,
562 OCL_TEST_TYPES_134, CmpCode::all()))
564 const CompareParams params = GetParam();
565 const Size srcSize = get<0>(params);
566 const int type = get<1>(params);
567 const int cmpCode = get<2>(params);
569 checkDeviceMaxMemoryAllocSize(srcSize, type);
571 UMat src1(srcSize, type), dst(srcSize, CV_8UC(CV_MAT_CN(type)));
572 declare.in(src1, WARMUP_RNG).out(dst);
574 OCL_TEST_CYCLE() cv::compare(src1, 32, dst, cmpCode);
579 ///////////// pow ////////////////////////
581 typedef Size_MatType PowFixture;
583 OCL_PERF_TEST_P(PowFixture, Pow, ::testing::Combine(
584 OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
586 const Size_MatType_t params = GetParam();
587 const Size srcSize = get<0>(params);
588 const int type = get<1>(params);
590 checkDeviceMaxMemoryAllocSize(srcSize, type);
592 UMat src(srcSize, type), dst(srcSize, type);
593 randu(src, -100, 100);
594 declare.in(src).out(dst);
596 OCL_TEST_CYCLE() cv::pow(src, -2.0, dst);
598 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
601 ///////////// AddWeighted////////////////////////
603 typedef Size_MatType AddWeightedFixture;
605 OCL_PERF_TEST_P(AddWeightedFixture, AddWeighted,
606 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
608 const Size_MatType_t params = GetParam();
609 const Size srcSize = get<0>(params);
610 const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
612 checkDeviceMaxMemoryAllocSize(srcSize, type);
614 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
615 declare.in(src1, src2, WARMUP_RNG).out(dst);
616 double alpha = 2.0, beta = 1.0, gama = 3.0;
618 OCL_TEST_CYCLE() cv::addWeighted(src1, alpha, src2, beta, gama, dst);
621 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
626 ///////////// Sqrt ///////////////////////
628 typedef Size_MatType SqrtFixture;
630 OCL_PERF_TEST_P(SqrtFixture, Sqrt, ::testing::Combine(
631 OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
633 const Size_MatType_t params = GetParam();
634 const Size srcSize = get<0>(params);
635 const int type = get<1>(params);
637 checkDeviceMaxMemoryAllocSize(srcSize, type);
639 UMat src(srcSize, type), dst(srcSize, type);
641 declare.in(src).out(dst);
643 OCL_TEST_CYCLE() cv::sqrt(src, dst);
645 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
648 ///////////// SetIdentity ////////////////////////
650 typedef Size_MatType SetIdentityFixture;
652 OCL_PERF_TEST_P(SetIdentityFixture, SetIdentity,
653 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
655 const Size_MatType_t params = GetParam();
656 const Size srcSize = get<0>(params);
657 const int type = get<1>(params);
659 checkDeviceMaxMemoryAllocSize(srcSize, type);
661 UMat dst(srcSize, type);
664 OCL_TEST_CYCLE() cv::setIdentity(dst, cv::Scalar::all(181));
669 ///////////// MeanStdDev ////////////////////////
671 typedef Size_MatType MeanStdDevFixture;
673 OCL_PERF_TEST_P(MeanStdDevFixture, MeanStdDev,
674 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
677 const Size_MatType_t params = GetParam();
678 const Size srcSize = get<0>(params);
679 const int type = get<1>(params);
680 const double eps = 2e-5;
682 checkDeviceMaxMemoryAllocSize(srcSize, type);
684 UMat src(srcSize, type);
686 declare.in(src, WARMUP_RNG);
688 OCL_TEST_CYCLE() cv::meanStdDev(src, mean, stddev);
690 double mean0 = mean[0], mean1 = mean[1], mean2 = mean[2], mean3 = mean[3];
691 double stddev0 = stddev[0], stddev1 = stddev[1], stddev2 = stddev[2], stddev3 = stddev[3];
693 SANITY_CHECK(mean0, eps, ERROR_RELATIVE);
694 SANITY_CHECK(mean1, eps, ERROR_RELATIVE);
695 SANITY_CHECK(mean2, eps, ERROR_RELATIVE);
696 SANITY_CHECK(mean3, eps, ERROR_RELATIVE);
697 SANITY_CHECK(stddev0, eps, ERROR_RELATIVE);
698 SANITY_CHECK(stddev1, eps, ERROR_RELATIVE);
699 SANITY_CHECK(stddev2, eps, ERROR_RELATIVE);
700 SANITY_CHECK(stddev3, eps, ERROR_RELATIVE);
703 ///////////// Norm ////////////////////////
705 CV_ENUM(NormType, NORM_INF, NORM_L1, NORM_L2)
707 typedef std::tr1::tuple<Size, MatType, NormType> NormParams;
708 typedef TestBaseWithParam<NormParams> NormFixture;
710 OCL_PERF_TEST_P(NormFixture, Norm,
711 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
712 OCL_TEST_TYPES_134, NormType::all()))
714 const NormParams params = GetParam();
715 const Size srcSize = get<0>(params);
716 const int type = get<1>(params);
717 const int normType = get<2>(params);
719 checkDeviceMaxMemoryAllocSize(srcSize, type);
721 UMat src1(srcSize, type), src2(srcSize, type);
723 declare.in(src1, src2, WARMUP_RNG);
725 OCL_TEST_CYCLE() res = cv::norm(src1, src2, normType);
727 SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);
730 ///////////// UMat::dot ////////////////////////
732 typedef Size_MatType UMatDotFixture;
734 OCL_PERF_TEST_P(UMatDotFixture, UMatDot,
735 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
738 const Size_MatType_t params = GetParam();
739 const Size srcSize = get<0>(params);
740 const int type = get<1>(params);
743 checkDeviceMaxMemoryAllocSize(srcSize, type);
745 UMat src1(srcSize, type), src2(srcSize, type);
746 declare.in(src1, src2, WARMUP_RNG);
748 OCL_TEST_CYCLE() r = src1.dot(src2);
750 SANITY_CHECK(r, 1e-5, ERROR_RELATIVE);
753 ///////////// Repeat ////////////////////////
755 typedef Size_MatType RepeatFixture;
757 OCL_PERF_TEST_P(RepeatFixture, Repeat,
758 ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), OCL_TEST_TYPES))
760 const Size_MatType_t params = GetParam();
761 const Size srcSize = get<0>(params);
762 const int type = get<1>(params), nx = 2, ny = 2;
764 checkDeviceMaxMemoryAllocSize(srcSize, type);
766 UMat src(srcSize, type), dst(Size(srcSize.width * nx, srcSize.height * ny), type);
767 declare.in(src, WARMUP_RNG).out(dst);
769 OCL_TEST_CYCLE() cv::repeat(src, nx, ny, dst);
774 ///////////// Min ////////////////////////
776 typedef Size_MatType MinFixture;
778 OCL_PERF_TEST_P(MinFixture, Min,
779 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
781 const Size_MatType_t params = GetParam();
782 const Size srcSize = get<0>(params);
783 const int type = get<1>(params);
785 checkDeviceMaxMemoryAllocSize(srcSize, type);
787 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
788 declare.in(src1, src2, WARMUP_RNG).out(dst);
790 OCL_TEST_CYCLE() cv::min(src1, src2, dst);
795 ///////////// Max ////////////////////////
797 typedef Size_MatType MaxFixture;
799 OCL_PERF_TEST_P(MaxFixture, Max,
800 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
802 const Size_MatType_t params = GetParam();
803 const Size srcSize = get<0>(params);
804 const int type = get<1>(params);
806 checkDeviceMaxMemoryAllocSize(srcSize, type);
808 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
809 declare.in(src1, src2, WARMUP_RNG).out(dst);
811 OCL_TEST_CYCLE() cv::max(src1, src2, dst);
816 ///////////// InRange ////////////////////////
818 typedef Size_MatType InRangeFixture;
820 OCL_PERF_TEST_P(InRangeFixture, InRange,
821 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
823 const Size_MatType_t params = GetParam();
824 const Size srcSize = get<0>(params);
825 const int type = get<1>(params);
827 checkDeviceMaxMemoryAllocSize(srcSize, type);
829 UMat src(srcSize, type), lb(srcSize, type), ub(srcSize, type), dst(srcSize, CV_8UC1);
830 declare.in(src, lb, ub, WARMUP_RNG).out(dst);
832 OCL_TEST_CYCLE() cv::inRange(src, lb, ub, dst);
837 ///////////// Normalize ////////////////////////
839 CV_ENUM(NormalizeModes, CV_MINMAX, CV_L2, CV_L1, CV_C)
841 typedef tuple<Size, MatType, NormalizeModes> NormalizeParams;
842 typedef TestBaseWithParam<NormalizeParams> NormalizeFixture;
844 OCL_PERF_TEST_P(NormalizeFixture, Normalize,
845 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
846 NormalizeModes::all()))
848 const NormalizeParams params = GetParam();
849 const Size srcSize = get<0>(params);
850 const int type = get<1>(params), mode = get<2>(params);
852 checkDeviceMaxMemoryAllocSize(srcSize, type);
854 UMat src(srcSize, type), dst(srcSize, type);
855 declare.in(src, WARMUP_RNG).out(dst);
857 OCL_TEST_CYCLE() cv::normalize(src, dst, 10, 110, mode);
859 SANITY_CHECK(dst, 5e-2);
862 ///////////// ConvertScaleAbs ////////////////////////
864 typedef Size_MatType ConvertScaleAbsFixture;
866 OCL_PERF_TEST_P(ConvertScaleAbsFixture, ConvertScaleAbs,
867 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
869 const Size_MatType_t params = GetParam();
870 const Size srcSize = get<0>(params);
871 const int type = get<1>(params), cn = CV_MAT_CN(type);
873 checkDeviceMaxMemoryAllocSize(srcSize, type);
875 UMat src(srcSize, type), dst(srcSize, CV_8UC(cn));
876 declare.in(src, WARMUP_RNG).out(dst);
878 OCL_TEST_CYCLE() cv::convertScaleAbs(src, dst, 0.5, 2);
883 ///////////// PatchNaNs ////////////////////////
885 typedef Size_MatType PatchNaNsFixture;
887 OCL_PERF_TEST_P(PatchNaNsFixture, PatchNaNs,
888 ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
890 const Size_MatType_t params = GetParam();
891 Size srcSize = get<0>(params);
892 const int type = get<1>(params), cn = CV_MAT_CN(type);
894 checkDeviceMaxMemoryAllocSize(srcSize, type);
896 UMat src(srcSize, type);
897 declare.in(src, WARMUP_RNG).out(src);
901 Mat src_ = src.getMat(ACCESS_RW);
903 for (int y = 0; y < srcSize.height; ++y)
905 float * const ptr = src_.ptr<float>(y);
906 for (int x = 0; x < srcSize.width; ++x)
907 ptr[x] = (x + y) % 2 == 0 ? std::numeric_limits<float>::quiet_NaN() : ptr[x];
911 OCL_TEST_CYCLE() cv::patchNaNs(src, 17.7);
917 ///////////// ScaleAdd ////////////////////////
919 typedef Size_MatType ScaleAddFixture;
921 OCL_PERF_TEST_P(ScaleAddFixture, ScaleAdd,
922 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
924 const Size_MatType_t params = GetParam();
925 const Size srcSize = get<0>(params);
926 const int type = get<1>(params);
928 checkDeviceMaxMemoryAllocSize(srcSize, type);
930 UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
931 declare.in(src1, src2, WARMUP_RNG).out(dst);
933 OCL_TEST_CYCLE() cv::scaleAdd(src1, 0.6, src2, dst);
935 SANITY_CHECK(dst, 1e-6);
938 ///////////// PSNR ////////////////////////
940 typedef Size_MatType PSNRFixture;
942 OCL_PERF_TEST_P(PSNRFixture, PSNR,
943 ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_8UC4)))
945 const Size_MatType_t params = GetParam();
946 const Size srcSize = get<0>(params);
947 const int type = get<1>(params);
949 checkDeviceMaxMemoryAllocSize(srcSize, type);
952 UMat src1(srcSize, type), src2(srcSize, type);
953 declare.in(src1, src2, WARMUP_RNG);
955 OCL_TEST_CYCLE() psnr = cv::PSNR(src1, src2);
957 SANITY_CHECK(psnr, 1e-4, ERROR_RELATIVE);
960 ///////////// Reduce ////////////////////////
962 CV_ENUM(ReduceMinMaxOp, CV_REDUCE_MIN, CV_REDUCE_MAX)
964 typedef tuple<Size, std::pair<MatType, MatType>, int, ReduceMinMaxOp> ReduceMinMaxParams;
965 typedef TestBaseWithParam<ReduceMinMaxParams> ReduceMinMaxFixture;
967 OCL_PERF_TEST_P(ReduceMinMaxFixture, Reduce,
968 ::testing::Combine(OCL_TEST_SIZES,
969 OCL_PERF_ENUM(std::make_pair<MatType, MatType>(CV_8UC1, CV_8UC1),
970 std::make_pair<MatType, MatType>(CV_32FC4, CV_32FC4)),
972 ReduceMinMaxOp::all()))
974 const ReduceMinMaxParams params = GetParam();
975 const std::pair<MatType, MatType> types = get<1>(params);
976 const int stype = types.first, dtype = types.second,
977 dim = get<2>(params), op = get<3>(params);
978 const Size srcSize = get<0>(params),
979 dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height);
980 const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 1e-5;
982 checkDeviceMaxMemoryAllocSize(srcSize, stype);
983 checkDeviceMaxMemoryAllocSize(srcSize, dtype);
985 UMat src(srcSize, stype), dst(dstSize, dtype);
986 declare.in(src, WARMUP_RNG).out(dst);
988 OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype);
990 SANITY_CHECK(dst, eps);
993 CV_ENUM(ReduceAccOp, CV_REDUCE_SUM, CV_REDUCE_AVG)
995 typedef tuple<Size, std::pair<MatType, MatType>, int, ReduceAccOp> ReduceAccParams;
996 typedef TestBaseWithParam<ReduceAccParams> ReduceAccFixture;
998 OCL_PERF_TEST_P(ReduceAccFixture, Reduce,
999 ::testing::Combine(OCL_TEST_SIZES,
1000 OCL_PERF_ENUM(std::make_pair<MatType, MatType>(CV_8UC4, CV_32SC4),
1001 std::make_pair<MatType, MatType>(CV_32FC1, CV_32FC1)),
1002 OCL_PERF_ENUM(0, 1),
1003 ReduceAccOp::all()))
1005 const ReduceAccParams params = GetParam();
1006 const std::pair<MatType, MatType> types = get<1>(params);
1007 const int stype = types.first, dtype = types.second,
1008 dim = get<2>(params), op = get<3>(params);
1009 const Size srcSize = get<0>(params),
1010 dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height);
1011 const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 3e-4;
1013 checkDeviceMaxMemoryAllocSize(srcSize, stype);
1014 checkDeviceMaxMemoryAllocSize(srcSize, dtype);
1016 UMat src(srcSize, stype), dst(dstSize, dtype);
1017 declare.in(src, WARMUP_RNG).out(dst);
1019 OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype);
1021 SANITY_CHECK(dst, eps);
1024 } } // namespace cvtest::ocl
1026 #endif // HAVE_OPENCL