Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Cuda.cpp
Line
Count
Source (jump to first uncovered line)
1
#include "clang/Basic/Cuda.h"
2
3
#include "llvm/ADT/StringRef.h"
4
#include "llvm/ADT/StringSwitch.h"
5
#include "llvm/ADT/Twine.h"
6
#include "llvm/Support/ErrorHandling.h"
7
#include "llvm/Support/VersionTuple.h"
8
9
namespace clang {
10
11
136
const char *CudaVersionToString(CudaVersion V) {
12
136
  switch (V) {
13
0
  case CudaVersion::UNKNOWN:
14
0
    return "unknown";
15
74
  case CudaVersion::CUDA_70:
16
74
    return "7.0";
17
0
  case CudaVersion::CUDA_75:
18
0
    return "7.5";
19
48
  case CudaVersion::CUDA_80:
20
48
    return "8.0";
21
3
  case CudaVersion::CUDA_90:
22
3
    return "9.0";
23
0
  case CudaVersion::CUDA_91:
24
0
    return "9.1";
25
0
  case CudaVersion::CUDA_92:
26
0
    return "9.2";
27
0
  case CudaVersion::CUDA_100:
28
0
    return "10.0";
29
11
  case CudaVersion::CUDA_101:
30
11
    return "10.1";
31
0
  }
32
0
  llvm_unreachable("invalid enum");
33
0
}
34
35
32
CudaVersion CudaStringToVersion(const llvm::Twine &S) {
36
32
  return llvm::StringSwitch<CudaVersion>(S.str())
37
32
      .Case("7.0", CudaVersion::CUDA_70)
38
32
      .Case("7.5", CudaVersion::CUDA_75)
39
32
      .Case("8.0", CudaVersion::CUDA_80)
40
32
      .Case("9.0", CudaVersion::CUDA_90)
41
32
      .Case("9.1", CudaVersion::CUDA_91)
42
32
      .Case("9.2", CudaVersion::CUDA_92)
43
32
      .Case("10.0", CudaVersion::CUDA_100)
44
32
      .Case("10.1", CudaVersion::CUDA_101)
45
32
      .Default(CudaVersion::UNKNOWN);
46
32
}
47
48
2.76k
const char *CudaArchToString(CudaArch A) {
49
2.76k
  switch (A) {
50
0
  case CudaArch::LAST:
51
0
    break;
52
5
  case CudaArch::UNKNOWN:
53
5
    return "unknown";
54
1.04k
  case CudaArch::SM_20:
55
1.04k
    return "sm_20";
56
15
  case CudaArch::SM_21:
57
15
    return "sm_21";
58
101
  case CudaArch::SM_30:
59
101
    return "sm_30";
60
10
  case CudaArch::SM_32:
61
10
    return "sm_32";
62
143
  case CudaArch::SM_35:
63
143
    return "sm_35";
64
11
  case CudaArch::SM_37:
65
11
    return "sm_37";
66
22
  case CudaArch::SM_50:
67
22
    return "sm_50";
68
11
  case CudaArch::SM_52:
69
11
    return "sm_52";
70
77
  case CudaArch::SM_53:
71
77
    return "sm_53";
72
535
  case CudaArch::SM_60:
73
535
    return "sm_60";
74
80
  case CudaArch::SM_61:
75
80
    return "sm_61";
76
7
  case CudaArch::SM_62:
77
7
    return "sm_62";
78
319
  case CudaArch::SM_70:
79
319
    return "sm_70";
80
3
  case CudaArch::SM_72:
81
3
    return "sm_72";
82
239
  case CudaArch::SM_75:
83
239
    return "sm_75";
84
4
  case CudaArch::GFX600: // tahiti
85
4
    return "gfx600";
86
4
  case CudaArch::GFX601: // pitcairn, verde, oland,hainan
87
4
    return "gfx601";
88
4
  case CudaArch::GFX700: // kaveri
89
4
    return "gfx700";
90
4
  case CudaArch::GFX701: // hawaii
91
4
    return "gfx701";
92
4
  case CudaArch::GFX702: // 290,290x,R390,R390x
93
4
    return "gfx702";
94
4
  case CudaArch::GFX703: // kabini mullins
95
4
    return "gfx703";
96
4
  case CudaArch::GFX704: // bonaire
97
4
    return "gfx704";
98
4
  case CudaArch::GFX801: // carrizo
99
4
    return "gfx801";
100
4
  case CudaArch::GFX802: // tonga,iceland
101
4
    return "gfx802";
102
41
  case CudaArch::GFX803: // fiji,polaris10
103
41
    return "gfx803";
104
4
  case CudaArch::GFX810: // stoney
105
4
    return "gfx810";
106
45
  case CudaArch::GFX900: // vega, instinct
107
45
    return "gfx900";
108
4
  case CudaArch::GFX902: // TBA
109
4
    return "gfx902";
110
1
  case CudaArch::GFX904: // TBA
111
1
    return "gfx904";
112
2
  case CudaArch::GFX906: // TBA
113
2
    return "gfx906";
114
4
  case CudaArch::GFX908: // TBA
115
4
    return "gfx908";
116
1
  case CudaArch::GFX909: // TBA
117
1
    return "gfx909";
118
1
  case CudaArch::GFX1010: // TBA
119
1
    return "gfx1010";
120
1
  case CudaArch::GFX1011: // TBA
121
1
    return "gfx1011";
122
1
  case CudaArch::GFX1012: // TBA
123
1
    return "gfx1012";
124
0
  }
125
0
  llvm_unreachable("invalid enum");
126
0
}
127
128
1.27k
CudaArch StringToCudaArch(llvm::StringRef S) {
129
1.27k
  return llvm::StringSwitch<CudaArch>(S)
130
1.27k
      .Case("sm_20", CudaArch::SM_20)
131
1.27k
      .Case("sm_21", CudaArch::SM_21)
132
1.27k
      .Case("sm_30", CudaArch::SM_30)
133
1.27k
      .Case("sm_32", CudaArch::SM_32)
134
1.27k
      .Case("sm_35", CudaArch::SM_35)
135
1.27k
      .Case("sm_37", CudaArch::SM_37)
136
1.27k
      .Case("sm_50", CudaArch::SM_50)
137
1.27k
      .Case("sm_52", CudaArch::SM_52)
138
1.27k
      .Case("sm_53", CudaArch::SM_53)
139
1.27k
      .Case("sm_60", CudaArch::SM_60)
140
1.27k
      .Case("sm_61", CudaArch::SM_61)
141
1.27k
      .Case("sm_62", CudaArch::SM_62)
142
1.27k
      .Case("sm_70", CudaArch::SM_70)
143
1.27k
      .Case("sm_72", CudaArch::SM_72)
144
1.27k
      .Case("sm_75", CudaArch::SM_75)
145
1.27k
      .Case("gfx600", CudaArch::GFX600)
146
1.27k
      .Case("gfx601", CudaArch::GFX601)
147
1.27k
      .Case("gfx700", CudaArch::GFX700)
148
1.27k
      .Case("gfx701", CudaArch::GFX701)
149
1.27k
      .Case("gfx702", CudaArch::GFX702)
150
1.27k
      .Case("gfx703", CudaArch::GFX703)
151
1.27k
      .Case("gfx704", CudaArch::GFX704)
152
1.27k
      .Case("gfx801", CudaArch::GFX801)
153
1.27k
      .Case("gfx802", CudaArch::GFX802)
154
1.27k
      .Case("gfx803", CudaArch::GFX803)
155
1.27k
      .Case("gfx810", CudaArch::GFX810)
156
1.27k
      .Case("gfx900", CudaArch::GFX900)
157
1.27k
      .Case("gfx902", CudaArch::GFX902)
158
1.27k
      .Case("gfx904", CudaArch::GFX904)
159
1.27k
      .Case("gfx906", CudaArch::GFX906)
160
1.27k
      .Case("gfx908", CudaArch::GFX908)
161
1.27k
      .Case("gfx909", CudaArch::GFX909)
162
1.27k
      .Case("gfx1010", CudaArch::GFX1010)
163
1.27k
      .Case("gfx1011", CudaArch::GFX1011)
164
1.27k
      .Case("gfx1012", CudaArch::GFX1012)
165
1.27k
      .Default(CudaArch::UNKNOWN);
166
1.27k
}
167
168
175
const char *CudaVirtualArchToString(CudaVirtualArch A) {
169
175
  switch (A) {
170
0
  case CudaVirtualArch::UNKNOWN:
171
0
    return "unknown";
172
96
  case CudaVirtualArch::COMPUTE_20:
173
96
    return "compute_20";
174
14
  case CudaVirtualArch::COMPUTE_30:
175
14
    return "compute_30";
176
2
  case CudaVirtualArch::COMPUTE_32:
177
2
    return "compute_32";
178
26
  case CudaVirtualArch::COMPUTE_35:
179
26
    return "compute_35";
180
2
  case CudaVirtualArch::COMPUTE_37:
181
2
    return "compute_37";
182
5
  case CudaVirtualArch::COMPUTE_50:
183
5
    return "compute_50";
184
2
  case CudaVirtualArch::COMPUTE_52:
185
2
    return "compute_52";
186
1
  case CudaVirtualArch::COMPUTE_53:
187
1
    return "compute_53";
188
9
  case CudaVirtualArch::COMPUTE_60:
189
9
    return "compute_60";
190
2
  case CudaVirtualArch::COMPUTE_61:
191
2
    return "compute_61";
192
1
  case CudaVirtualArch::COMPUTE_62:
193
1
    return "compute_62";
194
1
  case CudaVirtualArch::COMPUTE_70:
195
1
    return "compute_70";
196
0
  case CudaVirtualArch::COMPUTE_72:
197
0
    return "compute_72";
198
0
  case CudaVirtualArch::COMPUTE_75:
199
0
    return "compute_75";
200
14
  case CudaVirtualArch::COMPUTE_AMDGCN:
201
14
    return "compute_amdgcn";
202
0
  }
203
0
  llvm_unreachable("invalid enum");
204
0
}
205
206
0
CudaVirtualArch StringToCudaVirtualArch(llvm::StringRef S) {
207
0
  return llvm::StringSwitch<CudaVirtualArch>(S)
208
0
      .Case("compute_20", CudaVirtualArch::COMPUTE_20)
209
0
      .Case("compute_30", CudaVirtualArch::COMPUTE_30)
210
0
      .Case("compute_32", CudaVirtualArch::COMPUTE_32)
211
0
      .Case("compute_35", CudaVirtualArch::COMPUTE_35)
212
0
      .Case("compute_37", CudaVirtualArch::COMPUTE_37)
213
0
      .Case("compute_50", CudaVirtualArch::COMPUTE_50)
214
0
      .Case("compute_52", CudaVirtualArch::COMPUTE_52)
215
0
      .Case("compute_53", CudaVirtualArch::COMPUTE_53)
216
0
      .Case("compute_60", CudaVirtualArch::COMPUTE_60)
217
0
      .Case("compute_61", CudaVirtualArch::COMPUTE_61)
218
0
      .Case("compute_62", CudaVirtualArch::COMPUTE_62)
219
0
      .Case("compute_70", CudaVirtualArch::COMPUTE_70)
220
0
      .Case("compute_72", CudaVirtualArch::COMPUTE_72)
221
0
      .Case("compute_75", CudaVirtualArch::COMPUTE_75)
222
0
      .Case("compute_amdgcn", CudaVirtualArch::COMPUTE_AMDGCN)
223
0
      .Default(CudaVirtualArch::UNKNOWN);
224
0
}
225
226
175
CudaVirtualArch VirtualArchForCudaArch(CudaArch A) {
227
175
  switch (A) {
228
0
  case CudaArch::LAST:
229
0
    break;
230
0
  case CudaArch::UNKNOWN:
231
0
    return CudaVirtualArch::UNKNOWN;
232
96
  case CudaArch::SM_20:
233
96
  case CudaArch::SM_21:
234
96
    return CudaVirtualArch::COMPUTE_20;
235
96
  case CudaArch::SM_30:
236
14
    return CudaVirtualArch::COMPUTE_30;
237
96
  case CudaArch::SM_32:
238
2
    return CudaVirtualArch::COMPUTE_32;
239
96
  case CudaArch::SM_35:
240
26
    return CudaVirtualArch::COMPUTE_35;
241
96
  case CudaArch::SM_37:
242
2
    return CudaVirtualArch::COMPUTE_37;
243
96
  case CudaArch::SM_50:
244
5
    return CudaVirtualArch::COMPUTE_50;
245
96
  case CudaArch::SM_52:
246
2
    return CudaVirtualArch::COMPUTE_52;
247
96
  case CudaArch::SM_53:
248
1
    return CudaVirtualArch::COMPUTE_53;
249
96
  case CudaArch::SM_60:
250
9
    return CudaVirtualArch::COMPUTE_60;
251
96
  case CudaArch::SM_61:
252
2
    return CudaVirtualArch::COMPUTE_61;
253
96
  case CudaArch::SM_62:
254
1
    return CudaVirtualArch::COMPUTE_62;
255
96
  case CudaArch::SM_70:
256
1
    return CudaVirtualArch::COMPUTE_70;
257
96
  case CudaArch::SM_72:
258
0
    return CudaVirtualArch::COMPUTE_72;
259
96
  case CudaArch::SM_75:
260
0
    return CudaVirtualArch::COMPUTE_75;
261
96
  case CudaArch::GFX600:
262
14
  case CudaArch::GFX601:
263
14
  case CudaArch::GFX700:
264
14
  case CudaArch::GFX701:
265
14
  case CudaArch::GFX702:
266
14
  case CudaArch::GFX703:
267
14
  case CudaArch::GFX704:
268
14
  case CudaArch::GFX801:
269
14
  case CudaArch::GFX802:
270
14
  case CudaArch::GFX803:
271
14
  case CudaArch::GFX810:
272
14
  case CudaArch::GFX900:
273
14
  case CudaArch::GFX902:
274
14
  case CudaArch::GFX904:
275
14
  case CudaArch::GFX906:
276
14
  case CudaArch::GFX908:
277
14
  case CudaArch::GFX909:
278
14
  case CudaArch::GFX1010:
279
14
  case CudaArch::GFX1011:
280
14
  case CudaArch::GFX1012:
281
14
    return CudaVirtualArch::COMPUTE_AMDGCN;
282
0
  }
283
0
  llvm_unreachable("invalid enum");
284
0
}
285
286
109
CudaVersion MinVersionForCudaArch(CudaArch A) {
287
109
  switch (A) {
288
0
  case CudaArch::LAST:
289
0
    break;
290
0
  case CudaArch::UNKNOWN:
291
0
    return CudaVersion::UNKNOWN;
292
73
  case CudaArch::SM_20:
293
73
  case CudaArch::SM_21:
294
73
  case CudaArch::SM_30:
295
73
  case CudaArch::SM_32:
296
73
  case CudaArch::SM_35:
297
73
  case CudaArch::SM_37:
298
73
  case CudaArch::SM_50:
299
73
  case CudaArch::SM_52:
300
73
  case CudaArch::SM_53:
301
73
    return CudaVersion::CUDA_70;
302
73
  case CudaArch::SM_60:
303
24
  case CudaArch::SM_61:
304
24
  case CudaArch::SM_62:
305
24
    return CudaVersion::CUDA_80;
306
24
  case CudaArch::SM_70:
307
4
    return CudaVersion::CUDA_90;
308
24
  case CudaArch::SM_72:
309
4
    return CudaVersion::CUDA_91;
310
24
  case CudaArch::SM_75:
311
4
    return CudaVersion::CUDA_100;
312
24
  case CudaArch::GFX600:
313
0
  case CudaArch::GFX601:
314
0
  case CudaArch::GFX700:
315
0
  case CudaArch::GFX701:
316
0
  case CudaArch::GFX702:
317
0
  case CudaArch::GFX703:
318
0
  case CudaArch::GFX704:
319
0
  case CudaArch::GFX801:
320
0
  case CudaArch::GFX802:
321
0
  case CudaArch::GFX803:
322
0
  case CudaArch::GFX810:
323
0
  case CudaArch::GFX900:
324
0
  case CudaArch::GFX902:
325
0
  case CudaArch::GFX904:
326
0
  case CudaArch::GFX906:
327
0
  case CudaArch::GFX908:
328
0
  case CudaArch::GFX909:
329
0
  case CudaArch::GFX1010:
330
0
  case CudaArch::GFX1011:
331
0
  case CudaArch::GFX1012:
332
0
    return CudaVersion::CUDA_70;
333
0
  }
334
0
  llvm_unreachable("invalid enum");
335
0
}
336
337
105
CudaVersion MaxVersionForCudaArch(CudaArch A) {
338
105
  switch (A) {
339
0
  case CudaArch::UNKNOWN:
340
0
    return CudaVersion::UNKNOWN;
341
21
  case CudaArch::SM_20:
342
21
  case CudaArch::SM_21:
343
21
  case CudaArch::GFX600:
344
21
  case CudaArch::GFX601:
345
21
  case CudaArch::GFX700:
346
21
  case CudaArch::GFX701:
347
21
  case CudaArch::GFX702:
348
21
  case CudaArch::GFX703:
349
21
  case CudaArch::GFX704:
350
21
  case CudaArch::GFX801:
351
21
  case CudaArch::GFX802:
352
21
  case CudaArch::GFX803:
353
21
  case CudaArch::GFX810:
354
21
  case CudaArch::GFX900:
355
21
  case CudaArch::GFX902:
356
21
  case CudaArch::GFX1010:
357
21
  case CudaArch::GFX1011:
358
21
  case CudaArch::GFX1012:
359
21
    return CudaVersion::CUDA_80;
360
84
  default:
361
84
    return CudaVersion::LATEST;
362
105
  }
363
105
}
364
365
1.74k
static CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
366
1.74k
  int IVer =
367
1.74k
      Version.getMajor() * 10 + Version.getMinor().getValueOr(0);
368
1.74k
  switch(IVer) {
369
0
  case 70:
370
0
    return CudaVersion::CUDA_70;
371
0
  case 75:
372
0
    return CudaVersion::CUDA_75;
373
45
  case 80:
374
45
    return CudaVersion::CUDA_80;
375
0
  case 90:
376
0
    return CudaVersion::CUDA_90;
377
0
  case 91:
378
0
    return CudaVersion::CUDA_91;
379
39
  case 92:
380
39
    return CudaVersion::CUDA_92;
381
0
  case 100:
382
0
    return CudaVersion::CUDA_100;
383
0
  case 101:
384
0
    return CudaVersion::CUDA_101;
385
1.65k
  default:
386
1.65k
    return CudaVersion::UNKNOWN;
387
1.74k
  }
388
1.74k
}
389
390
1.74k
bool CudaFeatureEnabled(llvm::VersionTuple  Version, CudaFeature Feature) {
391
1.74k
  return CudaFeatureEnabled(ToCudaVersion(Version), Feature);
392
1.74k
}
393
394
1.74k
bool CudaFeatureEnabled(CudaVersion Version, CudaFeature Feature) {
395
1.74k
  switch (Feature) {
396
1.74k
  case CudaFeature::CUDA_USES_NEW_LAUNCH:
397
1.74k
    return Version >= CudaVersion::CUDA_92;
398
2
  case CudaFeature::CUDA_USES_FATBIN_REGISTER_END:
399
2
    return Version >= CudaVersion::CUDA_101;
400
0
  }
401
0
  llvm_unreachable("Unknown CUDA feature.");
402
0
}
403
} // namespace clang