Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a188a0b

Browse files
committedSep 19, 2024·
[SYCL][Driver] Fix regression that enabled Cuda-mode in cc1 and defined __CUDA_ARCH__
1 parent c22d238 commit a188a0b

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed
 

‎clang/lib/Driver/ToolChains/Cuda.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,18 @@ void CudaToolChain::addClangTargetOptions(
938938
DeviceOffloadingKind == Action::OFK_Cuda) &&
939939
"Only OpenMP, SYCL or CUDA offloading kinds are supported for NVIDIA GPUs.");
940940

941-
CC1Args.append(
942-
{"-fcuda-is-device", "-mllvm", "-enable-memcpyopt-without-libcalls"});
941+
// If we are compiling SYCL kernels for Nvidia GPUs, we do not support Cuda
942+
// device code compatability, hence we do not set Cuda mode in that instance.
943+
if (DeviceOffloadingKind == Action::OFK_SYCL) {
944+
toolchains::SYCLToolChain::AddSYCLIncludeArgs(getDriver(), DriverArgs,
945+
CC1Args);
946+
947+
if (DriverArgs.hasArg(options::OPT_fsycl_fp32_prec_sqrt)) {
948+
CC1Args.push_back("-fcuda-prec-sqrt");
949+
}
950+
} else {
951+
CC1Args.append(
952+
{"-fcuda-is-device", "-mllvm", "-enable-memcpyopt-without-libcalls"});
943953

944954
// Unsized function arguments used for variadics were introduced in CUDA-9.0
945955
// We still do not support generating code that actually uses variadic
@@ -952,14 +962,6 @@ void CudaToolChain::addClangTargetOptions(
952962
// Add these flags for .cu SYCL compilation.
953963
CC1Args.append({"-std=c++17", "-fsycl-is-host"});
954964
}
955-
956-
if (DeviceOffloadingKind == Action::OFK_SYCL) {
957-
toolchains::SYCLToolChain::AddSYCLIncludeArgs(getDriver(), DriverArgs,
958-
CC1Args);
959-
960-
if (DriverArgs.hasArg(options::OPT_fsycl_fp32_prec_sqrt)) {
961-
CC1Args.push_back("-fcuda-prec-sqrt");
962-
}
963965
}
964966

965967
auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv) ||

‎clang/test/Preprocessor/sycl-macro.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
// RUNx: %clang_cc1 %s -fsycl-id-queries-fit-in-int -fsycl-is-device -E -dM -fms-compatibility | FileCheck --check-prefix=CHECK-MSVC %s
77
// RUN: %clang_cc1 -fno-sycl-id-queries-fit-in-int %s -E -dM | FileCheck \
88
// RUN: --check-prefix=CHECK-NO-SYCL_FIT_IN_INT %s
9-
// RUN: %clang_cc1 %s -triple nvptx64-nvidia-cuda -target-cpu sm_80 -fsycl-is-device -E -dM | FileCheck --check-prefix=CHECK-CUDA %s
9+
// RUN: %clang_cc1 %s -triple nvptx64-nvidia-cuda -target-cpu sm_80 -DARCH_CODE=800 -fsycl-is-device -E -dM | FileCheck \
10+
// RUN: --check-prefix=CHECK-CUDA %s -DARCH_CODE=800
11+
// RUN: %clangxx %s -fsycl -nocudalib -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --offload-arch=sm_80 -E -dM | FileCheck \
12+
// RUN: --check-prefix=CHECK-CUDA-SYCL-DRIVER %s
1013
// RUN: %clang_cc1 %s -triple amdgcn-amd-amdhsa -target-cpu gfx906 -fsycl-is-device -E -dM | FileCheck --check-prefix=CHECK-HIP %s
1114

1215
// RUN: %clang_cc1 %s -triple nvptx64-nvidia-cuda -target-cpu sm_90a -fsycl-is-device -E -dM | FileCheck --check-prefix=CHECK-CUDA-FEATURE %s
@@ -32,8 +35,10 @@
3235
// CHECK-NO-SYCL_FIT_IN_INT-NOT:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1
3336
// CHECK-SYCL-ID:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1
3437

35-
// CHECK-CUDA:#define __SYCL_CUDA_ARCH__ 800
36-
// CHECK-CUDA-NOT:#define __CUDA_ARCH__ 800
38+
// CHECK-CUDA:#define __SYCL_CUDA_ARCH__ [[ARCH_CODE]]
39+
// CHECK-CUDA-NOT:#define __CUDA_ARCH__ [[ARCH:[0-9]+]]
40+
41+
// CHECK-CUDA-SYCL-DRIVER-NOT: #define __CUDA_ARCH__ [[ARCH:[0-9]+]]
3742

3843
// CHECK-HIP:#define __CUDA_ARCH__ 0
3944

0 commit comments

Comments
 (0)
Please sign in to comment.