[CUDA] Add partial support for recent CUDA versions.

Generate PTX using newer versions of PTX and allow using sm_80 with CUDA-11.
None of the new features of CUDA-10.2+ have been implemented yet, so using these
versions will still produce a warning.

Differential Revision: https://reviews.llvm.org/D77670
This commit is contained in:
Artem Belevich 2020-04-07 11:00:19 -07:00
parent 33386b20aa
commit a9627b7ea7
6 changed files with 59 additions and 22 deletions

View File

@ -27,7 +27,10 @@ enum class CudaVersion {
CUDA_92, CUDA_92,
CUDA_100, CUDA_100,
CUDA_101, CUDA_101,
LATEST = CUDA_101, CUDA_102,
CUDA_110,
LATEST = CUDA_110,
LATEST_SUPPORTED = CUDA_101,
}; };
const char *CudaVersionToString(CudaVersion V); const char *CudaVersionToString(CudaVersion V);
// Input is "Major.Minor" // Input is "Major.Minor"
@ -50,6 +53,7 @@ enum class CudaArch {
SM_70, SM_70,
SM_72, SM_72,
SM_75, SM_75,
SM_80,
GFX600, GFX600,
GFX601, GFX601,
GFX700, GFX700,

View File

@ -28,6 +28,10 @@ const char *CudaVersionToString(CudaVersion V) {
return "10.0"; return "10.0";
case CudaVersion::CUDA_101: case CudaVersion::CUDA_101:
return "10.1"; return "10.1";
case CudaVersion::CUDA_102:
return "10.2";
case CudaVersion::CUDA_110:
return "11.0";
} }
llvm_unreachable("invalid enum"); llvm_unreachable("invalid enum");
} }
@ -42,6 +46,8 @@ CudaVersion CudaStringToVersion(const llvm::Twine &S) {
.Case("9.2", CudaVersion::CUDA_92) .Case("9.2", CudaVersion::CUDA_92)
.Case("10.0", CudaVersion::CUDA_100) .Case("10.0", CudaVersion::CUDA_100)
.Case("10.1", CudaVersion::CUDA_101) .Case("10.1", CudaVersion::CUDA_101)
.Case("10.2", CudaVersion::CUDA_102)
.Case("11.0", CudaVersion::CUDA_110)
.Default(CudaVersion::UNKNOWN); .Default(CudaVersion::UNKNOWN);
} }
@ -64,6 +70,7 @@ CudaArchToStringMap arch_names[] = {
SM(60), SM(61), SM(62), // Pascal SM(60), SM(61), SM(62), // Pascal
SM(70), SM(72), // Volta SM(70), SM(72), // Volta
SM(75), // Turing SM(75), // Turing
SM(80), // Ampere
GFX(600), // tahiti GFX(600), // tahiti
GFX(601), // pitcairn, verde, oland,hainan GFX(601), // pitcairn, verde, oland,hainan
GFX(700), // kaveri GFX(700), // kaveri
@ -140,6 +147,8 @@ CudaVersion MinVersionForCudaArch(CudaArch A) {
return CudaVersion::CUDA_91; return CudaVersion::CUDA_91;
case CudaArch::SM_75: case CudaArch::SM_75:
return CudaVersion::CUDA_100; return CudaVersion::CUDA_100;
case CudaArch::SM_80:
return CudaVersion::CUDA_110;
default: default:
llvm_unreachable("invalid enum"); llvm_unreachable("invalid enum");
} }

View File

@ -44,6 +44,8 @@ NVPTXTargetInfo::NVPTXTargetInfo(const llvm::Triple &Triple,
if (!Feature.startswith("+ptx")) if (!Feature.startswith("+ptx"))
continue; continue;
PTXVersion = llvm::StringSwitch<unsigned>(Feature) PTXVersion = llvm::StringSwitch<unsigned>(Feature)
.Case("+ptx70", 70)
.Case("+ptx65", 65)
.Case("+ptx64", 64) .Case("+ptx64", 64)
.Case("+ptx63", 63) .Case("+ptx63", 63)
.Case("+ptx61", 61) .Case("+ptx61", 61)
@ -231,6 +233,8 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts,
return "720"; return "720";
case CudaArch::SM_75: case CudaArch::SM_75:
return "750"; return "750";
case CudaArch::SM_80:
return "800";
} }
llvm_unreachable("unhandled CudaArch"); llvm_unreachable("unhandled CudaArch");
}(); }();

View File

