• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "clang/Basic/Cuda.h"
2 
3 #include "llvm/ADT/StringRef.h"
4 #include "llvm/ADT/StringSwitch.h"
5 #include "llvm/Support/ErrorHandling.h"
6 
7 namespace clang {
8 
CudaVersionToString(CudaVersion V)9 const char *CudaVersionToString(CudaVersion V) {
10   switch (V) {
11   case CudaVersion::UNKNOWN:
12     return "unknown";
13   case CudaVersion::CUDA_70:
14     return "7.0";
15   case CudaVersion::CUDA_75:
16     return "7.5";
17   case CudaVersion::CUDA_80:
18     return "8.0";
19   }
20   llvm_unreachable("invalid enum");
21 }
22 
CudaArchToString(CudaArch A)23 const char *CudaArchToString(CudaArch A) {
24   switch (A) {
25   case CudaArch::UNKNOWN:
26     return "unknown";
27   case CudaArch::SM_20:
28     return "sm_20";
29   case CudaArch::SM_21:
30     return "sm_21";
31   case CudaArch::SM_30:
32     return "sm_30";
33   case CudaArch::SM_32:
34     return "sm_32";
35   case CudaArch::SM_35:
36     return "sm_35";
37   case CudaArch::SM_37:
38     return "sm_37";
39   case CudaArch::SM_50:
40     return "sm_50";
41   case CudaArch::SM_52:
42     return "sm_52";
43   case CudaArch::SM_53:
44     return "sm_53";
45   case CudaArch::SM_60:
46     return "sm_60";
47   case CudaArch::SM_61:
48     return "sm_61";
49   case CudaArch::SM_62:
50     return "sm_62";
51   }
52   llvm_unreachable("invalid enum");
53 }
54 
StringToCudaArch(llvm::StringRef S)55 CudaArch StringToCudaArch(llvm::StringRef S) {
56   return llvm::StringSwitch<CudaArch>(S)
57       .Case("sm_20", CudaArch::SM_20)
58       .Case("sm_21", CudaArch::SM_21)
59       .Case("sm_30", CudaArch::SM_30)
60       .Case("sm_32", CudaArch::SM_32)
61       .Case("sm_35", CudaArch::SM_35)
62       .Case("sm_37", CudaArch::SM_37)
63       .Case("sm_50", CudaArch::SM_50)
64       .Case("sm_52", CudaArch::SM_52)
65       .Case("sm_53", CudaArch::SM_53)
66       .Case("sm_60", CudaArch::SM_60)
67       .Case("sm_61", CudaArch::SM_61)
68       .Case("sm_62", CudaArch::SM_62)
69       .Default(CudaArch::UNKNOWN);
70 }
71 
CudaVirtualArchToString(CudaVirtualArch A)72 const char *CudaVirtualArchToString(CudaVirtualArch A) {
73   switch (A) {
74   case CudaVirtualArch::UNKNOWN:
75     return "unknown";
76   case CudaVirtualArch::COMPUTE_20:
77     return "compute_20";
78   case CudaVirtualArch::COMPUTE_30:
79     return "compute_30";
80   case CudaVirtualArch::COMPUTE_32:
81     return "compute_32";
82   case CudaVirtualArch::COMPUTE_35:
83     return "compute_35";
84   case CudaVirtualArch::COMPUTE_37:
85     return "compute_37";
86   case CudaVirtualArch::COMPUTE_50:
87     return "compute_50";
88   case CudaVirtualArch::COMPUTE_52:
89     return "compute_52";
90   case CudaVirtualArch::COMPUTE_53:
91     return "compute_53";
92   case CudaVirtualArch::COMPUTE_60:
93     return "compute_60";
94   case CudaVirtualArch::COMPUTE_61:
95     return "compute_61";
96   case CudaVirtualArch::COMPUTE_62:
97     return "compute_62";
98   }
99   llvm_unreachable("invalid enum");
100 }
101 
StringToCudaVirtualArch(llvm::StringRef S)102 CudaVirtualArch StringToCudaVirtualArch(llvm::StringRef S) {
103   return llvm::StringSwitch<CudaVirtualArch>(S)
104       .Case("compute_20", CudaVirtualArch::COMPUTE_20)
105       .Case("compute_30", CudaVirtualArch::COMPUTE_30)
106       .Case("compute_32", CudaVirtualArch::COMPUTE_32)
107       .Case("compute_35", CudaVirtualArch::COMPUTE_35)
108       .Case("compute_37", CudaVirtualArch::COMPUTE_37)
109       .Case("compute_50", CudaVirtualArch::COMPUTE_50)
110       .Case("compute_52", CudaVirtualArch::COMPUTE_52)
111       .Case("compute_53", CudaVirtualArch::COMPUTE_53)
112       .Case("compute_60", CudaVirtualArch::COMPUTE_60)
113       .Case("compute_61", CudaVirtualArch::COMPUTE_61)
114       .Case("compute_62", CudaVirtualArch::COMPUTE_62)
115       .Default(CudaVirtualArch::UNKNOWN);
116 }
117 
VirtualArchForCudaArch(CudaArch A)118 CudaVirtualArch VirtualArchForCudaArch(CudaArch A) {
119   switch (A) {
120   case CudaArch::UNKNOWN:
121     return CudaVirtualArch::UNKNOWN;
122   case CudaArch::SM_20:
123   case CudaArch::SM_21:
124     return CudaVirtualArch::COMPUTE_20;
125   case CudaArch::SM_30:
126     return CudaVirtualArch::COMPUTE_30;
127   case CudaArch::SM_32:
128     return CudaVirtualArch::COMPUTE_32;
129   case CudaArch::SM_35:
130     return CudaVirtualArch::COMPUTE_35;
131   case CudaArch::SM_37:
132     return CudaVirtualArch::COMPUTE_37;
133   case CudaArch::SM_50:
134     return CudaVirtualArch::COMPUTE_50;
135   case CudaArch::SM_52:
136     return CudaVirtualArch::COMPUTE_52;
137   case CudaArch::SM_53:
138     return CudaVirtualArch::COMPUTE_53;
139   case CudaArch::SM_60:
140     return CudaVirtualArch::COMPUTE_60;
141   case CudaArch::SM_61:
142     return CudaVirtualArch::COMPUTE_61;
143   case CudaArch::SM_62:
144     return CudaVirtualArch::COMPUTE_62;
145   }
146   llvm_unreachable("invalid enum");
147 }
148 
MinVersionForCudaArch(CudaArch A)149 CudaVersion MinVersionForCudaArch(CudaArch A) {
150   switch (A) {
151   case CudaArch::UNKNOWN:
152     return CudaVersion::UNKNOWN;
153   case CudaArch::SM_20:
154   case CudaArch::SM_21:
155   case CudaArch::SM_30:
156   case CudaArch::SM_32:
157   case CudaArch::SM_35:
158   case CudaArch::SM_37:
159   case CudaArch::SM_50:
160   case CudaArch::SM_52:
161   case CudaArch::SM_53:
162     return CudaVersion::CUDA_70;
163   case CudaArch::SM_60:
164   case CudaArch::SM_61:
165   case CudaArch::SM_62:
166     return CudaVersion::CUDA_80;
167   }
168   llvm_unreachable("invalid enum");
169 }
170 
171 } // namespace clang
172