diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/Driver/ToolChains/ROCm.h')
-rw-r--r-- | contrib/llvm-project/clang/lib/Driver/ToolChains/ROCm.h | 111 |
1 files changed, 96 insertions, 15 deletions
diff --git a/contrib/llvm-project/clang/lib/Driver/ToolChains/ROCm.h b/contrib/llvm-project/clang/lib/Driver/ToolChains/ROCm.h index 21e62a465d7b..dceb0ab03669 100644 --- a/contrib/llvm-project/clang/lib/Driver/ToolChains/ROCm.h +++ b/contrib/llvm-project/clang/lib/Driver/ToolChains/ROCm.h @@ -15,13 +15,33 @@ #include "clang/Driver/Options.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringMap.h" -#include "llvm/ADT/Triple.h" #include "llvm/Option/ArgList.h" #include "llvm/Support/VersionTuple.h" +#include "llvm/TargetParser/Triple.h" namespace clang { namespace driver { +/// ABI version of device library. +struct DeviceLibABIVersion { + unsigned ABIVersion = 0; + DeviceLibABIVersion(unsigned V) : ABIVersion(V) {} + static DeviceLibABIVersion fromCodeObjectVersion(unsigned CodeObjectVersion) { + if (CodeObjectVersion < 4) + CodeObjectVersion = 4; + return DeviceLibABIVersion(CodeObjectVersion * 100); + } + /// Whether ABI version bc file is requested. + /// ABIVersion is code object version multiplied by 100. Code object v4 + /// and below works with ROCm 5.0 and below which does not have + /// abi_version_*.bc. Code object v5 requires abi_version_500.bc. + bool requiresLibrary() { return ABIVersion >= 500; } + std::string toString() { + assert(ABIVersion % 100 == 0 && "Not supported"); + return Twine(ABIVersion / 100).str(); + } +}; + /// A class to find a viable ROCM installation /// TODO: Generalize to handle libclc. class RocmInstallationDetector { @@ -42,14 +62,24 @@ private: struct Candidate { llvm::SmallString<0> Path; bool StrictChecking; - - Candidate(std::string Path, bool StrictChecking = false) - : Path(Path), StrictChecking(StrictChecking) {} + // Release string for ROCm packages built with SPACK if not empty. The + // installation directories of ROCm packages built with SPACK follow the + // convention <package_name>-<rocm_release_string>-<hash>. + std::string SPACKReleaseStr; + + bool isSPACK() const { return !SPACKReleaseStr.empty(); } + Candidate(std::string Path, bool StrictChecking = false, + StringRef SPACKReleaseStr = {}) + : Path(Path), StrictChecking(StrictChecking), + SPACKReleaseStr(SPACKReleaseStr.str()) {} }; const Driver &D; bool HasHIPRuntime = false; bool HasDeviceLibrary = false; + bool HasHIPStdParLibrary = false; + bool HasRocThrustLibrary = false; + bool HasRocPrimLibrary = false; // Default version if not detected or specified. const unsigned DefaultVersionMajor = 3; @@ -67,6 +97,15 @@ private: StringRef RocmPathArg; // ROCm device library paths specified by --rocm-device-lib-path. std::vector<std::string> RocmDeviceLibPathArg; + // HIP runtime path specified by --hip-path. + StringRef HIPPathArg; + // HIP Standard Parallel Algorithm acceleration library specified by + // --hipstdpar-path + StringRef HIPStdParPathArg; + // rocThrust algorithm library specified by --hipstdpar-thrust-path + StringRef HIPRocThrustPathArg; + // rocPrim algorithm library specified by --hipstdpar-prim-path + StringRef HIPRocPrimPathArg; // HIP version specified by --hip-version. StringRef HIPVersionArg; // Wheter -nogpulib is specified. @@ -78,6 +117,7 @@ private: SmallString<0> LibPath; SmallString<0> LibDevicePath; SmallString<0> IncludePath; + SmallString<0> SharePath; llvm::StringMap<std::string> LibDeviceMap; // Libraries that are always linked. @@ -88,6 +128,9 @@ private: SmallString<0> OpenCL; SmallString<0> HIP; + // Asan runtime library + SmallString<0> AsanRTL; + // Libraries swapped based on compile flags. ConditionalLibrary WavefrontSize64; ConditionalLibrary FiniteOnly; @@ -95,6 +138,15 @@ private: ConditionalLibrary DenormalsAreZero; ConditionalLibrary CorrectlyRoundedSqrt; + // Maps ABI version to library path. The version number is in the format of + // three digits as used in the ABI version library name. + std::map<unsigned, std::string> ABIVersionMap; + + // Cache ROCm installation search paths. + SmallVector<Candidate, 4> ROCmSearchDirs; + bool PrintROCmSearchDirs; + bool Verbose; + bool allGenericLibsValid() const { return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && !HIP.empty() && WavefrontSize64.isValid() && FiniteOnly.isValid() && @@ -104,7 +156,14 @@ private: void scanLibDevicePath(llvm::StringRef Path); bool parseHIPVersionFile(llvm::StringRef V); - SmallVector<Candidate, 4> getInstallationPathCandidates(); + const SmallVectorImpl<Candidate> &getInstallationPathCandidates(); + + /// Find the path to a SPACK package under the ROCm candidate installation + /// directory if the candidate is a SPACK ROCm candidate. \returns empty + /// string if the candidate is not SPACK ROCm candidate or the requested + /// package is not found. + llvm::SmallString<0> findSPACKPackage(const Candidate &Cand, + StringRef PackageName); public: RocmInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, @@ -112,12 +171,18 @@ public: bool DetectHIPRuntime = true, bool DetectDeviceLib = false); - /// Add arguments needed to link default bitcode libraries. - void addCommonBitcodeLibCC1Args(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args, - StringRef LibDeviceFile, bool Wave64, - bool DAZ, bool FiniteOnly, bool UnsafeMathOpt, - bool FastRelaxedMath, bool CorrectSqrt) const; + /// Get file paths of default bitcode libraries common to AMDGPU based + /// toolchains. + llvm::SmallVector<std::string, 12> + getCommonBitcodeLibs(const llvm::opt::ArgList &DriverArgs, + StringRef LibDeviceFile, bool Wave64, bool DAZ, + bool FiniteOnly, bool UnsafeMathOpt, + bool FastRelaxedMath, bool CorrectSqrt, + DeviceLibABIVersion ABIVer, bool isOpenMP) const; + /// Check file paths of default bitcode libraries common to AMDGPU based + /// toolchains. \returns false if there are invalid or missing files. + bool checkCommonBitcodeLibs(StringRef GPUArch, StringRef LibDeviceFile, + DeviceLibABIVersion ABIVer) const; /// Check whether we detected a valid HIP runtime. bool hasHIPRuntime() const { return HasHIPRuntime; } @@ -125,6 +190,9 @@ public: /// Check whether we detected a valid ROCm device library. bool hasDeviceLibrary() const { return HasDeviceLibrary; } + /// Check whether we detected a valid HIP STDPAR Acceleration library. + bool hasHIPStdParLibrary() const { return HasHIPStdParLibrary; } + /// Print information about the detected ROCm installation. void print(raw_ostream &OS) const; @@ -166,6 +234,9 @@ public: return HIP; } + /// Returns empty string of Asan runtime library is not available. + StringRef getAsanRTLPath() const { return AsanRTL; } + StringRef getWavefrontSize64Path(bool Enabled) const { return WavefrontSize64.get(Enabled); } @@ -186,9 +257,19 @@ public: return CorrectlyRoundedSqrt.get(Enabled); } + StringRef getABIVersionPath(DeviceLibABIVersion ABIVer) const { + auto Loc = ABIVersionMap.find(ABIVer.ABIVersion); + if (Loc == ABIVersionMap.end()) + return StringRef(); + return Loc->second; + } + /// Get libdevice file for given architecture - std::string getLibDeviceFile(StringRef Gpu) const { - return LibDeviceMap.lookup(Gpu); + StringRef getLibDeviceFile(StringRef Gpu) const { + auto Loc = LibDeviceMap.find(Gpu); + if (Loc == LibDeviceMap.end()) + return ""; + return Loc->second; } void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, @@ -198,7 +279,7 @@ public: void detectHIPRuntime(); /// Get the values for --rocm-device-lib-path arguments - std::vector<std::string> getRocmDeviceLibPathArg() const { + ArrayRef<std::string> getRocmDeviceLibPathArg() const { return RocmDeviceLibPathArg; } @@ -208,7 +289,7 @@ public: /// Get the value for --hip-version argument StringRef getHIPVersionArg() const { return HIPVersionArg; } - std::string getHIPVersion() const { return DetectedVersion; } + StringRef getHIPVersion() const { return DetectedVersion; } }; } // end namespace driver |