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