|
| 1 | +//===-- CudaInstallationDetector.h - Cuda Instalation Detector --*- 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 | +#ifndef LLVM_CLANG_DRIVER_CUDAINSTALLATIONDETECTOR_H |
| 10 | +#define LLVM_CLANG_DRIVER_CUDAINSTALLATIONDETECTOR_H |
| 11 | + |
| 12 | +#include "clang/Basic/Cuda.h" |
| 13 | +#include "clang/Driver/Driver.h" |
| 14 | +#include <bitset> |
| 15 | + |
| 16 | +namespace clang { |
| 17 | +namespace driver { |
| 18 | + |
| 19 | +/// A class to find a viable CUDA installation |
| 20 | +class CudaInstallationDetector { |
| 21 | +private: |
| 22 | + const Driver &D; |
| 23 | + bool IsValid = false; |
| 24 | + CudaVersion Version = CudaVersion::UNKNOWN; |
| 25 | + std::string InstallPath; |
| 26 | + std::string BinPath; |
| 27 | + std::string LibDevicePath; |
| 28 | + std::string IncludePath; |
| 29 | + llvm::StringMap<std::string> LibDeviceMap; |
| 30 | + |
| 31 | + // CUDA architectures for which we have raised an error in |
| 32 | + // CheckCudaVersionSupportsArch. |
| 33 | + mutable std::bitset<(int)OffloadArch::LAST> ArchsWithBadVersion; |
| 34 | + |
| 35 | +public: |
| 36 | + CudaInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, |
| 37 | + const llvm::opt::ArgList &Args); |
| 38 | + |
| 39 | + void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, |
| 40 | + llvm::opt::ArgStringList &CC1Args) const; |
| 41 | + |
| 42 | + /// Emit an error if Version does not support the given Arch. |
| 43 | + /// |
| 44 | + /// If either Version or Arch is unknown, does not emit an error. Emits at |
| 45 | + /// most one error per Arch. |
| 46 | + void CheckCudaVersionSupportsArch(OffloadArch Arch) const; |
| 47 | + |
| 48 | + /// Check whether we detected a valid Cuda install. |
| 49 | + bool isValid() const { return IsValid; } |
| 50 | + /// Print information about the detected CUDA installation. |
| 51 | + void print(raw_ostream &OS) const; |
| 52 | + |
| 53 | + /// Get the detected Cuda install's version. |
| 54 | + CudaVersion version() const { |
| 55 | + return Version == CudaVersion::NEW ? CudaVersion::PARTIALLY_SUPPORTED |
| 56 | + : Version; |
| 57 | + } |
| 58 | + /// Get the detected Cuda installation path. |
| 59 | + StringRef getInstallPath() const { return InstallPath; } |
| 60 | + /// Get the detected path to Cuda's bin directory. |
| 61 | + StringRef getBinPath() const { return BinPath; } |
| 62 | + /// Get the detected Cuda Include path. |
| 63 | + StringRef getIncludePath() const { return IncludePath; } |
| 64 | + /// Get the detected Cuda device library path. |
| 65 | + StringRef getLibDevicePath() const { return LibDevicePath; } |
| 66 | + /// Get libdevice file for given architecture |
| 67 | + std::string getLibDeviceFile(StringRef Gpu) const { |
| 68 | + return LibDeviceMap.lookup(Gpu); |
| 69 | + } |
| 70 | + void WarnIfUnsupportedVersion() const; |
| 71 | +}; |
| 72 | + |
| 73 | +} // namespace driver |
| 74 | +} // namespace clang |
| 75 | + |
| 76 | +#endif // LLVM_CLANG_DRIVER_CUDAINSTALLATIONDETECTOR_H |
0 commit comments