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