perf_umat.cpp 1.6 KB
Newer Older
1 2 3 4 5 6 7
// 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"

8 9 10
namespace opencv_test
{
using namespace perf;
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
using namespace ::cvtest::ocl;


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<Size, bool, int> > 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<char>(0, 0));
    }

    delete[] (unsigned char*)pData_allocated;

    SANITY_CHECK_NOTHING();
}
63 64

} // namespace