Skip to content

Input arguments are not required if they are also output

If I modify the example from the tutorial so that out is also an input,

import pyopencl as cl
import pyopencl.array as cla
import loopy as lp

ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

n = 2

knl = lp.make_kernel(
    "{ [i]: 0<=i<n }",
    "out[i] = 2*a[i] + out[i]",
    fixed_parameters=dict(n=n),
    lang_version=(2018, 2))

a = cla.zeros(queue, (n,), 'float64') + 1
out = cla.zeros(queue, (n,), 'float64') + 2

loopy does not require out to be passed to the kernel. (Both arguments have is_output_only == False.) E.g.,

evt, (out2,) = knl(queue, a=a)

will execute without error and seemingly use the out array (created by the executor) as input, resulting in out2 == 2 * a. I found the same behavior for a few random commits to master over the past year, as well as when using ExecutableCTarget.

I could attempt a fix if pointed in the right direction (assuming I'm not missing something here!).