Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does clEnqueueMapBuffer work

Tags:

opencl

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.

like image 778
Samuel Avatar asked Sep 04 '12 01:09

Samuel


1 Answers

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>

  1. Map the memory using clEnqueueMapBuffer.
  2. transfer the memory from device to/from host via memcpy.
  3. Unmap using 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:

  • OpenCL in Action
  • Heterogeneous computing with OpenCL
  • Devgurus forum
like image 108
6 revs, 3 users 80% Avatar answered Sep 20 '22 08:09

6 revs, 3 users 80%