perf_bufferpool.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
  6. #include "../perf_precomp.hpp"
  7. #include "opencv2/ts/ocl_perf.hpp"
  8. #ifdef HAVE_OPENCL
  9. namespace opencv_test {
  10. namespace ocl {
  11. struct BufferPoolState
  12. {
  13. BufferPoolController* controller_;
  14. size_t oldMaxReservedSize_;
  15. BufferPoolState(BufferPoolController* c, bool enable)
  16. : controller_(c)
  17. {
  18. if (!cv::ocl::useOpenCL())
  19. {
  20. throw ::perf::TestBase::PerfSkipTestException();
  21. }
  22. oldMaxReservedSize_ = c->getMaxReservedSize();
  23. if (oldMaxReservedSize_ == (size_t)-1)
  24. {
  25. throw ::perf::TestBase::PerfSkipTestException();
  26. }
  27. if (!enable)
  28. {
  29. c->setMaxReservedSize(0);
  30. }
  31. else
  32. {
  33. c->freeAllReservedBuffers();
  34. }
  35. }
  36. ~BufferPoolState()
  37. {
  38. controller_->setMaxReservedSize(oldMaxReservedSize_);
  39. }
  40. };
  41. typedef TestBaseWithParam<bool> BufferPoolFixture;
  42. OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatCreation100, Bool())
  43. {
  44. BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam());
  45. Size sz(1920, 1080);
  46. OCL_TEST_CYCLE()
  47. {
  48. for (int i = 0; i < 100; i++)
  49. {
  50. UMat u(sz, CV_8UC1);
  51. }
  52. }
  53. SANITY_CHECK_NOTHING();
  54. }
  55. OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatCountNonZero100, Bool())
  56. {
  57. BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam());
  58. Size sz(1920, 1080);
  59. OCL_TEST_CYCLE()
  60. {
  61. for (int i = 0; i < 100; i++)
  62. {
  63. UMat u(sz, CV_8UC1);
  64. countNonZero(u);
  65. }
  66. }
  67. SANITY_CHECK_NOTHING();
  68. }
  69. OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatCanny10, Bool())
  70. {
  71. BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam());
  72. Size sz(1920, 1080);
  73. int aperture = 3;
  74. bool useL2 = false;
  75. double thresh_low = 100;
  76. double thresh_high = 120;
  77. OCL_TEST_CYCLE()
  78. {
  79. for (int i = 0; i < 10; i++)
  80. {
  81. UMat src(sz, CV_8UC1);
  82. UMat dst;
  83. Canny(src, dst, thresh_low, thresh_high, aperture, useL2);
  84. dst.getMat(ACCESS_READ); // complete async operations
  85. }
  86. }
  87. SANITY_CHECK_NOTHING();
  88. }
  89. OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatIntegral10, Bool())
  90. {
  91. BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam());
  92. Size sz(1920, 1080);
  93. OCL_TEST_CYCLE()
  94. {
  95. for (int i = 0; i < 10; i++)
  96. {
  97. UMat src(sz, CV_32FC1);
  98. UMat dst;
  99. integral(src, dst);
  100. dst.getMat(ACCESS_READ); // complete async operations
  101. }
  102. }
  103. SANITY_CHECK_NOTHING();
  104. }
  105. } } // namespace opencv_test::ocl
  106. #endif // HAVE_OPENCL