[PATCH] D146975: [NVPTX] Add __CUDA_ARCH__ macro to standalone NVPTX compilations
Joseph Huber via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 27 08:20:43 PDT 2023
jhuber6 created this revision.
jhuber6 added reviewers: tra, tianshilei1992, ye-luo, jdoerfert.
Herald added subscribers: mattd, gchakrabarti, asavonic, yaxunl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1, jholewinski.
Herald added a project: clang.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146975
Files:
clang/lib/Basic/Targets/NVPTX.cpp
clang/test/Frontend/nvptx-macros.c
Index: clang/test/Frontend/nvptx-macros.c
===================================================================
--- /dev/null
+++ clang/test/Frontend/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
Index: clang/lib/Basic/Targets/NVPTX.cpp
===================================================================
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -168,7 +168,7 @@
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146975.508672.patch
Type: text/x-patch
Size: 978 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230327/3a0c32dd/attachment.bin>
More information about the cfe-commits
mailing list