This is an archive of the discontinued LLVM Phabricator instance.

[CUDA] Improve clang's ability to detect recent CUDA versions.
ClosedPublic

Authored by tra on Oct 19 2020, 4:48 PM.

Details

Summary

CUDA-11.1 does not carry version.txt which causes clang to assume that it's
CUDA-7.0, which used to be the only CUDA version w/o version.txt.

In order to tell CUDA-7.0 apart from the new versions, clang now probes for the
presence of libdevice.10.bc which is not present in the old CUDA versions.

This should keep Clang working for CUDA-11.1.

Bug: https://bugs.llvm.org/show_bug.cgi?id=47332

Diff Detail

Event Timeline

tra created this revision.Oct 19 2020, 4:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2020, 4:48 PM
Herald added a subscriber: bixia. · View Herald Transcript
tra requested review of this revision.Oct 19 2020, 4:48 PM
tra updated this revision to Diff 299223.Oct 19 2020, 5:06 PM
tra edited the summary of this revision. (Show Details)

Added a test.

Harbormaster completed remote builds in B75623: Diff 299223.
yaxunl accepted this revision.Oct 20 2020, 4:46 AM

LGTM. Thanks.

This revision is now accepted and ready to land.Oct 20 2020, 4:46 AM
emankov added inline comments.Oct 20 2020, 5:10 AM
clang/lib/Driver/ToolChains/Cuda.cpp
158

CUDA 11.0+, actually

161

Do we have any other mechanism besides version.txt for determining an exact CUDA version? Setting the latest version in case of absence of version.txt doesn't suit all the needs: sometimes the exact version is taken into account, for instance in hipify-clang.

clang/test/Driver/cuda-version-check.cu
13

CUDA-11.0 Update 1 doesn't carry version.txt as well.

72

missing space before {{

emankov requested changes to this revision.Oct 20 2020, 5:20 AM
This revision now requires changes to proceed.Oct 20 2020, 5:20 AM
tra updated this revision to Diff 299410.Oct 20 2020, 10:35 AM
tra marked 2 inline comments as done.

addresses review comments.

clang/lib/Driver/ToolChains/Cuda.cpp
161

Not easily.

We could try running one of SDK binaries with --version. This would be fragile as the tool version does not necessarily match the SDK's and NVIDIA has already started versioning elements per-component. E.g. some shared libraries in 11.1 are already versioned as 10.2, 11.0, 11.1 and 11.2. There are also situations when we had to cherry-pick a tool from a different release in order to work around a critical bug. We don't want to change compiler's idea of CUDA version based on that.

We could parse CUDA headers and try finding CUDA_VERSION macro. That's feasible. It may be somewhat fragile if we just search for a text string '#define CUDA_VERSION XXXX' -- nvidia may change it. On the other hand it's not that much worse than relying on version.txt. It also does not carry complete version, only major.minor, so we will not be able to tell 11.0 apart from 11.0 update 1. Probably not a big deal. I don't think we've needed it so far.

We could do something like this:

  • if version.txt is there -- use it
  • otherwise if cuda.h is found, extract version from CUDA_VERSION macro
  • if that failed, use libdevice bitcode format to detect CUDA-7.0
  • fall back to "last supported version" otherwise
tra added inline comments.Oct 20 2020, 3:10 PM
clang/test/Driver/cuda-version-check.cu
13

CUDA-11.0 Update 1 doesn't carry version.txt as well.

This assertion appears to be incorrect. I've just installed 11.0 update1 using Ubuntu .run installer I've got from https://developer.nvidia.com/cuda-11.0-update1-download-archive and the installed version does have version.txt saying

CUDA Version 11.0.228

Did you use some other installer variant?

emankov accepted this revision.Oct 21 2020, 3:51 AM

Thank you!
I've successfully applied your change in Cuda.cpp to the following clang versions: 10.0.0, 10.0.1, 11.0.0, and 12.0.0git; and have created the working patches (#206).

clang/test/Driver/cuda-version-check.cu
13
"c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin\nvcc" --version                                                                                                             nvcc: NVIDIA (R) Cuda compiler driver                                                                                                                                                                               Copyright (c) 2005-2020 NVIDIA Corporation                                                                                                                                                                          Built on Wed_Jul_22_19:09:35_Pacific_Daylight_Time_2020                                                                                                                                                             Cuda compilation tools, release 11.0, V11.0.221                                                                                                                                                                     Build cuda_11.0_bu.relgpu_drvr445TC445_37.28845127_0

CUDA Version 11.0.221 (distributive cuda_11.0.3_451.82_win10.exe) doesn't have version.txt as well.

This revision is now accepted and ready to land.Oct 21 2020, 3:51 AM
tra added a comment.Oct 21 2020, 10:11 AM

Thank you!
I've successfully applied your change in Cuda.cpp to the following clang versions: 10.0.0, 10.0.1, 11.0.0, and 12.0.0git; and have created the working patches (#206).

Thank you. Can you also take a look at D89832 which extracts CUDA version from .h file, when version.txt is not available?

clang/test/Driver/cuda-version-check.cu
13

Oh, Windows... That explains the disparity.
Thank you for testing the patch there. Could you also give D89832 a try?

emankov added inline comments.Oct 21 2020, 11:24 AM
clang/lib/Driver/ToolChains/Cuda.cpp
161

I'd appreciate the appearance of the step with a version extraction from CUDA_VERSION macro.

tra added inline comments.Oct 21 2020, 12:00 PM
clang/lib/Driver/ToolChains/Cuda.cpp
161

D89832 does exactly that. PTAL.

emankov added inline comments.Oct 21 2020, 12:09 PM
clang/lib/Driver/ToolChains/Cuda.cpp
161

Ok, I'll try it.