Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -3095,13 +3095,22 @@ for (auto Arch : GpuArchs) GpuArchList.push_back(Arch.data()); - // Default to sm_20 which is the lowest common denominator for + // CUDA defaults to sm_20 which is the lowest common denominator for // supported GPUs. sm_20 code should work correctly, if // suboptimally, on all newer GPUs. if (GpuArchList.empty()) { if (ToolChains.front()->getTriple().isSPIRV()) GpuArchList.push_back(CudaArch::Generic); - else + else if (ToolChains.front()->getTriple().isAMDGPU()) { + auto *TC = static_cast( + ToolChains.front()); + SmallVector GPUs; + if (!TC->detectSystemGPUs(Args, GPUs)) { + for (auto GPU : GPUs) + GpuArchList.push_back(Args.MakeArgString(GPU)); + } else + GpuArchList.push_back(DefaultCudaArch); + } else GpuArchList.push_back(DefaultCudaArch); } Index: clang/lib/Driver/ToolChains/AMDGPU.h =================================================================== --- clang/lib/Driver/ToolChains/AMDGPU.h +++ clang/lib/Driver/ToolChains/AMDGPU.h @@ -107,6 +107,9 @@ llvm::Error getSystemGPUArch(const llvm::opt::ArgList &Args, std::string &GPUArch) const; + llvm::Error detectSystemGPUs(const llvm::opt::ArgList &Args, + SmallVector &GPUArchs) const; + protected: /// Check and diagnose invalid target ID specified by -mcpu. virtual void checkTargetID(const llvm::opt::ArgList &DriverArgs) const; @@ -126,8 +129,6 @@ /// Get GPU arch from -mcpu without checking. StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const; - llvm::Error detectSystemGPUs(const llvm::opt::ArgList &Args, - SmallVector &GPUArchs) const; }; class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {