在 OpenCL 内核中使用 __constant 限定符

发布于 2024-08-08 04:00:59 字数 317 浏览 3 评论 0原文

我在 OpenCL 内核中使用 __constant 限定符时遇到问题。我的平台是雪豹。

我尝试在 GPU 上初始化一个 CL 只读内存对象,将常量数组从主机复制到其中。然后我像 __global 内存参数一样设置内核参数,但这并不能正常工作,但我没有看到任何错误或警告。我还尝试直接在 clSetKernelArg 函数中使用数据,就像 floatint 类型一样,但它都不起作用。

我是否犯了任何错误,或者苹果的实施有问题吗?我希望看到如何完成此操作的任何工作示例,包括 OpenCL(GPU)和主机代码。

I am having trouble using the __constant qualifier in my OpenCL kernels. My platform is Snow Leopard.

I have tried initializing a CL read-only memory object on the GPU, copying my constant array from host into it. Then I set the kernel argument just as with __global memory arguments, but this does not work as it should but I see no error or warnings. I have also tried using the data directly in the clSetKernelArg function as with float and int types, it works neither.

Do I make any mistakes or is there something wrong with Apple's implementation? I would like to see any working examples how this is done, both OpenCL (gpu) and host code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ぃ双果 2024-08-15 04:00:59

我怀疑苹果的实施是否存在如此根本的错误。我使用以下 OpenCL Hello World Examples 应用程序来获取我的关注基础知识。

在这个例子中,我用 __constant float* input 替换了 __global float* input 并且它工作得很好。您还需要确保您的缓冲区是CL_MEM_READ_ONLY,使用诸如clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(float) * count, NULL, NULL)之类的东西。

通过阅读规范,我认为 __constant => __global + CL_MEM_READ_ONLY。

我在 MBP 15" 上运行 Snow Leopard。

I doubt there is something so fundamental wrong with Apple's implementation. I used the following OpenCL Hello World Example application to get my head around the basics.

In this example I replaced the __global float* input with __constant float* input and it worked fine. You also need to make sure your buffer is CL_MEM_READ_ONLY, using something like clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(float) * count, NULL, NULL).

From reading the spec, I think __constant => __global + CL_MEM_READ_ONLY.

I'm running Snow Leopard on MBP 15".

想你的星星会说话 2024-08-15 04:00:59

“通过阅读规范,我认为 __constant => __global + CL_MEM_READ_ONLY。”

事实并非如此,当您指定 _constant 而不是 __global 时,您是在告诉您的设备将此数据保存在内存的不同部分中。在某些设备中,确实可以相同,但其他设备则不能。例如,在 NVIDIA 卡上,您只有 64kb 的 _constant 内存和 mb 的 __global 负载。 __constants 的优点是在 NVIDIA 设备中,它会被缓存:)

您可以查询您的设备:(我的设备查询示例)

CL_DEVICE_MAX_MEM_ALLOC_SIZE:128 MByte

CL_DEVICE_GLOBAL_MEM_SIZE:255 MByte

CL_DEVICE_LOCAL_MEM_SIZE:16 KByte

CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE: 64 字节

"From reading the spec, I think __constant => __global + CL_MEM_READ_ONLY."

Not really, when you specify _constant instead of __global, you are saying to your device to save this data in a different portion of memory. In some devices, its true that can be the same, but others couldn't be. On NVIDIA cards, for instance, you've only 64kb of _constant memory and loads of mb for __global. The advantage on __constants is that in NVIDIA devices, it is cached:)

You can query your device: (example of my device query)

CL_DEVICE_MAX_MEM_ALLOC_SIZE: 128 MByte

CL_DEVICE_GLOBAL_MEM_SIZE: 255 MByte

CL_DEVICE_LOCAL_MEM_SIZE: 16 KByte

CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE: 64 KByte

流年已逝 2024-08-15 04:00:59

Apple 的 OpenCL 编译器处理 GPU 上的 __constant 变量的方式存在一些错误。如果编译器日志显示类似内容

OpenCL Build Error : Compiler build log:
Error while compiling the ptx module: CLH_ERROR_NO_BINARY_FOR_GPU
PTX Info log: 
PTX Error log: 

,那么我遇到了与您相同的错误,并对其提交了错误。 Apple 的人员将其标记为重复项(显然是 rdar://7217974 的重复项),因此我认为这是一个已知问题,他们正在解决它。

There are some bugs with the way Apple's OpenCL compiler handles __constant variables on the GPU. If the compiler log says something like

OpenCL Build Error : Compiler build log:
Error while compiling the ptx module: CLH_ERROR_NO_BINARY_FOR_GPU
PTX Info log: 
PTX Error log: 

then I had the same error as you, and filed a bug on it. The folks at Apple marked it as a duplicate (of rdar://7217974 apparently) so I assume it's a known problem and they're working on it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文