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