Merge pull request #5242 from apavlenko:fix_releasing_temp_umat

pull/5265/head
Vadim Pisarevsky 10 years ago
commit a78da45fec
  1. 36
      modules/core/src/ocl.cpp
  2. 5
      modules/core/test/test_umat.cpp

@ -4571,17 +4571,13 @@ public:
}
else
{
// CL_MEM_USE_HOST_PTR (nothing is required) and OTHER cases
if (u->flags & UMatData::USER_ALLOCATED)
{
cl_int retval = 0;
void* data = clEnqueueMapBuffer(q, (cl_mem)u->handle, CL_TRUE,
(CL_MAP_READ | CL_MAP_WRITE),
0, u->size, 0, 0, 0, &retval);
CV_OclDbgAssert(retval == CL_SUCCESS);
CV_OclDbgAssert(clEnqueueUnmapMemObject(q, (cl_mem)u->handle, data, 0, 0, 0) == CL_SUCCESS);
CV_OclDbgAssert(clFinish(q) == CL_SUCCESS);
}
cl_int retval = 0;
void* data = clEnqueueMapBuffer(q, (cl_mem)u->handle, CL_TRUE,
(CL_MAP_READ | CL_MAP_WRITE),
0, u->size, 0, 0, 0, &retval);
CV_OclDbgAssert(retval == CL_SUCCESS);
CV_OclDbgAssert(clEnqueueUnmapMemObject(q, (cl_mem)u->handle, data, 0, 0, 0) == CL_SUCCESS);
CV_OclDbgAssert(clFinish(q) == CL_SUCCESS);
}
}
u->markHostCopyObsolete(false);
@ -4686,8 +4682,6 @@ public:
cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr();
// FIXIT Workaround for UMat synchronization issue
// if( u->refcount == 0 )
{
if( !u->copyOnMap() )
{
@ -4720,11 +4714,6 @@ public:
return;
}
#endif
if (!u->hostCopyObsolete()) // FIXIT Workaround for UMat synchronization issue
{
CV_Assert(u->data);
return;
}
cl_int retval = 0;
u->data = (uchar*)clEnqueueMapBuffer(q, (cl_mem)u->handle, CL_TRUE,
@ -4771,10 +4760,6 @@ public:
UMatDataAutoLock autolock(u);
// FIXIT Workaround for UMat synchronization issue
if(u->refcount > 0)
return;
cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr();
cl_int retval = 0;
if( !u->copyOnMap() && u->deviceMemMapped() )
@ -4800,7 +4785,8 @@ public:
u->allocatorFlags_ &= ~svm::OPENCL_SVM_BUFFER_MAP;
}
}
u->data = 0;
if (u->refcount == 0)
u->data = 0;
u->markDeviceCopyObsolete(false);
u->markHostCopyObsolete(true);
return;
@ -4813,7 +4799,9 @@ public:
// required for multithreaded applications (see stitching test)
CV_OclDbgAssert(clFinish(q) == CL_SUCCESS);
}
u->data = 0;
if (u->refcount == 0)
u->data = 0;
}
else if( u->copyOnMap() && u->deviceCopyObsolete() )
{

@ -1102,8 +1102,9 @@ TEST(UMat, map_unmap_counting)
Mat m(Size(10, 10), CV_8UC1);
UMat um = m.getUMat(ACCESS_RW);
{
Mat d = um.getMat(ACCESS_RW);
d.release();
Mat d1 = um.getMat(ACCESS_RW);
Mat d2 = um.getMat(ACCESS_RW);
d1.release();
}
void* h = NULL;
EXPECT_NO_THROW(h = um.handle(ACCESS_RW));

Loading…
Cancel
Save