Could anybody talk about the function clEnqueueMapBuffer
work mechanism. Actually I mainly concern what benefits on speed I can get from this function over clEnqueueRead/WriteBuffer
.
PS:
Does clEnqueueMapBuffer/clEnqueueMapImage
also alloc a buffer from the CPU automatically?
If yes.
I want to manage my CPU buffer. I mean I malloc a big buffer first. Then if I need buffer. I can allocate it from the big buffer which I allocate first. How to make the clEnqueueMapBuffer/clEnqueueMapImage
allocate buffer from the big buffer.
clEnqueueMapBuffer
/clEnqueueMapImage
OpenCL mechanism for accessing memory objects instead of using clEnqueueRead
/Write
. we can map a memory object on a device to a memory region on host. Once we have mapped the object we can read/write or modify anyway we like.
One more difference between Read
/Write
buffer and clEnqueueMapBuffer
is the map_flags
argument. If map_flags
is set to CL_MAP_READ
, the mapped memory will be read only, and if it is set as CL_MAP_WRITE
the mapped memory will be write only, if you want both read + write then make the flag CL_MAP_READ | CL_MAP_WRITE
.
Compared to read/write fns, memory mapping requires three step process>
clEnqueueMapBuffer
.memcpy
.clEnqueueUnmapObject
.It is common consensus that memory mapping gives significant improvement in performance compared to regular read/write, see here: what's faster - AMD devgurus forum link
If you want to copy a image or rectangular region of image then you can make use of clEnqueueMapImage
call as well.
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With