-
Notifications
You must be signed in to change notification settings - Fork 808
[SYCL] Allow free function kernel args be templated on integer expressions #20187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SYCL] Allow free function kernel args be templated on integer expressions #20187
Conversation
…ions `constexpr` variables are not forward-declarable so if one is used as a template parameter of a free function kernel argument, we cannot reference the variable, but must inline the value into the integration header.
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]] | ||
void constexpr_v(Arg<A>) {} | ||
|
||
// CHECK: void constexpr_v(Arg<2> ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for reviewers: we used to print Arg<A>
here where A
isn't forward-declared in the integration header (because we can't do for constexpr
variables) which caused compilation errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about putting constexpr
function calls there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added such test in e502a1b
|
||
auto TemplateArgPrinter = [&](const TemplateArgument &Arg) { | ||
if (Arg.getKind() != TemplateArgument::ArgKind::Expression || | ||
Arg.isInstantiationDependent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can Arg.isInstantiationDependent()
ever be true in SemaSYCL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can. This extra check was prompted by
template <int ArrSize>
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
void ff_7(KArgWithPtrArray<ArrSize> KArg) {
for (int j = 0; j < ArrSize; j++)
for (int i = KArg.start[j]; i <= KArg.end[j]; i++)
KArg.data[j][i] = KArg.start[j] + KArg.end[j];
}
(snippet from clang/test/CodeGenSYCL/free_function_int_header.cpp
).
ArrSize
template argument is instantiation dependent here
return; | ||
} | ||
|
||
Expr *E = Arg.getAsExpr(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can E
end up being null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be because I check the argument kind above, but I added an assertion just in case (and to help static analyzers)
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]] | ||
void constexpr_v(Arg<A>) {} | ||
|
||
// CHECK: void constexpr_v(Arg<2> ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about putting constexpr
function calls there?
@intel/llvm-gatekeepers please consider merging |
…sions (intel#20187) `constexpr` variables are not forward-declarable so if one is used as a template parameter of a free function kernel argument, we cannot reference the variable, but must inline the value into the integration header.
This is joined cherry-pick of #20187 and #20123 --- [SYCL] Allow free function kernel args be templated on integer expressions (#20187) `constexpr` variables are not forward-declarable so if one is used as a template parameter of a free function kernel argument, we cannot reference the variable, but must inline the value into the integration header. --- [SYCL] Fix error with type aliases used as free function kernel args (#20123) This PR fixes type name that is being printed as free function kernel argument type in its forward-declaration in the integration header. Before the change, we used the original argument type name, which could be an alias - this patch makes use of the canonical type's name to make sure that all type aliases are "unwrapped".
constexpr
variables are not forward-declarable so if one is used as a template parameter of a free function kernel argument, we cannot reference the variable, but must inline the value into the integration header.