perf_core.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #include "perf_precomp.hpp"
  43. namespace opencv_test { namespace {
  44. #define ARITHM_MAT_DEPTH Values(CV_8U, CV_16U, CV_32F, CV_64F)
  45. //////////////////////////////////////////////////////////////////////
  46. // Merge
  47. DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, MatCn);
  48. PERF_TEST_P(Sz_Depth_Cn, Merge,
  49. Combine(CUDA_TYPICAL_MAT_SIZES,
  50. ARITHM_MAT_DEPTH,
  51. Values(2, 3, 4)))
  52. {
  53. const cv::Size size = GET_PARAM(0);
  54. const int depth = GET_PARAM(1);
  55. const int channels = GET_PARAM(2);
  56. std::vector<cv::Mat> src(channels);
  57. for (int i = 0; i < channels; ++i)
  58. {
  59. src[i].create(size, depth);
  60. declare.in(src[i], WARMUP_RNG);
  61. }
  62. if (PERF_RUN_CUDA())
  63. {
  64. std::vector<cv::cuda::GpuMat> d_src(channels);
  65. for (int i = 0; i < channels; ++i)
  66. d_src[i].upload(src[i]);
  67. cv::cuda::GpuMat dst;
  68. TEST_CYCLE() cv::cuda::merge(d_src, dst);
  69. CUDA_SANITY_CHECK(dst, 1e-10);
  70. }
  71. else
  72. {
  73. cv::Mat dst;
  74. TEST_CYCLE() cv::merge(src, dst);
  75. CPU_SANITY_CHECK(dst);
  76. }
  77. }
  78. //////////////////////////////////////////////////////////////////////
  79. // Split
  80. PERF_TEST_P(Sz_Depth_Cn, Split,
  81. Combine(CUDA_TYPICAL_MAT_SIZES,
  82. ARITHM_MAT_DEPTH,
  83. Values(2, 3, 4)))
  84. {
  85. const cv::Size size = GET_PARAM(0);
  86. const int depth = GET_PARAM(1);
  87. const int channels = GET_PARAM(2);
  88. cv::Mat src(size, CV_MAKE_TYPE(depth, channels));
  89. declare.in(src, WARMUP_RNG);
  90. if (PERF_RUN_CUDA())
  91. {
  92. const cv::cuda::GpuMat d_src(src);
  93. std::vector<cv::cuda::GpuMat> dst;
  94. TEST_CYCLE() cv::cuda::split(d_src, dst);
  95. const cv::cuda::GpuMat& dst0 = dst[0];
  96. const cv::cuda::GpuMat& dst1 = dst[1];
  97. CUDA_SANITY_CHECK(dst0, 1e-10);
  98. CUDA_SANITY_CHECK(dst1, 1e-10);
  99. }
  100. else
  101. {
  102. std::vector<cv::Mat> dst;
  103. TEST_CYCLE() cv::split(src, dst);
  104. const cv::Mat& dst0 = dst[0];
  105. const cv::Mat& dst1 = dst[1];
  106. CPU_SANITY_CHECK(dst0);
  107. CPU_SANITY_CHECK(dst1);
  108. }
  109. }
  110. //////////////////////////////////////////////////////////////////////
  111. // Transpose
  112. PERF_TEST_P(Sz_Type, Transpose,
  113. Combine(CUDA_TYPICAL_MAT_SIZES,
  114. Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_16SC2, CV_32SC1, CV_32SC2, CV_64FC1)))
  115. {
  116. const cv::Size size = GET_PARAM(0);
  117. const int type = GET_PARAM(1);
  118. cv::Mat src(size, type);
  119. declare.in(src, WARMUP_RNG);
  120. if (PERF_RUN_CUDA())
  121. {
  122. const cv::cuda::GpuMat d_src(src);
  123. cv::cuda::GpuMat dst;
  124. TEST_CYCLE() cv::cuda::transpose(d_src, dst);
  125. CUDA_SANITY_CHECK(dst, 1e-10);
  126. }
  127. else
  128. {
  129. cv::Mat dst;
  130. TEST_CYCLE() cv::transpose(src, dst);
  131. CPU_SANITY_CHECK(dst);
  132. }
  133. }
  134. //////////////////////////////////////////////////////////////////////
  135. // Flip
  136. enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
  137. CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
  138. DEF_PARAM_TEST(Sz_Depth_Cn_Code, cv::Size, MatDepth, MatCn, FlipCode);
  139. PERF_TEST_P(Sz_Depth_Cn_Code, Flip,
  140. Combine(CUDA_TYPICAL_MAT_SIZES,
  141. Values(CV_8U, CV_16U, CV_32F),
  142. CUDA_CHANNELS_1_3_4,
  143. FlipCode::all()))
  144. {
  145. const cv::Size size = GET_PARAM(0);
  146. const int depth = GET_PARAM(1);
  147. const int channels = GET_PARAM(2);
  148. const int flipCode = GET_PARAM(3);
  149. const int type = CV_MAKE_TYPE(depth, channels);
  150. cv::Mat src(size, type);
  151. declare.in(src, WARMUP_RNG);
  152. if (PERF_RUN_CUDA())
  153. {
  154. const cv::cuda::GpuMat d_src(src);
  155. cv::cuda::GpuMat dst;
  156. TEST_CYCLE() cv::cuda::flip(d_src, dst, flipCode);
  157. CUDA_SANITY_CHECK(dst);
  158. }
  159. else
  160. {
  161. cv::Mat dst;
  162. TEST_CYCLE() cv::flip(src, dst, flipCode);
  163. CPU_SANITY_CHECK(dst);
  164. }
  165. }
  166. //////////////////////////////////////////////////////////////////////
  167. // LutOneChannel
  168. PERF_TEST_P(Sz_Type, LutOneChannel,
  169. Combine(CUDA_TYPICAL_MAT_SIZES,
  170. Values(CV_8UC1, CV_8UC3)))
  171. {
  172. const cv::Size size = GET_PARAM(0);
  173. const int type = GET_PARAM(1);
  174. cv::Mat src(size, type);
  175. declare.in(src, WARMUP_RNG);
  176. cv::Mat lut(1, 256, CV_8UC1);
  177. declare.in(lut, WARMUP_RNG);
  178. if (PERF_RUN_CUDA())
  179. {
  180. cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
  181. const cv::cuda::GpuMat d_src(src);
  182. cv::cuda::GpuMat dst;
  183. TEST_CYCLE() lutAlg->transform(d_src, dst);
  184. CUDA_SANITY_CHECK(dst);
  185. }
  186. else
  187. {
  188. cv::Mat dst;
  189. TEST_CYCLE() cv::LUT(src, lut, dst);
  190. CPU_SANITY_CHECK(dst);
  191. }
  192. }
  193. //////////////////////////////////////////////////////////////////////
  194. // LutMultiChannel
  195. PERF_TEST_P(Sz_Type, LutMultiChannel,
  196. Combine(CUDA_TYPICAL_MAT_SIZES,
  197. Values<MatType>(CV_8UC3)))
  198. {
  199. const cv::Size size = GET_PARAM(0);
  200. const int type = GET_PARAM(1);
  201. cv::Mat src(size, type);
  202. declare.in(src, WARMUP_RNG);
  203. cv::Mat lut(1, 256, CV_MAKE_TYPE(CV_8U, src.channels()));
  204. declare.in(lut, WARMUP_RNG);
  205. if (PERF_RUN_CUDA())
  206. {
  207. cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
  208. const cv::cuda::GpuMat d_src(src);
  209. cv::cuda::GpuMat dst;
  210. TEST_CYCLE() lutAlg->transform(d_src, dst);
  211. CUDA_SANITY_CHECK(dst);
  212. }
  213. else
  214. {
  215. cv::Mat dst;
  216. TEST_CYCLE() cv::LUT(src, lut, dst);
  217. CPU_SANITY_CHECK(dst);
  218. }
  219. }
  220. //////////////////////////////////////////////////////////////////////
  221. // CopyMakeBorder
  222. DEF_PARAM_TEST(Sz_Depth_Cn_Border, cv::Size, MatDepth, MatCn, BorderMode);
  223. PERF_TEST_P(Sz_Depth_Cn_Border, CopyMakeBorder,
  224. Combine(CUDA_TYPICAL_MAT_SIZES,
  225. Values(CV_8U, CV_16U, CV_32F),
  226. CUDA_CHANNELS_1_3_4,
  227. ALL_BORDER_MODES))
  228. {
  229. const cv::Size size = GET_PARAM(0);
  230. const int depth = GET_PARAM(1);
  231. const int channels = GET_PARAM(2);
  232. const int borderMode = GET_PARAM(3);
  233. const int type = CV_MAKE_TYPE(depth, channels);
  234. cv::Mat src(size, type);
  235. declare.in(src, WARMUP_RNG);
  236. if (PERF_RUN_CUDA())
  237. {
  238. const cv::cuda::GpuMat d_src(src);
  239. cv::cuda::GpuMat dst;
  240. TEST_CYCLE() cv::cuda::copyMakeBorder(d_src, dst, 5, 5, 5, 5, borderMode);
  241. CUDA_SANITY_CHECK(dst);
  242. }
  243. else
  244. {
  245. cv::Mat dst;
  246. TEST_CYCLE() cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderMode);
  247. CPU_SANITY_CHECK(dst);
  248. }
  249. }
  250. }} // namespace