CL_MEM_USE_HOST_PTR Vs CL_MEM_COPY_HOST_PTR Vs CL_MEM_ALLOC_HOST_PTR

In the OpenCl book By Action, I read the following:

CL_MEM_USE_HOST_PTR: A memory object will access the memory area indicated by the host pointer.

CL_MEM_COPY_HOST_PTR: A memory object will set the memory area indicated by the node pointer.

CL_MEM_ALLOC_HOST_PTR: The area in the memory available for the host will be allocated for use in data transfer.

I am completely confused by these three flags.

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

1-In CL_MEM_USE_HOST_PTR The memory object will access the memory area, while in CL_MEM_COPY_HOST_PTR the memory object will set the memory area (specified by the host in both cases). How is this setting and access to others? Then the third again confuses me a lot.

2- Are they all associated with dedicated memory?

+6
source share
1 answer

CL_MEM_COPY_HOST_PTR simply copies the values ​​during the creation of the buffer.

CL_MEM_USE_HOST_PTR maintains a reference to this memory area, and depending on the implementation, it may access it directly when the kernels are running or it may cache it. You should 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 often commits memory. As an example on AMD, this allocates a pinned memory area. Often, if you use CL_MEM_USE_HOST_PTR, it will simply memcpy internally to the pinned memory area and use this. Using ALLOC_HOST_PTR you will avoid this. But then again, it depends on the implementation, and you should read the manufacturers documentation if it provides you with a fixed memory or not.

+8
source

Source: https://habr.com/ru/post/974338/


All Articles