mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 12:22:51 +08:00
core(ocl): add flag OPENCV_OPENCL_ENABLE_MEM_USE_HOST_PTR
to control CL_MEM_USE_HOST_PTR usage
This commit is contained in:
parent
3cf9185159
commit
eacadf0e73
@ -267,6 +267,9 @@ static const String getBuildExtraOptions()
|
|||||||
return param_buildExtraOptions;
|
return param_buildExtraOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const bool CV_OPENCL_ENABLE_MEM_USE_HOST_PTR = utils::getConfigurationParameterBool("OPENCV_OPENCL_ENABLE_MEM_USE_HOST_PTR", true);
|
||||||
|
static const size_t CV_OPENCL_ALIGNMENT_MEM_USE_HOST_PTR = utils::getConfigurationParameterSizeT("OPENCV_OPENCL_ALIGNMENT_MEM_USE_HOST_PTR", 4);
|
||||||
|
|
||||||
#endif // HAVE_OPENCL
|
#endif // HAVE_OPENCL
|
||||||
|
|
||||||
struct UMat2D
|
struct UMat2D
|
||||||
@ -4675,6 +4678,9 @@ public:
|
|||||||
|
|
||||||
bool allocate(UMatData* u, int accessFlags, UMatUsageFlags usageFlags) const CV_OVERRIDE
|
bool allocate(UMatData* u, int accessFlags, UMatUsageFlags usageFlags) const CV_OVERRIDE
|
||||||
{
|
{
|
||||||
|
#ifndef HAVE_OPENCL
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
if(!u)
|
if(!u)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -4749,8 +4755,12 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
tempUMatFlags = UMatData::TEMP_UMAT;
|
tempUMatFlags = UMatData::TEMP_UMAT;
|
||||||
if (u->origdata == cv::alignPtr(u->origdata, 4) // There are OpenCL runtime issues for less aligned data
|
if (CV_OPENCL_ENABLE_MEM_USE_HOST_PTR
|
||||||
&& !(u->originalUMatData && u->originalUMatData->handle) // Avoid sharing of host memory between OpenCL buffers
|
// There are OpenCL runtime issues for less aligned data
|
||||||
|
&& (CV_OPENCL_ALIGNMENT_MEM_USE_HOST_PTR != 0
|
||||||
|
&& u->origdata == cv::alignPtr(u->origdata, (int)CV_OPENCL_ALIGNMENT_MEM_USE_HOST_PTR))
|
||||||
|
// Avoid sharing of host memory between OpenCL buffers
|
||||||
|
&& !(u->originalUMatData && u->originalUMatData->handle)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
handle = clCreateBuffer(ctx_handle, CL_MEM_USE_HOST_PTR|createFlags,
|
handle = clCreateBuffer(ctx_handle, CL_MEM_USE_HOST_PTR|createFlags,
|
||||||
@ -4780,6 +4790,7 @@ public:
|
|||||||
u->markHostCopyObsolete(true);
|
u->markHostCopyObsolete(true);
|
||||||
opencl_allocator_stats.onAllocate(u->size);
|
opencl_allocator_stats.onAllocate(u->size);
|
||||||
return true;
|
return true;
|
||||||
|
#endif // HAVE_OPENCL
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void sync(UMatData* u) const
|
/*void sync(UMatData* u) const
|
||||||
@ -4908,7 +4919,7 @@ public:
|
|||||||
(CL_MAP_READ | CL_MAP_WRITE),
|
(CL_MAP_READ | CL_MAP_WRITE),
|
||||||
0, u->size, 0, 0, 0, &retval);
|
0, u->size, 0, 0, 0, &retval);
|
||||||
CV_OCL_CHECK_RESULT(retval, cv::format("clEnqueueMapBuffer(handle=%p, sz=%lld) => %p", (void*)u->handle, (long long int)u->size, data).c_str());
|
CV_OCL_CHECK_RESULT(retval, cv::format("clEnqueueMapBuffer(handle=%p, sz=%lld) => %p", (void*)u->handle, (long long int)u->size, data).c_str());
|
||||||
CV_Assert(u->origdata == data);
|
CV_Assert(u->origdata == data && "Details: https://github.com/opencv/opencv/issues/6293");
|
||||||
if (u->originalUMatData)
|
if (u->originalUMatData)
|
||||||
{
|
{
|
||||||
CV_Assert(u->originalUMatData->data == data);
|
CV_Assert(u->originalUMatData->data == data);
|
||||||
|
Loading…
Reference in New Issue
Block a user