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   CUDA_122,
43   CUDA_123,
44   FULLY_SUPPORTED = CUDA_123,
45   PARTIALLY_SUPPORTED =
46       CUDA_123, // Partially supported. Proceed with a warning.
47   NEW = 10000,  // Too new. Issue a warning, but allow using it.
48 };
49 const char *CudaVersionToString(CudaVersion V);
50 // Input is "Major.Minor"
51 CudaVersion CudaStringToVersion(const llvm::Twine &S);
52 
53 enum class CudaArch {
54   UNUSED,
55   UNKNOWN,
56   SM_20,
57   SM_21,
58   SM_30,
59   SM_32,
60   SM_35,
61   SM_37,
62   SM_50,
63   SM_52,
64   SM_53,
65   SM_60,
66   SM_61,
67   SM_62,
68   SM_70,
69   SM_72,
70   SM_75,
71   SM_80,
72   SM_86,
73   SM_87,
74   SM_89,
75   SM_90,
76   SM_90a,
77   GFX600,
78   GFX601,
79   GFX602,
80   GFX700,
81   GFX701,
82   GFX702,
83   GFX703,
84   GFX704,
85   GFX705,
86   GFX801,
87   GFX802,
88   GFX803,
89   GFX805,
90   GFX810,
91   GFX900,
92   GFX902,
93   GFX904,
94   GFX906,
95   GFX908,
96   GFX909,
97   GFX90a,
98   GFX90c,
99   GFX940,
100   GFX941,
101   GFX942,
102   GFX1010,
103   GFX1011,
104   GFX1012,
105   GFX1013,
106   GFX1030,
107   GFX1031,
108   GFX1032,
109   GFX1033,
110   GFX1034,
111   GFX1035,
112   GFX1036,
113   GFX1100,
114   GFX1101,
115   GFX1102,
116   GFX1103,
117   GFX1150,
118   GFX1151,
119   GFX1200,
120   GFX1201,
121   Generic, // A processor model named 'generic' if the target backend defines a
122            // public one.
123   LAST,
124 
125   CudaDefault = CudaArch::SM_52,
126   HIPDefault = CudaArch::GFX803,
127 };
128 
129 static inline bool IsNVIDIAGpuArch(CudaArch A) {
130   return A >= CudaArch::SM_20 && A < CudaArch::GFX600;
131 }
132 
133 static inline bool IsAMDGpuArch(CudaArch A) {
134   // Generic processor model is for testing only.
135   return A >= CudaArch::GFX600 && A < CudaArch::Generic;
136 }
137 
138 const char *CudaArchToString(CudaArch A);
139 const char *CudaArchToVirtualArchString(CudaArch A);
140 
141 // The input should have the form "sm_20".
142 CudaArch StringToCudaArch(llvm::StringRef S);
143 
144 /// Get the earliest CudaVersion that supports the given CudaArch.
145 CudaVersion MinVersionForCudaArch(CudaArch A);
146 
147 /// Get the latest CudaVersion that supports the given CudaArch.
148 CudaVersion MaxVersionForCudaArch(CudaArch A);
149 
150 //  Various SDK-dependent features that affect CUDA compilation
151 enum class CudaFeature {
152   // CUDA-9.2+ uses a new API for launching kernels.
153   CUDA_USES_NEW_LAUNCH,
154   // CUDA-10.1+ needs explicit end of GPU binary registration.
155   CUDA_USES_FATBIN_REGISTER_END,
156 };
157 
158 CudaVersion ToCudaVersion(llvm::VersionTuple);
159 bool CudaFeatureEnabled(llvm::VersionTuple, CudaFeature);
160 bool CudaFeatureEnabled(CudaVersion, CudaFeature);
161 
162 } // namespace clang
163 
164 #endif
165