From bec8a66454882285db4c98311ba430adec2c8dac Mon Sep 17 00:00:00 2001 From: Yaxun Liu Date: Mon, 9 Apr 2018 15:43:01 +0000 Subject: [PATCH] [CUDA] Revert defining __CUDA_ARCH__ for amdgcn targets amdgcn targets only support HIP, which does not define __CUDA_ARCH__. this is a partial unroll of r329232 / D45277. Differential Revision: https://reviews.llvm.org/D45387 llvm-svn: 329584 --- clang/lib/Basic/Targets.cpp | 55 ------------------------------------ clang/lib/Basic/Targets.h | 4 --- clang/lib/Basic/Targets/AMDGPU.cpp | 5 ---- clang/lib/Basic/Targets/AMDGPU.h | 3 -- clang/lib/Basic/Targets/NVPTX.cpp | 57 ++++++++++++++++++++++++++++++++++++-- 5 files changed, 55 insertions(+), 69 deletions(-) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index f468588..e325403 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -112,61 +112,6 @@ void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts, addCygMingDefines(Opts, Builder); } -void defineCudaArchMacro(CudaArch GPU, clang::MacroBuilder &Builder) { - std::string CUDAArchCode = [GPU] { - switch (GPU) { - case CudaArch::LAST: - break; - case CudaArch::SM_20: - return "200"; - case CudaArch::SM_21: - return "210"; - case CudaArch::SM_30: - return "300"; - case CudaArch::SM_32: - return "320"; - case CudaArch::SM_35: - return "350"; - case CudaArch::SM_37: - return "370"; - case CudaArch::SM_50: - return "500"; - case CudaArch::SM_52: - return "520"; - case CudaArch::SM_53: - return "530"; - case CudaArch::SM_60: - return "600"; - case CudaArch::SM_61: - return "610"; - case CudaArch::SM_62: - return "620"; - case CudaArch::SM_70: - return "700"; - case CudaArch::SM_72: - return "720"; - case CudaArch::GFX600: - case CudaArch::GFX601: - case CudaArch::GFX700: - case CudaArch::GFX701: - case CudaArch::GFX702: - case CudaArch::GFX703: - case CudaArch::GFX704: - case CudaArch::GFX801: - case CudaArch::GFX802: - case CudaArch::GFX803: - case CudaArch::GFX810: - case CudaArch::GFX900: - case CudaArch::GFX902: - return "1"; - case CudaArch::UNKNOWN: - llvm_unreachable("unhandled Cuda/HIP Arch"); - } - llvm_unreachable("unhandled Cuda/HIP Arch"); - }(); - Builder.defineMacro("__CUDA_ARCH__", CUDAArchCode); -} - //===----------------------------------------------------------------------===// // Driver code //===----------------------------------------------------------------------===// diff --git a/clang/lib/Basic/Targets.h b/clang/lib/Basic/Targets.h index bb933c0..6fc967d 100644 --- a/clang/lib/Basic/Targets.h +++ b/clang/lib/Basic/Targets.h @@ -16,7 +16,6 @@ #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_H #define LLVM_CLANG_LIB_BASIC_TARGETS_H -#include "clang/Basic/Cuda.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetInfo.h" @@ -47,9 +46,6 @@ void addMinGWDefines(const llvm::Triple &Triple, const clang::LangOptions &Opts, LLVM_LIBRARY_VISIBILITY void addCygMingDefines(const clang::LangOptions &Opts, clang::MacroBuilder &Builder); - -LLVM_LIBRARY_VISIBILITY -void defineCudaArchMacro(CudaArch GPU, clang::MacroBuilder &Builder); } // namespace targets } // namespace clang #endif // LLVM_CLANG_LIB_BASIC_TARGETS_H diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp index 51943c7..d956d13 100644 --- a/clang/lib/Basic/Targets/AMDGPU.cpp +++ b/clang/lib/Basic/Targets/AMDGPU.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "AMDGPU.h" -#include "Targets.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/MacroBuilder.h" @@ -264,7 +263,6 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple, resetDataLayout(isAMDGCN(getTriple()) ? DataLayoutStringAMDGCN : DataLayoutStringR600); assert(DataLayout->getAllocaAddrSpace() == Private); - GCN_Subarch = CudaArch::GFX803; // Default to fiji setAddressSpaceMap(Triple.getOS() == llvm::Triple::Mesa3D || !isAMDGCN(Triple)); @@ -309,9 +307,6 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts, if (GPU.Kind != GK_NONE) Builder.defineMacro(Twine("__") + Twine(GPU.CanonicalName) + Twine("__")); - if (Opts.CUDAIsDevice) - defineCudaArchMacro(GCN_Subarch, Builder); - // TODO: __HAS_FMAF__, __HAS_LDEXPF__, __HAS_FP64__ are deprecated and will be // removed in the near future. if (GPU.HasFMAF) diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h index 1249031..f7c4776 100644 --- a/clang/lib/Basic/Targets/AMDGPU.h +++ b/clang/lib/Basic/Targets/AMDGPU.h @@ -14,7 +14,6 @@ #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H #define LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H -#include "clang/Basic/Cuda.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" #include "llvm/ADT/StringSet.h" @@ -175,7 +174,6 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo { static bool isAMDGCN(const llvm::Triple &TT) { return TT.getArch() == llvm::Triple::amdgcn; } - CudaArch GCN_Subarch; public: AMDGPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); @@ -332,7 +330,6 @@ public: else GPU = parseR600Name(Name); - GCN_Subarch = StringToCudaArch(Name); return GK_NONE != GPU.Kind; } diff --git a/clang/lib/Basic/Targets/NVPTX.cpp b/clang/lib/Basic/Targets/NVPTX.cpp index cb24fd9..c497e2e 100644 --- a/clang/lib/Basic/Targets/NVPTX.cpp +++ b/clang/lib/Basic/Targets/NVPTX.cpp @@ -153,8 +153,61 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { Builder.defineMacro("__PTX__"); Builder.defineMacro("__NVPTX__"); - if (Opts.CUDAIsDevice) - defineCudaArchMacro(GPU, Builder); + if (Opts.CUDAIsDevice) { + // Set __CUDA_ARCH__ for the GPU specified. + std::string CUDAArchCode = [this] { + switch (GPU) { + case CudaArch::GFX600: + case CudaArch::GFX601: + case CudaArch::GFX700: + case CudaArch::GFX701: + case CudaArch::GFX702: + case CudaArch::GFX703: + case CudaArch::GFX704: + case CudaArch::GFX801: + case CudaArch::GFX802: + case CudaArch::GFX803: + case CudaArch::GFX810: + case CudaArch::GFX900: + case CudaArch::GFX902: + case CudaArch::LAST: + break; + case CudaArch::UNKNOWN: + assert(false && "No GPU arch when compiling CUDA device code."); + return ""; + case CudaArch::SM_20: + return "200"; + case CudaArch::SM_21: + return "210"; + case CudaArch::SM_30: + return "300"; + case CudaArch::SM_32: + return "320"; + case CudaArch::SM_35: + return "350"; + case CudaArch::SM_37: + return "370"; + case CudaArch::SM_50: + return "500"; + case CudaArch::SM_52: + return "520"; + case CudaArch::SM_53: + return "530"; + case CudaArch::SM_60: + return "600"; + case CudaArch::SM_61: + return "610"; + case CudaArch::SM_62: + return "620"; + case CudaArch::SM_70: + return "700"; + case CudaArch::SM_72: + return "720"; + } + llvm_unreachable("unhandled CudaArch"); + }(); + Builder.defineMacro("__CUDA_ARCH__", CUDAArchCode); + } } ArrayRef NVPTXTargetInfo::getTargetBuiltins() const { -- 2.7.4