Coverage Report

Created: 2020-10-24 06:27

/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
157
const char *CudaVersionToString(CudaVersion V) {
12
157
  switch (V) {
13
0
  case CudaVersion::UNKNOWN:
14
0
    return "unknown";
15
78
  case CudaVersion::CUDA_70:
16
78
    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
12
  case CudaVersion::CUDA_90:
22
12
    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
3
  case CudaVersion::CUDA_101:
30
3
    return "10.1";
31
3
  case CudaVersion::CUDA_102:
32
3
    return "10.2";
33
13
  case CudaVersion::CUDA_110:
34
13
    return "11.0";
35
0
  }
36
0
  llvm_unreachable("invalid enum");
37
0
}
38
39
41
CudaVersion CudaStringToVersion(const llvm::Twine &S) {
40
41
  return llvm::StringSwitch<CudaVersion>(S.str())
41
41
      .Case("7.0", CudaVersion::CUDA_70)
42
41
      .Case("7.5", CudaVersion::CUDA_75)
43
41
      .Case("8.0", CudaVersion::CUDA_80)
44
41
      .Case("9.0", CudaVersion::CUDA_90)
45
41
      .Case("9.1", CudaVersion::CUDA_91)
46
41
      .Case("9.2", CudaVersion::CUDA_92)
47
41
      .Case("10.0", CudaVersion::CUDA_100)
48
41
      .Case("10.1", CudaVersion::CUDA_101)
49
41
      .Case("10.2", CudaVersion::CUDA_102)
50
41
      .Case("11.0", CudaVersion::CUDA_110)
51
41
      .Default(CudaVersion::UNKNOWN);
52
41
}
53
54
struct CudaArchToStringMap {
55
  CudaArch arch;
56
  const char *arch_name;
57
  const char *virtual_arch_name;
58
};
59
60
#define SM2(sm, ca)                                                            \
61
  { CudaArch::SM_##sm, "sm_" #sm, ca }
62
#define SM(sm) SM2(sm, "compute_" #sm)
63
#define GFX(gpu)                                                               \
64
  { CudaArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn" }
65
CudaArchToStringMap arch_names[] = {
66
    // clang-format off
67
    {CudaArch::UNUSED, "", ""},
68
    SM2(20, "compute_20"), SM2(21, "compute_20"), // Fermi
69
    SM(30), SM(32), SM(35), SM(37),  // Kepler
70
    SM(50), SM(52), SM(53),          // Maxwell
71
    SM(60), SM(61), SM(62),          // Pascal
72
    SM(70), SM(72),                  // Volta
73
    SM(75),                          // Turing
74
    SM(80),                          // Ampere
75
    GFX(600), // tahiti
76
    GFX(601), // pitcairn, verde
77
    GFX(602), // oland, hainan
78
    GFX(700), // kaveri
79
    GFX(701), // hawaii
80
    GFX(702), // 290,290x,R390,R390x
81
    GFX(703), // kabini mullins
82
    GFX(704), // bonaire
83
    GFX(705),
84
    GFX(801), // carrizo
85
    GFX(802), // tonga,iceland
86
    GFX(803), // fiji,polaris10
87
    GFX(805), // tongapro
88
    GFX(810), // stoney
89
    GFX(900), // vega, instinct
90
    GFX(902), GFX(904), GFX(906), GFX(908), GFX(909),
91
    GFX(1010), GFX(1011), GFX(1012), GFX(1030), GFX(1031)
92
    // clang-format on
93
};
94
#undef SM
95
#undef SM2
96
#undef GFX
97
98
1.44k
const char *CudaArchToString(CudaArch A) {
99
1.44k
  auto result = std::find_if(
100
1.44k
      std::begin(arch_names), std::end(arch_names),
101
8.87k
      [A](const CudaArchToStringMap &map) { return A == map.arch; });
102
1.44k
  if (result == std::end(arch_names))
103
1
    return "unknown";
104
1.44k
  return result->arch_name;
105
1.44k
}
106
107
188
const char *CudaArchToVirtualArchString(CudaArch A) {
108
188
  auto result = std::find_if(
109
188
      std::begin(arch_names), std::end(arch_names),
110
1.22k
      [A](const CudaArchToStringMap &map) { return A == map.arch; });
111
188
  if (result == std::end(arch_names))
112
0
    return "unknown";
113
188
  return result->virtual_arch_name;
114
188
}
115
116
1.21k
CudaArch StringToCudaArch(llvm::StringRef S) {
117
1.21k
  auto result = std::find_if(
118
1.21k
      std::begin(arch_names), std::end(arch_names),
119
8.81k
      [S](const CudaArchToStringMap &map) { return S == map.arch_name; });
120
1.21k
  if (result == std::end(arch_names))
121
22
    return CudaArch::UNKNOWN;
122
1.19k
  return result->arch;
123
1.19k
}
124
125
69
CudaVersion MinVersionForCudaArch(CudaArch A) {
126
69
  if (A == CudaArch::UNKNOWN)
127
0
    return CudaVersion::UNKNOWN;
128
129
  // AMD GPUs do not depend on CUDA versions.
130
69
  if (IsAMDGpuArch(A))
131
0
    return CudaVersion::CUDA_70;
132
133
69
  switch (A) {
134
51
  case CudaArch::SM_20:
135
51
  case CudaArch::SM_21:
136
51
  case CudaArch::SM_30:
137
51
  case CudaArch::SM_32:
138
51
  case CudaArch::SM_35:
139
51
  case CudaArch::SM_37:
140
51
  case CudaArch::SM_50:
141
51
  case CudaArch::SM_52:
142
51
  case CudaArch::SM_53:
143
51
    return CudaVersion::CUDA_70;
144
18
  case CudaArch::SM_60:
145
18
  case CudaArch::SM_61:
146
18
  case CudaArch::SM_62:
147
18
    return CudaVersion::CUDA_80;
148
0
  case CudaArch::SM_70:
149
0
    return CudaVersion::CUDA_90;
150
0
  case CudaArch::SM_72:
151
0
    return CudaVersion::CUDA_91;
152
0
  case CudaArch::SM_75:
153
0
    return CudaVersion::CUDA_100;
154
0
  case CudaArch::SM_80:
155
0
    return CudaVersion::CUDA_110;
156
0
  default:
157
0
    llvm_unreachable("invalid enum");
158
69
  }
159
69
}
160
161
69
CudaVersion MaxVersionForCudaArch(CudaArch A) {
162
  // AMD GPUs do not depend on CUDA versions.
163
69
  if (IsAMDGpuArch(A))
164
0
    return CudaVersion::LATEST;
165
166
69
  switch (A) {
167
0
  case CudaArch::UNKNOWN:
168
0
    return CudaVersion::UNKNOWN;
169
23
  case CudaArch::SM_20:
170
23
  case CudaArch::SM_21:
171
23
    return CudaVersion::CUDA_80;
172
46
  default:
173
46
    return CudaVersion::LATEST;
174
69
  }
175
69
}
176
177
1.96k
CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
178
1.96k
  int IVer =
179
1.96k
      Version.getMajor() * 10 + Version.getMinor().getValueOr(0);
180
1.96k
  switch(IVer) {
181
4
  case 70:
182
4
    return CudaVersion::CUDA_70;
183
0
  case 75:
184
0
    return CudaVersion::CUDA_75;
185
86
  case 80:
186
86
    return CudaVersion::CUDA_80;
187
0
  case 90:
188
0
    return CudaVersion::CUDA_90;
189
0
  case 91:
190
0
    return CudaVersion::CUDA_91;
191
50
  case 92:
192
50
    return CudaVersion::CUDA_92;
193
0
  case 100:
194
0
    return CudaVersion::CUDA_100;
195
0
  case 101:
196
0
    return CudaVersion::CUDA_101;
197
0
  case 102:
198
0
    return CudaVersion::CUDA_102;
199
0
  case 110:
200
0
    return CudaVersion::CUDA_110;
201
1.82k
  default:
202
1.82k
    return CudaVersion::UNKNOWN;
203
1.96k
  }
204
1.96k
}
205
206
1.95k
bool CudaFeatureEnabled(llvm::VersionTuple  Version, CudaFeature Feature) {
207
1.95k
  return CudaFeatureEnabled(ToCudaVersion(Version), Feature);
208
1.95k
}
209
210
1.95k
bool CudaFeatureEnabled(CudaVersion Version, CudaFeature Feature) {
211
1.95k
  switch (Feature) {
212
1.94k
  case CudaFeature::CUDA_USES_NEW_LAUNCH:
213
1.94k
    return Version >= CudaVersion::CUDA_92;
214
7
  case CudaFeature::CUDA_USES_FATBIN_REGISTER_END:
215
7
    return Version >= CudaVersion::CUDA_101;
216
0
  }
217
0
  llvm_unreachable("Unknown CUDA feature.");
218
0
}
219
} // namespace clang