clang  15.0.0git
Cuda.cpp
Go to the documentation of this file.
1 //===--- Cuda.cpp - Cuda Tool and ToolChain Implementations -----*- 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 #include "Cuda.h"
10 #include "CommonArgs.h"
11 #include "clang/Basic/Cuda.h"
12 #include "clang/Config/config.h"
14 #include "clang/Driver/Distro.h"
15 #include "clang/Driver/Driver.h"
17 #include "clang/Driver/InputInfo.h"
18 #include "clang/Driver/Options.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/StringExtras.h"
21 #include "llvm/Option/ArgList.h"
22 #include "llvm/Support/FileSystem.h"
23 #include "llvm/Support/Host.h"
24 #include "llvm/Support/Path.h"
25 #include "llvm/Support/Process.h"
26 #include "llvm/Support/Program.h"
27 #include "llvm/Support/TargetParser.h"
28 #include "llvm/Support/VirtualFileSystem.h"
29 #include <system_error>
30 
31 using namespace clang::driver;
32 using namespace clang::driver::toolchains;
33 using namespace clang::driver::tools;
34 using namespace clang;
35 using namespace llvm::opt;
36 
37 namespace {
38 
39 CudaVersion getCudaVersion(uint32_t raw_version) {
40  if (raw_version < 7050)
41  return CudaVersion::CUDA_70;
42  if (raw_version < 8000)
43  return CudaVersion::CUDA_75;
44  if (raw_version < 9000)
45  return CudaVersion::CUDA_80;
46  if (raw_version < 9010)
47  return CudaVersion::CUDA_90;
48  if (raw_version < 9020)
49  return CudaVersion::CUDA_91;
50  if (raw_version < 10000)
51  return CudaVersion::CUDA_92;
52  if (raw_version < 10010)
53  return CudaVersion::CUDA_100;
54  if (raw_version < 10020)
55  return CudaVersion::CUDA_101;
56  if (raw_version < 11000)
57  return CudaVersion::CUDA_102;
58  if (raw_version < 11010)
59  return CudaVersion::CUDA_110;
60  if (raw_version < 11020)
61  return CudaVersion::CUDA_111;
62  if (raw_version < 11030)
63  return CudaVersion::CUDA_112;
64  if (raw_version < 11040)
65  return CudaVersion::CUDA_113;
66  if (raw_version < 11050)
67  return CudaVersion::CUDA_114;
68  if (raw_version < 11060)
69  return CudaVersion::CUDA_115;
70  return CudaVersion::NEW;
71 }
72 
73 CudaVersion parseCudaHFile(llvm::StringRef Input) {
74  // Helper lambda which skips the words if the line starts with them or returns
75  // None otherwise.
76  auto StartsWithWords =
77  [](llvm::StringRef Line,
79  for (StringRef word : words) {
80  if (!Line.consume_front(word))
81  return {};
82  Line = Line.ltrim();
83  }
84  return Line;
85  };
86 
87  Input = Input.ltrim();
88  while (!Input.empty()) {
89  if (auto Line =
90  StartsWithWords(Input.ltrim(), {"#", "define", "CUDA_VERSION"})) {
91  uint32_t RawVersion;
92  Line->consumeInteger(10, RawVersion);
93  return getCudaVersion(RawVersion);
94  }
95  // Find next non-empty line.
96  Input = Input.drop_front(Input.find_first_of("\n\r")).ltrim();
97  }
98  return CudaVersion::UNKNOWN;
99 }
100 } // namespace
101 
103  if (Version > CudaVersion::PARTIALLY_SUPPORTED) {
104  std::string VersionString = CudaVersionToString(Version);
105  if (!VersionString.empty())
106  VersionString.insert(0, " ");
107  D.Diag(diag::warn_drv_new_cuda_version)
108  << VersionString
111  } else if (Version > CudaVersion::FULLY_SUPPORTED)
112  D.Diag(diag::warn_drv_partially_supported_cuda_version)
113  << CudaVersionToString(Version);
114 }
115 
117  const Driver &D, const llvm::Triple &HostTriple,
118  const llvm::opt::ArgList &Args)
119  : D(D) {
120  struct Candidate {
121  std::string Path;
122  bool StrictChecking;
123 
124  Candidate(std::string Path, bool StrictChecking = false)
125  : Path(Path), StrictChecking(StrictChecking) {}
126  };
127  SmallVector<Candidate, 4> Candidates;
128 
129  // In decreasing order so we prefer newer versions to older versions.
130  std::initializer_list<const char *> Versions = {"8.0", "7.5", "7.0"};
131  auto &FS = D.getVFS();
132 
133  if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) {
134  Candidates.emplace_back(
135  Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str());
136  } else if (HostTriple.isOSWindows()) {
137  for (const char *Ver : Versions)
138  Candidates.emplace_back(
139  D.SysRoot + "/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v" +
140  Ver);
141  } else {
142  if (!Args.hasArg(clang::driver::options::OPT_cuda_path_ignore_env)) {
143  // Try to find ptxas binary. If the executable is located in a directory
144  // called 'bin/', its parent directory might be a good guess for a valid
145  // CUDA installation.
146  // However, some distributions might installs 'ptxas' to /usr/bin. In that
147  // case the candidate would be '/usr' which passes the following checks
148  // because '/usr/include' exists as well. To avoid this case, we always
149  // check for the directory potentially containing files for libdevice,
150  // even if the user passes -nocudalib.
151  if (llvm::ErrorOr<std::string> ptxas =
152  llvm::sys::findProgramByName("ptxas")) {
153  SmallString<256> ptxasAbsolutePath;
154  llvm::sys::fs::real_path(*ptxas, ptxasAbsolutePath);
155 
156  StringRef ptxasDir = llvm::sys::path::parent_path(ptxasAbsolutePath);
157  if (llvm::sys::path::filename(ptxasDir) == "bin")
158  Candidates.emplace_back(
159  std::string(llvm::sys::path::parent_path(ptxasDir)),
160  /*StrictChecking=*/true);
161  }
162  }
163 
164  Candidates.emplace_back(D.SysRoot + "/usr/local/cuda");
165  for (const char *Ver : Versions)
166  Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
167 
168  Distro Dist(FS, llvm::Triple(llvm::sys::getProcessTriple()));
169  if (Dist.IsDebian() || Dist.IsUbuntu())
170  // Special case for Debian to have nvidia-cuda-toolkit work
171  // out of the box. More info on http://bugs.debian.org/882505
172  Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");
173  }
174 
175  bool NoCudaLib = Args.hasArg(options::OPT_nogpulib);
176 
177  for (const auto &Candidate : Candidates) {
178  InstallPath = Candidate.Path;
179  if (InstallPath.empty() || !FS.exists(InstallPath))
180  continue;
181 
182  BinPath = InstallPath + "/bin";
183  IncludePath = InstallPath + "/include";
184  LibDevicePath = InstallPath + "/nvvm/libdevice";
185 
186  if (!(FS.exists(IncludePath) && FS.exists(BinPath)))
187  continue;
188  bool CheckLibDevice = (!NoCudaLib || Candidate.StrictChecking);
189  if (CheckLibDevice && !FS.exists(LibDevicePath))
190  continue;
191 
192  // On Linux, we have both lib and lib64 directories, and we need to choose
193  // based on our triple. On MacOS, we have only a lib directory.
194  //
195  // It's sufficient for our purposes to be flexible: If both lib and lib64
196  // exist, we choose whichever one matches our triple. Otherwise, if only
197  // lib exists, we use it.
198  if (HostTriple.isArch64Bit() && FS.exists(InstallPath + "/lib64"))
199  LibPath = InstallPath + "/lib64";
200  else if (FS.exists(InstallPath + "/lib"))
201  LibPath = InstallPath + "/lib";
202  else
203  continue;
204 
205  Version = CudaVersion::UNKNOWN;
206  if (auto CudaHFile = FS.getBufferForFile(InstallPath + "/include/cuda.h"))
207  Version = parseCudaHFile((*CudaHFile)->getBuffer());
208  // As the last resort, make an educated guess between CUDA-7.0, which had
209  // old-style libdevice bitcode, and an unknown recent CUDA version.
210  if (Version == CudaVersion::UNKNOWN) {
211  Version = FS.exists(LibDevicePath + "/libdevice.10.bc")
214  }
215 
216  if (Version >= CudaVersion::CUDA_90) {
217  // CUDA-9+ uses single libdevice file for all GPU variants.
218  std::string FilePath = LibDevicePath + "/libdevice.10.bc";
219  if (FS.exists(FilePath)) {
220  for (int Arch = (int)CudaArch::SM_30, E = (int)CudaArch::LAST; Arch < E;
221  ++Arch) {
222  CudaArch GpuArch = static_cast<CudaArch>(Arch);
223  if (!IsNVIDIAGpuArch(GpuArch))
224  continue;
225  std::string GpuArchName(CudaArchToString(GpuArch));
226  LibDeviceMap[GpuArchName] = FilePath;
227  }
228  }
229  } else {
230  std::error_code EC;
231  for (llvm::vfs::directory_iterator LI = FS.dir_begin(LibDevicePath, EC),
232  LE;
233  !EC && LI != LE; LI = LI.increment(EC)) {
234  StringRef FilePath = LI->path();
235  StringRef FileName = llvm::sys::path::filename(FilePath);
236  // Process all bitcode filenames that look like
237  // libdevice.compute_XX.YY.bc
238  const StringRef LibDeviceName = "libdevice.";
239  if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc")))
240  continue;
241  StringRef GpuArch = FileName.slice(
242  LibDeviceName.size(), FileName.find('.', LibDeviceName.size()));
243  LibDeviceMap[GpuArch] = FilePath.str();
244  // Insert map entries for specific devices with this compute
245  // capability. NVCC's choice of the libdevice library version is
246  // rather peculiar and depends on the CUDA version.
247  if (GpuArch == "compute_20") {
248  LibDeviceMap["sm_20"] = std::string(FilePath);
249  LibDeviceMap["sm_21"] = std::string(FilePath);
250  LibDeviceMap["sm_32"] = std::string(FilePath);
251  } else if (GpuArch == "compute_30") {
252  LibDeviceMap["sm_30"] = std::string(FilePath);
253  if (Version < CudaVersion::CUDA_80) {
254  LibDeviceMap["sm_50"] = std::string(FilePath);
255  LibDeviceMap["sm_52"] = std::string(FilePath);
256  LibDeviceMap["sm_53"] = std::string(FilePath);
257  }
258  LibDeviceMap["sm_60"] = std::string(FilePath);
259  LibDeviceMap["sm_61"] = std::string(FilePath);
260  LibDeviceMap["sm_62"] = std::string(FilePath);
261  } else if (GpuArch == "compute_35") {
262  LibDeviceMap["sm_35"] = std::string(FilePath);
263  LibDeviceMap["sm_37"] = std::string(FilePath);
264  } else if (GpuArch == "compute_50") {
265  if (Version >= CudaVersion::CUDA_80) {
266  LibDeviceMap["sm_50"] = std::string(FilePath);
267  LibDeviceMap["sm_52"] = std::string(FilePath);
268  LibDeviceMap["sm_53"] = std::string(FilePath);
269  }
270  }
271  }
272  }
273 
274  // Check that we have found at least one libdevice that we can link in if
275  // -nocudalib hasn't been specified.
276  if (LibDeviceMap.empty() && !NoCudaLib)
277  continue;
278 
279  IsValid = true;
280  break;
281  }
282 }
283 
285  const ArgList &DriverArgs, ArgStringList &CC1Args) const {
286  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
287  // Add cuda_wrappers/* to our system include path. This lets us wrap
288  // standard library headers.
290  llvm::sys::path::append(P, "include");
291  llvm::sys::path::append(P, "cuda_wrappers");
292  CC1Args.push_back("-internal-isystem");
293  CC1Args.push_back(DriverArgs.MakeArgString(P));
294  }
295 
296  if (DriverArgs.hasArg(options::OPT_nogpuinc))
297  return;
298 
299  if (!isValid()) {
300  D.Diag(diag::err_drv_no_cuda_installation);
301  return;
302  }
303 
304  CC1Args.push_back("-include");
305  CC1Args.push_back("__clang_cuda_runtime_wrapper.h");
306 }
307 
309  CudaArch Arch) const {
310  if (Arch == CudaArch::UNKNOWN || Version == CudaVersion::UNKNOWN ||
311  ArchsWithBadVersion[(int)Arch])
312  return;
313 
314  auto MinVersion = MinVersionForCudaArch(Arch);
315  auto MaxVersion = MaxVersionForCudaArch(Arch);
316  if (Version < MinVersion || Version > MaxVersion) {
317  ArchsWithBadVersion[(int)Arch] = true;
318  D.Diag(diag::err_drv_cuda_version_unsupported)
319  << CudaArchToString(Arch) << CudaVersionToString(MinVersion)
320  << CudaVersionToString(MaxVersion) << InstallPath
321  << CudaVersionToString(Version);
322  }
323 }
324 
325 void CudaInstallationDetector::print(raw_ostream &OS) const {
326  if (isValid())
327  OS << "Found CUDA installation: " << InstallPath << ", version "
328  << CudaVersionToString(Version) << "\n";
329 }
330 
331 namespace {
332 /// Debug info level for the NVPTX devices. We may need to emit different debug
333 /// info level for the host and for the device itselfi. This type controls
334 /// emission of the debug info for the devices. It either prohibits disable info
335 /// emission completely, or emits debug directives only, or emits same debug
336 /// info as for the host.
337 enum DeviceDebugInfoLevel {
338  DisableDebugInfo, /// Do not emit debug info for the devices.
339  DebugDirectivesOnly, /// Emit only debug directives.
340  EmitSameDebugInfoAsHost, /// Use the same debug info level just like for the
341  /// host.
342 };
343 } // anonymous namespace
344 
345 /// Define debug info level for the NVPTX devices. If the debug info for both
346 /// the host and device are disabled (-g0/-ggdb0 or no debug options at all). If
347 /// only debug directives are requested for the both host and device
348 /// (-gline-directvies-only), or the debug info only for the device is disabled
349 /// (optimization is on and --cuda-noopt-device-debug was not specified), the
350 /// debug directves only must be emitted for the device. Otherwise, use the same
351 /// debug info level just like for the host (with the limitations of only
352 /// supported DWARF2 standard).
353 static DeviceDebugInfoLevel mustEmitDebugInfo(const ArgList &Args) {
354  const Arg *A = Args.getLastArg(options::OPT_O_Group);
355  bool IsDebugEnabled = !A || A->getOption().matches(options::OPT_O0) ||
356  Args.hasFlag(options::OPT_cuda_noopt_device_debug,
357  options::OPT_no_cuda_noopt_device_debug,
358  /*Default=*/false);
359  if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
360  const Option &Opt = A->getOption();
361  if (Opt.matches(options::OPT_gN_Group)) {
362  if (Opt.matches(options::OPT_g0) || Opt.matches(options::OPT_ggdb0))
363  return DisableDebugInfo;
364  if (Opt.matches(options::OPT_gline_directives_only))
365  return DebugDirectivesOnly;
366  }
367  return IsDebugEnabled ? EmitSameDebugInfoAsHost : DebugDirectivesOnly;
368  }
369  return willEmitRemarks(Args) ? DebugDirectivesOnly : DisableDebugInfo;
370 }
371 
372 void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
373  const InputInfo &Output,
374  const InputInfoList &Inputs,
375  const ArgList &Args,
376  const char *LinkingOutput) const {
377  const auto &TC =
378  static_cast<const toolchains::CudaToolChain &>(getToolChain());
379  assert(TC.getTriple().isNVPTX() && "Wrong platform");
380 
381  StringRef GPUArchName;
382  // If this is an OpenMP action we need to extract the device architecture
383  // from the -march=arch option. This option may come from -Xopenmp-target
384  // flag or the default value.
386  GPUArchName = Args.getLastArgValue(options::OPT_march_EQ);
387  assert(!GPUArchName.empty() && "Must have an architecture passed in.");
388  } else
389  GPUArchName = JA.getOffloadingArch();
390 
391  // Obtain architecture from the action.
392  CudaArch gpu_arch = StringToCudaArch(GPUArchName);
393  assert(gpu_arch != CudaArch::UNKNOWN &&
394  "Device action expected to have an architecture.");
395 
396  // Check that our installation's ptxas supports gpu_arch.
397  if (!Args.hasArg(options::OPT_no_cuda_version_check)) {
398  TC.CudaInstallation.CheckCudaVersionSupportsArch(gpu_arch);
399  }
400 
401  ArgStringList CmdArgs;
402  CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-m64" : "-m32");
403  DeviceDebugInfoLevel DIKind = mustEmitDebugInfo(Args);
404  if (DIKind == EmitSameDebugInfoAsHost) {
405  // ptxas does not accept -g option if optimization is enabled, so
406  // we ignore the compiler's -O* options if we want debug info.
407  CmdArgs.push_back("-g");
408  CmdArgs.push_back("--dont-merge-basicblocks");
409  CmdArgs.push_back("--return-at-end");
410  } else if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
411  // Map the -O we received to -O{0,1,2,3}.
412  //
413  // TODO: Perhaps we should map host -O2 to ptxas -O3. -O3 is ptxas's
414  // default, so it may correspond more closely to the spirit of clang -O2.
415 
416  // -O3 seems like the least-bad option when -Osomething is specified to
417  // clang but it isn't handled below.
418  StringRef OOpt = "3";
419  if (A->getOption().matches(options::OPT_O4) ||
420  A->getOption().matches(options::OPT_Ofast))
421  OOpt = "3";
422  else if (A->getOption().matches(options::OPT_O0))
423  OOpt = "0";
424  else if (A->getOption().matches(options::OPT_O)) {
425  // -Os, -Oz, and -O(anything else) map to -O2, for lack of better options.
426  OOpt = llvm::StringSwitch<const char *>(A->getValue())
427  .Case("1", "1")
428  .Case("2", "2")
429  .Case("3", "3")
430  .Case("s", "2")
431  .Case("z", "2")
432  .Default("2");
433  }
434  CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-O") + OOpt));
435  } else {
436  // If no -O was passed, pass -O0 to ptxas -- no opt flag should correspond
437  // to no optimizations, but ptxas's default is -O3.
438  CmdArgs.push_back("-O0");
439  }
440  if (DIKind == DebugDirectivesOnly)
441  CmdArgs.push_back("-lineinfo");
442 
443  // Pass -v to ptxas if it was passed to the driver.
444  if (Args.hasArg(options::OPT_v))
445  CmdArgs.push_back("-v");
446 
447  CmdArgs.push_back("--gpu-name");
448  CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch)));
449  CmdArgs.push_back("--output-file");
450  const char *OutputFileName = Args.MakeArgString(TC.getInputFilename(Output));
451  if (std::string(OutputFileName) != std::string(Output.getFilename()))
452  C.addTempFile(OutputFileName);
453  CmdArgs.push_back(OutputFileName);
454  for (const auto& II : Inputs)
455  CmdArgs.push_back(Args.MakeArgString(II.getFilename()));
456 
457  for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
458  CmdArgs.push_back(Args.MakeArgString(A));
459 
460  bool Relocatable = false;
462  // In OpenMP we need to generate relocatable code.
463  Relocatable = Args.hasFlag(options::OPT_fopenmp_relocatable_target,
464  options::OPT_fnoopenmp_relocatable_target,
465  /*Default=*/true);
466  else if (JA.isOffloading(Action::OFK_Cuda))
467  Relocatable = Args.hasFlag(options::OPT_fgpu_rdc,
468  options::OPT_fno_gpu_rdc, /*Default=*/false);
469 
470  if (Relocatable)
471  CmdArgs.push_back("-c");
472 
473  const char *Exec;
474  if (Arg *A = Args.getLastArg(options::OPT_ptxas_path_EQ))
475  Exec = A->getValue();
476  else
477  Exec = Args.MakeArgString(TC.GetProgramPath("ptxas"));
478  C.addCommand(std::make_unique<Command>(
479  JA, *this,
481  "--options-file"},
482  Exec, CmdArgs, Inputs, Output));
483 }
484 
485 static bool shouldIncludePTX(const ArgList &Args, const char *gpu_arch) {
486  bool includePTX = true;
487  for (Arg *A : Args) {
488  if (!(A->getOption().matches(options::OPT_cuda_include_ptx_EQ) ||
489  A->getOption().matches(options::OPT_no_cuda_include_ptx_EQ)))
490  continue;
491  A->claim();
492  const StringRef ArchStr = A->getValue();
493  if (ArchStr == "all" || ArchStr == gpu_arch) {
494  includePTX = A->getOption().matches(options::OPT_cuda_include_ptx_EQ);
495  continue;
496  }
497  }
498  return includePTX;
499 }
500 
501 // All inputs to this linker must be from CudaDeviceActions, as we need to look
502 // at the Inputs' Actions in order to figure out which GPU architecture they
503 // correspond to.
504 void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
505  const InputInfo &Output,
506  const InputInfoList &Inputs,
507  const ArgList &Args,
508  const char *LinkingOutput) const {
509  const auto &TC =
510  static_cast<const toolchains::CudaToolChain &>(getToolChain());
511  assert(TC.getTriple().isNVPTX() && "Wrong platform");
512 
513  ArgStringList CmdArgs;
514  if (TC.CudaInstallation.version() <= CudaVersion::CUDA_100)
515  CmdArgs.push_back("--cuda");
516  CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-64" : "-32");
517  CmdArgs.push_back(Args.MakeArgString("--create"));
518  CmdArgs.push_back(Args.MakeArgString(Output.getFilename()));
519  if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
520  CmdArgs.push_back("-g");
521 
522  for (const auto& II : Inputs) {
523  auto *A = II.getAction();
524  assert(A->getInputs().size() == 1 &&
525  "Device offload action is expected to have a single input");
526  const char *gpu_arch_str = A->getOffloadingArch();
527  assert(gpu_arch_str &&
528  "Device action expected to have associated a GPU architecture!");
529  CudaArch gpu_arch = StringToCudaArch(gpu_arch_str);
530 
531  if (II.getType() == types::TY_PP_Asm &&
532  !shouldIncludePTX(Args, gpu_arch_str))
533  continue;
534  // We need to pass an Arch of the form "sm_XX" for cubin files and
535  // "compute_XX" for ptx.
536  const char *Arch = (II.getType() == types::TY_PP_Asm)
537  ? CudaArchToVirtualArchString(gpu_arch)
538  : gpu_arch_str;
539  CmdArgs.push_back(Args.MakeArgString(llvm::Twine("--image=profile=") +
540  Arch + ",file=" + II.getFilename()));
541  }
542 
543  for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_fatbinary))
544  CmdArgs.push_back(Args.MakeArgString(A));
545 
546  const char *Exec = Args.MakeArgString(TC.GetProgramPath("fatbinary"));
547  C.addCommand(std::make_unique<Command>(
548  JA, *this,
550  "--options-file"},
551  Exec, CmdArgs, Inputs, Output));
552 }
553 
554 void NVPTX::OpenMPLinker::ConstructJob(Compilation &C, const JobAction &JA,
555  const InputInfo &Output,
556  const InputInfoList &Inputs,
557  const ArgList &Args,
558  const char *LinkingOutput) const {
559  const auto &TC =
560  static_cast<const toolchains::CudaToolChain &>(getToolChain());
561  assert(TC.getTriple().isNVPTX() && "Wrong platform");
562 
563  ArgStringList CmdArgs;
564 
565  // OpenMP uses nvlink to link cubin files. The result will be embedded in the
566  // host binary by the host linker.
567  assert(!JA.isHostOffloading(Action::OFK_OpenMP) &&
568  "CUDA toolchain not expected for an OpenMP host device.");
569 
570  if (Output.isFilename()) {
571  CmdArgs.push_back("-o");
572  CmdArgs.push_back(Output.getFilename());
573  } else
574  assert(Output.isNothing() && "Invalid output.");
575  if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
576  CmdArgs.push_back("-g");
577 
578  if (Args.hasArg(options::OPT_v))
579  CmdArgs.push_back("-v");
580 
581  StringRef GPUArch =
582  Args.getLastArgValue(options::OPT_march_EQ);
583  assert(!GPUArch.empty() && "At least one GPU Arch required for ptxas.");
584 
585  CmdArgs.push_back("-arch");
586  CmdArgs.push_back(Args.MakeArgString(GPUArch));
587 
588  // Add paths specified in LIBRARY_PATH environment variable as -L options.
589  addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
590 
591  // Add paths for the default clang library path.
592  SmallString<256> DefaultLibPath =
593  llvm::sys::path::parent_path(TC.getDriver().Dir);
594  llvm::sys::path::append(DefaultLibPath, "lib" CLANG_LIBDIR_SUFFIX);
595  CmdArgs.push_back(Args.MakeArgString(Twine("-L") + DefaultLibPath));
596 
597  for (const auto &II : Inputs) {
598  if (II.getType() == types::TY_LLVM_IR ||
599  II.getType() == types::TY_LTO_IR ||
600  II.getType() == types::TY_LTO_BC ||
601  II.getType() == types::TY_LLVM_BC) {
602  C.getDriver().Diag(diag::err_drv_no_linker_llvm_support)
603  << getToolChain().getTripleString();
604  continue;
605  }
606 
607  // Currently, we only pass the input files to the linker, we do not pass
608  // any libraries that may be valid only for the host.
609  if (!II.isFilename())
610  continue;
611 
612  const char *CubinF =
613  C.getArgs().MakeArgString(getToolChain().getInputFilename(II));
614 
615  CmdArgs.push_back(CubinF);
616  }
617 
618  AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, CmdArgs, "nvptx",
619  GPUArch, /*isBitCodeSDL=*/false,
620  /*postClangLink=*/false);
621 
622  // Find nvlink and pass it as "--nvlink-path=" argument of
623  // clang-nvlink-wrapper.
624  CmdArgs.push_back(Args.MakeArgString(
625  Twine("--nvlink-path=" + getToolChain().GetProgramPath("nvlink"))));
626 
627  const char *Exec =
628  Args.MakeArgString(getToolChain().GetProgramPath("clang-nvlink-wrapper"));
629  C.addCommand(std::make_unique<Command>(
630  JA, *this,
632  "--options-file"},
633  Exec, CmdArgs, Inputs, Output));
634 }
635 
636 void NVPTX::getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple,
637  const llvm::opt::ArgList &Args,
638  std::vector<StringRef> &Features,
640  if (Args.hasArg(options::OPT_cuda_feature_EQ)) {
641  StringRef PtxFeature =
642  Args.getLastArgValue(options::OPT_cuda_feature_EQ, "+ptx42");
643  Features.push_back(Args.MakeArgString(PtxFeature));
644  return;
645  } else if (!Version) {
646  CudaInstallationDetector CudaInstallation(D, Triple, Args);
647  Version = CudaInstallation.version();
648  }
649 
650  // New CUDA versions often introduce new instructions that are only supported
651  // by new PTX version, so we need to raise PTX level to enable them in NVPTX
652  // back-end.
653  const char *PtxFeature = nullptr;
654  switch (*Version) {
655 #define CASE_CUDA_VERSION(CUDA_VER, PTX_VER) \
656  case CudaVersion::CUDA_##CUDA_VER: \
657  PtxFeature = "+ptx" #PTX_VER; \
658  break;
659  CASE_CUDA_VERSION(115, 75);
660  CASE_CUDA_VERSION(114, 74);
661  CASE_CUDA_VERSION(113, 73);
662  CASE_CUDA_VERSION(112, 72);
663  CASE_CUDA_VERSION(111, 71);
664  CASE_CUDA_VERSION(110, 70);
665  CASE_CUDA_VERSION(102, 65);
666  CASE_CUDA_VERSION(101, 64);
667  CASE_CUDA_VERSION(100, 63);
668  CASE_CUDA_VERSION(92, 61);
669  CASE_CUDA_VERSION(91, 61);
670  CASE_CUDA_VERSION(90, 60);
671 #undef CASE_CUDA_VERSION
672  default:
673  PtxFeature = "+ptx42";
674  }
675  Features.push_back(PtxFeature);
676 }
677 
678 /// CUDA toolchain. Our assembler is ptxas, and our "linker" is fatbinary,
679 /// which isn't properly a linker but nonetheless performs the step of stitching
680 /// together object files from the assembler into a single blob.
681 
682 CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
683  const ToolChain &HostTC, const ArgList &Args,
684  const Action::OffloadKind OK)
685  : ToolChain(D, Triple, Args), HostTC(HostTC),
686  CudaInstallation(D, HostTC.getTriple(), Args), OK(OK) {
687  if (CudaInstallation.isValid()) {
690  }
691  // Lookup binaries into the driver directory, this is used to
692  // discover the clang-offload-bundler executable.
693  getProgramPaths().push_back(getDriver().Dir);
694 }
695 
697  // Only object files are changed, for example assembly files keep their .s
698  // extensions. CUDA also continues to use .o as they don't use nvlink but
699  // fatbinary.
700  if (!(OK == Action::OFK_OpenMP && Input.getType() == types::TY_Object))
701  return ToolChain::getInputFilename(Input);
702 
703  // Replace extension for object files with cubin because nvlink relies on
704  // these particular file names.
706  llvm::sys::path::replace_extension(Filename, "cubin");
707  return std::string(Filename.str());
708 }
709 
711  const llvm::opt::ArgList &DriverArgs,
712  llvm::opt::ArgStringList &CC1Args,
713  Action::OffloadKind DeviceOffloadingKind) const {
714  HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
715 
716  StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
717  assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
718  assert((DeviceOffloadingKind == Action::OFK_OpenMP ||
719  DeviceOffloadingKind == Action::OFK_Cuda) &&
720  "Only OpenMP or CUDA offloading kinds are supported for NVIDIA GPUs.");
721 
722  if (DeviceOffloadingKind == Action::OFK_Cuda) {
723  CC1Args.append(
724  {"-fcuda-is-device", "-mllvm", "-enable-memcpyopt-without-libcalls"});
725 
726  if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals,
727  options::OPT_fno_cuda_approx_transcendentals, false))
728  CC1Args.push_back("-fcuda-approx-transcendentals");
729  }
730 
731  if (DriverArgs.hasArg(options::OPT_nogpulib))
732  return;
733 
734  if (DeviceOffloadingKind == Action::OFK_OpenMP &&
735  DriverArgs.hasArg(options::OPT_S))
736  return;
737 
738  std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
739  if (LibDeviceFile.empty()) {
740  getDriver().Diag(diag::err_drv_no_cuda_libdevice) << GpuArch;
741  return;
742  }
743 
744  CC1Args.push_back("-mlink-builtin-bitcode");
745  CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile));
746 
747  clang::CudaVersion CudaInstallationVersion = CudaInstallation.version();
748 
749  std::vector<StringRef> Features;
750  NVPTX::getNVPTXTargetFeatures(getDriver(), getTriple(), DriverArgs, Features,
751  CudaInstallationVersion);
752  for (StringRef PtxFeature : Features)
753  CC1Args.append({"-target-feature", DriverArgs.MakeArgString(PtxFeature)});
754  if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
755  options::OPT_fno_cuda_short_ptr, false))
756  CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
757 
758  if (CudaInstallationVersion >= CudaVersion::UNKNOWN)
759  CC1Args.push_back(
760  DriverArgs.MakeArgString(Twine("-target-sdk-version=") +
761  CudaVersionToString(CudaInstallationVersion)));
762 
763  if (DeviceOffloadingKind == Action::OFK_OpenMP) {
764  if (CudaInstallationVersion < CudaVersion::CUDA_92) {
765  getDriver().Diag(
766  diag::err_drv_omp_offload_target_cuda_version_not_support)
767  << CudaVersionToString(CudaInstallationVersion);
768  return;
769  }
770 
771  // Link the bitcode library late if we're using device LTO.
772  if (getDriver().isUsingLTO(/* IsOffload */ true))
773  return;
774 
775  addOpenMPDeviceRTL(getDriver(), DriverArgs, CC1Args, GpuArch.str(),
776  getTriple());
777  AddStaticDeviceLibsPostLinking(getDriver(), DriverArgs, CC1Args, "nvptx",
778  GpuArch, /*isBitCodeSDL=*/true,
779  /*postClangLink=*/true);
780  }
781 }
782 
784  const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
785  const llvm::fltSemantics *FPType) const {
787  if (FPType && FPType == &llvm::APFloat::IEEEsingle() &&
788  DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
789  options::OPT_fno_gpu_flush_denormals_to_zero, false))
790  return llvm::DenormalMode::getPreserveSign();
791  }
792 
794  return llvm::DenormalMode::getIEEE();
795 }
796 
797 bool CudaToolChain::supportsDebugInfoOption(const llvm::opt::Arg *A) const {
798  const Option &O = A->getOption();
799  return (O.matches(options::OPT_gN_Group) &&
800  !O.matches(options::OPT_gmodules)) ||
801  O.matches(options::OPT_g_Flag) ||
802  O.matches(options::OPT_ggdbN_Group) || O.matches(options::OPT_ggdb) ||
803  O.matches(options::OPT_gdwarf) || O.matches(options::OPT_gdwarf_2) ||
804  O.matches(options::OPT_gdwarf_3) || O.matches(options::OPT_gdwarf_4) ||
805  O.matches(options::OPT_gdwarf_5) ||
806  O.matches(options::OPT_gcolumn_info);
807 }
808 
810  codegenoptions::DebugInfoKind &DebugInfoKind, const ArgList &Args) const {
811  switch (mustEmitDebugInfo(Args)) {
812  case DisableDebugInfo:
814  break;
815  case DebugDirectivesOnly:
817  break;
818  case EmitSameDebugInfoAsHost:
819  // Use same debug info level as the host.
820  break;
821  }
822 }
823 
824 void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
825  ArgStringList &CC1Args) const {
826  // Check our CUDA version if we're going to include the CUDA headers.
827  if (!DriverArgs.hasArg(options::OPT_nogpuinc) &&
828  !DriverArgs.hasArg(options::OPT_no_cuda_version_check)) {
829  StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
830  assert(!Arch.empty() && "Must have an explicit GPU arch.");
832  }
833  CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
834 }
835 
836 llvm::opt::DerivedArgList *
837 CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
838  StringRef BoundArch,
839  Action::OffloadKind DeviceOffloadKind) const {
840  DerivedArgList *DAL =
841  HostTC.TranslateArgs(Args, BoundArch, DeviceOffloadKind);
842  if (!DAL)
843  DAL = new DerivedArgList(Args.getBaseArgs());
844 
845  const OptTable &Opts = getDriver().getOpts();
846 
847  // For OpenMP device offloading, append derived arguments. Make sure
848  // flags are not duplicated.
849  // Also append the compute capability.
850  if (DeviceOffloadKind == Action::OFK_OpenMP) {
851  for (Arg *A : Args)
852  if (!llvm::is_contained(*DAL, A))
853  DAL->append(A);
854 
855  if (!DAL->hasArg(options::OPT_march_EQ))
856  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
857  !BoundArch.empty() ? BoundArch
858  : CLANG_OPENMP_NVPTX_DEFAULT_ARCH);
859 
860  return DAL;
861  }
862 
863  for (Arg *A : Args) {
864  DAL->append(A);
865  }
866 
867  if (!BoundArch.empty()) {
868  DAL->eraseArg(options::OPT_march_EQ);
869  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch);
870  }
871  return DAL;
872 }
873 
875  return new tools::NVPTX::Assembler(*this);
876 }
877 
879  if (OK == Action::OFK_OpenMP)
880  return new tools::NVPTX::OpenMPLinker(*this);
881  return new tools::NVPTX::Linker(*this);
882 }
883 
884 void CudaToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
886 }
887 
889 CudaToolChain::GetCXXStdlibType(const ArgList &Args) const {
890  return HostTC.GetCXXStdlibType(Args);
891 }
892 
893 void CudaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
894  ArgStringList &CC1Args) const {
895  HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
896 
897  if (!DriverArgs.hasArg(options::OPT_nogpuinc) && CudaInstallation.isValid())
898  CC1Args.append(
899  {"-internal-isystem",
900  DriverArgs.MakeArgString(CudaInstallation.getIncludePath())});
901 }
902 
904  ArgStringList &CC1Args) const {
905  HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
906 }
907 
908 void CudaToolChain::AddIAMCUIncludeArgs(const ArgList &Args,
909  ArgStringList &CC1Args) const {
910  HostTC.AddIAMCUIncludeArgs(Args, CC1Args);
911 }
912 
914  // The CudaToolChain only supports sanitizers in the sense that it allows
915  // sanitizer arguments on the command line if they are supported by the host
916  // toolchain. The CudaToolChain will actually ignore any command line
917  // arguments for any of these "supported" sanitizers. That means that no
918  // sanitization of device code is actually supported at this time.
919  //
920  // This behavior is necessary because the host and device toolchains
921  // invocations often share the command line, so the device toolchain must
922  // tolerate flags meant only for the host toolchain.
924 }
925 
927  const ArgList &Args) const {
928  return HostTC.computeMSVCVersion(D, Args);
929 }
clang::driver::toolchains
Definition: AIX.h:55
clang::CudaVersion::CUDA_91
@ CUDA_91
clang::driver::Distro::IsUbuntu
bool IsUbuntu() const
Definition: Distro.h:127
clang::driver::Action::getOffloadingArch
const char * getOffloadingArch() const
Definition: Action.h:212
clang::CudaVersion::CUDA_114
@ CUDA_114
clang::driver::ResponseFileSupport::RF_Full
@ RF_Full
Definition: Job.h:48
clang::driver::toolchains::CudaToolChain::addClangWarningOptions
void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override
Add warning options that need to be passed to cc1 for this target.
Definition: Cuda.cpp:884
clang::CudaVersion::CUDA_100
@ CUDA_100
clang::driver::toolchains::CudaToolChain::AddIAMCUIncludeArgs
void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use MCU GCC toolchain includes.
Definition: Cuda.cpp:908
clang::CudaArchToVirtualArchString
const char * CudaArchToVirtualArchString(CudaArch A)
Definition: Cuda.cpp:148
clang::driver::ToolChain::getProgramPaths
path_list & getProgramPaths()
Definition: ToolChain.h:266
clang::CudaVersion::NEW
@ NEW
Driver.h
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::CudaVersion::CUDA_70
@ CUDA_70
clang::driver::ToolChain::computeMSVCVersion
virtual VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const
On Windows, returns the MSVC compatibility version.
Definition: ToolChain.cpp:1084
clang::driver::tools::NVPTX::Assembler
Definition: Cuda.h:88
clang::driver::Action::OFK_Cuda
@ OFK_Cuda
Definition: Action.h:95
llvm::SmallVector
Definition: LLVM.h:38
clang::driver::Distro::IsDebian
bool IsDebian() const
Definition: Distro.h:123
clang::driver::toolchains::CudaToolChain
Definition: Cuda.h:137
clang::driver::toolchains::CudaToolChain::TranslateArgs
llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition: Cuda.cpp:837
clang::driver::ToolChain::AddClangCXXStdlibIncludeArgs
virtual void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: ToolChain.cpp:940
clang::driver::tools
Definition: AIX.h:17
clang::driver::toolchains::CudaToolChain::buildAssembler
Tool * buildAssembler() const override
Definition: Cuda.cpp:874
clang::driver::CudaInstallationDetector::isValid
bool isValid() const
Check whether we detected a valid Cuda install.
Definition: Cuda.h:58
clang::driver::ToolChain::getDriver
const Driver & getDriver() const
Definition: ToolChain.h:225
Filename
StringRef Filename
Definition: Format.cpp:2551
int
__device__ int
Definition: __clang_hip_libdevice_declares.h:63
clang::CudaVersion::CUDA_101
@ CUDA_101
clang::MinVersionForCudaArch
CudaVersion MinVersionForCudaArch(CudaArch A)
Get the earliest CudaVersion that supports the given CudaArch.
Definition: Cuda.cpp:166
clang::codegenoptions::NoDebugInfo
@ NoDebugInfo
Don't generate debug info.
Definition: DebugInfoOptions.h:22
clang::driver::toolchains::CudaToolChain::computeMSVCVersion
VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const override
On Windows, returns the MSVC compatibility version.
Definition: Cuda.cpp:926
clang::StringToCudaArch
CudaArch StringToCudaArch(llvm::StringRef S)
Definition: Cuda.cpp:157
llvm::Optional
Definition: LLVM.h:40
clang::driver::ToolChain::addClangWarningOptions
virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const
Add warning options that need to be passed to cc1 for this target.
Definition: ToolChain.cpp:780
clang::driver::Driver::getOpts
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:358
clang::driver::toolchains::CudaToolChain::getSupportedSanitizers
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: Cuda.cpp:913
clang::driver::ToolChain::getInputFilename
virtual std::string getInputFilename(const InputInfo &Input) const
Some toolchains need to modify the file name, for example to replace the extension for object files w...
Definition: ToolChain.cpp:258
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
clang::codegenoptions::DebugDirectivesOnly
@ DebugDirectivesOnly
Emit only debug directives with the line numbers data.
Definition: DebugInfoOptions.h:31
clang::driver::Action::OFK_OpenMP
@ OFK_OpenMP
Definition: Action.h:96
InputInfo.h
clang::driver::toolchains::CudaToolChain::CudaInstallation
CudaInstallationDetector CudaInstallation
Definition: Cuda.h:200
clang::driver::Driver::Diag
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:132
clang::driver::tools::AddStaticDeviceLibsLinking
void AddStaticDeviceLibsLinking(Compilation &C, const Tool &T, const JobAction &JA, const InputInfoList &Inputs, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CmdArgs, StringRef Arch, StringRef Target, bool isBitCodeSDL, bool postClangLink)
Definition: CommonArgs.cpp:1837
clang::CudaVersion::CUDA_90
@ CUDA_90
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
Options.h
clang::driver::InputInfo::isFilename
bool isFilename() const
Definition: InputInfo.h:75
clang::driver::toolchains::CudaToolChain::supportsDebugInfoOption
bool supportsDebugInfoOption(const llvm::opt::Arg *A) const override
Does this toolchain supports given debug info option or not.
Definition: Cuda.cpp:797
clang::driver::toolchains::CudaToolChain::buildLinker
Tool * buildLinker() const override
Definition: Cuda.cpp:878
clang::interp::LE
bool LE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:239
clang::driver::toolchains::CudaToolChain::HostTC
const ToolChain & HostTC
Definition: Cuda.h:199
clang::CudaVersion::CUDA_102
@ CUDA_102
llvm::opt
Definition: DiagnosticOptions.h:19
DriverDiagnostic.h
clang::CudaVersion::CUDA_110
@ CUDA_110
clang::driver::InputInfo::isNothing
bool isNothing() const
Definition: InputInfo.h:74
clang::CudaVersion
CudaVersion
Definition: Cuda.h:20
clang::driver::ToolChain::AddClangSystemIncludeArgs
virtual void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add the clang cc1 arguments for system include paths.
Definition: ToolChain.cpp:771
clang::driver::ToolChain::CXXStdlibType
CXXStdlibType
Definition: ToolChain.h:95
clang::driver::CudaInstallationDetector::getBinPath
StringRef getBinPath() const
Get the detected path to Cuda's bin directory.
Definition: Cuda.h:70
llvm::SmallString
Definition: LLVM.h:37
clang::driver::ToolChain::getTriple
const llvm::Triple & getTriple() const
Definition: ToolChain.h:227
clang::driver::Driver::SysRoot
std::string SysRoot
sysroot, if present
Definition: Driver.h:171
clang::driver::Action::isHostOffloading
bool isHostOffloading(unsigned int OKind) const
Check if this action have any offload kinds.
Definition: Action.h:219
clang::driver::Action::OFK_Host
@ OFK_Host
Definition: Action.h:92
clang::driver::CudaInstallationDetector::getIncludePath
StringRef getIncludePath() const
Get the detected Cuda Include path.
Definition: Cuda.h:72
clang::CudaVersion::CUDA_75
@ CUDA_75
clang::driver::CudaInstallationDetector::getLibDeviceFile
std::string getLibDeviceFile(StringRef Gpu) const
Get libdevice file for given architecture.
Definition: Cuda.h:78
Line
const AnnotatedLine * Line
Definition: UsingDeclarationsSorter.cpp:68
clang::CudaVersion::FULLY_SUPPORTED
@ FULLY_SUPPORTED
clang::driver::tools::addOpenMPDeviceRTL
void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, StringRef BitcodeSuffix, const llvm::Triple &Triple)
Definition: CommonArgs.cpp:2030
clang::driver::Driver::ResourceDir
std::string ResourceDir
The path to the compiler resource directory.
Definition: Driver.h:155
clang::CudaVersion::CUDA_111
@ CUDA_111
clang::CudaArch::LAST
@ LAST
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::driver::ToolChain::getSupportedSanitizers
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:1031
clang::driver::toolchains::CudaToolChain::AddClangCXXStdlibIncludeArgs
void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CC1Args) const override
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: Cuda.cpp:903
clang::driver::toolchains::CudaToolChain::getInputFilename
std::string getInputFilename(const InputInfo &Input) const override
Some toolchains need to modify the file name, for example to replace the extension for object files w...
Definition: Cuda.cpp:696
clang::driver::toolchains::CudaToolChain::addClangTargetOptions
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: Cuda.cpp:710
Compilation.h
clang::CudaArch::SM_30
@ SM_30
mustEmitDebugInfo
static DeviceDebugInfoLevel mustEmitDebugInfo(const ArgList &Args)
Define debug info level for the NVPTX devices.
Definition: Cuda.cpp:353
clang::driver::Distro
Distro - Helper class for detecting and classifying Linux distributions.
Definition: Distro.h:23
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
clang::driver::CudaInstallationDetector::WarnIfUnsupportedVersion
void WarnIfUnsupportedVersion()
Definition: Cuda.cpp:102
clang::CudaVersion::PARTIALLY_SUPPORTED
@ PARTIALLY_SUPPORTED
clang::driver::tools::NVPTX::Linker
Definition: Cuda.h:102
clang::driver::toolchains::CudaToolChain::AddCudaIncludeArgs
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific CUDA includes.
Definition: Cuda.cpp:824
clang::CudaArchToString
const char * CudaArchToString(CudaArch A)
Definition: Cuda.cpp:139
clang::CudaArch::UNKNOWN
@ UNKNOWN
clang::driver::toolchains::CudaToolChain::AddClangSystemIncludeArgs
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: Cuda.cpp:893
clang::driver::Action::getOffloadingDeviceKind
OffloadKind getOffloadingDeviceKind() const
Definition: Action.h:211
clang::driver::CudaInstallationDetector::AddCudaIncludeArgs
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Cuda.cpp:284
clang::CudaVersion::CUDA_92
@ CUDA_92
clang::driver::CudaInstallationDetector
A class to find a viable CUDA installation.
Definition: Cuda.h:28
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
clang::CudaVersionToString
const char * CudaVersionToString(CudaVersion V)
Definition: Cuda.cpp:11
clang::driver::Action::isDeviceOffloading
bool isDeviceOffloading(OffloadKind OKind) const
Definition: Action.h:222
clang::driver::willEmitRemarks
bool willEmitRemarks(const llvm::opt::ArgList &Args)
clang::driver::ToolChain::GetCXXStdlibType
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:852
clang::driver::ToolChain::AddIAMCUIncludeArgs
virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use MCU GCC toolchain includes.
Definition: ToolChain.cpp:1067
Cuda.h
clang::driver::CudaInstallationDetector::CudaInstallationDetector
CudaInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, const llvm::opt::ArgList &Args)
Definition: Cuda.cpp:116
clang::driver::InputInfo::getFilename
const char * getFilename() const
Definition: InputInfo.h:83
clang::MaxVersionForCudaArch
CudaVersion MaxVersionForCudaArch(CudaArch A)
Get the latest CudaVersion that supports the given CudaArch.
Definition: Cuda.cpp:204
clang::driver::tools::NVPTX::getNVPTXTargetFeatures
void getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, Optional< clang::CudaVersion > Version=None)
Definition: Cuda.cpp:636
CommonArgs.h
clang
Definition: CalledOnceCheck.h:17
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:71
clang::driver::InputInfo::getType
types::ID getType() const
Definition: InputInfo.h:77
shouldIncludePTX
static bool shouldIncludePTX(const ArgList &Args, const char *gpu_arch)
Definition: Cuda.cpp:485
clang::CudaVersion::CUDA_80
@ CUDA_80
clang::driver::ToolChain::TranslateArgs
virtual llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition: ToolChain.h:310
clang::driver::toolchains::CudaToolChain::adjustDebugInfoKind
void adjustDebugInfoKind(codegenoptions::DebugInfoKind &DebugInfoKind, const llvm::opt::ArgList &Args) const override
Adjust debug information kind considering all passed options.
Definition: Cuda.cpp:809
clang::driver::CudaInstallationDetector::version
CudaVersion version() const
Get the detected Cuda install's version.
Definition: Cuda.h:63
clang::CudaArch
CudaArch
Definition: Cuda.h:46
clang::codegenoptions::DebugInfoKind
DebugInfoKind
Definition: DebugInfoOptions.h:20
clang::driver::tools::addDirectoryList
void addDirectoryList(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const char *ArgName, const char *EnvVar)
EnvVar is split by system delimiter for environment variables.
clang::driver::Driver::getVFS
llvm::vfs::FileSystem & getVFS() const
Definition: Driver.h:362
clang::driver::ToolChain::addClangTargetOptions
virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const
Add options that need to be passed to cc1 for this target.
Definition: ToolChain.cpp:776
Distro.h
clang::CudaVersion::CUDA_115
@ CUDA_115
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:88
clang::driver
Definition: Action.h:31
clang::driver::Action::isOffloading
bool isOffloading(OffloadKind OKind) const
Definition: Action.h:225
clang::driver::CudaInstallationDetector::print
void print(raw_ostream &OS) const
Print information about the detected CUDA installation.
Definition: Cuda.cpp:325
clang::driver::tools::AddStaticDeviceLibsPostLinking
void AddStaticDeviceLibsPostLinking(const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CmdArgs, StringRef Arch, StringRef Target, bool isBitCodeSDL, bool postClangLink)
Definition: CommonArgs.cpp:1850
clang::CudaVersion::CUDA_113
@ CUDA_113
clang::driver::tools::NVPTX::OpenMPLinker
Definition: Cuda.h:114
clang::driver::JobAction
Definition: Action.h:395
clang::driver::CudaInstallationDetector::CheckCudaVersionSupportsArch
void CheckCudaVersionSupportsArch(CudaArch Arch) const
Emit an error if Version does not support the given Arch.
Definition: Cuda.cpp:308
clang::CudaVersion::UNKNOWN
@ UNKNOWN
clang::driver::toolchains::CudaToolChain::GetCXXStdlibType
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition: Cuda.cpp:889
clang::driver::toolchains::CudaToolChain::getDefaultDenormalModeForType
llvm::DenormalMode getDefaultDenormalModeForType(const llvm::opt::ArgList &DriverArgs, const JobAction &JA, const llvm::fltSemantics *FPType=nullptr) const override
Returns the output denormal handling type in the default floating point environment for the given FPT...
Definition: Cuda.cpp:783
clang::IsNVIDIAGpuArch
static bool IsNVIDIAGpuArch(CudaArch A)
Definition: Cuda.h:112
CASE_CUDA_VERSION
#define CASE_CUDA_VERSION(CUDA_VER, PTX_VER)
clang::SanitizerMask
Definition: Sanitizers.h:30
clang::driver::ResponseFileSupport
Definition: Job.h:44
clang::CudaVersion::CUDA_112
@ CUDA_112