gpt4 book ai didi

c - 与 CL_MEM_USE_HOST_PTR 缓冲区一起使用的 clEnqueueMapBuffer 是否返回相同的主机指针?

转载 作者:太空狗 更新时间:2023-10-29 16:12:47 33 4
gpt4 key购买 nike

我的理解是,如果我使用 clCreateBuffer 使用标志 CL_MEM_USE_HOST_PTR 设置一个 cl_mem 对象,那 block 内存现在位于控制设备。

如果我想以某种方式改变主机上的内存,我应该首先使用 clEnqueueMapBuffer 映射内存,它返回一个指针。

在这种情况下返回的指针是否保证与用于创建缓冲区的指针相同(即我最初传递给 clCreateBuffer 的指针),尽管类型为 void * ?

通过扩展,如果我现在希望将内存的控制权返回给设备,我可以调用 clEnqueueUnmapMemObject 并使用用于为 mapped_pointer 创建缓冲区的原始指针 参数?

编辑:进一步调查表明,如果在调用 clEnqueueMapBuffer 时使用非零偏移量,则指针明显不同。因此,上面的问题是在我确实设置零偏移的情况下。

最佳答案

我无法直接回答您的问题是或否,但我可以提供一些建议(无双关语意)。

我没有在标准中找到任何保证这两个指针实际上应该相同的内容。然而,在标准的第 5.2.4 节中,有一条有趣的注释指出:

If the buffer object is created with CL_MEM_USE_HOST_PTR set in mem_flags, the following will be true:

  • The host_ptr specified in clCreateBuffer is guaranteed to contain the latest bits in the region being mapped when the clEnqueueMapBuffer command has completed.
  • The pointer value returned by clEnqueueMapBuffer will be derived from the host_ptr specified when the buffer object is created.

我不知道你为什么问这个问题,但至少从第一个要点你知道你可以在映射区域时使用“原始”指针。

我发现第二个要点不太清楚,但可能是因为我不是本地人。你可能比我更了解它。在我看来,它仍然可能对您的问题提出"is"的建议...

最后我在"Heterogeneous Computing with OpenCL"的第10章找到了脚注(第 200 页)说明:

Note that CL_MEM_ALLOC_HOST_PTR guarantees that when map is called onthe buffer, the passed pointer becomes the host pointer returned bymap. Data is still only valid at the host pointer between calls to mapand unmap.

当然这个注释是关于CL_MEM_ALLOC_HOST_PTR而不是CL_MEM_USE_HOST_PTR的,也没有指明相关的标准部分。不过,很容易假设 CL_MEM_USE_HOST_PTR 也是这种情况。

关于c - 与 CL_MEM_USE_HOST_PTR 缓冲区一起使用的 clEnqueueMapBuffer 是否返回相同的主机指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20355798/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com