Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/core/perf/perf_umat.cpp
16354 views
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
namespace opencv_test
9
{
10
using namespace perf;
11
using namespace ::cvtest::ocl;
12
13
14
struct OpenCLState
15
{
16
OpenCLState(bool useOpenCL)
17
{
18
isOpenCL_enabled = cv::ocl::useOpenCL();
19
cv::ocl::setUseOpenCL(useOpenCL);
20
}
21
22
~OpenCLState()
23
{
24
cv::ocl::setUseOpenCL(isOpenCL_enabled);
25
}
26
27
private:
28
bool isOpenCL_enabled;
29
};
30
31
typedef TestBaseWithParam< tuple<Size, bool, int> > UMatTest;
32
33
OCL_PERF_TEST_P(UMatTest, CustomPtr, Combine(Values(sz1080p, sz2160p), Bool(), ::testing::Values(4, 64, 4096)))
34
{
35
OpenCLState s(get<1>(GetParam()));
36
37
int type = CV_8UC1;
38
cv::Size size = get<0>(GetParam());
39
size_t align_base = 4096;
40
const int align_offset = get<2>(GetParam());
41
42
void* pData_allocated = new unsigned char [size.area() * CV_ELEM_SIZE(type) + (align_base + align_offset)];
43
void* pData = (char*)alignPtr(pData_allocated, (int)align_base) + align_offset;
44
size_t step = size.width * CV_ELEM_SIZE(type);
45
46
OCL_TEST_CYCLE()
47
{
48
Mat m = Mat(size, type, pData, step);
49
m.setTo(cv::Scalar::all(2));
50
51
UMat u = m.getUMat(ACCESS_RW);
52
cv::add(u, cv::Scalar::all(2), u);
53
cv::add(u, cv::Scalar::all(3), u);
54
55
Mat d = u.getMat(ACCESS_READ);
56
ASSERT_EQ(7, d.at<char>(0, 0));
57
}
58
59
delete[] (unsigned char*)pData_allocated;
60
61
SANITY_CHECK_NOTHING();
62
}
63
64
} // namespace
65
66