Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between clEnqueueMapBuffer and clEnqueueWriteBuffer

Tags:

buffer

opencl

They can both transfer data from host to device right? So, what's the difference? One needs to create a buffer one doesn't? Thanks!

The explanation on khronos's website:

clEnqueueMapBuffer:

Enqueues a command to map a region of the buffer object given by buffer into the host address space and returns a pointer to this mapped region.

clEnqueueWriteBuffer

Enqueue commands to write to a buffer object from host memory.

like image 902
David Ding Avatar asked Dec 26 '22 12:12

David Ding


1 Answers

Writing the buffer means that you have 2 memory objects - one on host, which is allocated by malloc, etc and one on Device, which is allocated via OpenCL API.

Mapping means that you have one object, allocated by OpenCL API, and you are translating it's address into Host address space.

If your Device has memory from RAM, you would better use mapping - address translation takes less time than copying.

If your Device has separate memory, you will see no speed difference - data will be implicitly copied.

Anyway, mapping allows you to get rid of memory duplication.

like image 117
Roman Arzumanyan Avatar answered May 19 '23 10:05

Roman Arzumanyan