You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SYCL spec restricts device code not to allow recursion.
In cases when recursion can be evaluated at compile-time, and the restriction can be lifted for programmer convenience. Even though the spec says
Recursion is not allowed in a SYCL kernel or any code called from the kernel
the intent is likely to reliably prevent recursive function code generation for the devices, the spec seems to need clarification.
With the proposed relaxation the following code should compile:
template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
kernelFunc();
}
staticconstexprunsignedintgetNextPowerOf2(unsignedint n,
unsignedint k = 1) {
return (k >= n) ? k : getNextPowerOf2(n, k * 2);
}
unsignedtest_constexpr_recursion(unsignedint val) {
unsignedint res = val;
unsignedint *addr = &res;
kernel_single_task<classConstexprRecursionKernel>([=]() {
// Compiler must evaluate recursion, no errors expected.constexprunsignedint x = getNextPowerOf2(3);
*addr += x;
});
return res;
}
But if getNextPowerOf2 is called from non-constexpr context, it still should not compile:
template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
kernelFunc(); //#call_kernelFunc // expected-note 3{{called by 'kernel_single_task<fake_kernel, (lambda at}}
}
staticconstexprunsignedintgetNextPowerOf2(unsignedint n,
unsignedint k = 1) {
return (k >= n) ? k : getNextPowerOf2(n, k * 2);
}
unsignedtest_constexpr_recursion(unsignedint val) {
unsignedint res = val;
unsignedint *addr = &res;
kernel_single_task<classConstexprRecursionKernel>([=]() {
// This call should still generate an error, as getNextPowerOf2// will not be compile-time evaluated in this case and will be code-generated:unsignedint x = getNextPowerOf2(3);
*addr += x;
});
return res;
}
The text was updated successfully, but these errors were encountered:
Note this is actually more complicated than just when assigning to a constexpr variable. Things like, the condition of a static assert, "constexpr if", array bounds, etc (basically, anywhere a constant expression is required!) should not diagnose if we are to allow this.
SYCL spec restricts device code not to allow recursion.
In cases when recursion can be evaluated at compile-time, and the restriction can be lifted for programmer convenience. Even though the spec says
the intent is likely to reliably prevent recursive function code generation for the devices, the spec seems to need clarification.
With the proposed relaxation the following code should compile:
But if
getNextPowerOf2
is called from non-constexpr context, it still should not compile:The text was updated successfully, but these errors were encountered: