Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CL_MEM_USE_HOST_PTR Vs CL_MEM_COPY_HOST_PTR Vs CL_MEM_ALLOC_HOST_PTR

Tags:

opencl

In the book OpenCl By Action I read this:

CL_MEM_USE_HOST_PTR: The memory object will access the memory region specified by the host pointer.

CL_MEM_COPY_HOST_PTR: The memory object will set the memory region specified by the host pointer.

CL_MEM_ALLOC_HOST_PTR: A region in host-accessible memory will be allocated for use in data transfer.

I am utterly confused o these three flags.

I would like to know at least how are the first two different.

1-In CL_MEM_USE_HOST_PTR Memory Object will access the memory region while in CL_MEM_COPY_HOST_PTR Memory Object will set the memory region (specified by host in both cases). How is this setting and accessing different ? Then the third one is again confusing me a lot.

2- Are all of these pinned memory allocation?

like image 503
user3891236 Avatar asked Aug 26 '14 01:08

user3891236


1 Answers

CL_MEM_COPY_HOST_PTR simply copies the values at a time of creation of the buffer.

CL_MEM_USE_HOST_PTR maintains a reference to that memory area and depending on the implementation it might access it directly while kernels are executing or it might cache it. You must use mapbuffer to provide synchronization points if you want to write cross platform code using this.

CL_MEM_ALLOC_HOST_PTR is the only one that is often pinned memory. As an example on AMD this one allocates a pinned memory area. Often if you use CL_MEM_USE_HOST_PTR it will simply memcpy internally to a pinned memory area and use that. By using ALLOC_HOST_PTR you will avoid that. But yet again this depends on the implementation and you must read the manufacturers documentation on if this will provide you with pinned memory or not.

like image 113
sharpneli Avatar answered Nov 11 '22 15:11

sharpneli