2

嗨,我正在使用 python 尝试 OpenCL。我正在尝试将一个数组和一个 const 变量传递给 cl 程序,并简单地将 const 变量复制到 cl 设备上的数组中。这应该很简单,但我收到以下错误:

Traceback (most recent call last):
File "<pyshell#103>", line 1, in <module>
test()
File "D:/Programming/Programs_OpenCL_Python/Host_CL_Parameter_Passing.py", line 141,    in test
event = prg.test( queue, (10,1), None, a_dev, b)
File "C:\Python27\lib\site-packages\pyopencl-2012.1-py2.7-win32.egg\pyopencl\__init__.py", line 457, in kernel_call
self.set_args(*args)
File "C:\Python27\lib\site-packages\pyopencl-2012.1-py2.7-win32.egg\pyopencl\__init__.py", line 509, in kernel_set_args
% (i+1, str(e), advice))
LogicError: when processing argument #2 (1-based): Kernel.set_arg failed: invalid     value - invalid kernel argument

这是代码代码:

def test():
    ctx = cl.create_some_context()
    queue = cl.CommandQueue(ctx)
    a = np.empty(10, dtype = int)
    b = int(1)
    a_dev = cl.Buffer(ctx, cl.mem_flags.WRITE_ONLY, a.nbytes)
    prg = cl.Program( ctx, """__kernel void test(__global int *a, const int b){
        int i = get_global_id(0);
        a[i] = b;
    }""").build()
    event = prg.test( queue, (10,1), None, a_dev, b)
    event.wait()
    cl.enqueue_copy( queue, a, a_dev)
    print a

有人可以告诉我问题并给我解决方案吗?这真让我抓狂。谢谢

4

1 回答 1

2

您需要将整数参数转换为 numpyint32类型:

event = prg.test( queue, (10,1), None, a_dev, np.int32(b))

顺便说一句,我可以通过查看Mandelbrot 示例来弄清楚这一点

于 2012-10-19T17:14:48.023 回答