Skip to content

Commit 7f924a8

Browse files
s-kanaevArtem Gindinson
andauthored
[SYCL][Driver] Fix SYCL standards' handling for '-fsycl -fsycl-device-only' invocations (#1371)
Signed-off-by: Sergey Kanaev sergey.kanaev@intel.com Co-Authored-By: Artem Gindinson <artem.gindinson@intel.com>
1 parent 808c5c8 commit 7f924a8

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4115,6 +4115,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41154115
CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
41164116
}
41174117

4118+
Arg *SYCLStdArg = Args.getLastArg(options::OPT_sycl_std_EQ);
4119+
41184120
if (UseSYCLTriple) {
41194121
// We want to compile sycl kernels.
41204122
CmdArgs.push_back("-fsycl");
@@ -4147,21 +4149,24 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41474149
options::OPT_fno_sycl_allow_func_ptr, false)) {
41484150
CmdArgs.push_back("-fsycl-allow-func-ptr");
41494151
}
4150-
}
41514152

4152-
if (IsSYCL) {
4153-
if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
4154-
A->render(Args, CmdArgs);
4155-
CmdArgs.push_back("-fsycl-std-layout-kernel-params");
4156-
} else {
4157-
// Ensure the default version in SYCL mode is 1.2.1 (aka 2017)
4158-
CmdArgs.push_back("-sycl-std=2017");
4153+
if (!SYCLStdArg) {
41594154
// The user had not pass SYCL version, thus we'll employ no-sycl-strict
41604155
// to allow address-space unqualified pointers in function params/return
41614156
// along with marking the same function with explicit SYCL_EXTERNAL
41624157
CmdArgs.push_back("-Wno-sycl-strict");
41634158
}
4159+
}
4160+
4161+
if (IsSYCL) {
4162+
if (SYCLStdArg) {
4163+
SYCLStdArg->render(Args, CmdArgs);
4164+
CmdArgs.push_back("-fsycl-std-layout-kernel-params");
4165+
} else {
4166+
// Ensure the default version in SYCL mode is 1.2.1 (aka 2017)
4167+
CmdArgs.push_back("-sycl-std=2017");
41644168
}
4169+
}
41654170

