summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunyan He <junyan.he@intel.com>2016-04-28 21:32:17 +0800
committerJunyan He <junyan.he@intel.com>2016-04-28 21:32:17 +0800
commit21fd51b5aad4c19a6cd8e318babac1e1a4dd221b (patch)
tree6b2d2a4ef55fe5ba1d00b68e8455a07b709d0c78
parent69ea32876e7a8c6689cab56331ecb94600c39508 (diff)
-rw-r--r--backend/src/driver/cl_gen_mem.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/backend/src/driver/cl_gen_mem.cpp b/backend/src/driver/cl_gen_mem.cpp
index 3d8cd219..ea263662 100644
--- a/backend/src/driver/cl_gen_mem.cpp
+++ b/backend/src/driver/cl_gen_mem.cpp
@@ -387,7 +387,7 @@ cl_int GenReleaseMem(cl_mem mem, const cl_device_id device)
return CL_SUCCESS;
}
-static void* genDoMapBuffer(GenGPUMem* genMem, cl_mem mem, cl_map_flags flags, size_t offset, size_t size)
+static void* genDoMapBufferSync(GenGPUMem* genMem, cl_mem mem, cl_map_flags flags, size_t offset, size_t size)
{
cl_mem_buffer buffer = cl_mem_to_buffer(mem);
@@ -401,16 +401,20 @@ static void* genDoMapBuffer(GenGPUMem* genMem, cl_mem mem, cl_map_flags flags, s
return NULL;
}
- if (mem->flags & CL_MEM_USE_HOST_PTR) {
- retAddr = (char*)mem->host_ptr + buffer->sub_offset + offset;
+ if (mem->flags & (CL_MEM_USE_HOST_PTR|CL_MEM_ALLOC_HOST_PTR)) {
+ if (genMem->bindedHostPtr) {
+ GBE_ASSERT(genMem->bindedHostPtr == mem->host_ptr - buffer->sub_offset);
+ }
+ retAddr = (char*)mem->host_ptr + offset;
} else {
retAddr = (char*)mappedAddr + buffer->sub_offset + offset;
}
/* We might need to call back the data in GPU side to host. */
- if ((mem->flags & CL_MEM_USE_HOST_PTR) && genMem->alignedHostPtr == NULL) {
+ if ((mem->flags & (CL_MEM_USE_HOST_PTR|CL_MEM_ALLOC_HOST_PTR))
+ && genMem->bindedHostPtr == NULL) {
char* ptr = (char*)mappedAddr + buffer->sub_offset + offset;
- memcpy((char*)mem->host_ptr + buffer->sub_offset + offset, ptr, size);
+ memcpy(retAddr, ptr, size);
}
return (void*)retAddr;
@@ -442,7 +446,7 @@ bool GenGPUWorkItemMapBuf::complete(void)
bool GenGPUWorkItemMapBuf::submit(void)
{
- void* retAddr = genDoMapBuffer(genMem, mem, flags, offset, size);
+ void* retAddr = genDoMapBufferSync(genMem, mem, flags, offset, size);
if (retAddr == NULL) {
return false;
}
@@ -477,7 +481,7 @@ cl_int GenEnqueueMapBuffer(cl_command_queue queue, cl_mem mem, void** ret_addr,
}
if (block || item->depend_events == NULL) { // We do not need to do it async, just map it.
- retAddr = genDoMapBuffer(genMem, mem, flags, offset, size);
+ retAddr = genDoMapBufferSync(genMem, mem, flags, offset, size);
if (retAddr == NULL) {
return CL_MAP_FAILURE;
}