Skip to content

Commit 83d3448

Browse files
JackAKirkJackAKirk
andauthored
[SYCL] Always warn when -fno-sycl-libspirv opt used. (intel#7378)
This PR addresses intel#7238 The -fno-sycl-libspirv flag only has an effect when using nvptx64-nvidia-cuda or amdgcn-amd-amdhsa triples. The effect is to not link the libspirv libraries built by libclc that are only used by CUDA/HIP backends. This flag is never recommended for normal DPC++ use because both CUDA and HIP backends require linking with libspirv for lots of the basic functionality. However the option is there in case someone for whatever reason doesn't want to link libspirv, so this PR adds (triple dependent) warnings whenever the -fno-sycl-libspirv option is used. If used with CUDA/HIP the warning is: "warning: no-sycl-libspirv option is not meant for regular application development and severely limits the correct behavior of DPC++ when using the 'triple' triple" For other triples the warning is: "warning: no-sycl-libspirv option has no effect when compiled with the 'triple' triple" Signed-off-by: JackAKirk <[email protected]> Co-authored-by: JackAKirk <[email protected]>
1 parent a3ae0dd commit 83d3448

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def err_drv_cuda_host_arch : Error<
9696
def err_drv_no_sycl_libspirv : Error<
9797
"cannot find '%0'; provide path to libspirv library via '-fsycl-libspirv-path', or "
9898
"pass '-fno-sycl-libspirv' to build without linking with libspirv">;
99+
def warn_flag_no_sycl_libspirv
100+
: Warning<"'-fno-sycl-libspirv' should not be used with target '%0'; "
101+
"libspirv is required for correct behavior">,
102+
InGroup<NoLibspirvHipCuda>;
99103
def err_drv_mix_cuda_hip : Error<
100104
"mixed CUDA and HIP compilation is not supported">;
101105
def err_drv_bad_target_id : Error<

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,10 @@ def CudaUnknownVersion: DiagGroup<"unknown-cuda-version">;
13161316
// ignored by CUDA.
13171317
def HIPOnly : DiagGroup<"hip-only">;
13181318

1319+
// A warning generated when compiling SYCL applications for HIP or CUDA backends
1320+
// without linking LIBSPIRV.
1321+
def NoLibspirvHipCuda : DiagGroup<"no-libspirv-hip-cuda">;
1322+
13191323
// Warnings which cause linking of the runtime libraries like
13201324
// libc and the CRT to be skipped.
13211325
def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;

clang/lib/Driver/Driver.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,19 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
12301230
addSYCLDefaultTriple(C, UniqueSYCLTriplesVec);
12311231
}
12321232
}
1233+
// -fno-sycl-libspirv flag is reserved for very unusual cases where the
1234+
// libspirv library is not linked when using CUDA/HIP: so output appropriate
1235+
// warnings.
1236+
if (C.getInputArgs().hasArg(options::OPT_fno_sycl_libspirv)) {
1237+
for (auto &TT : UniqueSYCLTriplesVec) {
1238+
if (TT.isNVPTX() || TT.isAMDGCN()) {
1239+
Diag(diag::warn_flag_no_sycl_libspirv) << TT.getTriple();
1240+
} else {
1241+
Diag(diag::warn_drv_unsupported_option_for_target)
1242+
<< "-fno-sycl-libspirv" << TT.getTriple();
1243+
}
1244+
}
1245+
}
12331246
// We'll need to use the SYCL and host triples as the key into
12341247
// getOffloadingDeviceToolChain, because the device toolchains we're
12351248
// going to create will depend on both.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// Test that appropriate warnings are output when -fno-sycl-libspirv is used.
2+
3+
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda,amdgcn-amd-amdhsa -fno-sycl-libspirv %s -### 2>&1 | FileCheck %s
4+
// CHECK: warning: '-fno-sycl-libspirv' should not be used with target 'nvptx64-nvidia-cuda'; libspirv is required for correct behavior [-Wno-libspirv-hip-cuda]
5+
// CHECK: warning: '-fno-sycl-libspirv' should not be used with target 'amdgcn-amd-amdhsa'; libspirv is required for correct behavior [-Wno-libspirv-hip-cuda]
6+
// RUN: %clangxx -fsycl -fsycl-targets=spir64-unknown-unknown -fno-sycl-libspirv %s -### 2>&1 | FileCheck --check-prefix=CHECK-SPIR64 %s
7+
// CHECK-SPIR64: ignoring '-fno-sycl-libspirv' option as it is not currently supported for target 'spir64-unknown-unknown' [-Woption-ignored]

0 commit comments

Comments
 (0)