Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -3312,13 +3312,25 @@ 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; + auto Err = TC->detectSystemGPUs(Args, GPUs); + if (!Err) { + for (auto GPU : GPUs) + GpuArchList.push_back(Args.MakeArgString(GPU)); + } else { + llvm::consumeError(std::move(Err)); + 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 @@ -118,6 +118,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; @@ -137,8 +140,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 {