OpenCL provides a mechanism to map a region of a buffer directly into host memory instead of using the clEnqueue[Read|Write]Buffer
functions. These mapped regions can be returned to the application. The application can use this mapped memory region based on the cl_map_flags
flag value which is set during mapping. Now the first question which would arise in the readers mind is that how different are the two APIs clEnqueueMapBuffer
and clEnqueueReadBuffer
.
The clEnqueueReadBuffer
function reads into a memory location pre-allocated. But clEnqueueMapBuffer
returns a pointer to the mapped region.
Other difference between clEnqueueReadBuffer
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 and write, then set the flags as CL_MAP_READ|CL_MAP_WRITE
. The importance of CL_MAP_READ
lies when an unmap is called on...