TypeInference failure for copysign
Correction: copysign
fails to be resolved regardless of datatypes, I think. The following code raises a RuntimeError: unable to resolve function 'copysign' with 2 given arguments
:
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] = copysign(a[i], b[i])",
[
lp.GlobalArg('a', dtype='float64'),
lp.GlobalArg('b', dtype='float64'),
...
],
fixed_parameters=dict(n=n),
lang_version=(2018, 2))
a = cla.zeros(queue, (n,), 'float64') + 1
b = cla.zeros(queue, (n,), 'float64') + 1
evt, (out,) = knl(queue, a=a, b=b)
Still happy to quickly fix this, but I'm not familiar with loopy's function mangling so direction would be appreciated!
Original text:
Datatype inference in LoopKernel.mangle_function
fails when parsing copysign(1, x)
for float-type x
. The OpenCL spec requires both arguments to have the same type, but here the type of 1
is inferred to be integer (and sadly 1.
as a float32
).
For context, this is coming from here, but without knowing the type of the second argument to copysign
I don't see how it could be fixed there. Maybe if one argument is constant, mangle_function
should match its dtype to the other argument? If a proper fix is clear, I can throw together a patch (ASAP).