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 LATEST = CUDA_110, 33 LATEST_SUPPORTED = CUDA_101, 34 }; 35 const char *CudaVersionToString(CudaVersion V); 36 // Input is "Major.Minor" 37 CudaVersion CudaStringToVersion(const llvm::Twine &S); 38 39 enum class CudaArch { 40 UNKNOWN, 41 SM_20, 42 SM_21, 43 SM_30, 44 SM_32, 45 SM_35, 46 SM_37, 47 SM_50, 48 SM_52, 49 SM_53, 50 SM_60, 51 SM_61, 52 SM_62, 53 SM_70, 54 SM_72, 55 SM_75, 56 SM_80, 57 GFX600, 58 GFX601, 59 GFX700, 60 GFX701, 61 GFX702, 62 GFX703, 63 GFX704, 64 GFX801, 65 GFX802, 66 GFX803, 67 GFX810, 68 GFX900, 69 GFX902, 70 GFX904, 71 GFX906, 72 GFX908, 73 GFX909, 74 GFX1010, 75 GFX1011, 76 GFX1012, 77 GFX1030, 78 LAST, 79 }; 80 81 static inline bool IsNVIDIAGpuArch(CudaArch A) { 82 return A >= CudaArch::SM_20 && A < CudaArch::GFX600; 83 } 84 85 static inline bool IsAMDGpuArch(CudaArch A) { 86 return A >= CudaArch::GFX600 && A < CudaArch::LAST; 87 } 88 89 const char *CudaArchToString(CudaArch A); 90 const char *CudaArchToVirtualArchString(CudaArch A); 91 92 // The input should have the form "sm_20". 93 CudaArch StringToCudaArch(llvm::StringRef S); 94 95 /// Get the earliest CudaVersion that supports the given CudaArch. 96 CudaVersion MinVersionForCudaArch(CudaArch A); 97 98 /// Get the latest CudaVersion that supports the given CudaArch. 99 CudaVersion MaxVersionForCudaArch(CudaArch A); 100 101 // Various SDK-dependent features that affect CUDA compilation 102 enum class CudaFeature { 103 // CUDA-9.2+ uses a new API for launching kernels. 104 CUDA_USES_NEW_LAUNCH, 105 // CUDA-10.1+ needs explicit end of GPU binary registration. 106 CUDA_USES_FATBIN_REGISTER_END, 107 }; 108 109 CudaVersion ToCudaVersion(llvm::VersionTuple); 110 bool CudaFeatureEnabled(llvm::VersionTuple, CudaFeature); 111 bool CudaFeatureEnabled(CudaVersion, CudaFeature); 112 113 } // namespace clang 114 115 #endif 116