c - Pinned memory with offset in OpenCL -
so i'm reading data in file using mmap()
follows :
unsigned char* mapped; mapped = mmap(0,size,prot_read,map_private,input,0);
then created host buffer , device buffer pinned memory :
cl_mem pinned_buffer_input = clcreatebuffer(context, cl_mem_read_only | cl_mem_alloc_host_ptr, size, mapped, null); cl_mem buffer_input = clcreatebuffer(context, cl_mem_read_only, input_size, null, null);
within for
loop :
mapping buffer :
void *pinnedmemory = clenqueuemapbuffer(cmd_queue, pinned_buffer_input, cl_true, cl_map_write, header[3]+b*input_size, input_size_cur, 0, null, &ev, null);
enqueuing buffer :
clenqueuewritebuffer(cmd_queue, buffer_input, cl_false, 0, input_size_cur, pinnedmemory, 0, null, &ev);
unmapping object :
clenqueueunmapmemobject(cmd_queue, pinned_buffer_input, pinnedmemory, 0, null, &ev);
here mapped
contains whole file , of size size
. want have buffers of size input_size
(or input_size_cur
, same thing simplify) send data blocks. offset header[3]+b*input_size
b
incremented in loop copies wrong data.
edit : if don't initialize pinned_buffer_input
mapped
can pointer host buffer clenqueuemapbuffer()
, copy data of mapped
place :
memcpy(pinnedmemory, mapped+header[3]+b*input_size, input_size_cur);
by doing works want avoid memcpy
in for
loop , creates huge delays in program. solve problem wanted use offset
parameter of clenqueuemapbuffer()
screws up.
edit 2 : cl_mem_copy_host_ptr
instead of cl_mem_alloc_host_ptr
result correct takes ages create pinned_buffer_input
.
i haven't got clear picture tell why not working guesses are:
- are waiting unmap/write complete?
- how checking data writen properly? if reading back, how reading back? maybe problem there well.
Comments
Post a Comment