在OpenCL内核中使用__constant限定词 [英] Using __constant qualifer in OpenCL kernels
问题描述
我在OpenCL内核中使用 __ constant 限定符时遇到麻烦.我的平台是雪豹.
I am having trouble using the __constant qualifier in my OpenCL kernels. My platform is Snow Leopard.
我尝试在GPU上初始化CL只读存储对象,将常量数组从主机复制到其中.然后,我像设置 __ global 内存参数一样设置内核参数,但这并不能正常工作,但是我看不到任何错误或警告.我还尝试过像 float 和 int 类型一样,直接在clSetKernelArg函数中使用数据,但这两种方法都不起作用.
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.
我会犯任何错误,或者Apple的实施存在问题吗?我想看一下任何可行的示例,包括OpenCL(gpu)和主机代码.
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.
推荐答案
我怀疑Apple的实现存在如此根本的错误.我使用以下 OpenCL Hello World Example 应用程序来获取我的深入了解基础知识.
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.
在此示例中,我将__global float* input
替换为__constant float* input
,并且效果很好.您还需要使用clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(float) * count, NULL, NULL)
之类的东西来确保缓冲区为CL_MEM_READ_ONLY
.
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)
.
通过阅读规范,我认为__constant => __global + CL_MEM_READ_ONLY.
From reading the spec, I think __constant => __global + CL_MEM_READ_ONLY.
我正在MBP 15上运行Snow Leopard".
I'm running Snow Leopard on MBP 15".
这篇关于在OpenCL内核中使用__constant限定词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!