Skip to content

Commit bed7005

Browse files
committed
[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
1 parent 4a38d33 commit bed7005

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/Basic/Targets/NVPTX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts,
168168
MacroBuilder &Builder) const {
169169
Builder.defineMacro("__PTX__");
170170
Builder.defineMacro("__NVPTX__");
171-
if (Opts.CUDAIsDevice || Opts.OpenMPIsDevice) {
171+
if (Opts.CUDAIsDevice || Opts.OpenMPIsDevice || !HostTarget) {
172172
// Set __CUDA_ARCH__ for the GPU specified.
173173
std::string CUDAArchCode = [this] {
174174
switch (GPU) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// REQUIRES: nvptx-registered-target
2+
3+
// RUN: %clang %s -c -E -dM --target=nvptx64-nvidia-cuda -march=sm_70 -o - | \
4+
// RUN: FileCheck --check-prefix=CHECK-CUDA-ARCH %s
5+
// CHECK-CUDA-ARCH: #define __CUDA_ARCH__ 700

0 commit comments

Comments
 (0)