Skip to content
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
4 changes: 2 additions & 2 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5272,9 +5272,9 @@ class OffloadingActionBuilder final {
// Select remangled libclc variant
std::string LibSpirvTargetName =
(TC->getAuxTriple()->isOSWindows())
? "remangled-l32-signed_char.libspirv-nvptx64--nvidiacl."
? "remangled-l32-signed_char.libspirv-nvptx64-nvidia-cuda."
"bc"
: "remangled-l64-signed_char.libspirv-nvptx64--nvidiacl."
: "remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda."
"bc";

for (StringRef LibraryPath : LibraryPaths) {
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ std::string CudaToolChain::getInputFilename(const InputInfo &Input) const {
// 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";
return "remangled-l32-signed_char.libspirv-nvptx64-nvidia-cuda.bc";
return "remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda.bc";
}

void CudaToolChain::addClangTargetOptions(
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/HIPAMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ HIPAMDToolChain::HIPAMDToolChain(const Driver &D, const llvm::Triple &Triple,
}

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

void HIPAMDToolChain::addClangTargetOptions(
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
StringRef InputFilename = llvm::sys::path::filename(FileName);
if (this->getToolChain().getTriple().isNVPTX()) {
// Linking SYCL Device libs requires libclc as well as libdevice
if ((InputFilename.find("nvidiacl") != InputFilename.npos ||
if ((InputFilename.find("libspirv") != InputFilename.npos ||
InputFilename.find("libdevice") != InputFilename.npos))
return true;
LibPostfix = ".cubin";
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Driver/cuda-nvptx-target.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib -target x86_64-unknown-windows-msvc %s 2> %t.win.out
// RUN: FileCheck %s --check-prefixes=CHECK-WINDOWS --input-file %t.win.out
// CHECK-WINDOWS: remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc
// CHECK-WINDOWS: remangled-l32-signed_char.libspirv-nvptx64-nvidia-cuda.bc
//
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib -target x86_64-unknown-linux-gnu %s 2> %t.lnx.out
// RUN: FileCheck %s --check-prefixes=CHECK-LINUX --input-file %t.lnx.out
// CHECK-LINUX: remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc
// CHECK-LINUX: remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda.bc
10 changes: 5 additions & 5 deletions clang/test/Driver/sycl-libspirv-invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
// 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 %s
// ERR-CUDA: cannot find 'remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc';
// ERR-CUDA: cannot find 'remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda.bc';
// ERR-CUDA-SAME: provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv

// 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';
// ERR-CUDA-WIN: cannot find 'remangled-l32-signed_char.libspirv-nvptx64-nvidia-cuda.bc';
// ERR-CUDA-WIN-SAME: provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv

// 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';
// ERR-HIP: cannot find 'remangled-l64-signed_char.libspirv-amdgcn-amd-amdhsa.bc';
// ERR-HIP-SAME: provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv

// 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'
// OK-CUDA-NOT: cannot find suitable 'remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda.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 -fno-sycl-libspirv %s 2>&1 \
// RUN: | FileCheck --check-prefix=OK-HIP %s
// OK-HIP-NOT: cannot find 'remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc'
// OK-HIP-NOT: cannot find 'remangled-l64-signed_char.libspirv-amdgcn-amd-amdhsa.bc'
15 changes: 11 additions & 4 deletions libclc/cmake/modules/AddLibclc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,34 @@ macro(add_libclc_builtin_set arch_suffix)
if( LIBCLC_GENERATE_REMANGLED_VARIANTS )
set(long_widths l32 l64)
set(char_signedness signed unsigned)
if( ${obj_suffix} STREQUAL "libspirv-nvptx64--nvidiacl.bc")
set( obj_suffix_mangled "libspirv-nvptx64-nvidia-cuda.bc")
elseif( ${obj_suffix} STREQUAL "libspirv-amdgcn--amdhsa.bc")
set( obj_suffix_mangled "libspirv-amdgcn-amd-amdhsa.bc")
else()
set( obj_suffix_mangled "${obj_suffix}")
endif()
# All permutations of [l32, l64] and [signed, unsigned]
foreach(long_width ${long_widths})
foreach(signedness ${char_signedness})
# Remangle
set( builtins_remangle_path
"${LIBCLC_LIBRARY_OUTPUT_INTDIR}/remangled-${long_width}-${signedness}_char.${obj_suffix}" )
"${LIBCLC_LIBRARY_OUTPUT_INTDIR}/remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}" )
add_custom_command( OUTPUT "${builtins_remangle_path}"
COMMAND libclc-remangler
-o "${builtins_remangle_path}"
--long-width=${long_width}
--char-signedness=${signedness}
"$<TARGET_PROPERTY:prepare-${obj_suffix},TARGET_FILE>"
DEPENDS "${builtins_obj_path}" "prepare-${obj_suffix}" libclc-remangler )
add_custom_target( "remangled-${long_width}-${signedness}_char.${obj_suffix}" ALL
add_custom_target( "remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}" ALL
DEPENDS "${builtins_remangle_path}" )
set_target_properties("remangled-${long_width}-${signedness}_char.${obj_suffix}"
set_target_properties("remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}"
PROPERTIES TARGET_FILE "${builtins_remangle_path}")

# Add dependency to top-level pseudo target to ease making other
# targets dependent on libclc.
add_dependencies(${ARG_PARENT_TARGET} "remangled-${long_width}-${signedness}_char.${obj_suffix}")
add_dependencies(${ARG_PARENT_TARGET} "remangled-${long_width}-${signedness}_char.${obj_suffix_mangled}")

# Keep remangled variants
install(
Expand Down
9 changes: 9 additions & 0 deletions libclc/utils/libclc-remangler/LibclcRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,15 @@ int main(int argc, const char **argv) {
std::unique_ptr<llvm::Module> M =
ExitOnErr(parseBitcodeFile(BufferPtr.get()->getMemBufferRef(), Context));

// This module is built explicitly for linking with any .bc compiled with the
// "nvptx64-nvidia-cuda" (CUDA) or "amdgcn-amd-amdhsa" (HIP AMD) triples.
// Therefore we update the module triple.
if (M.get()->getTargetTriple() == "nvptx64-unknown-nvidiacl") {
M.get()->setTargetTriple("nvptx64-nvidia-cuda");
}
else if (M.get()->getTargetTriple() == "amdgcn-unknown-amdhsa") {
M.get()->setTargetTriple("amdgcn-amd-amdhsa");
}
std::error_code EC;
std::unique_ptr<ToolOutputFile> Out(
new ToolOutputFile(OutputFilename, EC, sys::fs::OF_None));
Expand Down