-
Notifications
You must be signed in to change notification settings - Fork 740
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] Emit a warning on constexprs captured in SYCL kernels #2824
Changes from all commits
43eca38
2f4908e
4b315e9
e441366
98043f9
004e0fa
b1fb78b
71a9085
1f39874
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2020 -verify %s | ||
|
||
// This test warns users when an ODR-use of a constexpr variable causes the kernel lambda to capture it as a | ||
// kernel argument | ||
|
||
#include "sycl.hpp" | ||
|
||
using namespace cl::sycl; | ||
|
||
queue q; | ||
|
||
class LambdaKernel; | ||
|
||
int main() { | ||
|
||
constexpr unsigned OdrUsedVar = 10; | ||
|
||
q.submit([&](handler &h) { | ||
// expected-note@+1 {{in instantiation of function template specialization}} | ||
h.single_task<LambdaKernel>( | ||
[=]() { | ||
// constexpr 'OdrUsedVar' is odr-used here. | ||
const unsigned *ptr = &OdrUsedVar; // expected-warning {{captured constexpr 'OdrUsedVar' will be a kernel argument in device code}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite get the purpose of this warning. I think in order to understand this warning message, user must know DPC++ implementation details about lowering lambda object into kernel function and how kernel function parameters are composed. Do you think it's clear for DPC++ users? Another point it's generic C++ behavior and not SYCL specific issue: template <typename T>
void foo(T t) {t();}
// ...
foo([=]() { const unsigned *ptr = &OdrUsedVar; }); // OdrUsedVar is captured and might cause performance issues
foo([=]() { unsigned x = 10 + OdrUsedVar; }); // OdrUsedVar is not captured. No performance issues? Should we emit similar warning for any lambda expression? It's probably more useful to implement such diagnostics in performance profiler because passing additional argument might be not a problem at all. @premanandrao, @srividya-sundaram, @erichkeane, what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tagging @kbobrovs to give his feedback as well since this was originally brought up by him. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more thing: this diagnostics warns that current implementation is not optimal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I suspect many people (like myself) writing code similar to
will expect V to be compile-time constant inside the lambda. In some cases this expectation is not true and V is captured and hence is not a compile-time constant. This can potentially lead to performance problems. I'm not sure what 'performance compiler' is. If it can be built from this github repo - I'm OK with making this feature available only in 'performance compiler'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, that is a fairly well known property of constexpr: It isn't necessarily a compile time constant unless you make it so in some way. I'm generally not in favor of a warning that tells you that the language is still working the way it is designed, particularly since there isn't a code-way to suppress this warning. If we had some sort of perf-analysis tool, that would be a good place for that. Have we considered seeing if the Static Analysis effort would be a better place for this? |
||
}); | ||
}); | ||
return 0; | ||
} |
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.