Skip to content

Commit 1704d16

Browse files
authored
[SYCL][CUDA] Add CoreOption flag to CUDA backend options (#4930)
This PR updates `cuda-gpu-arch`, `cuda-path`, `nocudalib`, and `fno-sycl-libspirv` options to have `CoreOption` flag. The change allows the options to be used with `clang-cl` for Windows. Tests are modified and added to check that these options work with `clang-cl`. I believe this resolves issue #4764.
1 parent 2cdcbed commit 1704d16

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ def offload_arch_EQ : Joined<["--"], "offload-arch=">, Flags<[NoXarchOption]>,
937937
"device architecture followed by target ID features delimited by a colon. Each target ID feature "
938938
"is a pre-defined string followed by a plus or minus sign (e.g. gfx908:xnack+:sramecc-). May be "
939939
"specified more than once.">;
940-
def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, Flags<[NoXarchOption]>,
940+
def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, Flags<[NoXarchOption, CoreOption]>,
941941
Alias<offload_arch_EQ>;
942942
def hip_link : Flag<["--"], "hip-link">,
943943
HelpText<"Link clang-offload-bundler bundles for HIP">;
@@ -954,7 +954,7 @@ def no_cuda_version_check : Flag<["--"], "no-cuda-version-check">,
954954
HelpText<"Don't error out if the detected version of the CUDA install is "
955955
"too low for the requested CUDA gpu architecture.">;
956956
def no_cuda_noopt_device_debug : Flag<["--"], "no-cuda-noopt-device-debug">;
957-
def cuda_path_EQ : Joined<["--"], "cuda-path=">, Group<i_Group>,
957+
def cuda_path_EQ : Joined<["--"], "cuda-path=">, Flags<[CoreOption]>, Group<i_Group>,
958958
HelpText<"CUDA installation path">;
959959
def cuda_path_ignore_env : Flag<["--"], "cuda-path-ignore-env">, Group<i_Group>,
960960
HelpText<"Ignore environment variables to detect CUDA installation">;
@@ -2691,7 +2691,7 @@ def fsycl_help : Flag<["-"], "fsycl-help">, Alias<fsycl_help_EQ>,
26912691
"from all of the offline compilation tools">;
26922692
def fsycl_libspirv_path_EQ : Joined<["-"], "fsycl-libspirv-path=">,
26932693
Flags<[CC1Option, CoreOption]>, HelpText<"Path to libspirv library">;
2694-
def fno_sycl_libspirv : Flag<["-"], "fno-sycl-libspirv">, HelpText<"Disable check for libspirv">;
2694+
def fno_sycl_libspirv : Flag<["-"], "fno-sycl-libspirv">, Flags<[CoreOption]>, HelpText<"Disable check for libspirv">;
26952695
def fsycl_host_compiler_EQ : Joined<["-"], "fsycl-host-compiler=">,
26962696
Flags<[CoreOption]>, HelpText<"Specify C++ compiler binary to perform host "
26972697
"compilation with during SYCL offload compiles.">;
@@ -3843,7 +3843,7 @@ def nogpuinc : Flag<["-"], "nogpuinc">, HelpText<"Do not add include paths for C
38433843
def : Flag<["-"], "nocudainc">, Alias<nogpuinc>;
38443844
def nogpulib : Flag<["-"], "nogpulib">,
38453845
HelpText<"Do not link device library for CUDA/HIP device compilation">;
3846-
def : Flag<["-"], "nocudalib">, Alias<nogpulib>;
3846+
def : Flag<["-"], "nocudalib">, Flags<[CoreOption]>, Alias<nogpulib>;
38473847
def nodefaultlibs : Flag<["-"], "nodefaultlibs">;
38483848
def nofixprebinding : Flag<["-"], "nofixprebinding">;
38493849
def nolibc : Flag<["-"], "nolibc">;

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

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --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+
//
12+
// RUN: %clang_cl -### -fsycl \
13+
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
14+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc %s 2>&1 \
15+
// RUN: | FileCheck -check-prefix=CHK-ACTIONS-WIN %s
1116

1217
// CHK-ACTIONS: "-cc1" "-triple" "nvptx64-nvidia-cuda" "-aux-triple" "x86_64-unknown-linux-gnu"{{.*}} "-fsycl-is-device"{{.*}} "-Wno-sycl-strict"{{.*}} "-sycl-std=2020" {{.*}} "-emit-llvm-bc" {{.*}} "-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_50"{{.*}} "-std=c++11"{{.*}}
1318
// CHK-ACTIONS: sycl-post-link{{.*}} "-split=auto"
@@ -19,17 +24,32 @@
1924
// CHK-ACTIONS-NOT: "-mllvm -sycl-opt"
2025
// CHK-ACTIONS: clang-offload-wrapper"{{.*}} "-host=x86_64-unknown-linux-gnu" "-target=nvptx64" "-kind=sycl"{{.*}}
2126

27+
// CHK-ACTIONS-WIN: "-cc1" "-triple" "nvptx64-nvidia-cuda" "-aux-triple" "x86_64-pc-windows-msvc"{{.*}} "-fsycl-is-device"{{.*}} "-Wno-sycl-strict"{{.*}} "-sycl-std=2020" {{.*}} "-emit-llvm-bc" {{.*}} "-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_50"{{.*}}
28+
// CHK-ACTIONS-WIN: sycl-post-link{{.*}} "-split=auto"
29+
// CHK-ACTIONS-WIN: file-table-tform" "-extract=Code" "-drop_titles"
30+
// CHK-ACTIONS-WIN: llvm-foreach" {{.*}} "--" "{{.*}}clang-{{[0-9]+}}"
31+
// CHK-ACTIONS-WIN: llvm-foreach" {{.*}} "--" "{{.*}}ptxas"
32+
// CHK-ACTIONS-WIN: llvm-foreach" {{.*}} "--" "{{.*}}fatbinary"
33+
// CHK-ACTIONS-WIN: file-table-tform" "-replace=Code,Code"
34+
// CHK-ACTIONS-WIN-NOT: "-mllvm -sycl-opt"
35+
// CHK-ACTIONS-WIN: clang-offload-wrapper"{{.*}} "-host=x86_64-pc-windows-msvc" "-target=nvptx64" "-kind=sycl"{{.*}}
36+
2237
/// Check phases w/out specifying a compute capability.
2338
// RUN: %clangxx -ccc-print-phases -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
2439
// RUN: -fsycl-targets=nvptx64-nvidia-cuda %s 2>&1 \
2540
// RUN: | FileCheck -check-prefix=CHK-PHASES-NO-CC %s
41+
//
42+
// RUN: %clang_cl -ccc-print-phases -fsycl \
43+
// RUN: -fsycl-targets=nvptx64-nvidia-cuda %s 2>&1 \
44+
// RUN: | FileCheck -check-prefix=CHK-PHASES-NO-CC %s
45+
//
2646
// CHK-PHASES-NO-CC: 0: input, "{{.*}}", c++, (host-sycl)
2747
// CHK-PHASES-NO-CC: 1: append-footer, {0}, c++, (host-sycl)
2848
// CHK-PHASES-NO-CC: 2: preprocessor, {1}, c++-cpp-output, (host-sycl)
2949
// CHK-PHASES-NO-CC: 3: input, "{{.*}}", c++, (device-sycl, sm_50)
3050
// CHK-PHASES-NO-CC: 4: preprocessor, {3}, c++-cpp-output, (device-sycl, sm_50)
3151
// CHK-PHASES-NO-CC: 5: compiler, {4}, ir, (device-sycl, sm_50)
32-
// CHK-PHASES-NO-CC: 6: offload, "host-sycl (x86_64-unknown-linux-gnu)" {2}, "device-sycl (nvptx64-nvidia-cuda:sm_50)" {5}, c++-cpp-output
52+
// CHK-PHASES-NO-CC: 6: offload, "host-sycl (x86_64-{{.*}})" {2}, "device-sycl (nvptx64-nvidia-cuda:sm_50)" {5}, c++-cpp-output
3353
// CHK-PHASES-NO-CC: 7: compiler, {6}, ir, (host-sycl)
3454
// CHK-PHASES-NO-CC: 8: backend, {7}, assembler, (host-sycl)
3555
// CHK-PHASES-NO-CC: 9: assembler, {8}, object, (host-sycl)
@@ -43,21 +63,26 @@
4363
// CHK-PHASES-NO-CC: 17: foreach, {13, 16}, cuda-fatbin, (device-sycl, sm_50)
4464
// CHK-PHASES-NO-CC: 18: file-table-tform, {12, 17}, tempfiletable, (device-sycl, sm_50)
4565
// CHK-PHASES-NO-CC: 19: clang-offload-wrapper, {18}, object, (device-sycl, sm_50)
46-
// CHK-PHASES-NO-CC: 20: offload, "host-sycl (x86_64-unknown-linux-gnu)" {10}, "device-sycl (nvptx64-nvidia-cuda:sm_50)" {19}, image
66+
// CHK-PHASES-NO-CC: 20: offload, "host-sycl (x86_64-{{.*}})" {10}, "device-sycl (nvptx64-nvidia-cuda:sm_50)" {19}, image
4767

4868
/// Check phases specifying a compute capability.
4969
// RUN: %clangxx -ccc-print-phases -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
5070
// RUN: -fsycl-targets=nvptx64-nvidia-cuda \
51-
N.)
5271
// RUN: -Xsycl-target-backend "--cuda-gpu-arch=sm_35" %s 2>&1 \
5372
// RUN: | FileCheck -check-prefix=CHK-PHASES %s
73+
//
74+
// RUN: %clang_cl -ccc-print-phases -fsycl \
75+
// RUN: -fsycl-targets=nvptx64-nvidia-cuda \
76+
// RUN: -Xsycl-target-backend "--cuda-gpu-arch=sm_35" %s 2>&1 \
77+
// RUN: | FileCheck -check-prefix=CHK-PHASES %s
78+
//
5479
// CHK-PHASES: 0: input, "{{.*}}", c++, (host-sycl)
5580
// CHK-PHASES: 1: append-footer, {0}, c++, (host-sycl)
5681
// CHK-PHASES: 2: preprocessor, {1}, c++-cpp-output, (host-sycl)
5782
// CHK-PHASES: 3: input, "{{.*}}", c++, (device-sycl, sm_35)
5883
// CHK-PHASES: 4: preprocessor, {3}, c++-cpp-output, (device-sycl, sm_35)
5984
// CHK-PHASES: 5: compiler, {4}, ir, (device-sycl, sm_35)
60-
// CHK-PHASES: 6: offload, "host-sycl (x86_64-unknown-linux-gnu)" {2}, "device-sycl (nvptx64-nvidia-cuda:sm_35)" {5}, c++-cpp-output
85+
// CHK-PHASES: 6: offload, "host-sycl (x86_64-{{.*}})" {2}, "device-sycl (nvptx64-nvidia-cuda:sm_35)" {5}, c++-cpp-output
6186
// CHK-PHASES: 7: compiler, {6}, ir, (host-sycl)
6287
// CHK-PHASES: 8: backend, {7}, assembler, (host-sycl)
6388
// CHK-PHASES: 9: assembler, {8}, object, (host-sycl)
@@ -71,11 +96,37 @@ N.)
7196
// CHK-PHASES: 17: foreach, {13, 16}, cuda-fatbin, (device-sycl, sm_35)
7297
// CHK-PHASES: 18: file-table-tform, {12, 17}, tempfiletable, (device-sycl, sm_35)
7398
// CHK-PHASES: 19: clang-offload-wrapper, {18}, object, (device-sycl, sm_35)
74-
// CHK-PHASES: 20: offload, "host-sycl (x86_64-unknown-linux-gnu)" {10}, "device-sycl (nvptx64-nvidia-cuda:sm_35)" {19}, image
99+
// CHK-PHASES: 20: offload, "host-sycl (x86_64-{{.*}})" {10}, "device-sycl (nvptx64-nvidia-cuda:sm_35)" {19}, image
75100