@ -4992,6 +4992,7 @@ void CGOpenMPRuntimeNVPTX::processRequiresDirective(
case CudaArch::SM_70: case CudaArch::SM_70:
case CudaArch::SM_72: case CudaArch::SM_72:
case CudaArch::SM_75: case CudaArch::SM_75:
case CudaArch::SM_80:
case CudaArch::GFX600: case CudaArch::GFX600:
case CudaArch::GFX601: case CudaArch::GFX601:
case CudaArch::GFX700: case CudaArch::GFX700:
@ -5049,6 +5050,7 @@ static std::pair<unsigned, unsigned> getSMsBlocksPerSM(CodeGenModule &CGM) {
case CudaArch::SM_70: case CudaArch::SM_70:
case CudaArch::SM_72: case CudaArch::SM_72:
case CudaArch::SM_75: case CudaArch::SM_75:
case CudaArch::SM_80:
return {84, 32}; return {84, 32};
case CudaArch::GFX600: case CudaArch::GFX600:
case CudaArch::GFX601: case CudaArch::GFX601:

View File

@ -45,17 +45,22 @@ void CudaInstallationDetector::ParseCudaVersionFile(llvm::StringRef V) {
return; return;
DetectedVersion = join_items(".", VersionParts[0], VersionParts[1]); DetectedVersion = join_items(".", VersionParts[0], VersionParts[1]);
Version = CudaStringToVersion(DetectedVersion); Version = CudaStringToVersion(DetectedVersion);
if (Version != CudaVersion::UNKNOWN) if (Version != CudaVersion::UNKNOWN) {
// TODO(tra): remove the warning once we have all features of 10.2 and 11.0
// implemented.
DetectedVersionIsNotSupported = Version > CudaVersion::LATEST_SUPPORTED;
return; return;
}
Version = CudaVersion::LATEST; Version = CudaVersion::LATEST_SUPPORTED;
DetectedVersionIsNotSupported = true; DetectedVersionIsNotSupported = true;
} }
void CudaInstallationDetector::WarnIfUnsupportedVersion() { void CudaInstallationDetector::WarnIfUnsupportedVersion() {
if (DetectedVersionIsNotSupported) if (DetectedVersionIsNotSupported)
D.Diag(diag::warn_drv_unknown_cuda_version) D.Diag(diag::warn_drv_unknown_cuda_version)
<< DetectedVersion << CudaVersionToString(Version); << DetectedVersion
<< CudaVersionToString(CudaVersion::LATEST_SUPPORTED);
} }
CudaInstallationDetector::CudaInstallationDetector( CudaInstallationDetector::CudaInstallationDetector(
@ -639,24 +644,30 @@ void CudaToolChain::addClangTargetOptions(
// by new PTX version, so we need to raise PTX level to enable them in NVPTX // by new PTX version, so we need to raise PTX level to enable them in NVPTX
// back-end. // back-end.
const char *PtxFeature = nullptr; const char *PtxFeature = nullptr;
switch(CudaInstallation.version()) { switch (CudaInstallation.version()) {
case CudaVersion::CUDA_101: case CudaVersion::CUDA_110:
PtxFeature = "+ptx64"; PtxFeature = "+ptx70";
break; break;
case CudaVersion::CUDA_100: case CudaVersion::CUDA_102:
PtxFeature = "+ptx63"; PtxFeature = "+ptx65";
break; break;
case CudaVersion::CUDA_92: case CudaVersion::CUDA_101:
PtxFeature = "+ptx61"; PtxFeature = "+ptx64";
break; break;
case CudaVersion::CUDA_91: case CudaVersion::CUDA_100:
PtxFeature = "+ptx61"; PtxFeature = "+ptx63";
break; break;
case CudaVersion::CUDA_90: case CudaVersion::CUDA_92:
PtxFeature = "+ptx60"; PtxFeature = "+ptx61";
break; break;
default: case CudaVersion::CUDA_91:
PtxFeature = "+ptx42"; PtxFeature = "+ptx61";
break;
case CudaVersion::CUDA_90:
PtxFeature = "+ptx60";
break;
default:
PtxFeature = "+ptx42";
} }
CC1Args.append({"-target-feature", PtxFeature}); CC1Args.append({"-target-feature", PtxFeature});
if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr, if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,

View File

@ -55,6 +55,8 @@ def SM72 : SubtargetFeature<"sm_72", "SmVersion", "72",
"Target SM 7.2">; "Target SM 7.2">;
def SM75 : SubtargetFeature<"sm_75", "SmVersion", "75", def SM75 : SubtargetFeature<"sm_75", "SmVersion", "75",
"Target SM 7.5">; "Target SM 7.5">;
def SM80 : SubtargetFeature<"sm_80", "SmVersion", "80",
"Target SM 8.0">;
// PTX Versions // PTX Versions
def PTX32 : SubtargetFeature<"ptx32", "PTXVersion", "32", def PTX32 : SubtargetFeature<"ptx32", "PTXVersion", "32",
@ -77,6 +79,10 @@ def PTX63 : SubtargetFeature<"ptx63", "PTXVersion", "63",
"Use PTX version 6.3">; "Use PTX version 6.3">;
def PTX64 : SubtargetFeature<"ptx64", "PTXVersion", "64", def PTX64 : SubtargetFeature<"ptx64", "PTXVersion", "64",
"Use PTX version 6.4">; "Use PTX version 6.4">;
def PTX65 : SubtargetFeature<"ptx65", "PTXVersion", "65",
"Use PTX version 6.5">;
def PTX70 : SubtargetFeature<"ptx70", "PTXVersion", "70",
"Use PTX version 7.0">;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// NVPTX supported processors. // NVPTX supported processors.
@ -100,6 +106,7 @@ def : Proc<"sm_62", [SM62, PTX50]>;
def : Proc<"sm_70", [SM70, PTX60]>; def : Proc<"sm_70", [SM70, PTX60]>;
def : Proc<"sm_72", [SM72, PTX61]>; def : Proc<"sm_72", [SM72, PTX61]>;
def : Proc<"sm_75", [SM75, PTX63]>; def : Proc<"sm_75", [SM75, PTX63]>;
def : Proc<"sm_80", [SM80, PTX70]>;
def NVPTXInstrInfo : InstrInfo { def NVPTXInstrInfo : InstrInfo {
} }