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