使用 CL_MEM_USE_HOST_PTR 时是否需要排队读/写? [英] Is it necessary to enqueue read/write when using CL_MEM_USE_HOST_PTR?

查看:59
本文介绍了使用 CL_MEM_USE_HOST_PTR 时是否需要排队读/写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在wait()让内核计算工作.

Assume that I am wait()ing for the kernel to compute the work.

我想知道,在使用 CL_MEM_USE_HOST_PTR 标志分配缓冲区时,是否需要在缓冲区上使用 enqueueRead/Write,或者它们可以总是被省略?

I was wondering if, when allocating a buffer using the CL_MEM_USE_HOST_PTR flag, it is necessary to use enqueueRead/Write on the buffer, or they can always be omitted?

注意

我知道参考文献中的这个注释:

I am aware of this note on the reference:

调用 clEnqueueReadBuffer 读取缓冲区对象的一个​​区域ptr 参数值设置为 host_ptr + offset,其中 host_ptr 是一个指向缓冲区对象时指定的内存区域的指针read是用CL_MEM_USE_HOST_PTR创建的,必须满足以下避免未定义行为的要求:

Calling clEnqueueReadBuffer to read a region of the buffer object with the ptr argument value set to host_ptr + offset, where host_ptr is a pointer to the memory region specified when the buffer object being read is created with CL_MEM_USE_HOST_PTR, must meet the following requirements in order to avoid undefined behavior:

  1. 在读取命令开始执行之前,所有使用此缓冲区对象的命令都已执行完毕
  2. 缓冲区对象未映射
  3. 在读取命令完成执行之前,任何命令队列都不会使用缓冲区对象

所以,为了澄清我的问题,我把它分成两部分:

So, to clarify my question, I split it in two:

  1. 如果我使用 CL_MEM_USE_HOST_PTR 标志创建缓冲区,我是否可以假设 OpenCL 实现将在必要时写入设备缓存,以便我可以总是避免enqueueWriteBuffer()?
  2. 如果我在启动内核后调用 event.wait(),我是否可以总是避免 enqueueReadBuffer() 访问计算数据使用标志 CL_MEM_USE_HOST_PTR 创建的缓冲区?
  1. if I create a buffer using CL_MEM_USE_HOST_PTR flag, can I assume the OpenCL implementation will write to device cache when necessary, so I can always avoid to enqueueWriteBuffer()?
  2. if I call event.wait() after launching a kernel, can I always avoid to enqueueReadBuffer() to access computed data on a buffer created with flag CL_MEM_USE_HOST_PTR?

也许是我多虑了,但是即使flag的描述清楚了将使用主机内存来存储数据的事实,也不清楚(或者我没有找到清除的地方)关于数据何时可用以及读/写是否总是隐式的.

Maybe I am overthinking about it, but even if the description of the flag is clear about the fact that the host memory will be used to store the data, it is not clear (or I did not find where it is cleared) about when data is available and if the read/write is always implicit.

推荐答案

你永远不必使用 enqueueWriteBuffer(),但你必须使用 enqueueMapBuffer.

You'll never have to use enqueueWriteBuffer(), however you have to use enqueueMapBuffer.

参见 http://www.khronos.org/registry/cl/specs/opencl-1.2.pdf 第 89 页(在 1.1 中也是如此).

See http://www.khronos.org/registry/cl/specs/opencl-1.2.pdf page 89 (it's the same also in 1.1).

数据仅在您映射对象后可用,并且在您取消对象映射后将再次变为未定义状态.还有这个旧线程 http://www.khronos.org/message_boards/showthread.php/6912-Clarify-CL_MEM_USE_HOST_PTR 包含相当有用的描述.

The data is available only after you have mapped the object and will again become undefined after you unmap the object. Also this old thread http://www.khronos.org/message_boards/showthread.php/6912-Clarify-CL_MEM_USE_HOST_PTR contains rather useful description.

这篇关于使用 CL_MEM_USE_HOST_PTR 时是否需要排队读/写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