clang 22.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 "clang/Basic/Cuda.h"
11#include "clang/Config/config.h"
14#include "clang/Driver/Distro.h"
15#include "clang/Driver/Driver.h"
18#include "llvm/ADT/StringExtras.h"
19#include "llvm/Config/llvm-config.h" // for LLVM_HOST_TRIPLE
20#include "llvm/Option/ArgList.h"
21#include "llvm/Support/FileSystem.h"
22#include "llvm/Support/Path.h"
23#include "llvm/Support/Process.h"
24#include "llvm/Support/Program.h"
25#include "llvm/Support/VirtualFileSystem.h"
26#include "llvm/TargetParser/Host.h"
27#include "llvm/TargetParser/TargetParser.h"
28#include <system_error>
29
30using namespace clang::driver;
31using namespace clang::driver::toolchains;
32using namespace clang::driver::tools;
33using namespace clang;
34using namespace llvm::opt;
35
36namespace {
37
38CudaVersion getCudaVersion(uint32_t raw_version) {
39 if (raw_version < 7050)
41 if (raw_version < 8000)
43 if (raw_version < 9000)
45 if (raw_version < 9010)
47 if (raw_version < 9020)
49 if (raw_version < 10000)
51 if (raw_version < 10010)
53 if (raw_version < 10020)
55 if (raw_version < 11000)
57 if (raw_version < 11010)
59 if (raw_version < 11020)
61 if (raw_version < 11030)
63 if (raw_version < 11040)
65 if (raw_version < 11050)
67 if (raw_version < 11060)
69 if (raw_version < 11070)
71 if (raw_version < 11080)
73 if (raw_version < 11090)
75 if (raw_version < 12010)
77 if (raw_version < 12020)
79 if (raw_version < 12030)
81 if (raw_version < 12040)
83 if (raw_version < 12050)
85 if (raw_version < 12060)
87 if (raw_version < 12070)
89 if (raw_version < 12090)
91 if (raw_version < 13000)
93 return CudaVersion::NEW;
94}
95
96CudaVersion parseCudaHFile(llvm::StringRef Input) {
97 // Helper lambda which skips the words if the line starts with them or returns
98 // std::nullopt otherwise.
99 auto StartsWithWords =
100 [](llvm::StringRef Line,
101 const SmallVector<StringRef, 3> words) -> std::optional<StringRef> {
102 for (StringRef word : words) {
103 if (!Line.consume_front(word))
104 return {};
105 Line = Line.ltrim();
106 }
107 return Line;
108 };
109
110 Input = Input.ltrim();
111 while (!Input.empty()) {
112 if (auto Line =
113 StartsWithWords(Input.ltrim(), {"#", "define", "CUDA_VERSION"})) {
114 uint32_t RawVersion;
115 Line->consumeInteger(10, RawVersion);
116 return getCudaVersion(RawVersion);
117 }
118 // Find next non-empty line.
119 Input = Input.drop_front(Input.find_first_of("\n\r")).ltrim();
120 }
122}
123} // namespace
124
126 if (Version > CudaVersion::PARTIALLY_SUPPORTED) {
127 std::string VersionString = CudaVersionToString(Version);
128 if (!VersionString.empty())
129 VersionString.insert(0, " ");
130 D.Diag(diag::warn_drv_new_cuda_version)
131 << VersionString
134 } else if (Version > CudaVersion::FULLY_SUPPORTED)
135 D.Diag(diag::warn_drv_partially_supported_cuda_version)
136 << CudaVersionToString(Version);
137}
138
140 const Driver &D, const llvm::Triple &HostTriple,
141 const llvm::opt::ArgList &Args)
142 : D(D) {
143 struct Candidate {
144 std::string Path;
145 bool StrictChecking;
146
147 Candidate(std::string Path, bool StrictChecking = false)
148 : Path(Path), StrictChecking(StrictChecking) {}
149 };
150 SmallVector<Candidate, 4> Candidates;
151
152 // In decreasing order so we prefer newer versions to older versions.
153 std::initializer_list<const char *> Versions = {"8.0", "7.5", "7.0"};
154 auto &FS = D.getVFS();
155
156 if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) {
157 Candidates.emplace_back(
158 Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str());
159 } else if (HostTriple.isOSWindows()) {
160 for (const char *Ver : Versions)
161 Candidates.emplace_back(
162 D.SysRoot + "/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v" +
163 Ver);
164 } else {
165 if (!Args.hasArg(clang::driver::options::OPT_cuda_path_ignore_env)) {
166 // Try to find ptxas binary. If the executable is located in a directory
167 // called 'bin/', its parent directory might be a good guess for a valid
168 // CUDA installation.
169 // However, some distributions might installs 'ptxas' to /usr/bin. In that
170 // case the candidate would be '/usr' which passes the following checks
171 // because '/usr/include' exists as well. To avoid this case, we always
172 // check for the directory potentially containing files for libdevice,
173 // even if the user passes -nocudalib.
174 if (llvm::ErrorOr<std::string> ptxas =
175 llvm::sys::findProgramByName("ptxas")) {
176 SmallString<256> ptxasAbsolutePath;
177 llvm::sys::fs::real_path(*ptxas, ptxasAbsolutePath);
178
179 StringRef ptxasDir = llvm::sys::path::parent_path(ptxasAbsolutePath);
180 if (llvm::sys::path::filename(ptxasDir) == "bin")
181 Candidates.emplace_back(
182 std::string(llvm::sys::path::parent_path(ptxasDir)),
183 /*StrictChecking=*/true);
184 }
185 }
186
187 Candidates.emplace_back(D.SysRoot + "/usr/local/cuda");
188 for (const char *Ver : Versions)
189 Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
190
191 Distro Dist(FS, llvm::Triple(llvm::sys::getProcessTriple()));
192 if (Dist.IsDebian() || Dist.IsUbuntu())
193 // Special case for Debian to have nvidia-cuda-toolkit work
194 // out of the box. More info on http://bugs.debian.org/882505
195 Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");
196 }
197
198 bool NoCudaLib =
199 !Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib, true);
200
201 for (const auto &Candidate : Candidates) {
202 InstallPath = Candidate.Path;
203 if (InstallPath.empty() || !FS.exists(InstallPath))
204 continue;
205
206 BinPath = InstallPath + "/bin";
207 IncludePath = InstallPath + "/include";
208 LibDevicePath = InstallPath + "/nvvm/libdevice";
209
210 if (!(FS.exists(IncludePath) && FS.exists(BinPath)))
211 continue;
212 bool CheckLibDevice = (!NoCudaLib || Candidate.StrictChecking);
213 if (CheckLibDevice && !FS.exists(LibDevicePath))
214 continue;
215
216 Version = CudaVersion::UNKNOWN;
217 if (auto CudaHFile = FS.getBufferForFile(InstallPath + "/include/cuda.h"))
218 Version = parseCudaHFile((*CudaHFile)->getBuffer());
219 // As the last resort, make an educated guess between CUDA-7.0, which had
220 // old-style libdevice bitcode, and an unknown recent CUDA version.
221 if (Version == CudaVersion::UNKNOWN) {
222 Version = FS.exists(LibDevicePath + "/libdevice.10.bc")
225 }
226
227 if (Version >= CudaVersion::CUDA_90) {
228 // CUDA-9+ uses single libdevice file for all GPU variants.
229 std::string FilePath = LibDevicePath + "/libdevice.10.bc";
230 if (FS.exists(FilePath)) {
231 for (int Arch = (int)OffloadArch::SM_30, E = (int)OffloadArch::LAST;
232 Arch < E; ++Arch) {
233 OffloadArch OA = static_cast<OffloadArch>(Arch);
234 if (!IsNVIDIAOffloadArch(OA))
235 continue;
236 std::string OffloadArchName(OffloadArchToString(OA));
237 LibDeviceMap[OffloadArchName] = FilePath;
238 }
239 }
240 } else {
241 std::error_code EC;
242 for (llvm::vfs::directory_iterator LI = FS.dir_begin(LibDevicePath, EC),
243 LE;
244 !EC && LI != LE; LI = LI.increment(EC)) {
245 StringRef FilePath = LI->path();
246 StringRef FileName = llvm::sys::path::filename(FilePath);
247 // Process all bitcode filenames that look like
248 // libdevice.compute_XX.YY.bc
249 const StringRef LibDeviceName = "libdevice.";
250 if (!(FileName.starts_with(LibDeviceName) && FileName.ends_with(".bc")))
251 continue;
252 StringRef GpuArch = FileName.slice(
253 LibDeviceName.size(), FileName.find('.', LibDeviceName.size()));
254 LibDeviceMap[GpuArch] = FilePath.str();
255 // Insert map entries for specific devices with this compute
256 // capability. NVCC's choice of the libdevice library version is
257 // rather peculiar and depends on the CUDA version.
258 if (GpuArch == "compute_20") {
259 LibDeviceMap["sm_20"] = std::string(FilePath);
260 LibDeviceMap["sm_21"] = std::string(FilePath);
261 LibDeviceMap["sm_32"] = std::string(FilePath);
262 } else if (GpuArch == "compute_30") {
263 LibDeviceMap["sm_30"] = std::string(FilePath);
264 if (Version < CudaVersion::CUDA_80) {
265 LibDeviceMap["sm_50"] = std::string(FilePath);
266 LibDeviceMap["sm_52"] = std::string(FilePath);
267 LibDeviceMap["sm_53"] = std::string(FilePath);
268 }
269 LibDeviceMap["sm_60"] = std::string(FilePath);
270 LibDeviceMap["sm_61"] = std::string(FilePath);
271 LibDeviceMap["sm_62"] = std::string(FilePath);
272 } else if (GpuArch == "compute_35") {
273 LibDeviceMap["sm_35"] = std::string(FilePath);
274 LibDeviceMap["sm_37"] = std::string(FilePath);
275 } else if (GpuArch == "compute_50") {
276 if (Version >= CudaVersion::CUDA_80) {
277 LibDeviceMap["sm_50"] = std::string(FilePath);
278 LibDeviceMap["sm_52"] = std::string(FilePath);
279 LibDeviceMap["sm_53"] = std::string(FilePath);
280 }
281 }
282 }
283 }
284
285 // Check that we have found at least one libdevice that we can link in if
286 // -nocudalib hasn't been specified.
287 if (LibDeviceMap.empty() && !NoCudaLib)
288 continue;
289
290 IsValid = true;
291 break;
292 }
293}
294
296 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
297 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
298 // Add cuda_wrappers/* to our system include path. This lets us wrap
299 // standard library headers.
300 SmallString<128> P(D.ResourceDir);
301 llvm::sys::path::append(P, "include");
302 llvm::sys::path::append(P, "cuda_wrappers");
303 CC1Args.push_back("-internal-isystem");
304 CC1Args.push_back(DriverArgs.MakeArgString(P));
305 }
306
307 if (!DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
308 true))
309 return;
310
311 if (!isValid()) {
312 D.Diag(diag::err_drv_no_cuda_installation);
313 return;
314 }
315
316 CC1Args.push_back("-include");
317 CC1Args.push_back("__clang_cuda_runtime_wrapper.h");
318}
319
321 OffloadArch Arch) const {
322 if (Arch == OffloadArch::UNKNOWN || Version == CudaVersion::UNKNOWN ||
323 ArchsWithBadVersion[(int)Arch])
324 return;
325
326 auto MinVersion = MinVersionForOffloadArch(Arch);
327 auto MaxVersion = MaxVersionForOffloadArch(Arch);
328 if (Version < MinVersion || Version > MaxVersion) {
329 ArchsWithBadVersion[(int)Arch] = true;
330 D.Diag(diag::err_drv_cuda_version_unsupported)
332 << CudaVersionToString(MaxVersion) << InstallPath
333 << CudaVersionToString(Version);
334 }
335}
336
337void CudaInstallationDetector::print(raw_ostream &OS) const {
338 if (isValid())
339 OS << "Found CUDA installation: " << InstallPath << ", version "
340 << CudaVersionToString(Version) << "\n";
341}
342
343namespace {
344/// Debug info level for the NVPTX devices. We may need to emit different debug
345/// info level for the host and for the device itselfi. This type controls
346/// emission of the debug info for the devices. It either prohibits disable info
347/// emission completely, or emits debug directives only, or emits same debug
348/// info as for the host.
349enum DeviceDebugInfoLevel {
350 DisableDebugInfo, /// Do not emit debug info for the devices.
351 DebugDirectivesOnly, /// Emit only debug directives.
352 EmitSameDebugInfoAsHost, /// Use the same debug info level just like for the
353 /// host.
354};
355} // anonymous namespace
356
357/// Define debug info level for the NVPTX devices. If the debug info for both
358/// the host and device are disabled (-g0/-ggdb0 or no debug options at all). If
359/// only debug directives are requested for the both host and device
360/// (-gline-directvies-only), or the debug info only for the device is disabled
361/// (optimization is on and --cuda-noopt-device-debug was not specified), the
362/// debug directves only must be emitted for the device. Otherwise, use the same
363/// debug info level just like for the host (with the limitations of only
364/// supported DWARF2 standard).
365static DeviceDebugInfoLevel mustEmitDebugInfo(const ArgList &Args) {
366 const Arg *A = Args.getLastArg(options::OPT_O_Group);
367 bool IsDebugEnabled = !A || A->getOption().matches(options::OPT_O0) ||
368 Args.hasFlag(options::OPT_cuda_noopt_device_debug,
369 options::OPT_no_cuda_noopt_device_debug,
370 /*Default=*/false);
371 if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
372 const Option &Opt = A->getOption();
373 if (Opt.matches(options::OPT_gN_Group)) {
374 if (Opt.matches(options::OPT_g0) || Opt.matches(options::OPT_ggdb0))
375 return DisableDebugInfo;
376 if (Opt.matches(options::OPT_gline_directives_only))
377 return DebugDirectivesOnly;
378 }
379 return IsDebugEnabled ? EmitSameDebugInfoAsHost : DebugDirectivesOnly;
380 }
381 return willEmitRemarks(Args) ? DebugDirectivesOnly : DisableDebugInfo;
382}
383
385 const InputInfo &Output,
386 const InputInfoList &Inputs,
387 const ArgList &Args,
388 const char *LinkingOutput) const {
389 const auto &TC =
390 static_cast<const toolchains::NVPTXToolChain &>(getToolChain());
391 assert(TC.getTriple().isNVPTX() && "Wrong platform");
392
393 StringRef GPUArchName;
394 // If this is a CUDA action we need to extract the device architecture
395 // from the Job's associated architecture, otherwise use the -march=arch
396 // option. This option may come from -Xopenmp-target flag or the default
397 // value.
399 GPUArchName = JA.getOffloadingArch();
400 } else {
401 GPUArchName = Args.getLastArgValue(options::OPT_march_EQ);
402 if (GPUArchName.empty()) {
403 C.getDriver().Diag(diag::err_drv_offload_missing_gpu_arch)
404 << getToolChain().getArchName() << getShortName();
405 return;
406 }
407 }
408
409 // Obtain architecture from the action.
410 OffloadArch gpu_arch = StringToOffloadArch(GPUArchName);
411 assert(gpu_arch != OffloadArch::UNKNOWN &&
412 "Device action expected to have an architecture.");
413
414 // Check that our installation's ptxas supports gpu_arch.
415 if (!Args.hasArg(options::OPT_no_cuda_version_check)) {
416 TC.CudaInstallation.CheckCudaVersionSupportsArch(gpu_arch);
417 }
418
419 ArgStringList CmdArgs;
420 CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-m64" : "-m32");
421 DeviceDebugInfoLevel DIKind = mustEmitDebugInfo(Args);
422 if (DIKind == EmitSameDebugInfoAsHost) {
423 // ptxas does not accept -g option if optimization is enabled, so
424 // we ignore the compiler's -O* options if we want debug info.
425 CmdArgs.push_back("-g");
426 CmdArgs.push_back("--dont-merge-basicblocks");
427 CmdArgs.push_back("--return-at-end");
428 } else if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
429 // Map the -O we received to -O{0,1,2,3}.
430 //
431 // TODO: Perhaps we should map host -O2 to ptxas -O3. -O3 is ptxas's
432 // default, so it may correspond more closely to the spirit of clang -O2.
433
434 // -O3 seems like the least-bad option when -Osomething is specified to
435 // clang but it isn't handled below.
436 StringRef OOpt = "3";
437 if (A->getOption().matches(options::OPT_O4) ||
438 A->getOption().matches(options::OPT_Ofast))
439 OOpt = "3";
440 else if (A->getOption().matches(options::OPT_O0))
441 OOpt = "0";
442 else if (A->getOption().matches(options::OPT_O)) {
443 // -Os, -Oz, and -O(anything else) map to -O2, for lack of better options.
444 OOpt = llvm::StringSwitch<const char *>(A->getValue())
445 .Case("1", "1")
446 .Case("2", "2")
447 .Case("3", "3")
448 .Case("s", "2")
449 .Case("z", "2")
450 .Default("2");
451 }
452 CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-O") + OOpt));
453 } else {
454 // If no -O was passed, pass -O0 to ptxas -- no opt flag should correspond
455 // to no optimizations, but ptxas's default is -O3.
456 CmdArgs.push_back("-O0");
457 }
458 if (DIKind == DebugDirectivesOnly)
459 CmdArgs.push_back("-lineinfo");
460
461 // Pass -v to ptxas if it was passed to the driver.
462 if (Args.hasArg(options::OPT_v))
463 CmdArgs.push_back("-v");
464
465 CmdArgs.push_back("--gpu-name");
466 CmdArgs.push_back(Args.MakeArgString(OffloadArchToString(gpu_arch)));
467 CmdArgs.push_back("--output-file");
468 std::string OutputFileName = TC.getInputFilename(Output);
469
470 if (Output.isFilename() && OutputFileName != Output.getFilename())
471 C.addTempFile(Args.MakeArgString(OutputFileName));
472
473 CmdArgs.push_back(Args.MakeArgString(OutputFileName));
474 for (const auto &II : Inputs)
475 CmdArgs.push_back(Args.MakeArgString(II.getFilename()));
476
477 for (const auto &A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
478 CmdArgs.push_back(Args.MakeArgString(A));
479
480 bool Relocatable;
482 // In OpenMP we need to generate relocatable code.
483 Relocatable = Args.hasFlag(options::OPT_fopenmp_relocatable_target,
484 options::OPT_fnoopenmp_relocatable_target,
485 /*Default=*/true);
486 else if (JA.isOffloading(Action::OFK_Cuda))
487 // In CUDA we generate relocatable code by default.
488 Relocatable = Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
489 /*Default=*/false);
490 else
491 // Otherwise, we are compiling directly and should create linkable output.
492 Relocatable = true;
493
494 if (Relocatable)
495 CmdArgs.push_back("-c");
496
497 const char *Exec;
498 if (Arg *A = Args.getLastArg(options::OPT_ptxas_path_EQ))
499 Exec = A->getValue();
500 else
501 Exec = Args.MakeArgString(TC.GetProgramPath("ptxas"));
502 C.addCommand(std::make_unique<Command>(
503 JA, *this,
505 "--options-file"},
506 Exec, CmdArgs, Inputs, Output));
507}
508
509static bool shouldIncludePTX(const ArgList &Args, StringRef InputArch) {
510 // The new driver does not include PTX by default to avoid overhead.
511 bool includePTX = !Args.hasFlag(options::OPT_offload_new_driver,
512 options::OPT_no_offload_new_driver, true);
513 for (Arg *A : Args.filtered(options::OPT_cuda_include_ptx_EQ,
514 options::OPT_no_cuda_include_ptx_EQ)) {
515 A->claim();
516 const StringRef ArchStr = A->getValue();
517 if (A->getOption().matches(options::OPT_cuda_include_ptx_EQ) &&
518 (ArchStr == "all" || ArchStr == InputArch))
519 includePTX = true;
520 else if (A->getOption().matches(options::OPT_no_cuda_include_ptx_EQ) &&
521 (ArchStr == "all" || ArchStr == InputArch))
522 includePTX = false;
523 }
524 return includePTX;
525}
526
527// All inputs to this linker must be from CudaDeviceActions, as we need to look
528// at the Inputs' Actions in order to figure out which GPU architecture they
529// correspond to.
531 const InputInfo &Output,
532 const InputInfoList &Inputs,
533 const ArgList &Args,
534 const char *LinkingOutput) const {
535 const auto &TC =
536 static_cast<const toolchains::CudaToolChain &>(getToolChain());
537 assert(TC.getTriple().isNVPTX() && "Wrong platform");
538
539 ArgStringList CmdArgs;
540 if (TC.CudaInstallation.version() <= CudaVersion::CUDA_100)
541 CmdArgs.push_back("--cuda");
542 CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-64" : "-32");
543 CmdArgs.push_back(Args.MakeArgString("--create"));
544 CmdArgs.push_back(Args.MakeArgString(Output.getFilename()));
545 if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
546 CmdArgs.push_back("-g");
547
548 for (const auto &II : Inputs) {
549 auto *A = II.getAction();
550 assert(A->getInputs().size() == 1 &&
551 "Device offload action is expected to have a single input");
552 StringRef GpuArch = A->getOffloadingArch();
553 assert(!GpuArch.empty() &&
554 "Device action expected to have associated a GPU architecture!");
555
556 if (II.getType() == types::TY_PP_Asm && !shouldIncludePTX(Args, GpuArch))
557 continue;
558 StringRef Kind = (II.getType() == types::TY_PP_Asm) ? "ptx" : "elf";
559 CmdArgs.push_back(Args.MakeArgString(
560 "--image3=kind=" + Kind + ",sm=" + GpuArch.drop_front(3) +
561 ",file=" + getToolChain().getInputFilename(II)));
562 }
563
564 for (const auto &A : Args.getAllArgValues(options::OPT_Xcuda_fatbinary))
565 CmdArgs.push_back(Args.MakeArgString(A));
566
567 const char *Exec = Args.MakeArgString(TC.GetProgramPath("fatbinary"));
568 C.addCommand(std::make_unique<Command>(
569 JA, *this,
571 "--options-file"},
572 Exec, CmdArgs, Inputs, Output));
573}
574
576 const InputInfo &Output,
577 const InputInfoList &Inputs,
578 const ArgList &Args,
579 const char *LinkingOutput) const {
580 const auto &TC =
581 static_cast<const toolchains::NVPTXToolChain &>(getToolChain());
582 ArgStringList CmdArgs;
583
584 assert(TC.getTriple().isNVPTX() && "Wrong platform");
585
586 assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
587 if (Output.isFilename()) {
588 CmdArgs.push_back("-o");
589 CmdArgs.push_back(Output.getFilename());
590 }
591
592 if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
593 CmdArgs.push_back("-g");
594
595 if (Args.hasArg(options::OPT_v))
596 CmdArgs.push_back("-v");
597
598 StringRef GPUArch = Args.getLastArgValue(options::OPT_march_EQ);
599 if (GPUArch.empty() && !C.getDriver().isUsingLTO()) {
600 C.getDriver().Diag(diag::err_drv_offload_missing_gpu_arch)
601 << getToolChain().getArchName() << getShortName();
602 return;
603 }
604
605 if (!GPUArch.empty()) {
606 CmdArgs.push_back("-arch");
607 CmdArgs.push_back(Args.MakeArgString(GPUArch));
608 }
609
610 if (Args.hasArg(options::OPT_ptxas_path_EQ))
611 CmdArgs.push_back(Args.MakeArgString(
612 "--pxtas-path=" + Args.getLastArgValue(options::OPT_ptxas_path_EQ)));
613
614 if (Args.hasArg(options::OPT_cuda_path_EQ) || TC.CudaInstallation.isValid()) {
615 StringRef CudaPath = Args.getLastArgValue(
616 options::OPT_cuda_path_EQ,
617 llvm::sys::path::parent_path(TC.CudaInstallation.getBinPath()));
618 CmdArgs.push_back(Args.MakeArgString("--cuda-path=" + CudaPath));
619 }
620
621 // Add paths specified in LIBRARY_PATH environment variable as -L options.
622 addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
623
624 // Add standard library search paths passed on the command line.
625 Args.AddAllArgs(CmdArgs, options::OPT_L);
626 getToolChain().AddFilePathLibArgs(Args, CmdArgs);
627 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
628
629 if (C.getDriver().isUsingLTO())
630 addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs,
631 C.getDriver().getLTOMode() == LTOK_Thin);
632
633 // Forward the PTX features if the nvlink-wrapper needs it.
634 std::vector<StringRef> Features;
635 getNVPTXTargetFeatures(C.getDriver(), getToolChain().getTriple(), Args,
636 Features);
637 CmdArgs.push_back(
638 Args.MakeArgString("--plugin-opt=-mattr=" + llvm::join(Features, ",")));
639
640 // Add paths for the default clang library path.
641 SmallString<256> DefaultLibPath =
642 llvm::sys::path::parent_path(TC.getDriver().Dir);
643 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
644 CmdArgs.push_back(Args.MakeArgString(Twine("-L") + DefaultLibPath));
645
646 if (Args.hasArg(options::OPT_stdlib))
647 CmdArgs.append({"-lc", "-lm"});
648 if (Args.hasArg(options::OPT_startfiles)) {
649 std::optional<std::string> IncludePath = getToolChain().getStdlibPath();
650 if (!IncludePath)
651 IncludePath = "/lib";
652 SmallString<128> P(*IncludePath);
653 llvm::sys::path::append(P, "crt1.o");
654 CmdArgs.push_back(Args.MakeArgString(P));
655 }
656
657 C.addCommand(std::make_unique<Command>(
658 JA, *this,
660 "--options-file"},
661 Args.MakeArgString(getToolChain().GetProgramPath("clang-nvlink-wrapper")),
662 CmdArgs, Inputs, Output));
663}
664
665void NVPTX::getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple,
666 const llvm::opt::ArgList &Args,
667 std::vector<StringRef> &Features) {
668 if (Args.hasArg(options::OPT_cuda_feature_EQ)) {
669 StringRef PtxFeature =
670 Args.getLastArgValue(options::OPT_cuda_feature_EQ, "+ptx42");
671 Features.push_back(Args.MakeArgString(PtxFeature));
672 return;
673 }
674 CudaInstallationDetector CudaInstallation(D, Triple, Args);
675
676 // New CUDA versions often introduce new instructions that are only supported
677 // by new PTX version, so we need to raise PTX level to enable them in NVPTX
678 // back-end.
679 const char *PtxFeature = nullptr;
680 switch (CudaInstallation.version()) {
681#define CASE_CUDA_VERSION(CUDA_VER, PTX_VER) \
682 case CudaVersion::CUDA_##CUDA_VER: \
683 PtxFeature = "+ptx" #PTX_VER; \
684 break;
685 CASE_CUDA_VERSION(129, 88);
686 CASE_CUDA_VERSION(128, 87);
687 CASE_CUDA_VERSION(126, 85);
688 CASE_CUDA_VERSION(125, 85);
689 CASE_CUDA_VERSION(124, 84);
690 CASE_CUDA_VERSION(123, 83);
691 CASE_CUDA_VERSION(122, 82);
692 CASE_CUDA_VERSION(121, 81);
693 CASE_CUDA_VERSION(120, 80);
694 CASE_CUDA_VERSION(118, 78);
695 CASE_CUDA_VERSION(117, 77);
696 CASE_CUDA_VERSION(116, 76);
697 CASE_CUDA_VERSION(115, 75);
698 CASE_CUDA_VERSION(114, 74);
699 CASE_CUDA_VERSION(113, 73);
700 CASE_CUDA_VERSION(112, 72);
701 CASE_CUDA_VERSION(111, 71);
702 CASE_CUDA_VERSION(110, 70);
703 CASE_CUDA_VERSION(102, 65);
704 CASE_CUDA_VERSION(101, 64);
705 CASE_CUDA_VERSION(100, 63);
706 CASE_CUDA_VERSION(92, 61);
707 CASE_CUDA_VERSION(91, 61);
708 CASE_CUDA_VERSION(90, 60);
709#undef CASE_CUDA_VERSION
710 // TODO: Use specific CUDA version once it's public.
712 PtxFeature = "+ptx86";
713 break;
714 default:
715 PtxFeature = "+ptx42";
716 }
717 Features.push_back(PtxFeature);
718}
719
720/// NVPTX toolchain. Our assembler is ptxas, and our linker is nvlink. This
721/// operates as a stand-alone version of the NVPTX tools without the host
722/// toolchain.
723NVPTXToolChain::NVPTXToolChain(const Driver &D, const llvm::Triple &Triple,
724 const llvm::Triple &HostTriple,
725 const ArgList &Args)
726 : ToolChain(D, Triple, Args), CudaInstallation(D, HostTriple, Args) {
727 if (CudaInstallation.isValid())
728 getProgramPaths().push_back(std::string(CudaInstallation.getBinPath()));
729 // Lookup binaries into the driver directory, this is used to
730 // discover the 'nvptx-arch' executable.
731 getProgramPaths().push_back(getDriver().Dir);
732}
733
734/// We only need the host triple to locate the CUDA binary utilities, use the
735/// system's default triple if not provided.
736NVPTXToolChain::NVPTXToolChain(const Driver &D, const llvm::Triple &Triple,
737 const ArgList &Args)
738 : NVPTXToolChain(D, Triple, llvm::Triple(LLVM_HOST_TRIPLE), Args) {}
739
740llvm::opt::DerivedArgList *
741NVPTXToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
742 StringRef BoundArch,
743 Action::OffloadKind OffloadKind) const {
744 DerivedArgList *DAL = ToolChain::TranslateArgs(Args, BoundArch, OffloadKind);
745 if (!DAL)
746 DAL = new DerivedArgList(Args.getBaseArgs());
747
748 const OptTable &Opts = getDriver().getOpts();
749
750 for (Arg *A : Args)
751 if (!llvm::is_contained(*DAL, A))
752 DAL->append(A);
753
754 if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
755 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
757 } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "generic" &&
758 OffloadKind == Action::OFK_None) {
759 DAL->eraseArg(options::OPT_march_EQ);
760 } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
761 auto GPUsOrErr = getSystemGPUArchs(Args);
762 if (!GPUsOrErr) {
763 getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
764 << getArchName() << llvm::toString(GPUsOrErr.takeError()) << "-march";
765 } else {
766 if (GPUsOrErr->size() > 1)
767 getDriver().Diag(diag::warn_drv_multi_gpu_arch)
768 << getArchName() << llvm::join(*GPUsOrErr, ", ") << "-march";
769 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
770 Args.MakeArgString(GPUsOrErr->front()));
771 }
772 }
773
774 return DAL;
775}
776
778 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
779 Action::OffloadKind DeviceOffloadingKind) const {}
780
781bool NVPTXToolChain::supportsDebugInfoOption(const llvm::opt::Arg *A) const {
782 const Option &O = A->getOption();
783 return (O.matches(options::OPT_gN_Group) &&
784 !O.matches(options::OPT_gmodules)) ||
785 O.matches(options::OPT_g_Flag) ||
786 O.matches(options::OPT_ggdbN_Group) || O.matches(options::OPT_ggdb) ||
787 O.matches(options::OPT_gdwarf) || O.matches(options::OPT_gdwarf_2) ||
788 O.matches(options::OPT_gdwarf_3) || O.matches(options::OPT_gdwarf_4) ||
789 O.matches(options::OPT_gdwarf_5) ||
790 O.matches(options::OPT_gcolumn_info);
791}
792
794 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
795 const ArgList &Args) const {
796 switch (mustEmitDebugInfo(Args)) {
797 case DisableDebugInfo:
798 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
799 break;
800 case DebugDirectivesOnly:
801 DebugInfoKind = llvm::codegenoptions::DebugDirectivesOnly;
802 break;
803 case EmitSameDebugInfoAsHost:
804 // Use same debug info level as the host.
805 break;
806 }
807}
808
810NVPTXToolChain::getSystemGPUArchs(const ArgList &Args) const {
811 // Detect NVIDIA GPUs availible on the system.
812 std::string Program;
813 if (Arg *A = Args.getLastArg(options::OPT_offload_arch_tool_EQ))
814 Program = A->getValue();
815 else
816 Program = GetProgramPath("nvptx-arch");
817
818 auto StdoutOrErr = getDriver().executeProgram({Program});
819 if (!StdoutOrErr)
820 return StdoutOrErr.takeError();
821
823 for (StringRef Arch : llvm::split((*StdoutOrErr)->getBuffer(), "\n"))
824 if (!Arch.empty())
825 GPUArchs.push_back(Arch.str());
826
827 if (GPUArchs.empty())
828 return llvm::createStringError(std::error_code(),
829 "No NVIDIA GPU detected in the system");
830
831 return std::move(GPUArchs);
832}
833
834/// CUDA toolchain. Our assembler is ptxas, and our "linker" is fatbinary,
835/// which isn't properly a linker but nonetheless performs the step of stitching
836/// together object files from the assembler into a single blob.
837
838CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
839 const ToolChain &HostTC, const ArgList &Args)
840 : NVPTXToolChain(D, Triple, HostTC.getTriple(), Args), HostTC(HostTC) {}
841
843 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
844 Action::OffloadKind DeviceOffloadingKind) const {
845 HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
846
847 StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
848 assert((DeviceOffloadingKind == Action::OFK_OpenMP ||
849 DeviceOffloadingKind == Action::OFK_Cuda) &&
850 "Only OpenMP or CUDA offloading kinds are supported for NVIDIA GPUs.");
851
852 CC1Args.append({"-fcuda-is-device", "-mllvm",
853 "-enable-memcpyopt-without-libcalls",
854 "-fno-threadsafe-statics"});
855
856 // Unsized function arguments used for variadics were introduced in CUDA-9.0
857 // We still do not support generating code that actually uses variadic
858 // arguments yet, but we do need to allow parsing them as recent CUDA
859 // headers rely on that. https://github.com/llvm/llvm-project/issues/58410
860 if (CudaInstallation.version() >= CudaVersion::CUDA_90)
861 CC1Args.push_back("-fcuda-allow-variadic-functions");
862
863 if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
864 options::OPT_fno_cuda_short_ptr, false))
865 CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
866
867 if (!DriverArgs.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib,
868 true))
869 return;
870
871 if (DeviceOffloadingKind == Action::OFK_OpenMP &&
872 DriverArgs.hasArg(options::OPT_S))
873 return;
874
875 std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
876 if (LibDeviceFile.empty()) {
877 getDriver().Diag(diag::err_drv_no_cuda_libdevice) << GpuArch;
878 return;
879 }
880
881 CC1Args.push_back("-mlink-builtin-bitcode");
882 CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile));
883
884 // For now, we don't use any Offload/OpenMP device runtime when we offload
885 // CUDA via LLVM/Offload. We should split the Offload/OpenMP device runtime
886 // and include the "generic" (or CUDA-specific) parts.
887 if (DriverArgs.hasFlag(options::OPT_foffload_via_llvm,
888 options::OPT_fno_offload_via_llvm, false))
889 return;
890
891 clang::CudaVersion CudaInstallationVersion = CudaInstallation.version();
892
893 if (CudaInstallationVersion >= CudaVersion::UNKNOWN)
894 CC1Args.push_back(
895 DriverArgs.MakeArgString(Twine("-target-sdk-version=") +
896 CudaVersionToString(CudaInstallationVersion)));
897
898 if (DeviceOffloadingKind == Action::OFK_OpenMP) {
899 if (CudaInstallationVersion < CudaVersion::CUDA_92) {
900 getDriver().Diag(
901 diag::err_drv_omp_offload_target_cuda_version_not_support)
902 << CudaVersionToString(CudaInstallationVersion);
903 return;
904 }
905
906 // Link the bitcode library late if we're using device LTO.
907 if (getDriver().isUsingOffloadLTO())
908 return;
909
910 addOpenMPDeviceRTL(getDriver(), DriverArgs, CC1Args, GpuArch.str(),
911 getTriple(), HostTC);
912 }
913}
914
916 const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
917 const llvm::fltSemantics *FPType) const {
919 if (FPType && FPType == &llvm::APFloat::IEEEsingle() &&
920 DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
921 options::OPT_fno_gpu_flush_denormals_to_zero, false))
922 return llvm::DenormalMode::getPreserveSign();
923 }
924
926 return llvm::DenormalMode::getIEEE();
927}
928
929void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
930 ArgStringList &CC1Args) const {
931 // Check our CUDA version if we're going to include the CUDA headers.
932 if (DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
933 true) &&
934 !DriverArgs.hasArg(options::OPT_no_cuda_version_check)) {
935 StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
936 assert(!Arch.empty() && "Must have an explicit GPU arch.");
937 CudaInstallation.CheckCudaVersionSupportsArch(StringToOffloadArch(Arch));
938 }
939 CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
940}
941
942std::string CudaToolChain::getInputFilename(const InputInfo &Input) const {
943 // Only object files are changed, for example assembly files keep their .s
944 // extensions. If the user requested device-only compilation don't change it.
945 if (Input.getType() != types::TY_Object || getDriver().offloadDeviceOnly())
946 return ToolChain::getInputFilename(Input);
947
948 return ToolChain::getInputFilename(Input);
949}
950
951llvm::opt::DerivedArgList *
952CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
953 StringRef BoundArch,
954 Action::OffloadKind DeviceOffloadKind) const {
955 DerivedArgList *DAL =
956 HostTC.TranslateArgs(Args, BoundArch, DeviceOffloadKind);
957 if (!DAL)
958 DAL = new DerivedArgList(Args.getBaseArgs());
959
960 const OptTable &Opts = getDriver().getOpts();
961
962 for (Arg *A : Args) {
963 // Make sure flags are not duplicated.
964 if (!llvm::is_contained(*DAL, A)) {
965 DAL->append(A);
966 }
967 }
968
969 if (!BoundArch.empty()) {
970 DAL->eraseArg(options::OPT_march_EQ);
971 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
972 BoundArch);
973 }
974 return DAL;
975}
976
978 return new tools::NVPTX::Assembler(*this);
979}
980
982 return new tools::NVPTX::Linker(*this);
983}
984
986 return new tools::NVPTX::Assembler(*this);
987}
988
990 return new tools::NVPTX::FatBinary(*this);
991}
992
993void CudaToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
994 HostTC.addClangWarningOptions(CC1Args);
995}
996
998CudaToolChain::GetCXXStdlibType(const ArgList &Args) const {
999 return HostTC.GetCXXStdlibType(Args);
1000}
1001
1002void CudaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
1003 ArgStringList &CC1Args) const {
1004 HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
1005
1006 if (DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
1007 true) &&
1008 CudaInstallation.isValid())
1009 CC1Args.append(
1010 {"-internal-isystem",
1011 DriverArgs.MakeArgString(CudaInstallation.getIncludePath())});
1012}
1013
1015 ArgStringList &CC1Args) const {
1016 HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
1017}
1018
1019void CudaToolChain::AddIAMCUIncludeArgs(const ArgList &Args,
1020 ArgStringList &CC1Args) const {
1021 HostTC.AddIAMCUIncludeArgs(Args, CC1Args);
1022}
1023
1025 // The CudaToolChain only supports sanitizers in the sense that it allows
1026 // sanitizer arguments on the command line if they are supported by the host
1027 // toolchain. The CudaToolChain will actually ignore any command line
1028 // arguments for any of these "supported" sanitizers. That means that no
1029 // sanitization of device code is actually supported at this time.
1030 //
1031 // This behavior is necessary because the host and device toolchains
1032 // invocations often share the command line, so the device toolchain must
1033 // tolerate flags meant only for the host toolchain.
1034 return HostTC.getSupportedSanitizers();
1035}
1036
1038 const ArgList &Args) const {
1039 return HostTC.computeMSVCVersion(D, Args);
1040}
static DeviceDebugInfoLevel mustEmitDebugInfo(const ArgList &Args)
Define debug info level for the NVPTX devices.
Definition Cuda.cpp:365
static bool shouldIncludePTX(const ArgList &Args, StringRef InputArch)
Definition Cuda.cpp:509
#define CASE_CUDA_VERSION(CUDA_VER, PTX_VER)
const char * getOffloadingArch() const
Definition Action.h:213
OffloadKind getOffloadingDeviceKind() const
Definition Action.h:212
bool isDeviceOffloading(OffloadKind OKind) const
Definition Action.h:223
bool isOffloading(OffloadKind OKind) const
Definition Action.h:226
Compilation - A set of tasks to perform for a single driver invocation.
Definition Compilation.h:45
A class to find a viable CUDA installation.
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition Cuda.cpp:295
CudaInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, const llvm::opt::ArgList &Args)
Definition Cuda.cpp:139
CudaVersion version() const
Get the detected Cuda install's version.
void CheckCudaVersionSupportsArch(OffloadArch Arch) const
Emit an error if Version does not support the given Arch.
Definition Cuda.cpp:320
void print(raw_ostream &OS) const
Print information about the detected CUDA installation.
Definition Cuda.cpp:337
bool isValid() const
Check whether we detected a valid Cuda install.
Distro - Helper class for detecting and classifying Linux distributions.
Definition Distro.h:23
bool IsDebian() const
Definition Distro.h:133
bool IsUbuntu() const
Definition Distro.h:137
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:99
DiagnosticBuilder Diag(unsigned DiagID) const
Definition Driver.h:169
const llvm::opt::OptTable & getOpts() const
Definition Driver.h:428
InputInfo - Wrapper for information about an input source.
Definition InputInfo.h:22
const char * getFilename() const
Definition InputInfo.h:83
bool isNothing() const
Definition InputInfo.h:74
bool isFilename() const
Definition InputInfo.h:75
types::ID getType() const
Definition InputInfo.h:77
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:92
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...
const Driver & getDriver() const
Definition ToolChain.h:253
ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
Definition ToolChain.cpp:89
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:359
const llvm::Triple & getTriple() const
Definition ToolChain.h:255
std::string GetProgramPath(const char *Name) const
StringRef getArchName() const
Definition ToolChain.h:270
Tool - Information on a specific compilation tool.
Definition Tool.h:32
const ToolChain & getToolChain() const
Definition Tool.h:52
const char * getShortName() const
Definition Tool.h:50
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:942
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific CUDA includes.
Definition Cuda.cpp:929
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:1014
void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override
Add warning options that need to be passed to cc1 for this target.
Definition Cuda.cpp:993
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition Cuda.cpp:1024
void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use MCU GCC toolchain includes.
Definition Cuda.cpp:1019
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:842
VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const override
On Windows, returns the MSVC compatibility version.
Definition Cuda.cpp:1037
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition Cuda.cpp:998
CudaToolChain(const Driver &D, const llvm::Triple &Triple, const ToolChain &HostTC, const llvm::opt::ArgList &Args)
CUDA toolchain.
Definition Cuda.cpp:838
Tool * buildLinker() const override
Definition Cuda.cpp:989
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:1002
Tool * buildAssembler() const override
Definition Cuda.cpp:985
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:915
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:952
CudaInstallationDetector CudaInstallation
Definition Cuda.h:123
Tool * buildAssembler() const override
Definition Cuda.cpp:977
Tool * buildLinker() const override
Definition Cuda.cpp:981
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:741
bool supportsDebugInfoOption(const llvm::opt::Arg *A) const override
Does this toolchain supports given debug info option or not.
Definition Cuda.cpp:781
virtual Expected< SmallVector< std::string > > getSystemGPUArchs(const llvm::opt::ArgList &Args) const override
Uses nvptx-arch tool to get arch of the system GPU.
Definition Cuda.cpp:810
void adjustDebugInfoKind(llvm::codegenoptions::DebugInfoKind &DebugInfoKind, const llvm::opt::ArgList &Args) const override
Adjust debug information kind considering all passed options.
Definition Cuda.cpp:793
NVPTXToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::Triple &HostTriple, const llvm::opt::ArgList &Args)
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:777
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition Cuda.cpp:384
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition Cuda.cpp:530
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition Cuda.cpp:575
void getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features)
Definition Cuda.cpp:665
void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, StringRef BitcodeSuffix, const llvm::Triple &Triple, const ToolChain &HostTC)
void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output, const InputInfoList &Inputs, bool IsThinLTO)
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.
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
SmallVector< InputInfo, 4 > InputInfoList
Definition Driver.h:50
bool willEmitRemarks(const llvm::opt::ArgList &Args)
The JSON file list parser is used to communicate input to InstallAPI.
CudaVersion MaxVersionForOffloadArch(OffloadArch A)
Get the latest CudaVersion that supports the given OffloadArch.
Definition Cuda.cpp:133
static bool IsNVIDIAOffloadArch(OffloadArch A)
const char * CudaVersionToString(CudaVersion V)
Definition Cuda.cpp:53
OffloadArch StringToOffloadArch(llvm::StringRef S)
CudaVersion
Definition Cuda.h:22
@ PARTIALLY_SUPPORTED
Definition Cuda.h:52
const char * OffloadArchToString(OffloadArch A)
CudaVersion MinVersionForOffloadArch(OffloadArch A)
Get the earliest CudaVersion that supports the given OffloadArch.
Definition Cuda.cpp:76
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30