Skip to content

[SYCL][CUDA] Define __SYCL_CUDA_ARCH__ instead of __CUDA_ARCH__ for SYCL #8257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions clang/lib/Basic/Targets/NVPTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__PTX__");
Builder.defineMacro("__NVPTX__");
if (Opts.CUDAIsDevice || Opts.OpenMPIsDevice || Opts.SYCLIsDevice) {
// Set __CUDA_ARCH__ for the GPU specified.
// Set __CUDA_ARCH__ or __SYCL_CUDA_ARCH__ for the GPU specified.
// The SYCL-specific macro is used to distinguish the SYCL and CUDA APIs.
std::string CUDAArchCode = [this] {
switch (GPU) {
case CudaArch::GFX600:
Expand Down Expand Up @@ -260,7 +261,12 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts,
}
llvm_unreachable("unhandled CudaArch");
}();
Builder.defineMacro("__CUDA_ARCH__", CUDAArchCode);

if (Opts.SYCLIsDevice) {
Builder.defineMacro("__SYCL_CUDA_ARCH__", CUDAArchCode);
} else {
Builder.defineMacro("__CUDA_ARCH__", CUDAArchCode);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion clang/test/Preprocessor/sycl-macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// CHECK-NO-SYCL_FIT_IN_INT-NOT:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1
// CHECK-SYCL-ID:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1

// CHECK-CUDA:#define __CUDA_ARCH__ 800
// CHECK-CUDA:#define __SYCL_CUDA_ARCH__ 800
// CHECK-CUDA-NOT:#define __CUDA_ARCH__ 800

// CHECK-HIP:#define __CUDA_ARCH__ 0
4 changes: 2 additions & 2 deletions sycl/include/sycl/ext/oneapi/bfloat16.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class bfloat16 {
static detail::Bfloat16StorageT from_float(const float &a) {
#if defined(__SYCL_DEVICE_ONLY__)
#if defined(__NVPTX__)
#if (__CUDA_ARCH__ >= 800)
#if (__SYCL_CUDA_ARCH__ >= 800)
return __nvvm_f2bf16_rn(a);
#else
// TODO find a better way to check for NaN
Expand Down Expand Up @@ -126,7 +126,7 @@ class bfloat16 {
friend bfloat16 operator-(bfloat16 &lhs) {
#if defined(__SYCL_DEVICE_ONLY__)
#if defined(__NVPTX__)
#if (__CUDA_ARCH__ >= 800)
#if (__SYCL_CUDA_ARCH__ >= 800)
return detail::bitsToBfloat16(__nvvm_neg_bf16(lhs.value));
#else
return -to_float(lhs.value);
Expand Down