Can anyone offer any suggestions? I'm unable to separate my kernel into two
calls, a set_arg(s) and an enqueue_nd_range_kernel. I'm running on Windows
10 64 bit and have tried against a OpenCL 1.2 Intel CPU and a OpenCL 1.1
Nvidia GPU. I've also tried using 2015.1 version as found at
http://www.lfd.uci.edu/~gohlke/pythonlibs/ as well as one compiled directly
from Git using mingwpy.

Perhaps someone can test if the following code will run on a different
platform?

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)
> ctx = cl.create_some_context()
> queue = cl.CommandQueue(ctx)
> mf = cl.mem_flags
> a_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a_np)
> b_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b_np)
> prg = cl.Program(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()
> res_g = cl.Buffer(ctx, mf.WRITE_ONLY, a_np.nbytes)
> #prg.sum(queue, a_np.shape, None, a_g, b_g, res_g)
> prg.sum.set_arg(0, a_g)
> prg.sum.set_arg(1, b_g)
> prg.sum.set_arg(2, res_g)
> #prg.sum.set_args(a_g, b_g, res_g)
> ev = cl.enqueue_nd_range_kernel(queue, prg.sum, a_np.shape, None)
> ev.wait()
> res_np = np.empty_like(a_np)
> cl.enqueue_copy(queue, res_np, res_g)
> # Check on CPU with Numpy:
> print(res_np - (a_np + b_np))
> print(np.linalg.norm(res_np - (a_np + b_np)))


 I get the following traceback:

Traceback (most recent call last):
>   File "C:\..\Scratch\opencl.py", line 28, in <module>
>     ev = cl.enqueue_nd_range_kernel(queue, prg.sum, a_np.shape, None)
>   File
> "D:\..l\pyo\lib\site-packages\pyopencl-2015.1-py3.4-win-amd64.egg\pyopencl\cffi_cl.py",
> line 1197, in enqueue_nd_range_kernel
>     global_work_size, local_work_size, c_wait_for, num_wait_for))
>   File
> "D:\..\pyo\lib\site-packages\pyopencl-2015.1-py3.4-win-amd64.egg\pyopencl\cffi_cl.py",
> line 549, in _handle_error
>     raise e
> pyopencl.cffi_cl.LogicError: clenqueuendrangekernel failed:
> INVALID_KERNEL_ARGS


On Mon, Oct 5, 2015 at 4:27 PM, Blair Azzopardi <[email protected]> wrote:

> Thanks; although I think I may be missing something. I'm using the example
> from the main pyopencl page <http://documen.tician.de/pyopencl/index.html>.
> I substituted
>
> prg.sum(queue, a_np.shape, None, a_g, b_g, res_g)
>
>
> with
>
> prg.sum.set_args(a_g, b_g, res_g)
> cl.enqueue_nd_range_kernel(queue, prg.sum, a_np.shape, None)
>
>
> but I get a LogicError
>
> pyopencl.LogicError: clEnqueueNDRangeKernel failed: invalid kernel args
>
>
> Anything else I should be doing?
>
> On Mon, Oct 5, 2015 at 3:36 PM, Andreas Kloeckner <[email protected]
> > wrote:
>
>> Blair Azzopardi <[email protected]> writes:
>> > How would I execute multiple kernels sequentially without needing to
>> resend
>> > data to the GPU.
>> >
>> > I'm thinking it would be something along the lines of:
>> >
>> > data1_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=..)
>> > data2_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=..)
>> >
>> > dataX_g = cl.Buffer(ctx, mf.READ_WRITE | mf.COPY_HOST_PTR,
>> > hostbuf=local_var)
>> >
>> > my_kernel1.set_args(0, data1_g, data2_g, .., dataX_g)
>> > my_kernel2.set_args(0, data1_g, data2_g, .., dataX_g)
>> > my_kernel2.set_args(0, data1_g, data2_g, .., dataX_g)
>> >
>> > cl.enqueue_nd_range_kernel(queue, my_kernel1, global_ws, local_ws)
>> > cl.enqueue_nd_range_kernel(queue, my_kernel2, global_ws, local_ws)
>> > cl.enqueue_task(queue, my_kernel3)
>> >
>> > cl.enqueue_copy(queue, local_var, z_g)
>> >
>> > Does that look right?
>>
>> Yep.
>>
>> > Does one need to set_args for each kernel or is there
>> > a device specific method for setting global memory?
>>
>> Neither.
>>
>> > Perhaps there's an
>> > example somewhere?
>>
>> https://github.com/pyopencl/pyopencl/tree/master/examples
>>
>> Andreas
>>
>>
>
_______________________________________________
PyOpenCL mailing list
[email protected]
http://lists.tiker.net/listinfo/pyopencl

Reply via email to