As the host code shares the physical memory with CPU OpenCL™ device, you can do one of the following to avoid unnecessary copies:
clEnqueueMapBuffer
and clEnqueueUnmapBuffer
instead of calls to clEnqueueReadBuffer
or clEnqueueWriteBuffer
.If your application uses a specific memory management algorithm, or
if you need more control over memory allocation, you can allocate a buffer
and then pass the pointer at clCreateBuffer
time with the
CL_MEM_USE_HOST_PTR
flag. However, the pointer must be aligned
to the certain boundary. Otherwise, the framework may perform memory copies.
Consider to query the required memory alignment using clGetDeviceInfo
with CL_DEVICE_MEM_BASE_ADDR_ALIGN
token.
You can also map image objects (for CPU OpenCL device), creating them
with the CL_MEM_USE_HOST_PTR
flag.