Author: Joseph Huber Date: 2023-03-27T18:08:15-05:00 New Revision: bed7005eb4d4850b6f9d93707213ced5c0c19de0
URL: https://github.com/llvm/llvm-project/commit/bed7005eb4d4850b6f9d93707213ced5c0c19de0 DIFF: https://github.com/llvm/llvm-project/commit/bed7005eb4d4850b6f9d93707213ced5c0c19de0.diff LOG: [NVPTX] Add __CUDA_ARCH__ macro to standalone NVPTX compilations We can now target the NVPTX architecture directly via `--target=nvptx64-nvidia-cuda`. This currently does not define the `__CUDA_ARCH__` macro with is used to allow code to target different codes based on support. This patch simply adds this support. Reviewed By: tra, jdoerfert Differential Revision: https://reviews.llvm.org/D146975 Added: clang/test/Frontend/standalone-nvptx-macros.c Modified: clang/lib/Basic/Targets/NVPTX.cpp Removed: ################################################################################ diff --git a/clang/lib/Basic/Targets/NVPTX.cpp b/clang/lib/Basic/Targets/NVPTX.cpp index aca51b2b95b59..7f4c5d83d8bd7 100644 --- a/clang/lib/Basic/Targets/NVPTX.cpp +++ b/clang/lib/Basic/Targets/NVPTX.cpp @@ -168,7 +168,7 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { Builder.defineMacro("__PTX__"); Builder.defineMacro("__NVPTX__"); - if (Opts.CUDAIsDevice || Opts.OpenMPIsDevice) { + if (Opts.CUDAIsDevice || Opts.OpenMPIsDevice || !HostTarget) { // Set __CUDA_ARCH__ for the GPU specified. std::string CUDAArchCode = [this] { switch (GPU) { diff --git a/clang/test/Frontend/standalone-nvptx-macros.c b/clang/test/Frontend/standalone-nvptx-macros.c new file mode 100644 index 0000000000000..5cf20ecdde25d --- /dev/null +++ b/clang/test/Frontend/standalone-nvptx-macros.c @@ -0,0 +1,5 @@ +// REQUIRES: nvptx-registered-target + +// RUN: %clang %s -c -E -dM --target=nvptx64-nvidia-cuda -march=sm_70 -o - | \ +// RUN: FileCheck --check-prefix=CHECK-CUDA-ARCH %s +// CHECK-CUDA-ARCH: #define __CUDA_ARCH__ 700 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits