clang 8.0.0

Cuda.h
Go to the documentation of this file.
1 //===--- Cuda.h - Cuda ToolChain Implementations ----------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H
11 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H
12
13 #include "clang/Basic/Cuda.h"
14 #include "clang/Driver/Action.h"
15 #include "clang/Driver/Multilib.h"
16 #include "clang/Driver/Tool.h"
17 #include "clang/Driver/ToolChain.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/ADT/SmallSet.h"
20 #include "llvm/Support/Compiler.h"
21 #include "llvm/Support/VersionTuple.h"
22 #include <set>
23 #include <vector>
24
25 namespace clang {
26 namespace driver {
27
28 /// A class to find a viable CUDA installation
29 class CudaInstallationDetector {
30 private:
31 const Driver &D;
32 bool IsValid = false;
33 CudaVersion Version = CudaVersion::UNKNOWN;
34 std::string InstallPath;
35 std::string BinPath;
36 std::string LibPath;
37 std::string LibDevicePath;
38 std::string IncludePath;
39 llvm::StringMap<std::string> LibDeviceMap;
40
41 // CUDA architectures for which we have raised an error in
42 // CheckCudaVersionSupportsArch.
43 mutable llvm::SmallSet<CudaArch, 4> ArchsWithBadVersion;
44
45 public:
46 CudaInstallationDetector(const Driver &D, const llvm::Triple &HostTriple,
47 const llvm::opt::ArgList &Args);
48
49 void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
50 llvm::opt::ArgStringList &CC1Args) const;
51
52 /// Emit an error if Version does not support the given Arch.
53 ///
54 /// If either Version or Arch is unknown, does not emit an error. Emits at
55 /// most one error per Arch.
56 void CheckCudaVersionSupportsArch(CudaArch Arch) const;
57
58 /// Check whether we detected a valid Cuda install.
59 bool isValid() const { return IsValid; }
60 /// Print information about the detected CUDA installation.
61 void print(raw_ostream &OS) const;
62
63 /// Get the detected Cuda install's version.
64 CudaVersion version() const { return Version; }
65 /// Get the detected Cuda installation path.
66 StringRef getInstallPath() const { return InstallPath; }
67 /// Get the detected path to Cuda's bin directory.
68 StringRef getBinPath() const { return BinPath; }
69 /// Get the detected Cuda Include path.
70 StringRef getIncludePath() const { return IncludePath; }
71 /// Get the detected Cuda library path.
72 StringRef getLibPath() const { return LibPath; }
73 /// Get the detected Cuda device library path.
74 StringRef getLibDevicePath() const { return LibDevicePath; }
75 /// Get libdevice file for given architecture
76 std::string getLibDeviceFile(StringRef Gpu) const {
77 return LibDeviceMap.lookup(Gpu);
78 }
79 };
80
81 namespace tools {
82 namespace NVPTX {
83
84 // Run ptxas, the NVPTX assembler.
85 class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
86 public:
87 Assembler(const ToolChain &TC)
88 : Tool("NVPTX::Assembler", "ptxas", TC, RF_Full, llvm::sys::WEM_UTF8,
89 "--options-file") {}
90
91 bool hasIntegratedCPP() const override { return false; }
92
93 void ConstructJob(Compilation &C, const JobAction &JA,
94 const InputInfo &Output, const InputInfoList &Inputs,
95 const llvm::opt::ArgList &TCArgs,
96 const char *LinkingOutput) const override;
97 };
98
99 // Runs fatbinary, which combines GPU object files ("cubin" files) and/or PTX
100 // assembly into a single output file.
101 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
102 public:
103 Linker(const ToolChain &TC)
104 : Tool("NVPTX::Linker", "fatbinary", TC, RF_Full, llvm::sys::WEM_UTF8,
105 "--options-file") {}
106
107 bool hasIntegratedCPP() const override { return false; }
108
109 void ConstructJob(Compilation &C, const JobAction &JA,
110 const InputInfo &Output, const InputInfoList &Inputs,
111 const llvm::opt::ArgList &TCArgs,
112 const char *LinkingOutput) const override;
113 };
114
115 class LLVM_LIBRARY_VISIBILITY OpenMPLinker : public Tool {
116 public:
117 OpenMPLinker(const ToolChain &TC)
118 : Tool("NVPTX::OpenMPLinker", "nvlink", TC, RF_Full, llvm::sys::WEM_UTF8,
119 "--options-file") {}
120
121 bool hasIntegratedCPP() const override { return false; }
122
123 void ConstructJob(Compilation &C, const JobAction &JA,
124 const InputInfo &Output, const InputInfoList &Inputs,
125 const llvm::opt::ArgList &TCArgs,
126 const char *LinkingOutput) const override;
127 };
128
129 } // end namespace NVPTX
130 } // end namespace tools
131
132 namespace toolchains {
133
134 class LLVM_LIBRARY_VISIBILITY CudaToolChain : public ToolChain {
135 public:
136 CudaToolChain(const Driver &D, const llvm::Triple &Triple,
137 const ToolChain &HostTC, const llvm::opt::ArgList &Args,
138 const Action::OffloadKind OK);
139
140 const llvm::Triple *getAuxTriple() const override {
141 return &HostTC.getTriple();
142 }
143
144 std::string getInputFilename(const InputInfo &Input) const override;
145
146 llvm::opt::DerivedArgList *
147 TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
148 Action::OffloadKind DeviceOffloadKind) const override;
149 void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
150 llvm::opt::ArgStringList &CC1Args,
151 Action::OffloadKind DeviceOffloadKind) const override;
152
153 // Never try to use the integrated assembler with CUDA; always fork out to
154 // ptxas.
155 bool useIntegratedAs() const override { return false; }
156 bool isCrossCompiling() const override { return true; }
157 bool isPICDefault() const override { return false; }
158 bool isPIEDefault() const override { return false; }
159 bool isPICDefaultForced() const override { return false; }
160 bool SupportsProfiling() const override { return false; }
161 bool supportsDebugInfoOption(const llvm::opt::Arg *A) const override;
162 void adjustDebugInfoKind(codegenoptions::DebugInfoKind &DebugInfoKind,
163 const llvm::opt::ArgList &Args) const override;
164 bool IsMathErrnoDefault() const override { return false; }
165
166 void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
167 llvm::opt::ArgStringList &CC1Args) const override;
168
169 void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
170 CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
171 void
172 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
173 llvm::opt::ArgStringList &CC1Args) const override;
174 void AddClangCXXStdlibIncludeArgs(
175 const llvm::opt::ArgList &Args,
176 llvm::opt::ArgStringList &CC1Args) const override;
177 void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
178 llvm::opt::ArgStringList &CC1Args) const override;
179
180 SanitizerMask getSupportedSanitizers() const override;
181
182 VersionTuple
183 computeMSVCVersion(const Driver *D,
184 const llvm::opt::ArgList &Args) const override;
185
186 unsigned GetDefaultDwarfVersion() const override { return 2; }
187
188 const ToolChain &HostTC;
189 CudaInstallationDetector CudaInstallation;
190
191 protected:
192 Tool *buildAssembler() const override; // ptxas
193 Tool *buildLinker() const override; // fatbinary (ok, not really a linker)
194
195 private:
196 const Action::OffloadKind OK;
197 };
198
199 } // end namespace toolchains
200 } // end namespace driver
201 } // end namespace clang
202
203 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H
clang::driver::CudaInstallationDetector::getLibPath
StringRef getLibPath() const
Get the detected Cuda library path.
Definition: Cuda.h:72
clang::codegenoptions::DebugInfoKind
DebugInfoKind
Definition: DebugInfoOptions.h:21
clang::driver::tools::NVPTX::Linker::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Cuda.h:107
clang::CudaArch
CudaArch
Definition: Cuda.h:35
llvm
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
clang::CudaVersion::UNKNOWN
Tool.h
clang::driver::tools::NVPTX::Assembler::Assembler
Assembler(const ToolChain &TC)
Definition: Cuda.h:87
clang::driver::CudaInstallationDetector::CudaInstallationDetector
CudaInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, const llvm::opt::ArgList &Args)
Definition: Cuda.cpp:67
Action.h
clang::driver::CudaInstallationDetector::print
void print(raw_ostream &OS) const
Print information about the detected CUDA installation.
Definition: Cuda.cpp:274
clang::driver::ToolChain::CXXStdlibType
CXXStdlibType
Definition: ToolChain.h:93
clang::driver::CudaInstallationDetector
A class to find a viable CUDA installation.
Definition: Cuda.h:29
clang::driver::CudaInstallationDetector::getInstallPath
StringRef getInstallPath() const
Get the detected Cuda installation path.
Definition: Cuda.h:66
clang::driver::JobAction
Definition: Action.h:374
clang::driver::toolchains::CudaToolChain::getAuxTriple
const llvm::Triple * getAuxTriple() const override
Get the toolchain&#39;s aux triple, if it has one.
Definition: Cuda.h:140
clang::driver::toolchains::CudaToolChain::IsMathErrnoDefault
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: Cuda.h:164
clang::driver::toolchains::CudaToolChain::isPIEDefault
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: Cuda.h:158
clang::driver::toolchains::CudaToolChain::isCrossCompiling
bool isCrossCompiling() const override
Returns true if the toolchain is targeting a non-native architecture.
Definition: Cuda.h:156
clang::driver::CudaInstallationDetector::CheckCudaVersionSupportsArch
void CheckCudaVersionSupportsArch(CudaArch Arch) const
Emit an error if Version does not support the given Arch.
Definition: Cuda.cpp:257
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:23
clang::driver::CudaInstallationDetector::getLibDeviceFile
std::string getLibDeviceFile(StringRef Gpu) const
Get libdevice file for given architecture.
Definition: Cuda.h:76
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:58
clang::driver::tools::NVPTX::Linker::Linker
Linker(const ToolChain &TC)
Definition: Cuda.h:103
clang::driver::CudaInstallationDetector::getLibDevicePath
StringRef getLibDevicePath() const
Get the detected Cuda device library path.
Definition: Cuda.h:74
clang::driver::toolchains::CudaToolChain::CudaInstallation
CudaInstallationDetector CudaInstallation
Definition: Cuda.h:189
clang::driver::toolchains::CudaToolChain
Definition: Cuda.h:134
clang::driver::toolchains::CudaToolChain::HostTC
const ToolChain & HostTC
Definition: Cuda.h:188
clang::driver::tools::NVPTX::OpenMPLinker::OpenMPLinker
OpenMPLinker(const ToolChain &TC)
Definition: Cuda.h:117
clang::driver::tools::NVPTX::OpenMPLinker::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Cuda.h:121
Cuda.h
clang::driver::CudaInstallationDetector::AddCudaIncludeArgs
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Cuda.cpp:231
clang::driver::CudaInstallationDetector::version
CudaVersion version() const
Get the detected Cuda install&#39;s version.
Definition: Cuda.h:64
clang::CudaVersion
CudaVersion
Definition: Cuda.h:19
Multilib.h
ToolChain.h
llvm::SmallVector
Definition: LLVM.h:36
clang::driver::CudaInstallationDetector::isValid
bool isValid() const
Check whether we detected a valid Cuda install.
Definition: Cuda.h:59
clang::driver::tools::NVPTX::OpenMPLinker
Definition: Cuda.h:115
clang::driver::CudaInstallationDetector::getIncludePath
StringRef getIncludePath() const
Get the detected Cuda Include path.
Definition: Cuda.h:70
clang::driver::toolchains::CudaToolChain::isPICDefaultForced
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: Cuda.h:159
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:83
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::driver::toolchains::CudaToolChain::isPICDefault
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: Cuda.h:157
clang::driver::tools::NVPTX::Assembler::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Cuda.h:91
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
clang::SanitizerMask
uint64_t SanitizerMask
Definition: Sanitizers.h:26
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:46
clang::driver::ToolChain::getTriple
const llvm::Triple & getTriple() const
Definition: ToolChain.h:188
clang::driver::toolchains::CudaToolChain::useIntegratedAs
bool useIntegratedAs() const override
Check if the toolchain should use the integrated assembler.
Definition: Cuda.h:155
clang::driver::tools::NVPTX::Assembler
Definition: Cuda.h:85
clang::driver::toolchains::CudaToolChain::GetDefaultDwarfVersion
unsigned GetDefaultDwarfVersion() const override
Definition: Cuda.h:186
clang::driver::tools::NVPTX::Linker
Definition: Cuda.h:101
clang::driver::toolchains::CudaToolChain::SupportsProfiling
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
Definition: Cuda.h:160
clang::driver::CudaInstallationDetector::getBinPath
StringRef getBinPath() const
Get the detected path to Cuda&#39;s bin directory.
Definition: Cuda.h:68
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:89