Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencl 为什么使用CL_MEM_USE_HOST_PTR时数据传输不可预测?_Opencl - Fatal编程技术网

Opencl 为什么使用CL_MEM_USE_HOST_PTR时数据传输不可预测?

Opencl 为什么使用CL_MEM_USE_HOST_PTR时数据传输不可预测?,opencl,Opencl,在OpenCL by action一书中,作者在pn0:46上说: If you want the buffer object to access the same memory referenced by the host pointer, set CL_MEM_USE_HOST_PTR . This is memory- efficient, but there’s a drawback. Data transfer between hosts and devices can be unp

在OpenCL by action一书中,作者在pn0:46上说:

If you want the buffer object to access the same
memory referenced by the host pointer, set  CL_MEM_USE_HOST_PTR . This is memory-
efficient, but there’s a drawback. Data transfer between hosts and devices can be
unpredictable, so you may not be able to safely access the host pointer memory after
communication starts.
我无法理解为什么数据传输不可预测,为什么通信开始后我可能无法安全访问主机指针内存?作者在这里想表达的观点是什么

用法示例:


我不知道作者打算传达什么


主机/设备内存访问的规则很明确:一旦您使用CL_MEM_USE_host_PTR将其移交,那么您只能在ClenqueueEmapBuffer阻塞或等待事件或clFinish后在主机上访问它。然后,在主机端访问它之后,在设备上访问它之前,必须先取消对它的访问。注意:您也可以使用CL_ALLOC_HOST_PTR代替,并让OpenCL运行时进行分配;之后的规则保持不变。

Dithermaster感谢您的留言。但是你能告诉我哪一个更快以及为什么吗?如果设备正在使用来自主机的内存,那么将设备端内存空间映射到主机端内存空间有什么意义呢?@user2799508:通常是相同的speed@RomanArzumanyan-设备仅在采用统一架构(即iGPU而非dGPU)时使用主机内存。否则,它们有单独的内存池,它们之间有PCIE总线,从一个到另一个的映射允许您假装它们是相同的;您需要使用clenqueemapbuffer来获取主机指针。如果使用CL_MEM_use_HOST_PTR并传入使用malloc分配的指针,则OpenCL运行时可以选择将主机内存复制到OpenCL分配的内存中。然后,从clenqueemapbuffer返回的指针将不同于从malloc获得的指针。清澈如泥?
cl_int err;
int a[16];
cl_mem newBuffer = clCreateBuffer(
context,
CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
16*sizeof(int),
a,
&err);
if( err !¼ CL_SUCCESS ) {
// Do whatever error test is necessary
}