pyopencl调用参数数量错误

时间:2014-04-28 15:52:34

标签: pyopencl

我在pyopencl中遇到此错误的问题:

pyopencl.RuntimeError: clBuildProgram failed: invalid binary - 

Build on <pyopencl.Device 'GeForce GTX 470' on 'NVIDIA CUDA' at 0x263c1b0>:

ptxas application ptx input, line 116; error   : Call has wrong number of parameters
ptxas fatal   : Ptx assembly aborted due to errors

这是Python代码:

    u_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=u)
    v_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=v)
    d_dev = cl_array.to_device(queue, delta)
    cont_buf = cl.Buffer(ctx, mf.READ_WRITE, size=cont1.nbytes)
    P_buf = cl.Buffer(ctx, mf.WRITE_ONLY, size=P.nbytes)
    sigma_buf = cl.Buffer(ctx, mf.READ_WRITE, size=sigma.nbytes)
    cl.enqueue_write_buffer(queue, sigma_buf, sigma)
    kernel = cl.Program(ctx, forward_kernel).build()
    kernel.forward(queue, u.shape, None, u_buf, v_buf, d_dev.data, numpy.int16(l), cont_buf, P_buf, sigma_buf)

和我内核的开头:

__kernel void forward(__global const int *u,
                  __global const int *v,
                  __global int *d,
                  const int l,
                  int cont,
                  __global int *P,
                  __global int *sigma )
{
    int gid = get_global_id(0);
...

u,v,d,P,sigma是numpy数组,l是整数(np.int_),cont1是bool值。

1 个答案:

答案 0 :(得分:0)

我不是100%确定你将要做什么,但也许下面的例子,在我的机器上运行,有助于:

import numpy as np
import pyopencl as cl
import pyopencl.array as cl_array

N = 100
deviceID = 0
platformID = 0
workGroup=(1,1)

dev = cl.get_platforms()[platformID].get_devices()[deviceID]
ctx = cl.Context([dev])
queue = cl.CommandQueue(ctx)

mf = cl.mem_flags

u = np.zeros([N], dtype = int)
v = np.ones([N], dtype = int)
delta = v - u
cont1 = np.int(4)
l = np.int32(3)
P = v
sigma = v


u_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=u)
v_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=v)
d_dev = cl_array.to_device(queue, delta)
P_buf = cl.Buffer(ctx, mf.WRITE_ONLY, size=P.nbytes)
sigma_buf = cl.Buffer(ctx, mf.READ_WRITE, size=sigma.nbytes)
cl.enqueue_write_buffer(queue, sigma_buf, sigma)


prg = cl.Program(ctx, """__kernel void forward(__global const int *u,
              __global const int *v,
              __global int *d,
              int l,
              int cont,
              __global int *P,
              __global int *sigma )
{
    int gid = get_global_id(0);
    d[gid] = gid;
}""").build()

prg.forward(queue, u.shape, None, u_buf, v_buf, d_dev.data, np.int32(l), np.int32(cont1), P_buf, sigma_buf)