This is an archive of the discontinued LLVM Phabricator instance.

[CUDA] Refactored CUDA version housekeeping to use less boilerplate.
ClosedPublic

Authored by tra on Oct 5 2022, 3:24 PM.

Diff Detail

Event Timeline

tra created this revision.Oct 5 2022, 3:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 3:24 PM
tra updated this revision to Diff 465598.Oct 5 2022, 4:31 PM

Fix handling unknown versions.

tra published this revision for review.Oct 5 2022, 4:33 PM
tra retitled this revision from Refactored CUDA version housekeeping to use less boilerplate. to [CUDA] Refactored CUDA version housekeeping to use less boilerplate..
tra added a reviewer: yaxunl.
tra added a project: Restricted Project.
tra updated this revision to Diff 465601.Oct 5 2022, 4:39 PM

Use int max for the "new" CUDA version value.

yaxunl added inline comments.Oct 5 2022, 5:01 PM
clang/lib/Basic/Cuda.cpp
60

should we assert Version.getMinor().value_or(0)<10 ?

clang/lib/Basic/Targets/NVPTX.cpp
45–46

This behaves differently when seeing a +ptx value not listed in the original code. Previously, it returns 32, now it will just return that value. Is this intended?

tra added inline comments.Oct 5 2022, 5:17 PM
clang/lib/Basic/Cuda.cpp
60

It's not an immediate issue, but you are correct that we may potentially have CUDA 12.34 and that will mess up the integer version encoding.

In fact, NVIDIA hit exactly this kind of problem in CUDA-11.7 when they had to version some of the libraries as 11.10 and had to change the binary representation and break existing ABIs. Here we're only dealing with internal use, but I'll update the encoding to give us more wiggle room.

clang/lib/Basic/Targets/NVPTX.cpp
45–46

Indeed, previously it would set PTXVersion=32 if the specific ptx feature was not listed. I believe it was a bug as it would clobber correctly parsed features before it.

Right now we will only update PTXVersion, if we did manage to parse the feature. The code looks a bit misleading. getAsInteger() returns true on failure and when that happens, we hit continue w/o setting PTXVersion.

I was considering erroring out here, but that would be a problem if we were to have another feature starting with +ptx.

tra updated this revision to Diff 465799.Oct 6 2022, 11:17 AM

Use VersionTuple instead of a manually encoded integer version.

tra marked an inline comment as done.Oct 6 2022, 11:19 AM
tra added inline comments.
clang/lib/Basic/Cuda.cpp
60

I've got rid of integer-encoded version altogether and switched to comparing VersionTuple directly.

tra added a comment.Oct 7 2022, 11:17 AM

@yaxunl - Are you OK with the patch? PTAL.

yaxunl accepted this revision.Oct 7 2022, 1:19 PM

LGTM. Thanks.

This revision is now accepted and ready to land.Oct 7 2022, 1:19 PM
This revision was automatically updated to reflect the committed changes.