summaryrefslogtreecommitdiff
path: root/backend/src/driver/cl_gen_mem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/driver/cl_gen_mem.cpp')
-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;
}