Skip to content

[SYCL] Fix devicelib identification for NVPTX #15357

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 6 commits into from
Sep 12, 2024
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
19 changes: 9 additions & 10 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,16 +592,15 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
NewLibPostfix = ".new.obj";
std::string FileName = this->getToolChain().getInputFilename(II);
StringRef InputFilename = llvm::sys::path::filename(FileName);
if (IsNVPTX || IsSYCLNativeCPU) {
// Linking SYCL Device libs requires libclc as well as libdevice
if ((InputFilename.find("libspirv") != InputFilename.npos ||
InputFilename.find("libdevice") != InputFilename.npos))
return true;
if (IsNVPTX) {
LibPostfix = ".cubin";
NewLibPostfix = ".new.cubin";
}
}
// NativeCPU links against libclc (libspirv)
if (IsSYCLNativeCPU && InputFilename.contains("libspirv"))
return true;
// NVPTX links against our libclc (libspirv), our libdevice (devicelib),
// and the CUDA libdevice
if (IsNVPTX && (InputFilename.starts_with("devicelib-") ||
InputFilename.contains("libspirv") ||
InputFilename.contains("libdevice")))
return true;
StringRef LibSyclPrefix("libsycl-");
if (!InputFilename.starts_with(LibSyclPrefix) ||
!InputFilename.ends_with(LibPostfix) ||
Expand Down
41 changes: 41 additions & 0 deletions clang/test/Driver/sycl-nvptx-link.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Check that we correctly determine that the final link command links
// devicelibs together, as far as the driver is concerned. This results in the
// -only-needed flag.
//
// Note we check the names of the various device libraries because that's the
// logic the driver uses.

// Older CUDA versions had versioned libdevice files. We don't support CUDA
// this old in SYCL, but we still test the driver's ability to pick out the
// correctly versioned libdevice. We use Inputs/CUDA_80 which has a full set of
// libdevice files.
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda \
// RUN: -Xsycl-target-backend --cuda-gpu-arch=sm_30 \
// RUN: --sysroot=%S/Inputs/SYCL --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
// RUN: | FileCheck %s --check-prefixes=CHECK,LIBDEVICE30
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda \
// RUN: -Xsycl-target-backend --cuda-gpu-arch=sm_35 \
// RUN: --sysroot=%S/Inputs/SYCL --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
// RUN: | FileCheck %s --check-prefixes=CHECK,LIBDEVICE35
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda \
// RUN: -Xsycl-target-backend --cuda-gpu-arch=sm_50 \
// RUN: --sysroot=%S/Inputs/SYCL --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
// RUN: | FileCheck %s --check-prefixes=CHECK,LIBDEVICE50

// CUDA-9+ uses the same libdevice for all GPU variants
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda \
// RUN: -Xsycl-target-backend --cuda-gpu-arch=sm_35 \
// RUN: --sysroot=%S/Inputs/SYCL --cuda-path=%S/Inputs/CUDA_90/usr/local/cuda %s 2>&1 \
// RUN: | FileCheck %s --check-prefixes=CHECK,LIBDEVICE10

// First link command: ignored
// CHECK: llvm-link

// CHECK: llvm-link
// CHECK-SAME: -only-needed
// CHECK-SAME: devicelib--cuda.bc
// CHECK-SAME: libspirv-nvptx64-nvidia-cuda.bc
// LIBDEVICE10-SAME: libdevice.10.bc
// LIBDEVICE30-SAME: libdevice.compute_30.10.bc
// LIBDEVICE35-SAME: libdevice.compute_35.10.bc
// LIBDEVICE50-SAME: libdevice.compute_50.10.bc
Loading