76101
/// Check calling preprocessor only
77102
// RUN: %clangxx -E -fsycl -fsycl-targets=nvptx64-nvidia-cuda -ccc-print-phases %s 2>&1 \
78103
// RUN: | FileCheck -check-prefix=CHK-PREPROC %s
79104
// CHK-PREPROC: 1: preprocessor, {0}, c++-cpp-output, (device-sycl, sm_[[CUDA_VERSION:[0-9.]+]])
80105
// CHK-PREPROC: 2: offload, "device-sycl (nvptx64-nvidia-cuda:sm_[[CUDA_VERSION]])" {1}, c++-cpp-output
81106
// CHK-PREPROC: 4: compiler, {1}, none, (device-sycl, sm_[[CUDA_VERSION]])
107+
//
108+
// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
109+
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/no/CUDA/path/here \
110+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc %s 2>&1 \
111+
// RUN: | FileCheck -check-prefix=CHK-CUDA-PATH-ERROR %s
112+
//
113+
// RUN: %clang_cl -### -fsycl \
114+
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/no/CUDA/path/here \
115+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc %s 2>&1 \
116+
// RUN: | FileCheck -check-prefix=CHK-CUDA-PATH-ERROR %s
117+
//
118+
// CHK-CUDA-PATH-ERROR: provide path to different CUDA installation via '--cuda-path', or pass '-nocudalib' to build without linking with libdevice
119+
//
120+
//
121+
// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
122+
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/no/CUDA/path/here \
123+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc -nocudalib %s 2>&1 \
124+
// RUN: | FileCheck -check-prefix=CHK-CUDA-NO-LIB %s
125+
//
126+
// RUN: %clang_cl -### -fsycl \
127+
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/no/CUDA/path/here \
128+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc -nocudalib %s 2>&1 \
129+
// RUN: | FileCheck -check-prefix=CHK-CUDA-NO-LIB %s
130+
//
131+
// CHK-CUDA-NO-LIB-NOT: provide path to different CUDA installation via '--cuda-path', or pass '-nocudalib' to build without linking with libdevice
132+
//

0 commit comments

Comments
 (0)