perf_umat.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "perf_precomp.hpp"
  5. #include "opencv2/ts/ocl_perf.hpp"
  6. namespace opencv_test
  7. {
  8. using namespace perf;
  9. using namespace ::cvtest::ocl;
  10. struct OpenCLState
  11. {
  12. OpenCLState(bool useOpenCL)
  13. {
  14. isOpenCL_enabled = cv::ocl::useOpenCL();
  15. cv::ocl::setUseOpenCL(useOpenCL);
  16. }
  17. ~OpenCLState()
  18. {
  19. cv::ocl::setUseOpenCL(isOpenCL_enabled);
  20. }
  21. private:
  22. bool isOpenCL_enabled;
  23. };
  24. typedef TestBaseWithParam< tuple<Size, bool, int> > UMatTest;
  25. OCL_PERF_TEST_P(UMatTest, CustomPtr, Combine(Values(sz1080p, sz2160p), Bool(), ::testing::Values(4, 64, 4096)))
  26. {
  27. OpenCLState s(get<1>(GetParam()));
  28. int type = CV_8UC1;
  29. cv::Size size = get<0>(GetParam());
  30. size_t align_base = 4096;
  31. const int align_offset = get<2>(GetParam());
  32. void* pData_allocated = new unsigned char [size.area() * CV_ELEM_SIZE(type) + (align_base + align_offset)];
  33. void* pData = (char*)alignPtr(pData_allocated, (int)align_base) + align_offset;
  34. size_t step = size.width * CV_ELEM_SIZE(type);
  35. OCL_TEST_CYCLE()
  36. {
  37. Mat m = Mat(size, type, pData, step);
  38. m.setTo(cv::Scalar::all(2));
  39. UMat u = m.getUMat(ACCESS_RW);
  40. cv::add(u, cv::Scalar::all(2), u);
  41. cv::add(u, cv::Scalar::all(3), u);
  42. Mat d = u.getMat(ACCESS_READ);
  43. ASSERT_EQ(7, d.at<char>(0, 0));
  44. }
  45. delete[] (unsigned char*)pData_allocated;
  46. SANITY_CHECK_NOTHING();
  47. }
  48. } // namespace