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