- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果使用 CL_MEM_USE_HOST_PTR 将变量传递给内核,是否意味着设备中变量的任何更改也会显示在主机内存中?
我所处的场景是使用 CPU 作为设备而不是 GPU,因此传递给内核的所有内容都将标记为 CL_MEM_USE_HOST_PTR。
如果这是真的,那么我不再需要将所有内容读回主机,这非常方便。
最佳答案
您的理解是正确的,除了一个可能的陷阱:documentation指出
OpenCL implementations are allowed to cache the buffer contents pointed to by
host_ptr
in device memory. This cached copy can be used when kernels are executed on a device.
这意味着内核执行的数据更改可能不会立即反射(reflect)在 host_ptr
中。事实上,不能保证 host_ptr
在用于缓冲区时包含有效数据。
为了获得有效且最新的数据,您必须强制同步。官方文档对这一刻的描述有点模糊,但是buffer mapping/unmapping绝对有效:
If the buffer object is created with
CL_MEM_USE_HOST_PTR
set inmem_flags
, thehost_ptr
specified inclCreateBuffer
is guaranteed to contain the latest bits in the region being mapped when theclEnqueueMapBuffer
command has completed; and the pointer value returned byclEnqueueMapBuffer
will be derived from thehost_ptr
specified when the buffer object is created.
这是改编自 Khronos group forum post 的示例:
cl_mem device_output = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, size, original_output, NULL);
// run the kernel
void* pointer = clEnqueueMapBuffer(queue, device_output, CL_TRUE, CL_MAP_READ, size, 0, 0, NULL, NULL, NULL);
// work with 'original_output'
clEnqueueUnmapMemObject(queue, device_output, pointer, 0, NULL, NULL);
clReleaseMemObject(device_output);
关于OpenCL:通过 CL_MEM_USE_HOST_PTR 传递给内核的变量的设备/主机内存一致性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12283537/
我在 OpenCL 中使用 clCreateBuffer 时遇到了一些问题。我正在使用 AMD Fusion 处理器 (A10-5800k),因此两个设备(CPU 和 GPU)都应该能够在彼此的内存上
如果使用 CL_MEM_USE_HOST_PTR 将变量传递给内核,是否意味着设备中变量的任何更改也会显示在主机内存中? 我所处的场景是使用 CPU 作为设备而不是 GPU,因此传递给内核的所有内容都
所以我现在一直在研究 OpenCL 并测试主机和设备之间的内存传输速度。我正在使用英特尔 OpenCL SDK 并在 Intel i5 Processor 上运行集成显卡。然后我发现 clEnqueu
在《 OpenCl By Action》一书中,我读到了以下内容: CL_MEM_USE_HOST_PTR:内存对象将访问主机指定的内存区域 指针。 CL_MEM_COPY_HOST_PTR:内存对象
我的理解是,如果我使用 clCreateBuffer 使用标志 CL_MEM_USE_HOST_PTR 设置一个 cl_mem 对象,那 block 内存现在位于控制设备。 如果我想以某种方式改变主机
我在主机上有一个向量,我想将它减半并发送到设备。做一个基准测试表明 CL_MEM_ALLOC_HOST_PTR比 CL_MEM_USE_HOST_PTR 快并且比 CL_MEM_COPY_HOST_P
我对嵌入式和 OpenCL 很陌生,我目前正在尝试开发一个示例代码以在支持 OpenCL 1.1 EP 的 i.MX6q 板上执行。 我不得不从头开始,所以我遵循了these tutorials ,
我是一名优秀的程序员,十分优秀!