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

时间:2014-08-05 09:39:06

标签: opencl

在作者OpenCL的书中,作者在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_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
}

1 个答案:

答案 0 :(得分:0)

我不知道作者打算与谁沟通。

主机/设备内存访问的规则很明确:一旦您将其移交(使用CL_MEM_USE_HOST_PTR),您只能在主机之后访问 {{ 1}}(阻止或等待事件或clEnqueueMapBuffer)。然后在主机端访问它之后,必须 clFinish才能在设备上访问它。注意:您也可以使用clEnqueueUnmapMemObject代替OpenCL运行时进行分配;之后的规则保持不变。