Error when generating code for conditionals inside `If`
Consider
knl = lp.make_kernel("{[p] : 0 <= p < 2}",
"""
for p
A[p] = if(fabs(A[p] >= 1), 0, 1)
end
""",
[lp.GlobalArg("A", shape=(2, ), dtype=np.float64)], target=lp.CTarget(), lang_version=(2018, 2))
print(lp.generate_code_v2(knl).device_code()
=>
~/Documents/work/src/firedrake/src/loopy/loopy/type_inference.py in map_call(self, expr, return_tuple)
464 # }}}
465
--> 466 raise LoopyError("Overwriting a specialized function "
467 "is illegal--maybe start with new instance of "
468 "InKernelCallable?")
LoopyError: Overwriting a specialized function is illegal--maybe start with new instance of InKernelCallable?
What did I do wrong?
This is related (?) to https://github.com/firedrakeproject/firedrake/issues/1464, which makes the attached (pickled) kernel which provokes this error:
import pickle
with open("foo.pickle", "rb") as f:
knl = pickle.load(f)
print(lp.generate_code_v2(knl).device_code())
=>
in with_callable(self, function, in_kernel_callable)
771 print('Old: ', self.resolved_functions[function.name])
772 print('New: ', in_kernel_callable)
--> 773 raise LoopyError("Use 'with_enter_edit_callables_mode' first.")
774
775 # }}}
LoopyError: Use 'with_enter_edit_callables_mode' first.