Hi

I'm trying to split my kernel invocations into class methods. Basically,
I'd like to call set_args in one method and then enqueue_nd_range_kernel in
another. However, when I try this I receive a "clEnqueueNDRangeKernel
failed: invalid mem object" exception.

I've adapted the front page example into a short snippet that demonstrates
the problem. Can anyone see if there's something obvious I', missing. If
not, I'll file an issue on gitbub.


> import numpy as np
> import pyopencl as cl
> a_np = np.random.rand(50000).astype(np.float32)
> b_np = np.random.rand(50000).astype(np.float32)
> class Test(object):
>     def __init__(self):
>         self.ctx = cl.create_some_context()
>         self.queue = cl.CommandQueue(self.ctx)
>         self.prg = cl.Program(self.ctx, """
>         __kernel void sum(__global const float *a_g, __global const float
> *b_g, __global float *res_g) {
>           int gid = get_global_id(0);
>           res_g[gid] = a_g[gid] + b_g[gid];
>         }
>         """).build()
>     def run_all(self):
>         mf = cl.mem_flags
>         a_g = cl.Buffer(self.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR,
> hostbuf=a_np)
>         b_g = cl.Buffer(self.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR,
> hostbuf=b_np)
>         res_g = cl.Buffer(self.ctx, mf.WRITE_ONLY, a_np.nbytes)
>         sum_k = self.prg.sum
>         sum_k.set_args(a_g, b_g, res_g)
>         cl.enqueue_nd_range_kernel(self.queue, sum_k, a_np.shape, None)
>     def run_set_args(self):
>         mf = cl.mem_flags
>         a_g = cl.Buffer(self.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR,
> hostbuf=a_np)
>         b_g = cl.Buffer(self.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR,
> hostbuf=b_np)
>         res_g = cl.Buffer(self.ctx, mf.WRITE_ONLY, a_np.nbytes)
>         self.sum_k = self.prg.sum
>         self.sum_k.set_args(a_g, b_g, res_g)
>
>     def run_enqueue(self):
>         cl.enqueue_nd_range_kernel(self.queue, self.sum_k, a_np.shape,
> None)
> o = Test()
> # runs fine
> o.run_all()
> # run separately gives "clEnqueueNDRangeKernel failed: invalid mem object"
> o.run_set_args()
> o.run_enqueue()


Thanks
Blair
_______________________________________________
PyOpenCL mailing list
[email protected]
http://lists.tiker.net/listinfo/pyopencl

Reply via email to