From 4ecc0232195c067a71f4336d2af0f9898c6162f3 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 2 Sep 2015 20:20:07 +0300 Subject: [PATCH] UMat: add perf test for custom ptr --- modules/core/perf/perf_umat.cpp | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 modules/core/perf/perf_umat.cpp diff --git a/modules/core/perf/perf_umat.cpp b/modules/core/perf/perf_umat.cpp new file mode 100644 index 000000000..ddeaa7abc --- /dev/null +++ b/modules/core/perf/perf_umat.cpp @@ -0,0 +1,68 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "perf_precomp.hpp" +#include "opencv2/ts/ocl_perf.hpp" + +using namespace std; +using namespace cv; +using namespace ::perf; +using namespace ::cvtest::ocl; +using namespace ::testing; +using std::tr1::tuple; +using std::tr1::get; + +namespace { + +struct OpenCLState +{ + OpenCLState(bool useOpenCL) + { + isOpenCL_enabled = cv::ocl::useOpenCL(); + cv::ocl::setUseOpenCL(useOpenCL); + } + + ~OpenCLState() + { + cv::ocl::setUseOpenCL(isOpenCL_enabled); + } + +private: + bool isOpenCL_enabled; +}; + +typedef TestBaseWithParam< tuple > UMatTest; + +OCL_PERF_TEST_P(UMatTest, CustomPtr, Combine(Values(sz1080p, sz2160p), Bool(), ::testing::Values(4, 64, 4096))) +{ + OpenCLState s(get<1>(GetParam())); + + int type = CV_8UC1; + cv::Size size = get<0>(GetParam()); + size_t align_base = 4096; + const int align_offset = get<2>(GetParam()); + + void* pData_allocated = new unsigned char [size.area() * CV_ELEM_SIZE(type) + (align_base + align_offset)]; + void* pData = (char*)alignPtr(pData_allocated, (int)align_base) + align_offset; + size_t step = size.width * CV_ELEM_SIZE(type); + + OCL_TEST_CYCLE() + { + Mat m = Mat(size, type, pData, step); + m.setTo(cv::Scalar::all(2)); + + UMat u = m.getUMat(ACCESS_RW); + cv::add(u, cv::Scalar::all(2), u); + cv::add(u, cv::Scalar::all(3), u); + + Mat d = u.getMat(ACCESS_READ); + ASSERT_EQ(7, d.at(0, 0)); + } + + delete[] (unsigned char*)pData_allocated; + + SANITY_CHECK_NOTHING(); +} + +} // namespace cvtest