perf_arithm.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  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. #include "../perf_precomp.hpp"
  42. #include "opencv2/ts/ocl_perf.hpp"
  43. #ifdef HAVE_OPENCL
  44. namespace opencv_test {
  45. namespace ocl {
  46. ///////////// Lut ////////////////////////
  47. typedef Size_MatType LUTFixture;
  48. OCL_PERF_TEST_P(LUTFixture, LUT,
  49. ::testing::Combine(OCL_TEST_SIZES,
  50. OCL_TEST_TYPES))
  51. {
  52. const Size_MatType_t params = GetParam();
  53. const Size srcSize = get<0>(params);
  54. const int type = get<1>(params), cn = CV_MAT_CN(type);
  55. checkDeviceMaxMemoryAllocSize(srcSize, type);
  56. UMat src(srcSize, CV_8UC(cn)), lut(1, 256, type);
  57. int dstType = CV_MAKETYPE(lut.depth(), src.channels());
  58. UMat dst(srcSize, dstType);
  59. declare.in(src, lut, WARMUP_RNG).out(dst);
  60. OCL_TEST_CYCLE() cv::LUT(src, lut, dst);
  61. SANITY_CHECK(dst);
  62. }
  63. ///////////// Exp ////////////////////////
  64. typedef Size_MatType ExpFixture;
  65. OCL_PERF_TEST_P(ExpFixture, Exp, ::testing::Combine(
  66. OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
  67. {
  68. const Size_MatType_t params = GetParam();
  69. const Size srcSize = get<0>(params);
  70. const int type = get<1>(params);
  71. checkDeviceMaxMemoryAllocSize(srcSize, type);
  72. UMat src(srcSize, type), dst(srcSize, type);
  73. declare.in(src).out(dst);
  74. randu(src, 5, 16);
  75. OCL_TEST_CYCLE() cv::exp(src, dst);
  76. if (CV_MAT_DEPTH(type) >= CV_32F)
  77. SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);
  78. else
  79. SANITY_CHECK(dst, 1);
  80. }
  81. ///////////// Log ////////////////////////
  82. typedef Size_MatType LogFixture;
  83. OCL_PERF_TEST_P(LogFixture, Log, ::testing::Combine(
  84. OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
  85. {
  86. const Size_MatType_t params = GetParam();
  87. const Size srcSize = get<0>(params);
  88. const int type = get<1>(params);
  89. checkDeviceMaxMemoryAllocSize(srcSize, type);
  90. UMat src(srcSize, type), dst(srcSize, type);
  91. randu(src, 1, 10000);
  92. declare.in(src).out(dst);
  93. OCL_TEST_CYCLE() cv::log(src, dst);
  94. if (CV_MAT_DEPTH(type) >= CV_32F)
  95. SANITY_CHECK(dst, 2e-4, ERROR_RELATIVE);
  96. else
  97. SANITY_CHECK(dst, 1);
  98. }
  99. ///////////// Add ////////////////////////
  100. typedef Size_MatType AddFixture;
  101. OCL_PERF_TEST_P(AddFixture, Add,
  102. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  103. {
  104. const Size srcSize = GET_PARAM(0);
  105. const int type = GET_PARAM(1);
  106. checkDeviceMaxMemoryAllocSize(srcSize, type);
  107. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  108. declare.in(src1, src2, WARMUP_RNG).out(dst);
  109. OCL_TEST_CYCLE() cv::add(src1, src2, dst);
  110. SANITY_CHECK(dst);
  111. }
  112. ///////////// Subtract ////////////////////////
  113. typedef Size_MatType SubtractFixture;
  114. OCL_PERF_TEST_P(SubtractFixture, Subtract,
  115. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  116. {
  117. const Size_MatType_t params = GetParam();
  118. const Size srcSize = get<0>(params);
  119. const int type = get<1>(params);
  120. checkDeviceMaxMemoryAllocSize(srcSize, type);
  121. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  122. declare.in(src1, src2, WARMUP_RNG).out(dst);
  123. OCL_TEST_CYCLE() cv::subtract(src1, src2, dst);
  124. SANITY_CHECK(dst);
  125. }
  126. ///////////// Mul ////////////////////////
  127. typedef Size_MatType MulFixture;
  128. OCL_PERF_TEST_P(MulFixture, Multiply, ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  129. {
  130. const Size_MatType_t params = GetParam();
  131. const Size srcSize = get<0>(params);
  132. const int type = get<1>(params);
  133. checkDeviceMaxMemoryAllocSize(srcSize, type);
  134. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  135. declare.in(src1, src2, WARMUP_RNG).out(dst);
  136. OCL_TEST_CYCLE() cv::multiply(src1, src2, dst);
  137. SANITY_CHECK(dst);
  138. }
  139. ///////////// Div ////////////////////////
  140. typedef Size_MatType DivFixture;
  141. OCL_PERF_TEST_P(DivFixture, Divide,
  142. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  143. {
  144. const Size_MatType_t params = GetParam();
  145. const Size srcSize = get<0>(params);
  146. const int type = get<1>(params);
  147. checkDeviceMaxMemoryAllocSize(srcSize, type);
  148. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  149. declare.in(src1, src2, WARMUP_RNG).out(dst);
  150. // remove zeros from src2
  151. {
  152. Mat m2 = src2.getMat(ACCESS_RW);
  153. Mat zero_mask = m2 == 0;
  154. Mat fix;
  155. zero_mask.convertTo(fix, type); // 0 or 255
  156. cv::add(m2, fix, m2);
  157. }
  158. OCL_TEST_CYCLE() cv::divide(src1, src2, dst);
  159. if (CV_MAT_DEPTH(type) >= CV_32F)
  160. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  161. else
  162. SANITY_CHECK(dst, 1);
  163. }
  164. ///////////// Absdiff ////////////////////////
  165. typedef Size_MatType AbsDiffFixture;
  166. OCL_PERF_TEST_P(AbsDiffFixture, Absdiff,
  167. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  168. {
  169. const Size_MatType_t params = GetParam();
  170. const Size srcSize = get<0>(params);
  171. const int type = get<1>(params);
  172. checkDeviceMaxMemoryAllocSize(srcSize, type);
  173. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  174. declare.in(src1, src2, WARMUP_RNG).in(dst);
  175. OCL_TEST_CYCLE() cv::absdiff(src1, src2, dst);
  176. SANITY_CHECK(dst);
  177. }
  178. ///////////// CartToPolar ////////////////////////
  179. typedef Size_MatType CartToPolarFixture;
  180. OCL_PERF_TEST_P(CartToPolarFixture, CartToPolar, ::testing::Combine(
  181. OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
  182. {
  183. const Size_MatType_t params = GetParam();
  184. const Size srcSize = get<0>(params);
  185. const int type = get<1>(params);
  186. checkDeviceMaxMemoryAllocSize(srcSize, type);
  187. UMat src1(srcSize, type), src2(srcSize, type),
  188. dst1(srcSize, type), dst2(srcSize, type);
  189. declare.in(src1, src2, WARMUP_RNG).out(dst1, dst2);
  190. OCL_TEST_CYCLE() cv::cartToPolar(src1, src2, dst1, dst2);
  191. SANITY_CHECK(dst1, 8e-3);
  192. SANITY_CHECK(dst2, 8e-3);
  193. }
  194. ///////////// PolarToCart ////////////////////////
  195. typedef Size_MatType PolarToCartFixture;
  196. OCL_PERF_TEST_P(PolarToCartFixture, PolarToCart, ::testing::Combine(
  197. OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
  198. {
  199. const Size_MatType_t params = GetParam();
  200. const Size srcSize = get<0>(params);
  201. const int type = get<1>(params);
  202. checkDeviceMaxMemoryAllocSize(srcSize, type);
  203. UMat src1(srcSize, type), src2(srcSize, type),
  204. dst1(srcSize, type), dst2(srcSize, type);
  205. declare.in(src1, src2, WARMUP_RNG).out(dst1, dst2);
  206. OCL_TEST_CYCLE() cv::polarToCart(src1, src2, dst1, dst2);
  207. SANITY_CHECK(dst1, 5e-5);
  208. SANITY_CHECK(dst2, 5e-5);
  209. }
  210. ///////////// Magnitude ////////////////////////
  211. typedef Size_MatType MagnitudeFixture;
  212. OCL_PERF_TEST_P(MagnitudeFixture, Magnitude, ::testing::Combine(
  213. OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
  214. {
  215. const Size_MatType_t params = GetParam();
  216. const Size srcSize = get<0>(params);
  217. const int type = get<1>(params);
  218. checkDeviceMaxMemoryAllocSize(srcSize, type);
  219. UMat src1(srcSize, type), src2(srcSize, type),
  220. dst(srcSize, type);
  221. declare.in(src1, src2, WARMUP_RNG).out(dst);
  222. OCL_TEST_CYCLE() cv::magnitude(src1, src2, dst);
  223. SANITY_CHECK(dst, 1e-6);
  224. }
  225. ///////////// Transpose ////////////////////////
  226. typedef Size_MatType TransposeFixture;
  227. OCL_PERF_TEST_P(TransposeFixture, Transpose, ::testing::Combine(
  228. OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  229. {
  230. const Size_MatType_t params = GetParam();
  231. const Size srcSize = get<0>(params);
  232. const int type = get<1>(params);
  233. checkDeviceMaxMemoryAllocSize(srcSize, type);
  234. UMat src(srcSize, type), dst(srcSize, type);
  235. declare.in(src, WARMUP_RNG).out(dst);
  236. OCL_TEST_CYCLE() cv::transpose(src, dst);
  237. SANITY_CHECK(dst);
  238. }
  239. OCL_PERF_TEST_P(TransposeFixture, TransposeInplace, ::testing::Combine(
  240. OCL_PERF_ENUM(Size(640, 640), Size(1280, 1280), Size(2160, 2160)), OCL_TEST_TYPES_134))
  241. {
  242. const Size_MatType_t params = GetParam();
  243. const Size srcSize = get<0>(params);
  244. const int type = get<1>(params);
  245. checkDeviceMaxMemoryAllocSize(srcSize, type);
  246. UMat src(srcSize, type);
  247. declare.in(src, WARMUP_RNG).out(src, WARMUP_NONE);
  248. OCL_TEST_CYCLE() cv::transpose(src, src);
  249. SANITY_CHECK_NOTHING();
  250. }
  251. ///////////// Flip ////////////////////////
  252. enum
  253. {
  254. FLIP_BOTH = 0, FLIP_ROWS, FLIP_COLS
  255. };
  256. CV_ENUM(FlipType, FLIP_BOTH, FLIP_ROWS, FLIP_COLS)
  257. typedef tuple<Size, MatType, FlipType> FlipParams;
  258. typedef TestBaseWithParam<FlipParams> FlipFixture;
  259. OCL_PERF_TEST_P(FlipFixture, Flip,
  260. ::testing::Combine(OCL_TEST_SIZES,
  261. OCL_TEST_TYPES, FlipType::all()))
  262. {
  263. const FlipParams params = GetParam();
  264. const Size srcSize = get<0>(params);
  265. const int type = get<1>(params);
  266. const int flipType = get<2>(params);
  267. checkDeviceMaxMemoryAllocSize(srcSize, type);
  268. UMat src(srcSize, type), dst(srcSize, type);
  269. declare.in(src, WARMUP_RNG).out(dst);
  270. OCL_TEST_CYCLE() cv::flip(src, dst, flipType - 1);
  271. SANITY_CHECK(dst);
  272. }
  273. ///////////// minMaxLoc ////////////////////////
  274. typedef Size_MatType MinMaxLocFixture;
  275. OCL_PERF_TEST_P(MinMaxLocFixture, MinMaxLoc,
  276. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  277. {
  278. const Size_MatType_t params = GetParam();
  279. const Size srcSize = get<0>(params);
  280. const int type = get<1>(params);
  281. bool onecn = CV_MAT_CN(type) == 1;
  282. checkDeviceMaxMemoryAllocSize(srcSize, type);
  283. UMat src(srcSize, type);;
  284. declare.in(src, WARMUP_RNG);
  285. double min_val = 0.0, max_val = 0.0;
  286. Point min_loc, max_loc;
  287. OCL_TEST_CYCLE() cv::minMaxLoc(src, &min_val, &max_val, onecn ? &min_loc : NULL,
  288. onecn ? &max_loc : NULL);
  289. ASSERT_GE(max_val, min_val);
  290. SANITY_CHECK(min_val);
  291. SANITY_CHECK(max_val);
  292. int min_loc_x = min_loc.x, min_loc_y = min_loc.y, max_loc_x = max_loc.x,
  293. max_loc_y = max_loc.y;
  294. SANITY_CHECK(min_loc_x);
  295. SANITY_CHECK(min_loc_y);
  296. SANITY_CHECK(max_loc_x);
  297. SANITY_CHECK(max_loc_y);
  298. }
  299. ///////////// Sum ////////////////////////
  300. typedef Size_MatType SumFixture;
  301. OCL_PERF_TEST_P(SumFixture, Sum,
  302. ::testing::Combine(OCL_TEST_SIZES,
  303. OCL_TEST_TYPES_134))
  304. {
  305. const Size_MatType_t params = GetParam();
  306. const Size srcSize = get<0>(params);
  307. const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
  308. checkDeviceMaxMemoryAllocSize(srcSize, type);
  309. UMat src(srcSize, type);
  310. Scalar result;
  311. randu(src, 0, 60);
  312. declare.in(src);
  313. OCL_TEST_CYCLE() result = cv::sum(src);
  314. if (depth >= CV_32F)
  315. SANITY_CHECK(result, 1e-6, ERROR_RELATIVE);
  316. else
  317. SANITY_CHECK(result);
  318. }
  319. ///////////// countNonZero ////////////////////////
  320. typedef Size_MatType CountNonZeroFixture;
  321. OCL_PERF_TEST_P(CountNonZeroFixture, CountNonZero,
  322. ::testing::Combine(OCL_TEST_SIZES,
  323. OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
  324. {
  325. const Size_MatType_t params = GetParam();
  326. const Size srcSize = get<0>(params);
  327. const int type = get<1>(params);
  328. checkDeviceMaxMemoryAllocSize(srcSize, type);
  329. UMat src(srcSize, type);
  330. int result = 0;
  331. randu(src, 0, 10);
  332. declare.in(src);
  333. OCL_TEST_CYCLE() result = cv::countNonZero(src);
  334. SANITY_CHECK(result);
  335. }
  336. ///////////// Phase ////////////////////////
  337. typedef Size_MatType PhaseFixture;
  338. OCL_PERF_TEST_P(PhaseFixture, Phase, ::testing::Combine(
  339. OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
  340. {
  341. const Size_MatType_t params = GetParam();
  342. const Size srcSize = get<0>(params);
  343. const int type = get<1>(params);
  344. checkDeviceMaxMemoryAllocSize(srcSize, type);
  345. UMat src1(srcSize, type), src2(srcSize, type),
  346. dst(srcSize, type);
  347. declare.in(src1, src2, WARMUP_RNG).out(dst);
  348. OCL_TEST_CYCLE() cv::phase(src1, src2, dst, 1);
  349. SANITY_CHECK(dst, 1e-2);
  350. }
  351. ///////////// bitwise_and ////////////////////////
  352. typedef Size_MatType BitwiseAndFixture;
  353. OCL_PERF_TEST_P(BitwiseAndFixture, Bitwise_and,
  354. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  355. {
  356. const Size_MatType_t params = GetParam();
  357. const Size srcSize = get<0>(params);
  358. const int type = get<1>(params);
  359. checkDeviceMaxMemoryAllocSize(srcSize, type);
  360. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  361. declare.in(src1, src2, WARMUP_RNG).out(dst);
  362. OCL_TEST_CYCLE() cv::bitwise_and(src1, src2, dst);
  363. SANITY_CHECK(dst);
  364. }
  365. ///////////// bitwise_xor ////////////////////////
  366. typedef Size_MatType BitwiseXorFixture;
  367. OCL_PERF_TEST_P(BitwiseXorFixture, Bitwise_xor,
  368. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  369. {
  370. const Size_MatType_t params = GetParam();
  371. const Size srcSize = get<0>(params);
  372. const int type = get<1>(params);
  373. checkDeviceMaxMemoryAllocSize(srcSize, type);
  374. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  375. declare.in(src1, src2, WARMUP_RNG).out(dst);
  376. OCL_TEST_CYCLE() cv::bitwise_xor(src1, src2, dst);
  377. SANITY_CHECK(dst);
  378. }
  379. ///////////// bitwise_or ////////////////////////
  380. typedef Size_MatType BitwiseOrFixture;
  381. OCL_PERF_TEST_P(BitwiseOrFixture, Bitwise_or,
  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. checkDeviceMaxMemoryAllocSize(srcSize, type);
  388. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  389. declare.in(src1, src2, WARMUP_RNG).out(dst);
  390. OCL_TEST_CYCLE() cv::bitwise_or(src1, src2, dst);
  391. SANITY_CHECK(dst);
  392. }
  393. ///////////// bitwise_not ////////////////////////
  394. typedef Size_MatType BitwiseNotFixture;
  395. OCL_PERF_TEST_P(BitwiseNotFixture, Bitwise_not,
  396. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  397. {
  398. const Size_MatType_t params = GetParam();
  399. const Size srcSize = get<0>(params);
  400. const int type = get<1>(params);
  401. checkDeviceMaxMemoryAllocSize(srcSize, type);
  402. UMat src(srcSize, type), dst(srcSize, type);
  403. declare.in(src, WARMUP_RNG).out(dst);
  404. OCL_TEST_CYCLE() cv::bitwise_not(src, dst);
  405. SANITY_CHECK(dst);
  406. }
  407. ///////////// compare ////////////////////////
  408. CV_ENUM(CmpCode, CMP_LT, CMP_LE, CMP_EQ, CMP_NE, CMP_GE, CMP_GT)
  409. typedef tuple<Size, MatType, CmpCode> CompareParams;
  410. typedef TestBaseWithParam<CompareParams> CompareFixture;
  411. OCL_PERF_TEST_P(CompareFixture, Compare,
  412. ::testing::Combine(OCL_TEST_SIZES,
  413. OCL_TEST_TYPES_134, CmpCode::all()))
  414. {
  415. const CompareParams params = GetParam();
  416. const Size srcSize = get<0>(params);
  417. const int type = get<1>(params);
  418. const int cmpCode = get<2>(params);
  419. checkDeviceMaxMemoryAllocSize(srcSize, type);
  420. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, CV_8UC(CV_MAT_CN(type)));
  421. declare.in(src1, src2, WARMUP_RNG).out(dst);
  422. OCL_TEST_CYCLE() cv::compare(src1, src2, dst, cmpCode);
  423. SANITY_CHECK(dst);
  424. }
  425. OCL_PERF_TEST_P(CompareFixture, CompareScalar,
  426. ::testing::Combine(OCL_TEST_SIZES,
  427. OCL_PERF_ENUM((MatType)CV_32FC1), // TODO: OCL_TEST_TYPES_134
  428. CmpCode::all()))
  429. {
  430. const CompareParams params = GetParam();
  431. const Size srcSize = get<0>(params);
  432. const int type = get<1>(params);
  433. const int cmpCode = get<2>(params);
  434. checkDeviceMaxMemoryAllocSize(srcSize, type);
  435. UMat src1(srcSize, type), dst(srcSize, CV_8UC(CV_MAT_CN(type)));
  436. declare.in(src1, WARMUP_RNG).out(dst);
  437. OCL_TEST_CYCLE() cv::compare(src1, 32, dst, cmpCode);
  438. SANITY_CHECK(dst);
  439. }
  440. ///////////// pow ////////////////////////
  441. typedef Size_MatType PowFixture;
  442. OCL_PERF_TEST_P(PowFixture, Pow, ::testing::Combine(
  443. OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
  444. {
  445. const Size_MatType_t params = GetParam();
  446. const Size srcSize = get<0>(params);
  447. const int type = get<1>(params);
  448. checkDeviceMaxMemoryAllocSize(srcSize, type);
  449. UMat src(srcSize, type), dst(srcSize, type);
  450. randu(src, 0, 100);
  451. declare.in(src).out(dst);
  452. OCL_TEST_CYCLE() cv::pow(src, 2.17, dst);
  453. SANITY_CHECK(dst, 1.5e-6, ERROR_RELATIVE);
  454. }
  455. ///////////// AddWeighted////////////////////////
  456. typedef Size_MatType AddWeightedFixture;
  457. OCL_PERF_TEST_P(AddWeightedFixture, AddWeighted,
  458. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
  459. {
  460. const Size_MatType_t params = GetParam();
  461. const Size srcSize = get<0>(params);
  462. const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
  463. checkDeviceMaxMemoryAllocSize(srcSize, type);
  464. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  465. declare.in(src1, src2, WARMUP_RNG).out(dst);
  466. double alpha = 2.0, beta = 1.0, gama = 3.0;
  467. OCL_TEST_CYCLE() cv::addWeighted(src1, alpha, src2, beta, gama, dst);
  468. if (depth >= CV_32F)
  469. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  470. else
  471. SANITY_CHECK(dst);
  472. }
  473. ///////////// Sqrt ///////////////////////
  474. typedef Size_MatType SqrtFixture;
  475. OCL_PERF_TEST_P(SqrtFixture, Sqrt, ::testing::Combine(
  476. OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
  477. {
  478. const Size_MatType_t params = GetParam();
  479. const Size srcSize = get<0>(params);
  480. const int type = get<1>(params);
  481. checkDeviceMaxMemoryAllocSize(srcSize, type);
  482. UMat src(srcSize, type), dst(srcSize, type);
  483. randu(src, 0, 1000);
  484. declare.in(src).out(dst);
  485. OCL_TEST_CYCLE() cv::sqrt(src, dst);
  486. // To square root 32 bit floats we use native_sqrt, which has implementation
  487. // defined accuracy. We know intel devices have accurate native_sqrt, but
  488. // otherwise stick to a relaxed sanity check. For types larger than 32 bits
  489. // we can do the accuracy check for all devices as normal.
  490. if (CV_MAT_DEPTH(type) > CV_32F || !ocl::useOpenCL() ||
  491. ocl::Device::getDefault().isIntel())
  492. SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);
  493. else
  494. SANITY_CHECK(dst, 1);
  495. }
  496. ///////////// SetIdentity ////////////////////////
  497. typedef Size_MatType SetIdentityFixture;
  498. OCL_PERF_TEST_P(SetIdentityFixture, SetIdentity,
  499. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
  500. {
  501. const Size_MatType_t params = GetParam();
  502. const Size srcSize = get<0>(params);
  503. const int type = get<1>(params);
  504. checkDeviceMaxMemoryAllocSize(srcSize, type);
  505. UMat dst(srcSize, type);
  506. declare.out(dst);
  507. OCL_TEST_CYCLE() cv::setIdentity(dst, cv::Scalar::all(181));
  508. SANITY_CHECK(dst);
  509. }
  510. ///////////// MeanStdDev ////////////////////////
  511. typedef Size_MatType MeanStdDevFixture;
  512. OCL_PERF_TEST_P(MeanStdDevFixture, MeanStdDev,
  513. ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
  514. OCL_TEST_TYPES_134))
  515. {
  516. const Size_MatType_t params = GetParam();
  517. const Size srcSize = get<0>(params);
  518. const int type = get<1>(params);
  519. const double eps = 2e-5;
  520. checkDeviceMaxMemoryAllocSize(srcSize, type);
  521. UMat src(srcSize, type);
  522. Scalar mean, stddev;
  523. declare.in(src, WARMUP_RNG);
  524. OCL_TEST_CYCLE() cv::meanStdDev(src, mean, stddev);
  525. double mean0 = mean[0], mean1 = mean[1], mean2 = mean[2], mean3 = mean[3];
  526. double stddev0 = stddev[0], stddev1 = stddev[1], stddev2 = stddev[2], stddev3 = stddev[3];
  527. SANITY_CHECK(mean0, eps, ERROR_RELATIVE);
  528. SANITY_CHECK(mean1, eps, ERROR_RELATIVE);
  529. SANITY_CHECK(mean2, eps, ERROR_RELATIVE);
  530. SANITY_CHECK(mean3, eps, ERROR_RELATIVE);
  531. SANITY_CHECK(stddev0, eps, ERROR_RELATIVE);
  532. SANITY_CHECK(stddev1, eps, ERROR_RELATIVE);
  533. SANITY_CHECK(stddev2, eps, ERROR_RELATIVE);
  534. SANITY_CHECK(stddev3, eps, ERROR_RELATIVE);
  535. }
  536. OCL_PERF_TEST_P(MeanStdDevFixture, MeanStdDevWithMask,
  537. ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
  538. OCL_TEST_TYPES_134))
  539. {
  540. const Size_MatType_t params = GetParam();
  541. const Size srcSize = get<0>(params);
  542. const int type = get<1>(params);
  543. const double eps = 2e-5;
  544. checkDeviceMaxMemoryAllocSize(srcSize, type);
  545. UMat src(srcSize, type), mask(srcSize, CV_8UC1);
  546. Scalar mean, stddev;
  547. declare.in(src, mask, WARMUP_RNG);
  548. OCL_TEST_CYCLE() cv::meanStdDev(src, mean, stddev, mask);
  549. double mean0 = mean[0], mean1 = mean[1], mean2 = mean[2], mean3 = mean[3];
  550. double stddev0 = stddev[0], stddev1 = stddev[1], stddev2 = stddev[2], stddev3 = stddev[3];
  551. SANITY_CHECK(mean0, eps, ERROR_RELATIVE);
  552. SANITY_CHECK(mean1, eps, ERROR_RELATIVE);
  553. SANITY_CHECK(mean2, eps, ERROR_RELATIVE);
  554. SANITY_CHECK(mean3, eps, ERROR_RELATIVE);
  555. SANITY_CHECK(stddev0, eps, ERROR_RELATIVE);
  556. SANITY_CHECK(stddev1, eps, ERROR_RELATIVE);
  557. SANITY_CHECK(stddev2, eps, ERROR_RELATIVE);
  558. SANITY_CHECK(stddev3, eps, ERROR_RELATIVE);
  559. }
  560. ///////////// Norm ////////////////////////
  561. CV_ENUM(NormType, NORM_INF, NORM_L1, NORM_L2)
  562. typedef tuple<Size, MatType, NormType> NormParams;
  563. typedef TestBaseWithParam<NormParams> NormFixture;
  564. OCL_PERF_TEST_P(NormFixture, Norm1Arg,
  565. ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
  566. OCL_TEST_TYPES_134, NormType::all()))
  567. {
  568. const NormParams params = GetParam();
  569. const Size srcSize = get<0>(params);
  570. const int type = get<1>(params);
  571. const int normType = get<2>(params);
  572. checkDeviceMaxMemoryAllocSize(srcSize, type);
  573. UMat src1(srcSize, type);
  574. double res;
  575. declare.in(src1, WARMUP_RNG);
  576. OCL_TEST_CYCLE() res = cv::norm(src1, normType);
  577. SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);
  578. }
  579. OCL_PERF_TEST_P(NormFixture, Norm,
  580. ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
  581. OCL_TEST_TYPES_134, NormType::all()))
  582. {
  583. const NormParams params = GetParam();
  584. const Size srcSize = get<0>(params);
  585. const int type = get<1>(params);
  586. const int normType = get<2>(params);
  587. checkDeviceMaxMemoryAllocSize(srcSize, type);
  588. UMat src1(srcSize, type), src2(srcSize, type);
  589. double res;
  590. declare.in(src1, src2, WARMUP_RNG);
  591. OCL_TEST_CYCLE() res = cv::norm(src1, src2, normType);
  592. SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);
  593. }
  594. OCL_PERF_TEST_P(NormFixture, NormRel,
  595. ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
  596. OCL_TEST_TYPES_134, NormType::all()))
  597. {
  598. const NormParams params = GetParam();
  599. const Size srcSize = get<0>(params);
  600. const int type = get<1>(params);
  601. const int normType = get<2>(params);
  602. checkDeviceMaxMemoryAllocSize(srcSize, type);
  603. UMat src1(srcSize, type), src2(srcSize, type);
  604. double res;
  605. declare.in(src1, src2, WARMUP_RNG);
  606. OCL_TEST_CYCLE() res = cv::norm(src1, src2, normType | cv::NORM_RELATIVE);
  607. SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);
  608. }
  609. ///////////// UMat::dot ////////////////////////
  610. typedef Size_MatType UMatDotFixture;
  611. OCL_PERF_TEST_P(UMatDotFixture, UMatDot,
  612. ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
  613. OCL_TEST_TYPES_134))
  614. {
  615. const Size_MatType_t params = GetParam();
  616. const Size srcSize = get<0>(params);
  617. const int type = get<1>(params);
  618. double r = 0.0;
  619. checkDeviceMaxMemoryAllocSize(srcSize, type);
  620. UMat src1(srcSize, type), src2(srcSize, type);
  621. declare.in(src1, src2, WARMUP_RNG);
  622. OCL_TEST_CYCLE() r = src1.dot(src2);
  623. SANITY_CHECK(r, 1e-5, ERROR_RELATIVE);
  624. }
  625. ///////////// Repeat ////////////////////////
  626. typedef Size_MatType RepeatFixture;
  627. OCL_PERF_TEST_P(RepeatFixture, Repeat,
  628. ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), OCL_TEST_TYPES))
  629. {
  630. const Size_MatType_t params = GetParam();
  631. const Size srcSize = get<0>(params);
  632. const int type = get<1>(params), nx = 2, ny = 2;
  633. checkDeviceMaxMemoryAllocSize(srcSize, type);
  634. UMat src(srcSize, type), dst(Size(srcSize.width * nx, srcSize.height * ny), type);
  635. declare.in(src, WARMUP_RNG).out(dst);
  636. OCL_TEST_CYCLE() cv::repeat(src, nx, ny, dst);
  637. SANITY_CHECK(dst);
  638. }
  639. ///////////// Min ////////////////////////
  640. typedef Size_MatType MinFixture;
  641. OCL_PERF_TEST_P(MinFixture, Min,
  642. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
  643. {
  644. const Size_MatType_t params = GetParam();
  645. const Size srcSize = get<0>(params);
  646. const int type = get<1>(params);
  647. checkDeviceMaxMemoryAllocSize(srcSize, type);
  648. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  649. declare.in(src1, src2, WARMUP_RNG).out(dst);
  650. OCL_TEST_CYCLE() cv::min(src1, src2, dst);
  651. SANITY_CHECK(dst);
  652. }
  653. ///////////// Max ////////////////////////
  654. typedef Size_MatType MaxFixture;
  655. OCL_PERF_TEST_P(MaxFixture, Max,
  656. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
  657. {
  658. const Size_MatType_t params = GetParam();
  659. const Size srcSize = get<0>(params);
  660. const int type = get<1>(params);
  661. checkDeviceMaxMemoryAllocSize(srcSize, type);
  662. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  663. declare.in(src1, src2, WARMUP_RNG).out(dst);
  664. OCL_TEST_CYCLE() cv::max(src1, src2, dst);
  665. SANITY_CHECK(dst);
  666. }
  667. ///////////// InRange ////////////////////////
  668. typedef Size_MatType InRangeFixture;
  669. OCL_PERF_TEST_P(InRangeFixture, InRange,
  670. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
  671. {
  672. const Size_MatType_t params = GetParam();
  673. const Size srcSize = get<0>(params);
  674. const int type = get<1>(params);
  675. checkDeviceMaxMemoryAllocSize(srcSize, type);
  676. UMat src(srcSize, type), lb(srcSize, type), ub(srcSize, type), dst(srcSize, CV_8UC1);
  677. declare.in(src, lb, ub, WARMUP_RNG).out(dst);
  678. OCL_TEST_CYCLE() cv::inRange(src, lb, ub, dst);
  679. SANITY_CHECK(dst);
  680. }
  681. ///////////// Normalize ////////////////////////
  682. CV_ENUM(NormalizeModes, CV_MINMAX, CV_L2, CV_L1, CV_C)
  683. typedef tuple<Size, MatType, NormalizeModes> NormalizeParams;
  684. typedef TestBaseWithParam<NormalizeParams> NormalizeFixture;
  685. OCL_PERF_TEST_P(NormalizeFixture, Normalize,
  686. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
  687. NormalizeModes::all()))
  688. {
  689. const NormalizeParams params = GetParam();
  690. const Size srcSize = get<0>(params);
  691. const int type = get<1>(params), mode = get<2>(params);
  692. checkDeviceMaxMemoryAllocSize(srcSize, type);
  693. UMat src(srcSize, type), dst(srcSize, type);
  694. declare.in(src, WARMUP_RNG).out(dst);
  695. OCL_TEST_CYCLE() cv::normalize(src, dst, 10, 110, mode);
  696. SANITY_CHECK(dst, 5e-2);
  697. }
  698. OCL_PERF_TEST_P(NormalizeFixture, NormalizeWithMask,
  699. ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1),
  700. NormalizeModes::all()))
  701. {
  702. const NormalizeParams params = GetParam();
  703. const Size srcSize = get<0>(params);
  704. const int type = get<1>(params), mode = get<2>(params);
  705. checkDeviceMaxMemoryAllocSize(srcSize, type);
  706. UMat src(srcSize, type), mask(srcSize, CV_8UC1), dst(srcSize, type);
  707. declare.in(src, mask, WARMUP_RNG).out(dst);
  708. OCL_TEST_CYCLE() cv::normalize(src, dst, 10, 110, mode, -1, mask);
  709. SANITY_CHECK(dst, 5e-2);
  710. }
  711. ///////////// ConvertScaleAbs ////////////////////////
  712. typedef Size_MatType ConvertScaleAbsFixture;
  713. OCL_PERF_TEST_P(ConvertScaleAbsFixture, ConvertScaleAbs,
  714. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
  715. {
  716. const Size_MatType_t params = GetParam();
  717. const Size srcSize = get<0>(params);
  718. const int type = get<1>(params), cn = CV_MAT_CN(type);
  719. checkDeviceMaxMemoryAllocSize(srcSize, type);
  720. UMat src(srcSize, type), dst(srcSize, CV_8UC(cn));
  721. declare.in(src, WARMUP_RNG).out(dst);
  722. OCL_TEST_CYCLE() cv::convertScaleAbs(src, dst, 0.5, 2);
  723. SANITY_CHECK(dst, 1); // CV_8U
  724. }
  725. ///////////// PatchNaNs ////////////////////////
  726. typedef Size_MatType PatchNaNsFixture;
  727. OCL_PERF_TEST_P(PatchNaNsFixture, PatchNaNs,
  728. ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
  729. {
  730. const Size_MatType_t params = GetParam();
  731. Size srcSize = get<0>(params);
  732. const int type = get<1>(params), cn = CV_MAT_CN(type);
  733. checkDeviceMaxMemoryAllocSize(srcSize, type);
  734. UMat src(srcSize, type);
  735. declare.in(src, WARMUP_RNG).out(src);
  736. // generating NaNs
  737. {
  738. Mat src_ = src.getMat(ACCESS_RW);
  739. srcSize.width *= cn;
  740. for (int y = 0; y < srcSize.height; ++y)
  741. {
  742. float * const ptr = src_.ptr<float>(y);
  743. for (int x = 0; x < srcSize.width; ++x)
  744. ptr[x] = (x + y) % 2 == 0 ? std::numeric_limits<float>::quiet_NaN() : ptr[x];
  745. }
  746. }
  747. OCL_TEST_CYCLE() cv::patchNaNs(src, 17.7);
  748. SANITY_CHECK(src);
  749. }
  750. ///////////// ScaleAdd ////////////////////////
  751. typedef Size_MatType ScaleAddFixture;
  752. OCL_PERF_TEST_P(ScaleAddFixture, ScaleAdd,
  753. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
  754. {
  755. const Size_MatType_t params = GetParam();
  756. const Size srcSize = get<0>(params);
  757. const int type = get<1>(params);
  758. checkDeviceMaxMemoryAllocSize(srcSize, type);
  759. UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
  760. declare.in(src1, src2, WARMUP_RNG).out(dst);
  761. OCL_TEST_CYCLE() cv::scaleAdd(src1, 0.6, src2, dst);
  762. SANITY_CHECK(dst, 1e-6);
  763. }
  764. ///////////// Transform ////////////////////////
  765. typedef Size_MatType TransformFixture;
  766. OCL_PERF_TEST_P(TransformFixture, Transform,
  767. ::testing::Combine(OCL_TEST_SIZES,
  768. ::testing::Values(CV_8UC3, CV_8SC3, CV_16UC3, CV_16SC3, CV_32SC3, CV_32FC3, CV_64FC3)))
  769. {
  770. const Size_MatType_t params = GetParam();
  771. const Size srcSize = get<0>(params);
  772. const int type = get<1>(params);
  773. checkDeviceMaxMemoryAllocSize(srcSize, type);
  774. const float transform[] = { 0.5f, 0.f, 0.86602540378f, 128,
  775. 0.f, 1.f, 0.f, -64,
  776. 0.86602540378f, 0.f, 0.5f, 32,};
  777. Mat mtx(Size(4, 3), CV_32FC1, (void*)transform);
  778. UMat src(srcSize, type), dst(srcSize, type);
  779. randu(src, 0, 30);
  780. declare.in(src).out(dst);
  781. OCL_TEST_CYCLE() cv::transform(src, dst, mtx);
  782. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  783. }
  784. ///////////// PSNR ////////////////////////
  785. typedef Size_MatType PSNRFixture;
  786. OCL_PERF_TEST_P(PSNRFixture, PSNR,
  787. ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_8UC4)))
  788. {
  789. const Size_MatType_t params = GetParam();
  790. const Size srcSize = get<0>(params);
  791. const int type = get<1>(params);
  792. checkDeviceMaxMemoryAllocSize(srcSize, type);
  793. double psnr = 0;
  794. UMat src1(srcSize, type), src2(srcSize, type);
  795. declare.in(src1, src2, WARMUP_RNG);
  796. OCL_TEST_CYCLE() psnr = cv::PSNR(src1, src2);
  797. SANITY_CHECK(psnr, 1e-4, ERROR_RELATIVE);
  798. }
  799. ///////////// Reduce ////////////////////////
  800. CV_ENUM(ReduceMinMaxOp, CV_REDUCE_MIN, CV_REDUCE_MAX)
  801. typedef tuple<Size, std::pair<MatType, MatType>, int, ReduceMinMaxOp> ReduceMinMaxParams;
  802. typedef TestBaseWithParam<ReduceMinMaxParams> ReduceMinMaxFixture;
  803. OCL_PERF_TEST_P(ReduceMinMaxFixture, Reduce,
  804. ::testing::Combine(OCL_TEST_SIZES,
  805. OCL_PERF_ENUM(std::make_pair<MatType, MatType>(CV_8UC1, CV_8UC1),
  806. std::make_pair<MatType, MatType>(CV_32FC4, CV_32FC4)),
  807. OCL_PERF_ENUM(0, 1),
  808. ReduceMinMaxOp::all()))
  809. {
  810. const ReduceMinMaxParams params = GetParam();
  811. const std::pair<MatType, MatType> types = get<1>(params);
  812. const int stype = types.first, dtype = types.second,
  813. dim = get<2>(params), op = get<3>(params);
  814. const Size srcSize = get<0>(params),
  815. dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height);
  816. const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 1e-5;
  817. checkDeviceMaxMemoryAllocSize(srcSize, stype);
  818. checkDeviceMaxMemoryAllocSize(srcSize, dtype);
  819. UMat src(srcSize, stype), dst(dstSize, dtype);
  820. declare.in(src, WARMUP_RNG).out(dst);
  821. OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype);
  822. SANITY_CHECK(dst, eps);
  823. }
  824. CV_ENUM(ReduceAccOp, CV_REDUCE_SUM, CV_REDUCE_AVG)
  825. typedef tuple<Size, std::pair<MatType, MatType>, int, ReduceAccOp> ReduceAccParams;
  826. typedef TestBaseWithParam<ReduceAccParams> ReduceAccFixture;
  827. OCL_PERF_TEST_P(ReduceAccFixture, Reduce,
  828. ::testing::Combine(OCL_TEST_SIZES,
  829. OCL_PERF_ENUM(std::make_pair<MatType, MatType>(CV_8UC4, CV_32SC4),
  830. std::make_pair<MatType, MatType>(CV_32FC1, CV_32FC1)),
  831. OCL_PERF_ENUM(0, 1),
  832. ReduceAccOp::all()))
  833. {
  834. const ReduceAccParams params = GetParam();
  835. const std::pair<MatType, MatType> types = get<1>(params);
  836. const int stype = types.first, dtype = types.second,
  837. dim = get<2>(params), op = get<3>(params);
  838. const Size srcSize = get<0>(params),
  839. dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height);
  840. const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 3e-4;
  841. checkDeviceMaxMemoryAllocSize(srcSize, stype);
  842. checkDeviceMaxMemoryAllocSize(srcSize, dtype);
  843. UMat src(srcSize, stype), dst(dstSize, dtype);
  844. declare.in(src, WARMUP_RNG).out(dst);
  845. OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype);
  846. SANITY_CHECK(dst, eps);
  847. }
  848. } } // namespace opencv_test::ocl
  849. #endif // HAVE_OPENCL