Coverage Report

Created: 2019-07-24 05:18

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