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