perf_gpumat.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #ifdef HAVE_CUDA
  44. #include "opencv2/core/cuda.hpp"
  45. #include "opencv2/ts/cuda_perf.hpp"
  46. namespace opencv_test { namespace {
  47. using namespace testing;
  48. using namespace perf;
  49. //////////////////////////////////////////////////////////////////////
  50. // SetTo
  51. PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_SetTo,
  52. Combine(CUDA_TYPICAL_MAT_SIZES,
  53. Values(CV_8U, CV_16U, CV_32F, CV_64F),
  54. CUDA_CHANNELS_1_3_4))
  55. {
  56. const cv::Size size = GET_PARAM(0);
  57. const int depth = GET_PARAM(1);
  58. const int channels = GET_PARAM(2);
  59. const int type = CV_MAKE_TYPE(depth, channels);
  60. const cv::Scalar val(1, 2, 3, 4);
  61. if (PERF_RUN_CUDA())
  62. {
  63. cv::cuda::GpuMat dst(size, type);
  64. TEST_CYCLE() dst.setTo(val);
  65. }
  66. else
  67. {
  68. cv::Mat dst(size, type);
  69. TEST_CYCLE() dst.setTo(val);
  70. }
  71. SANITY_CHECK_NOTHING();
  72. }
  73. //////////////////////////////////////////////////////////////////////
  74. // SetToMasked
  75. PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_SetToMasked,
  76. Combine(CUDA_TYPICAL_MAT_SIZES,
  77. Values(CV_8U, CV_16U, CV_32F, CV_64F),
  78. CUDA_CHANNELS_1_3_4))
  79. {
  80. const cv::Size size = GET_PARAM(0);
  81. const int depth = GET_PARAM(1);
  82. const int channels = GET_PARAM(2);
  83. const int type = CV_MAKE_TYPE(depth, channels);
  84. cv::Mat src(size, type);
  85. cv::Mat mask(size, CV_8UC1);
  86. declare.in(src, mask, WARMUP_RNG);
  87. const cv::Scalar val(1, 2, 3, 4);
  88. if (PERF_RUN_CUDA())
  89. {
  90. cv::cuda::GpuMat dst(src);
  91. const cv::cuda::GpuMat d_mask(mask);
  92. TEST_CYCLE() dst.setTo(val, d_mask);
  93. }
  94. else
  95. {
  96. cv::Mat dst = src;
  97. TEST_CYCLE() dst.setTo(val, mask);
  98. }
  99. SANITY_CHECK_NOTHING();
  100. }
  101. //////////////////////////////////////////////////////////////////////
  102. // CopyToMasked
  103. PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_CopyToMasked,
  104. Combine(CUDA_TYPICAL_MAT_SIZES,
  105. Values(CV_8U, CV_16U, CV_32F, CV_64F),
  106. CUDA_CHANNELS_1_3_4))
  107. {
  108. const cv::Size size = GET_PARAM(0);
  109. const int depth = GET_PARAM(1);
  110. const int channels = GET_PARAM(2);
  111. const int type = CV_MAKE_TYPE(depth, channels);
  112. cv::Mat src(size, type);
  113. cv::Mat mask(size, CV_8UC1);
  114. declare.in(src, mask, WARMUP_RNG);
  115. if (PERF_RUN_CUDA())
  116. {
  117. const cv::cuda::GpuMat d_src(src);
  118. const cv::cuda::GpuMat d_mask(mask);
  119. cv::cuda::GpuMat dst(d_src.size(), d_src.type(), cv::Scalar::all(0));
  120. TEST_CYCLE() d_src.copyTo(dst, d_mask);
  121. }
  122. else
  123. {
  124. cv::Mat dst(src.size(), src.type(), cv::Scalar::all(0));
  125. TEST_CYCLE() src.copyTo(dst, mask);
  126. }
  127. SANITY_CHECK_NOTHING();
  128. }
  129. //////////////////////////////////////////////////////////////////////
  130. // ConvertTo
  131. DEF_PARAM_TEST(Sz_2Depth, cv::Size, MatDepth, MatDepth);
  132. PERF_TEST_P(Sz_2Depth, CUDA_GpuMat_ConvertTo,
  133. Combine(CUDA_TYPICAL_MAT_SIZES,
  134. Values(CV_8U, CV_16U, CV_32F, CV_64F),
  135. Values(CV_8U, CV_16U, CV_32F, CV_64F)))
  136. {
  137. const cv::Size size = GET_PARAM(0);
  138. const int depth1 = GET_PARAM(1);
  139. const int depth2 = GET_PARAM(2);
  140. cv::Mat src(size, depth1);
  141. declare.in(src, WARMUP_RNG);
  142. const double a = 0.5;
  143. const double b = 1.0;
  144. if (PERF_RUN_CUDA())
  145. {
  146. const cv::cuda::GpuMat d_src(src);
  147. cv::cuda::GpuMat dst;
  148. TEST_CYCLE() d_src.convertTo(dst, depth2, a, b);
  149. }
  150. else
  151. {
  152. cv::Mat dst;
  153. TEST_CYCLE() src.convertTo(dst, depth2, a, b);
  154. }
  155. SANITY_CHECK_NOTHING();
  156. }
  157. }} // namespace
  158. #endif