Skip to content

Commit c54c605

Browse files
authored
[SYCL][CUDA][HIP] Update CUDA and HIP libspirv file diagnostic errors (#4804)
This patch updates CUDA and HIP's diagnostic errors for libspirv. Currently, they do not reflect that the libspirv file becomes remangled and is looking for different variants depending upon the OS. The HIP error also throws the same error as CUDA creating an incorrect message. This patch resolves these two problems and creates adds HIP tests for the error messages. This is proposed as a solution to fix #4370
1 parent a536022 commit c54c605

File tree

4 files changed

+45
-20
lines changed

4 files changed

+45
-20
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ def warn_drv_partially_supported_cuda_version: Warning<
9191
def err_drv_cuda_host_arch : Error<
9292
"unsupported architecture '%0' for host compilation">;
9393
def err_drv_no_sycl_libspirv : Error<
94-
"cannot find 'libspirv-nvptx64--nvidiacl.bc'; provide path to libspirv "
95-
"library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build "
96-
"without linking with libspirv">;
94+
"cannot find '%0'; provide path to libspirv library via '-fsycl-libspirv-path' or "
95+
"pass '-fno-sycl-libspirv' to build without linking with libspirv.">;
9796
def err_drv_mix_cuda_hip : Error<
9897
"mixed CUDA and HIP compilation is not supported">;
9998
def err_drv_bad_target_id : Error<

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,14 @@ std::string CudaToolChain::getInputFilename(const InputInfo &Input) const {
672672
return std::string(Filename.str());
673673
}
674674

675+
// Select remangled libclc variant. 64-bit longs default, 32-bit longs on
676+
// Windows
677+
static const char *getLibSpirvTargetName(const ToolChain &HostTC) {
678+
if (HostTC.getTriple().isOSWindows())
679+
return "remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc";
680+
return "remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc";
681+
}
682+
675683
void CudaToolChain::addClangTargetOptions(
676684
const llvm::opt::ArgList &DriverArgs,
677685
llvm::opt::ArgStringList &CC1Args,
@@ -722,13 +730,8 @@ void CudaToolChain::addClangTargetOptions(
722730
llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc"));
723731
LibraryPaths.emplace_back(WithInstallPath.c_str());
724732

725-
// Select remangled libclc variant. 64-bit longs default, 32-bit longs on
726-
// Windows
727-
std::string LibSpirvTargetName =
728-
"remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc";
729-
if (HostTC.getTriple().isOSWindows())
730-
LibSpirvTargetName =
731-
"remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc";
733+
// Select remangled libclc variant
734+
std::string LibSpirvTargetName = getLibSpirvTargetName(HostTC);
732735

733736
for (StringRef LibraryPath : LibraryPaths) {
734737
SmallString<128> LibSpirvTargetFile(LibraryPath);
@@ -742,7 +745,8 @@ void CudaToolChain::addClangTargetOptions(
742745
}
743746

744747
if (LibSpirvFile.empty()) {
745-
getDriver().Diag(diag::err_drv_no_sycl_libspirv);
748+
getDriver().Diag(diag::err_drv_no_sycl_libspirv)
749+
<< getLibSpirvTargetName(HostTC);
746750
return;
747751
}
748752

clang/lib/Driver/ToolChains/HIP.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ HIPToolChain::HIPToolChain(const Driver &D, const llvm::Triple &Triple,
240240
getProgramPaths().push_back(getDriver().Dir);
241241
}
242242

243+
static const char *getLibSpirvTargetName(const ToolChain &HostTC) {
244+
return "remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc";
245+
}
246+
243247
void HIPToolChain::addClangTargetOptions(
244248
const llvm::opt::ArgList &DriverArgs,
245249
llvm::opt::ArgStringList &CC1Args,
@@ -309,8 +313,7 @@ void HIPToolChain::addClangTargetOptions(
309313
llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc"));
310314
LibraryPaths.emplace_back(WithInstallPath.c_str());
311315

312-
std::string LibSpirvTargetName =
313-
"remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc";
316+
std::string LibSpirvTargetName = getLibSpirvTargetName(HostTC);
314317
for (StringRef LibraryPath : LibraryPaths) {
315318
SmallString<128> LibSpirvTargetFile(LibraryPath);
316319
llvm::sys::path::append(LibSpirvTargetFile, LibSpirvTargetName);
@@ -322,7 +325,8 @@ void HIPToolChain::addClangTargetOptions(
322325
}
323326

324327
if (LibSpirvFile.empty()) {
325-
getDriver().Diag(diag::err_drv_no_sycl_libspirv);
328+
getDriver().Diag(diag::err_drv_no_sycl_libspirv)
329+
<< getLibSpirvTargetName(HostTC);
326330
return;
327331
}
328332

clang/test/Driver/sycl-libspirv-invalid.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33
// UNSUPPORTED: system-windows
44

55
// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
6-
// RUN: -fsycl-targets=nvptx64-nvidia-nvcl --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
6+
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
77
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \
8-
// RUN: | FileCheck --check-prefix=ERR %s
9-
// ERR: cannot find 'libspirv-nvptx64--nvidiacl.bc'
8+
// RUN: | FileCheck --check-prefix=ERR-CUDA %s
9+
// ERR-CUDA: cannot find 'remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc'
10+
11+
// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-windows-msvc -fsycl \
12+
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
13+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \
14+
// RUN: | FileCheck --check-prefix=ERR-CUDA-WIN %s
15+
// ERR-CUDA-WIN: cannot find 'remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc'
16+
17+
// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
18+
// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 \
19+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \
20+
// RUN: | FileCheck --check-prefix=ERR-HIP %s
21+
// ERR-HIP: cannot find 'remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc'
22+
23+
// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
24+
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
25+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc -fno-sycl-libspirv %s 2>&1 \
26+
// RUN: | FileCheck --check-prefix=OK-CUDA %s
27+
// OK-CUDA-NOT: cannot find suitable 'remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc'
1028

1129
// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
12-
// RUN: -fsycl-targets=nvptx64-nvidia-nvcl --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
30+
// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 \
1331
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc -fno-sycl-libspirv %s 2>&1 \
14-
// RUN: | FileCheck --check-prefix=OK %s
15-
// OK-NOT: cannot find 'libspirv-nvptx64--nvidiacl.bc'
32+
// RUN: | FileCheck --check-prefix=OK-HIP %s
33+
// OK-HIP-NOT: cannot find 'remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc'

0 commit comments

Comments
 (0)