You can optimize memory allocation by using the correct commands.
8.3.1 About memory
8.3.2 Use CL_MEM_ALLOC_HOST_PTR
to avoid copying memory.
8.3.3 Do not create buffers with CL_MEM_USE_HOST_PTR if possible.
8.3.4 Do not allocate
memory buffers created with malloc() for OpenCL applications.
8.3.5 Sharing memory
between I/O devices and OpenCL.
8.3.6 Sharing memory in a fully coherent system.
8.3.7 Sharing memory in an I/O coherent system.