Skip to content

[SYCL][CUDA][HIP] Update CUDA and HIP libspirv file diagnostic errors #4804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ def warn_drv_partially_supported_cuda_version: Warning<
def err_drv_cuda_host_arch : Error<
"unsupported architecture '%0' for host compilation">;
def err_drv_no_sycl_libspirv : Error<
"cannot find 'libspirv-nvptx64--nvidiacl.bc'; provide path to libspirv "
"library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build "
"without linking with libspirv">;
"cannot find '%0'; provide path to libspirv library via '-fsycl-libspirv-path' or "
"pass '-fno-sycl-libspirv' to build without linking with libspirv.">;
def err_drv_mix_cuda_hip : Error<
"mixed CUDA and HIP compilation is not supported">;
def err_drv_bad_target_id : Error<
Expand Down
20 changes: 12 additions & 8 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,14 @@ std::string CudaToolChain::getInputFilename(const InputInfo &Input) const {
return std::string(Filename.str());
}

// Select remangled libclc variant. 64-bit longs default, 32-bit longs on
// Windows
static const char *getLibSpirvTargetName(const ToolChain &HostTC) {
if (HostTC.getTriple().isOSWindows())
return "remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc";
return "remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc";
}

void CudaToolChain::addClangTargetOptions(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
Expand Down Expand Up @@ -717,13 +725,8 @@ void CudaToolChain::addClangTargetOptions(
llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc"));
LibraryPaths.emplace_back(WithInstallPath.c_str());

// Select remangled libclc variant. 64-bit longs default, 32-bit longs on
// Windows
std::string LibSpirvTargetName =
"remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc";
if (HostTC.getTriple().isOSWindows())
LibSpirvTargetName =
"remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc";
// Select remangled libclc variant
std::string LibSpirvTargetName = getLibSpirvTargetName(HostTC);

for (StringRef LibraryPath : LibraryPaths) {
SmallString<128> LibSpirvTargetFile(LibraryPath);
Expand All @@ -737,7 +740,8 @@ void CudaToolChain::addClangTargetOptions(
}

if (LibSpirvFile.empty()) {
getDriver().Diag(diag::err_drv_no_sycl_libspirv);
getDriver().Diag(diag::err_drv_no_sycl_libspirv)
<< getLibSpirvTargetName(HostTC);
return;
}

Expand Down
10 changes: 7 additions & 3 deletions clang/lib/Driver/ToolChains/HIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ HIPToolChain::HIPToolChain(const Driver &D, const llvm::Triple &Triple,
getProgramPaths().push_back(getDriver().Dir);
}

static const char *getLibSpirvTargetName(const ToolChain &HostTC) {
return "remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc";
}

void HIPToolChain::addClangTargetOptions(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
Expand Down Expand Up @@ -309,8 +313,7 @@ void HIPToolChain::addClangTargetOptions(
llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc"));
LibraryPaths.emplace_back(WithInstallPath.c_str());

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

if (LibSpirvFile.empty()) {
getDriver().Diag(diag::err_drv_no_sycl_libspirv);
getDriver().Diag(diag::err_drv_no_sycl_libspirv)
<< getLibSpirvTargetName(HostTC);
return;
}

Expand Down
30 changes: 24 additions & 6 deletions clang/test/Driver/sycl-libspirv-invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,31 @@
// UNSUPPORTED: system-windows

// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=nvptx64-nvidia-nvcl --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \
// RUN: | FileCheck --check-prefix=ERR %s
// ERR: cannot find 'libspirv-nvptx64--nvidiacl.bc'
// RUN: | FileCheck --check-prefix=ERR-CUDA %s
// ERR-CUDA: cannot find 'remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc'

// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-windows-msvc -fsycl \
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \
// RUN: | FileCheck --check-prefix=ERR-CUDA-WIN %s
// ERR-CUDA-WIN: cannot find 'remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc'

// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \
// RUN: | FileCheck --check-prefix=ERR-HIP %s
// ERR-HIP: cannot find 'remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc'

// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc -fno-sycl-libspirv %s 2>&1 \
// RUN: | FileCheck --check-prefix=OK-CUDA %s
// OK-CUDA-NOT: cannot find suitable 'remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc'

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