CL_MEM_USE_HOST_PTR Vs CL_MEM_COPY_HOST_PTR Vs CL_MEM_ALLOC_HOST_PTR

微笑、不失礼 提交于 2019-12-30 08:23:37

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/25496656/cl-mem-use-host-ptr-vs-cl-mem-copy-host-ptr-vs-cl-mem-alloc-host-ptr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!