Skip to content

Commit 619c462

Browse files
author
Artem Gindinson
authored
[SYCL] Remove the __SYCL_NVPTX__ macro (#3977)
Since the macro is identical to a combination of `__SYCL_DEVICE_ONLY__` and `__NVPTX__`, showing up in the same circumstances (SYCL device compilation with an NVPTX triple), drop `__SYCL_NVPTX__` as unnecessary and solely rely on the combination of pre-existing macros. Signed-off-by: Artem Gindinson <[email protected]>
1 parent 77cae07 commit 619c462

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,8 +1180,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
11801180
Builder.defineMacro("SYCL_EXTERNAL", "__attribute__((sycl_device))");
11811181

11821182
const llvm::Triple &DeviceTriple = TI.getTriple();
1183-
if (DeviceTriple.isNVPTX())
1184-
Builder.defineMacro("__SYCL_NVPTX__", "1");
11851183
const llvm::Triple::SubArchType DeviceSubArch = DeviceTriple.getSubArch();
11861184
if (DeviceTriple.isSPIR() &&
11871185
DeviceSubArch != llvm::Triple::SPIRSubArch_fpga)

clang/test/Preprocessor/sycl-macro-target-specific.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// RUN: %clang_cc1 %s -fsycl-is-device -triple nvptx64-nvidia-nvcl-sycldevice -E -dM \
2+
// RUN: | FileCheck --check-prefix=CHECK-NVPTX %s
3+
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -E -dM \
4+
// RUN: | FileCheck --check-prefix=CHECK-NVPTX-NEG %s
5+
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64_gen-unknown-unknown-sycldevice -E -dM \
6+
// RUN: | FileCheck --check-prefix=CHECK-NVPTX-NEG %s
7+
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64_x86_64-unknown-unknown-sycldevice -E -dM \
8+
// RUN: | FileCheck --check-prefix=CHECK-NVPTX-NEG %s
9+
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64_fpga-unknown-unknown-sycldevice -E -dM \
10+
// RUN: | FileCheck --check-prefix=CHECK-NVPTX-NEG %s
11+
// CHECK-NVPTX: #define __NVPTX__
12+
// CHECK-NVPTX-NEG-NOT: #define __NVPTX__
13+
114
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -E -dM \
215
// RUN: | FileCheck --check-prefix=CHECK-SYCL-FP-ATOMICS %s
316
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64_gen-unknown-unknown-sycldevice -E -dM \
@@ -8,6 +21,5 @@
821
// RUN: | FileCheck --check-prefix=CHECK-SYCL-FP-ATOMICS-NEG %s
922
// RUN: %clang_cc1 %s -fsycl-is-device -triple nvptx64-nvidia-nvcl-sycldevice -E -dM \
1023
// RUN: | FileCheck --check-prefix=CHECK-SYCL-FP-ATOMICS-NEG %s
11-
1224
// CHECK-SYCL-FP-ATOMICS: #define SYCL_USE_NATIVE_FP_ATOMICS
1325
// CHECK-SYCL-FP-ATOMICS-NEG-NOT: #define SYCL_USE_NATIVE_FP_ATOMICS

sycl/doc/CompilerAndRuntimeDesign.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,11 @@ is then passed to the offload wrapper tool.
549549
##### Checking if the compiler is targeting NVPTX
550550

551551
When the SYCL compiler is in device mode and targeting the NVPTX backend,
552-
compiler defines the macro `__SYCL_NVPTX__`.
553-
This macro can safely be used to enable NVPTX specific code path in SYCL
554-
kernels.
552+
the compiler defines `__SYCL_DEVICE_ONLY__` and `__NVPTX__` macros. This
553+
macro combination can safely be used to enable NVPTX specific code
554+
path in SYCL kernels.
555555

556-
*Note: this macro is defined only during the device compilation phase.*
556+
*Note: these macros are defined only during the device compilation phase.*
557557

558558
##### NVPTX Builtins
559559

@@ -567,7 +567,7 @@ Example:
567567

568568
```cpp
569569
double my_min(double x, double y) {
570-
#ifdef __SYCL_NVPTX__
570+
#if defined(__NVPTX__) && defined(__SYCL_DEVICE_ONLY__)
571571
// Only available if in device mode and
572572
// while compiling for the NVPTX target.
573573
return __nvvm_fmin_d(x, y);

sycl/include/CL/__spirv/spirv_vars.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#define __SPIRV_VAR_QUALIFIERS extern "C" const
1717

18-
#if defined(__SYCL_NVPTX__) || defined(__AMDCGN__)
18+
#if defined(__NVPTX__) || defined(__AMDGCN__)
1919

2020
SYCL_EXTERNAL size_t __spirv_GlobalInvocationId_x();
2121
SYCL_EXTERNAL size_t __spirv_GlobalInvocationId_y();
@@ -51,7 +51,7 @@ SYCL_EXTERNAL uint32_t __spirv_NumSubgroups();
5151
SYCL_EXTERNAL uint32_t __spirv_SubgroupId();
5252
SYCL_EXTERNAL uint32_t __spirv_SubgroupLocalInvocationId();
5353

54-
#else // __SYCL_NVPTX__ || defined(__AMDCGN__)
54+
#else // defined(__NVPTX__) || defined(__AMDGCN__)
5555

5656
typedef size_t size_t_vec __attribute__((ext_vector_type(3)));
5757
__SPIRV_VAR_QUALIFIERS size_t_vec __spirv_BuiltInGlobalSize;
@@ -154,7 +154,7 @@ SYCL_EXTERNAL inline uint32_t __spirv_SubgroupLocalInvocationId() {
154154
return __spirv_BuiltInSubgroupLocalInvocationId;
155155
}
156156

157-
#endif // __SYCL_NVPTX__ || defined(__AMDCGN__)
157+
#endif // defined(__NVPTX__) || defined(__AMDGCN__)
158158

159159
#undef __SPIRV_VAR_QUALIFIERS
160160

0 commit comments

Comments
 (0)