This is an archive of the discontinued LLVM Phabricator instance.

[CUDA][HIP] Mark device var used by host only
ClosedPublic

Authored by yaxunl on Mar 17 2021, 1:47 PM.

Details

Summary

Add device variables to llvm.compiler.used if they are
ODR-used by either host or device functions.

This is necessary to prevent them from being
eliminated by whole-program optimization
where the compiler has no way to know a device
variable is used by some host code.

Diff Detail

Event Timeline

yaxunl requested review of this revision.Mar 17 2021, 1:47 PM
yaxunl created this revision.
tra added inline comments.Mar 17 2021, 4:39 PM
clang/lib/CodeGen/CGCUDANV.cpp
1102

Do we want to limit it further to only externally-visible variables?
I think we already externalize the variables we want to be visible across host/device boundary.
If the variable is not visible, there's no point keeping it around as the runtime will not be able to find it in the GPU binary.

yaxunl marked an inline comment as done.Mar 21 2021, 7:23 AM
yaxunl added inline comments.
clang/lib/CodeGen/CGCUDANV.cpp
1102

Good point. Will do

yaxunl updated this revision to Diff 332157.Mar 21 2021, 7:24 AM
yaxunl marked an inline comment as done.

revised by Artem's comments

tra accepted this revision.Mar 22 2021, 11:07 AM
tra added inline comments.
clang/test/CodeGenCUDA/host-used-device-var.cu
31–33

I'd rephrase it as 'but is not in llvm.compiler.used'

46

I'd add a comment that we're effectively matching the exact list of the variables here and that ensures that @_ZL2u4 is not among them.

This revision is now accepted and ready to land.Mar 22 2021, 11:07 AM
yaxunl marked 2 inline comments as done.Apr 17 2021, 7:47 AM
yaxunl added inline comments.
clang/test/CodeGenCUDA/host-used-device-var.cu
31–33

will do

46

will do

This revision was automatically updated to reflect the committed changes.
yaxunl marked 2 inline comments as done.
Herald added a project: Restricted Project. · View Herald TranscriptApr 17 2021, 8:26 AM