Skip to content

Commit 534645a

Browse files
committed
ocl: workaround option to disable usage of buffer "Rect" operations
1 parent 1bc1f3d commit 534645a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

modules/core/src/ocl.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ struct DummyImpl
151151
#define CV_OCL_DBG_CHECK_(expr, check_result) expr; (void)check_result
152152
#define CV_OCL_DBG_CHECK(expr) do { cl_int __cl_result = (expr); CV_OCL_CHECK_RESULT(__cl_result, #expr); } while (0)
153153

154+
static const bool CV_OPENCL_DISABLE_BUFFER_RECT_OPERATIONS = false;
155+
154156
#else // HAVE_OPENCL
155157

156158
#ifndef _DEBUG
@@ -225,6 +227,15 @@ static const bool CV_OPENCL_CACHE_CLEANUP = utils::getConfigurationParameterBool
225227
static const bool CV_OPENCL_VALIDATE_BINARY_PROGRAMS_VALUE = utils::getConfigurationParameterBool("OPENCV_OPENCL_VALIDATE_BINARY_PROGRAMS", false);
226228
#endif
227229

230+
// Option to disable calls clEnqueueReadBufferRect / clEnqueueWriteBufferRect / clEnqueueCopyBufferRect
231+
static const bool CV_OPENCL_DISABLE_BUFFER_RECT_OPERATIONS = utils::getConfigurationParameterBool("OPENCV_OPENCL_DISABLE_BUFFER_RECT_OPERATIONS",
232+
#ifdef __APPLE__
233+
true
234+
#else
235+
false
236+
#endif
237+
);
238+
228239
#endif // HAVE_OPENCL
229240

230241
struct UMat2D
@@ -5206,8 +5217,7 @@ class OpenCLAllocator : public MatAllocator
52065217
CV_OCL_CHECK(clEnqueueReadBuffer(q, (cl_mem)u->handle, CL_TRUE,
52075218
srcrawofs, total, alignedPtr.getAlignedPtr(), 0, 0, 0));
52085219
}
5209-
#ifdef __APPLE__
5210-
else
5220+
else if (CV_OPENCL_DISABLE_BUFFER_RECT_OPERATIONS)
52115221
{
52125222
const size_t padding = CV_OPENCL_DATA_PTR_ALIGNMENT;
52135223
size_t new_srcrawofs = srcrawofs & ~(padding-1);
@@ -5224,7 +5234,6 @@ class OpenCLAllocator : public MatAllocator
52245234
for( size_t i = 0; i < new_sz[1]; i++ )
52255235
memcpy( (uchar*)dstptr + i*new_dststep[0], ptr + i*new_srcstep[0] + membuf_ofs, new_sz[0]);
52265236
}
5227-
#else
52285237
else
52295238
{
52305239
AlignedDataPtr2D<false, true> alignedPtr((uchar*)dstptr, new_sz[1], new_sz[0], new_dststep[0], CV_OPENCL_DATA_PTR_ALIGNMENT);
@@ -5236,7 +5245,6 @@ class OpenCLAllocator : public MatAllocator
52365245
new_dststep[0], 0,
52375246
ptr, 0, 0, 0));
52385247
}
5239-
#endif
52405248
}
52415249
}
52425250

@@ -5343,8 +5351,7 @@ class OpenCLAllocator : public MatAllocator
53435351
CV_OCL_CHECK(clEnqueueWriteBuffer(q, (cl_mem)u->handle, CL_TRUE,
53445352
dstrawofs, total, alignedPtr.getAlignedPtr(), 0, 0, 0));
53455353
}
5346-
#ifdef __APPLE__
5347-
else
5354+
else if (CV_OPENCL_DISABLE_BUFFER_RECT_OPERATIONS)
53485355
{
53495356
const size_t padding = CV_OPENCL_DATA_PTR_ALIGNMENT;
53505357
size_t new_dstrawofs = dstrawofs & ~(padding-1);
@@ -5366,7 +5373,6 @@ class OpenCLAllocator : public MatAllocator
53665373
CV_OCL_CHECK(clEnqueueWriteBuffer(q, (cl_mem)u->handle, CL_TRUE,
53675374
new_dstrawofs, total, ptr, 0, 0, 0));
53685375
}
5369-
#else
53705376
else
53715377
{
53725378
AlignedDataPtr2D<true, false> alignedPtr((uchar*)srcptr, new_sz[1], new_sz[0], new_srcstep[0], CV_OPENCL_DATA_PTR_ALIGNMENT);
@@ -5378,7 +5384,6 @@ class OpenCLAllocator : public MatAllocator
53785384
new_srcstep[0], 0,
53795385
ptr, 0, 0, 0));
53805386
}
5381-
#endif
53825387
}
53835388
u->markHostCopyObsolete(true);
53845389
#ifdef HAVE_OPENCL_SVM
@@ -5520,8 +5525,7 @@ class OpenCLAllocator : public MatAllocator
55205525
CV_OCL_CHECK(retval = clEnqueueCopyBuffer(q, (cl_mem)src->handle, (cl_mem)dst->handle,
55215526
srcrawofs, dstrawofs, total, 0, 0, 0));
55225527
}
5523-
#ifdef __APPLE__
5524-
else
5528+
else if (CV_OPENCL_DISABLE_BUFFER_RECT_OPERATIONS)
55255529
{
55265530
const size_t padding = CV_OPENCL_DATA_PTR_ALIGNMENT;
55275531
size_t new_srcrawofs = srcrawofs & ~(padding-1);
@@ -5554,7 +5558,6 @@ class OpenCLAllocator : public MatAllocator
55545558
CV_OCL_CHECK(clEnqueueWriteBuffer(q, (cl_mem)dst->handle, CL_TRUE,
55555559
new_dstrawofs, dst_total, dstptr, 0, 0, 0));
55565560
}
5557-
#else
55585561
else
55595562
{
55605563
CV_OCL_CHECK(retval = clEnqueueCopyBufferRect(q, (cl_mem)src->handle, (cl_mem)dst->handle,
@@ -5563,7 +5566,6 @@ class OpenCLAllocator : public MatAllocator
55635566
new_dststep[0], 0,
55645567
0, 0, 0));
55655568
}
5566-
#endif
55675569
}
55685570
if (retval == CL_SUCCESS)
55695571
{

0 commit comments

Comments
 (0)