Currently non-ODR-use of static device variable by host code
causes static device variable to be emitted and registered,
which should not.
This patch fixes that.
Paths
| Differential D102237
[CUDA][HIP] Fix non-ODR-use of static device variable ClosedPublic Authored by yaxunl on May 11 2021, 7:15 AM.
Details
Summary Currently non-ODR-use of static device variable by host code This patch fixes that.
Diff Detail
Event TimelineComment Actions LGTM with few nits.
This revision is now accepted and ready to land.May 11 2021, 10:37 AM yaxunl added a child revision: D102270: [CUDA][HIP] Fix device template variables.May 11 2021, 12:09 PM yaxunl added inline comments. yaxunl removed a child revision: D102270: [CUDA][HIP] Fix device template variables.May 11 2021, 5:13 PM Closed by commit rG98575708da95: [CUDA][HIP] Fix device template variables (authored by yaxunl). · Explain WhyMay 12 2021, 8:14 AM This revision was automatically updated to reflect the committed changes. yaxunl marked 2 inline comments as done. Comment Actions Sam, this patch has apparently triggered some unwanted side effects. I'm still reducing the failures to something that could be used for debugging, but the rough symptoms are: We now end up emitting the code for the host-only static member functions of instantiated class templates during device-side compilation. Comment Actions
We limit the variables to device or constant variables, e.g. https://godbolt.org/z/seh1n7KnY xxx is emitted because it is implicitly constant, but yyy is not emitted. It would be interesting to know what kind of variables are emitted. Would you like the change reverted? Comment Actions
I'm still reducing the failure. I'll send you a reproducer once I have it.
We have a bit of time -- till the end of the week. Let's wait till we have a reproducer and a better idea what's going on and whether it's something easy to fix. Comment Actions Here's one example reproducer: https://godbolt.org/z/77M596W89 There are no CUDA attributes anywhere in sight, but we do end up emitting a host-only constructor for o_u which calls strlen. Comment Actions
I have a fix for this: https://reviews.llvm.org/D102801 It seems the issue was due to clang emits the implicit constant variable aw<ar>::c but it is invalid to be emitted on device side since it is initialized with a host function pointer. The fix is not to force emit implicit constant variables in device compilation. This basically limits our previous fix to explicit device variables. Comment Actions
Here's the second regression introduced by this patch. This one triggers an assertion in clang: class a { public: a(char *); }; void b() { [](char *c) { static a d(c); d; }; }
Revision Contents
Diff 344831 clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenCUDA/device-stub.cu
clang/test/CodeGenCUDA/host-used-device-var.cu
clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
clang/test/CodeGenCUDA/static-device-var-rdc.cu
|
This can be collapsed with the if (SemaRef.LangOpts.CUDA) above.