how to correctly read unmapped buffer

Hi:

I am having trouble using clenqueueunmapmemobject. I want to know how to actually use the output from an unmapped buffer.
Say for example I wished to print out the contents of the buffer to the screen. The way I have been doing it up to this point is using clenqueuereadbuffer to get the results I want.

Is there a simple example that shows how this is done?
I realize that reading and writing buffers works better/is easier in many situations but I still wish to know.

Thanks for the help!

You don’t use the contents after clEnqueueUnmapMemObject.

Instead of clEnqueueReadBuffer, do a clEnqueueMapBuffer (with blocking), use the pointer returned to access the buffer, then clEnqueueUnmapMemObject when done.

On some hardware it will be slightly faster than clEnqueueReadBuffer because it uses pinned memory.

Let me see if I understand. If I want to print out the data the GPU changed I:

  1. map the clbuffer
  2. run the kernel
  3. use the pointer retuned from maping to go through the buffer and print each item
    4: Unmap the buffer

Does this make sense?

Thanks for your help!

No, swap steps 1 and 2 so it becomes:

  1. run the kernel
  2. map the clbuffer
  3. use the pointer retuned from maping to go through the buffer and print each item
    4: Unmap the buffer

Mapping is what makes the buffer visible on the host side. Unmapping makes it usable by the GPU again.