1 //===--- Cuda.h - Utilities for compiling CUDA code ------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_CLANG_BASIC_CUDA_H 10 #define LLVM_CLANG_BASIC_CUDA_H 11 12 namespace llvm { 13 class StringRef; 14 class Twine; 15 class VersionTuple; 16 } // namespace llvm 17 18 namespace clang { 19 20 enum class CudaVersion { 21 UNKNOWN, 22 CUDA_70, 23 CUDA_75, 24 CUDA_80, 25 CUDA_90, 26 CUDA_91, 27 CUDA_92, 28 CUDA_100, 29 CUDA_101, 30 CUDA_102, 31 CUDA_110, 32 CUDA_111, 33 CUDA_112, 34 CUDA_113, 35 CUDA_114, 36 CUDA_115, 37 CUDA_116, 38 CUDA_117, 39 CUDA_118, 40 CUDA_120, 41 CUDA_121, 42 FULLY_SUPPORTED = CUDA_118, 43 PARTIALLY_SUPPORTED = 44 CUDA_121, // Partially supported. Proceed with a warning. 45 NEW = 10000, // Too new. Issue a warning, but allow using it. 46 }; 47 const char *CudaVersionToString(CudaVersion V); 48 // Input is "Major.Minor" 49 CudaVersion CudaStringToVersion(const llvm::Twine &S); 50 51 enum class CudaArch { 52 UNUSED, 53 UNKNOWN, 54 SM_20, 55 SM_21, 56 SM_30, 57 SM_32, 58 SM_35, 59 SM_37, 60 SM_50, 61 SM_52, 62 SM_53, 63 SM_60, 64 SM_61, 65 SM_62, 66 SM_70, 67 SM_72, 68 SM_75, 69 SM_80, 70 SM_86, 71 SM_87, 72 SM_89, 73 SM_90, 74 GFX600, 75 GFX601, 76 GFX602, 77 GFX700, 78 GFX701, 79 GFX702, 80 GFX703, 81 GFX704, 82 GFX705, 83 GFX801, 84 GFX802, 85 GFX803, 86 GFX805, 87 GFX810, 88 GFX900, 89 GFX902, 90 GFX904, 91 GFX906, 92 GFX908, 93 GFX909, 94 GFX90a, 95 GFX90c, 96 GFX940, 97 GFX941, 98 GFX942, 99 GFX1010, 100 GFX1011, 101 GFX1012, 102 GFX1013, 103 GFX1030, 104 GFX1031, 105 GFX1032, 106 GFX1033, 107 GFX1034, 108 GFX1035, 109 GFX1036, 110 GFX1100, 111 GFX1101, 112 GFX1102, 113 GFX1103, 114 GFX1150, 115 GFX1151, 116 Generic, // A processor model named 'generic' if the target backend defines a 117 // public one. 118 LAST, 119 120 CudaDefault = CudaArch::SM_35, 121 HIPDefault = CudaArch::GFX803, 122 }; 123 124 static inline bool IsNVIDIAGpuArch(CudaArch A) { 125 return A >= CudaArch::SM_20 && A < CudaArch::GFX600; 126 } 127 128 static inline bool IsAMDGpuArch(CudaArch A) { 129 // Generic processor model is for testing only. 130 return A >= CudaArch::GFX600 && A < CudaArch::Generic; 131 } 132 133 const char *CudaArchToString(CudaArch A); 134 const char *CudaArchToVirtualArchString(CudaArch A); 135 136 // The input should have the form "sm_20". 137 CudaArch StringToCudaArch(llvm::StringRef S); 138 139 /// Get the earliest CudaVersion that supports the given CudaArch. 140 CudaVersion MinVersionForCudaArch(CudaArch A); 141 142 /// Get the latest CudaVersion that supports the given CudaArch. 143 CudaVersion MaxVersionForCudaArch(CudaArch A); 144 145 // Various SDK-dependent features that affect CUDA compilation 146 enum class CudaFeature { 147 // CUDA-9.2+ uses a new API for launching kernels. 148 CUDA_USES_NEW_LAUNCH, 149 // CUDA-10.1+ needs explicit end of GPU binary registration. 150 CUDA_USES_FATBIN_REGISTER_END, 151 }; 152 153 CudaVersion ToCudaVersion(llvm::VersionTuple); 154 bool CudaFeatureEnabled(llvm::VersionTuple, CudaFeature); 155 bool CudaFeatureEnabled(CudaVersion, CudaFeature); 156 157 } // namespace clang 158 159 #endif 160