Commit b63a7e66 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #2953 from gongzg:master

parents f773cd9a 2e49ca49
...@@ -360,7 +360,7 @@ struct CV_EXPORTS UMatData ...@@ -360,7 +360,7 @@ struct CV_EXPORTS UMatData
{ {
enum { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2, enum { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2,
DEVICE_COPY_OBSOLETE=4, TEMP_UMAT=8, TEMP_COPIED_UMAT=24, DEVICE_COPY_OBSOLETE=4, TEMP_UMAT=8, TEMP_COPIED_UMAT=24,
USER_ALLOCATED=32 }; USER_ALLOCATED=32, DEVICE_MEM_MAPPED=64};
UMatData(const MatAllocator* allocator); UMatData(const MatAllocator* allocator);
~UMatData(); ~UMatData();
...@@ -370,11 +370,13 @@ struct CV_EXPORTS UMatData ...@@ -370,11 +370,13 @@ struct CV_EXPORTS UMatData
bool hostCopyObsolete() const; bool hostCopyObsolete() const;
bool deviceCopyObsolete() const; bool deviceCopyObsolete() const;
bool deviceMemMapped() const;
bool copyOnMap() const; bool copyOnMap() const;
bool tempUMat() const; bool tempUMat() const;
bool tempCopiedUMat() const; bool tempCopiedUMat() const;
void markHostCopyObsolete(bool flag); void markHostCopyObsolete(bool flag);
void markDeviceCopyObsolete(bool flag); void markDeviceCopyObsolete(bool flag);
void markDeviceMemMapped(bool flag);
const MatAllocator* prevAllocator; const MatAllocator* prevAllocator;
const MatAllocator* currAllocator; const MatAllocator* currAllocator;
......
...@@ -3350,10 +3350,19 @@ size_t UMat::total() const ...@@ -3350,10 +3350,19 @@ size_t UMat::total() const
inline bool UMatData::hostCopyObsolete() const { return (flags & HOST_COPY_OBSOLETE) != 0; } inline bool UMatData::hostCopyObsolete() const { return (flags & HOST_COPY_OBSOLETE) != 0; }
inline bool UMatData::deviceCopyObsolete() const { return (flags & DEVICE_COPY_OBSOLETE) != 0; } inline bool UMatData::deviceCopyObsolete() const { return (flags & DEVICE_COPY_OBSOLETE) != 0; }
inline bool UMatData::deviceMemMapped() const { return (flags & DEVICE_MEM_MAPPED) != 0; }
inline bool UMatData::copyOnMap() const { return (flags & COPY_ON_MAP) != 0; } inline bool UMatData::copyOnMap() const { return (flags & COPY_ON_MAP) != 0; }
inline bool UMatData::tempUMat() const { return (flags & TEMP_UMAT) != 0; } inline bool UMatData::tempUMat() const { return (flags & TEMP_UMAT) != 0; }
inline bool UMatData::tempCopiedUMat() const { return (flags & TEMP_COPIED_UMAT) == TEMP_COPIED_UMAT; } inline bool UMatData::tempCopiedUMat() const { return (flags & TEMP_COPIED_UMAT) == TEMP_COPIED_UMAT; }
inline void UMatData::markDeviceMemMapped(bool flag)
{
if(flag)
flags |= DEVICE_MEM_MAPPED;
else
flags &= ~DEVICE_MEM_MAPPED;
}
inline void UMatData::markHostCopyObsolete(bool flag) inline void UMatData::markHostCopyObsolete(bool flag)
{ {
if(flag) if(flag)
......
...@@ -3738,6 +3738,7 @@ public: ...@@ -3738,6 +3738,7 @@ public:
u->handle = clCreateBuffer(ctx_handle, CL_MEM_COPY_HOST_PTR|CL_MEM_READ_WRITE|createFlags, u->handle = clCreateBuffer(ctx_handle, CL_MEM_COPY_HOST_PTR|CL_MEM_READ_WRITE|createFlags,
u->size, u->origdata, &retval); u->size, u->origdata, &retval);
tempUMatFlags = UMatData::TEMP_COPIED_UMAT; tempUMatFlags = UMatData::TEMP_COPIED_UMAT;
} }
if(!u->handle || retval != CL_SUCCESS) if(!u->handle || retval != CL_SUCCESS)
return false; return false;
...@@ -3879,6 +3880,7 @@ public: ...@@ -3879,6 +3880,7 @@ public:
if(u->data && retval == CL_SUCCESS) if(u->data && retval == CL_SUCCESS)
{ {
u->markHostCopyObsolete(false); u->markHostCopyObsolete(false);
u->markDeviceMemMapped(true);
return; return;
} }
...@@ -3907,6 +3909,7 @@ public: ...@@ -3907,6 +3909,7 @@ public:
if(!u) if(!u)
return; return;
CV_Assert(u->handle != 0); CV_Assert(u->handle != 0);
UMatDataAutoLock autolock(u); UMatDataAutoLock autolock(u);
...@@ -3917,8 +3920,10 @@ public: ...@@ -3917,8 +3920,10 @@ public:
cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr(); cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr();
cl_int retval = 0; cl_int retval = 0;
if( !u->copyOnMap() && u->data ) if( !u->copyOnMap() && u->deviceMemMapped() )
{ {
CV_Assert(u->data != NULL);
u->markDeviceMemMapped(false);
CV_Assert( (retval = clEnqueueUnmapMemObject(q, CV_Assert( (retval = clEnqueueUnmapMemObject(q,
(cl_mem)u->handle, u->data, 0, 0, 0)) == CL_SUCCESS ); (cl_mem)u->handle, u->data, 0, 0, 0)) == CL_SUCCESS );
CV_OclDbgAssert(clFinish(q) == CL_SUCCESS); CV_OclDbgAssert(clFinish(q) == CL_SUCCESS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment