loopy
loopy copied to clipboard
[PyOpenCL execution]: Scalar argument always returned as pyopencl arrays
Minimal reproducer:
knl = lp.make_kernel(
"{:}",
"""
y = 2*x
""")
evt, (out,) = knl(cq, x=np.asarray(3.0, dtype=float))
print(repr(out)) # prints: cl.Array(6.)
However if 'y' was anything other than array with shape () we return a numpy array. Is this a bug?
- What would you like to happen?
- If you pass
out_host=True, you get a (transferred) numpy array - Using
np.float32(3)as an input type gives me the same result. Were you observing something different?
What would you like to happen?
I would prefer returning a np ndarrray as we do for any other array with shape != (). We can see this inconsistency in the snippet below:
knl = lp.make_kernel(
"{:}",
"""
y = 2*x
""")
evt, (out,) = knl(cq, x=np.asarray(3.0, dtype=float))
print(repr(out)) # prints: cl.Array(6.)
knl = lp.make_kernel(
"{:}",
"""
y = 2*x[0]
""")
evt, (out,) = knl(cq, x=np.asarray([3.0], dtype=float))
print(repr(out)) # prints: array(6.)
OIC. I'm not opposed. While I generally have grown to dislike the automatic-transfer-back-to-host functionality, I don't dislike it enough to want to rip it out. In your case, I think it's just a problem with the "are all inputs numpy arrays" predicate. I'd view the inconsistency you point out as a bug.