This is an archive of the discontinued LLVM Phabricator instance.

[CUDA] Fix static device variables with -fgpu-rdc
ClosedPublic

Authored by Hahnfeld on Aug 20 2021, 4:32 AM.

Details

Summary

NVPTX does not allow dots in the identifier, so ptxas errors out with

fatal   : Parsing error near '.static': syntax error

because it parses .static as a directive. Avoid this problem by using
two underscores, similar to what OpenMP does for outlined functions.

Diff Detail

Event Timeline

Hahnfeld requested review of this revision.Aug 20 2021, 4:32 AM
Hahnfeld created this revision.
Herald added a project: Restricted Project. · View Herald Transcript
tra added inline comments.Aug 20 2021, 10:38 AM
clang/lib/CodeGen/CodeGenModule.cpp
6447

I would expect NVPTXAssignValidGlobalNames.cpp to deal with this ptx quirk.
I'm fine with the underscores, but it would be good we're not just covering up an issue somewhere else.

Hahnfeld added inline comments.Aug 21 2021, 8:26 AM
clang/lib/CodeGen/CodeGenModule.cpp
6447

NVPTXAssignValidGlobalNames checks hasLocalLinkage, which the static variables here are not (see discussion in D85223). I think the reason is that we don't want variable and function names to differ between host and device, and this might even be important here for maintaining proper connection for cudaMemcpys and so on.

tra accepted this revision.Aug 23 2021, 10:27 AM

LGTM.

Please wait for @yaxunl . I believe he mentioned in D85223 that he'll check whether it works on AMD's end.

clang/lib/CodeGen/CodeGenModule.cpp
6447

Right. We do need to have the same names on both sides.

I wish there was a way to avoid breaking demangling, but looks like we don't have any good options here.

This revision is now accepted and ready to land.Aug 23 2021, 10:27 AM
yaxunl accepted this revision.Aug 24 2021, 8:14 AM

LGTM. Thanks.

Hahnfeld marked 2 inline comments as done.Aug 25 2021, 12:32 AM
This revision was automatically updated to reflect the committed changes.