41664171
if (IsOpenMPDevice) {
41674172
// We have to pass the triple of the host if compiling for an OpenMP device.

clang/test/Driver/sycl-device.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,18 @@
77
// RUN: %clang -### -fsycl-device-only %s 2>&1 \
88
// RUN: | FileCheck -check-prefix=CHECK-SYCL-DEV %s
99
// CHECK-SYCL-DEV: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"
10+
11+
/// Check that "-Wno-sycl-strict" is set on compiler invocation with "-fsycl"
12+
/// or "-fsycl-device-only" or both:
13+
// RUN: %clang -### -fsycl %s 2>&1 \
14+
// RUN: | FileCheck -check-prefix=CHECK-SYCL-NO_STRICT %s
15+
// RUN: %clang -### -fsycl-device-only %s 2>&1 \
16+
// RUN: | FileCheck -check-prefix=CHECK-SYCL-NO_STRICT %s
17+
// RUN: %clang -### -fsycl -fsycl-device-only %s 2>&1 \
18+
// RUN: | FileCheck -check-prefix=CHECK-SYCL-NO_STRICT %s
19+
// CHECK-SYCL-NO_STRICT: clang{{.*}} "-Wno-sycl-strict"
20+
21+
/// Check that -sycl-std=2017 is set if no std version is provided by user
22+
// RUN: %clang -### -fsycl %s 2>&1 \
23+
// RUN: | FileCheck -check-prefix=CHECK-SYCL-STD_VERSION %s
24+
// CHECK-SYCL-STD_VERSION: clang{{.*}} "-sycl-std=2017"

clang/test/Driver/sycl-offload-nvptx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// RUN: -fsycl-targets=nvptx64-nvidia-nvcl-sycldevice --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
99
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc %s 2>&1 \
1010
// RUN: | FileCheck -check-prefix=CHK-ACTIONS %s
11-
// CHK-ACTIONS: "-cc1" "-triple" "nvptx64-nvidia-nvcl-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-aux-triple" "x86_64-unknown-linux-gnu"{{.*}} "-sycl-std=2017"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-mlink-builtin-bitcode" "{{.*}}libspirv.bc"{{.*}} "-mlink-builtin-bitcode" "{{.*}}libdevice{{.*}}.10.bc"{{.*}} "-target-feature" "+ptx42"{{.*}} "-target-sdk-version=[[CUDA_VERSION:[0-9.]+]]"{{.*}} "-target-cpu" "sm_30"{{.*}} "-std=c++11"{{.*}}
11+
// CHK-ACTIONS: "-cc1" "-triple" "nvptx64-nvidia-nvcl-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-aux-triple" "x86_64-unknown-linux-gnu"{{.*}} "-Wno-sycl-strict" "-sycl-std=2017" {{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-mlink-builtin-bitcode" "{{.*}}libspirv.bc"{{.*}} "-mlink-builtin-bitcode" "{{.*}}libdevice{{.*}}.10.bc"{{.*}} "-target-feature" "+ptx42"{{.*}} "-target-sdk-version=[[CUDA_VERSION:[0-9.]+]]"{{.*}} "-target-cpu" "sm_30"{{.*}} "-std=c++11"{{.*}}
1212
// CHK-ACTIONS: clang-offload-wrapper"{{.*}} "-host=x86_64-unknown-linux-gnu" "-target=nvptx64" "-kind=sycl"{{.*}}
13-
// CHK-ACTIONS: "-cc1" "-triple" "nvptx64-nvidia-nvcl-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-aux-triple" "x86_64-unknown-linux-gnu"{{.*}} "-sycl-std=2017"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-mlink-builtin-bitcode" "{{.*}}libspirv.bc"{{.*}} "-mlink-builtin-bitcode" "{{.*}}libdevice{{.*}}.10.bc"{{.*}} "-target-feature" "+ptx42"{{.*}} "-target-sdk-version=[[CUDA_VERSION]]"{{.*}} "-target-cpu" "sm_30"{{.*}} "-std=c++11"{{.*}}
13+
// CHK-ACTIONS: "-cc1" "-triple" "nvptx64-nvidia-nvcl-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-aux-triple" "x86_64-unknown-linux-gnu"{{.*}} "-Wno-sycl-strict" "-sycl-std=2017" {{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-mlink-builtin-bitcode" "{{.*}}libspirv.bc"{{.*}} "-mlink-builtin-bitcode" "{{.*}}libdevice{{.*}}.10.bc"{{.*}} "-target-feature" "+ptx42"{{.*}} "-target-sdk-version=[[CUDA_VERSION]]"{{.*}} "-target-cpu" "sm_30"{{.*}} "-std=c++11"{{.*}}
1414

1515
/// Check phases w/out specifying a compute capability.
1616
// RUN: %clangxx -ccc-print-phases -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \

clang/test/Driver/sycl.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
55
// RUN: %clang -### -fsycl -sycl-std=2017 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
66
// RUN: %clang -### -fsycl -sycl-std=sycl-1.2.1 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
77
// RUN: %clang -### -fno-sycl -fsycl %s 2>&1 | FileCheck %s --check-prefix=ENABLED
8-
// RUN: %clang -### -sycl-std=2017 %s 2>&1 | FileCheck %s --check-prefix=DISABLED
8+
// RUN: %clang -### -sycl-std=2017 %s 2>&1 | FileCheck %s --check-prefix=NOT_ENABLED
99
// RUN: %clangxx -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=ENABLED
1010
// RUN: %clangxx -### -fno-sycl %s 2>&1 | FileCheck %s --check-prefix=DISABLED
1111
// RUN: %clangxx -### -fsycl -fno-sycl %s 2>&1 | FileCheck %s --check-prefix=DISABLED
12-
// RUN: %clangxx -### %s 2>&1 | FileCheck %s --check-prefix=DISABLED
12+
// RUN: %clangxx -### %s 2>&1 | FileCheck %s --check-prefix=NOT_ENABLED
13+
// RUN: %clangxx -### -sycl-std=some-std %s 2>&1 | FileCheck %s --check-prefix=NOT_ENABLED
1314
// RUN: %clang_cl -### -fsycl -sycl-std=2017 -- %s 2>&1 | FileCheck %s --check-prefix=ENABLED
1415
// RUN: %clang_cl -### -fsycl -- %s 2>&1 | FileCheck %s --check-prefix=ENABLED
15-
// RUN: %clang_cl -### -- %s 2>&1 | FileCheck %s --check-prefix=DISABLED
16+
// RUN: %clang_cl -### -- %s 2>&1 | FileCheck %s --check-prefix=NOT_ENABLED
17+
// RUN: %clang_cl -### -sycl-std=some-std -- %s 2>&1 | FileCheck %s --check-prefix=NOT_ENABLED
1618

1719
// ENABLED: "-cc1"{{.*}} "-fsycl-is-device"
1820
// ENABLED-SAME: "-sycl-std={{[-.sycl0-9]+}}"
1921
// ENABLED-SAME: "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"
2022

23+
// NOT_ENABLED-NOT: "-fsycl-is-device"
24+
// NOT_ENABLED-NOT: "-fsycl-std-layout-kernel-params"
25+
2126
// DISABLED-NOT: "-fsycl-is-device"
22-
// DISABLED-NOT: "-sycl-std="
27+
// DISABLED-NOT: "-sycl-std={{.*}}"
28+
// DISABLED-NOT: "-fsycl-std-layout-kernel-params"
2329

2430
// RUN: %clang -### -fsycl-device-only -c %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
2531
// RUN: %clang -### -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT

0 commit comments

Comments
 (0)