[libsycl][Driver] Move and rename the SYCL shared library (#188770)
Align the shared library with other runtime libraries: - Rename from libsycl.so to libLLVMSYCL.so - Make install dir include the host triple if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is ON. Also updates the Clang driver to be aligned with the new location by relanding https://github.com/llvm/llvm-project/pull/189053 --------- Co-authored-by: Srividya Sundaram <srividya.sundaram@intel.com>
This commit is contained in:
@@ -22,8 +22,7 @@ public:
|
||||
void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
|
||||
llvm::opt::ArgStringList &CC1Args) const;
|
||||
|
||||
// Return the filesystem path to the SYCL runtime library (libsycl.so), that
|
||||
// was detected.
|
||||
// Return the filesystem path to the detected SYCL runtime library.
|
||||
StringRef getSYCLRTLibPath() const { return SYCLRTLibPath; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -880,7 +880,8 @@ void Linux::addOffloadRTLibs(unsigned ActiveKinds, const ArgList &Args,
|
||||
if (ActiveKinds & Action::OFK_HIP)
|
||||
Libraries.emplace_back(RocmInstallation->getLibPath(), "libamdhip64.so");
|
||||
else if (ActiveKinds & Action::OFK_SYCL)
|
||||
Libraries.emplace_back(SYCLInstallation->getSYCLRTLibPath(), "libsycl.so");
|
||||
Libraries.emplace_back(SYCLInstallation->getSYCLRTLibPath(),
|
||||
"libLLVMSYCL.so");
|
||||
|
||||
for (auto [Path, Library] : Libraries) {
|
||||
if (Args.hasFlag(options::OPT_frtlib_add_rpath,
|
||||
|
||||
@@ -19,15 +19,28 @@ SYCLInstallationDetector::SYCLInstallationDetector(
|
||||
const Driver &D, const llvm::Triple &HostTriple,
|
||||
const llvm::opt::ArgList &Args)
|
||||
: D(D) {
|
||||
// Detect the presence of the SYCL runtime library (libsycl.so) in the
|
||||
// filesystem. This is used to determine whether a usable SYCL installation
|
||||
// is available for the current driver invocation.
|
||||
// When -fsycl is active, locate the SYCL runtime library and record its
|
||||
// directory in SYCLRTLibPath for use by the linker.
|
||||
StringRef SysRoot = D.SysRoot;
|
||||
SmallString<128> DriverDir(D.Dir);
|
||||
SmallString<128> LibPath(DriverDir);
|
||||
llvm::sys::path::append(LibPath, "..", "lib", HostTriple.str(),
|
||||
"libLLVMSYCL.so");
|
||||
// Flat lib path for LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF builds,
|
||||
// where the library is installed directly in lib/ with no triple subdir.
|
||||
SmallString<128> FlatLibPath(DriverDir);
|
||||
llvm::sys::path::append(FlatLibPath, "..", "lib", "libLLVMSYCL.so");
|
||||
|
||||
if (DriverDir.starts_with(SysRoot) &&
|
||||
(Args.hasArg(options::OPT_fsycl) ||
|
||||
D.getVFS().exists(DriverDir + "/../lib/libsycl.so"))) {
|
||||
llvm::sys::path::append(DriverDir, "..", "lib");
|
||||
Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false)) {
|
||||
// LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON: library is in lib/<triple>/
|
||||
if (D.getVFS().exists(LibPath))
|
||||
llvm::sys::path::append(DriverDir, "..", "lib", HostTriple.str());
|
||||
// LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF: library is in lib/
|
||||
else if (D.getVFS().exists(FlatLibPath))
|
||||
llvm::sys::path::append(DriverDir, "..", "lib");
|
||||
else
|
||||
return; // Neither path exists : broken install, leave SYCLRTLibPath unset
|
||||
SYCLRTLibPath = DriverDir;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
# RUN: llvm-as %S/Inputs/SYCL/foo.ll -o %t.foo.bc
|
||||
# RUN: llvm-as %S/Inputs/SYCL/bar.ll -o %t.bar.bc
|
||||
# RUN: llvm-as %S/Inputs/SYCL/baz.ll -o %t.baz.bc
|
||||
# RUN: llvm-as %S/Inputs/SYCL/libsycl.ll -o %t.libsycl.bc
|
||||
# RUN: llvm-as %S/Inputs/SYCL/libLLVMSYCL.ll -o %t.libLLVMSYCL.bc
|
||||
# RUN: clang-sycl-linker %t.foo.bc %t.bar.bc -triple=spirv64 --dry-run -o a.spv --print-linked-module 2>&1 | FileCheck %s --check-prefix=CHECK-SIMPLE
|
||||
|
||||
# RUN: not clang-sycl-linker %t.bar.bc %t.baz.bc -triple=spirv64 --dry-run -o a.spv --print-linked-module 2>&1 | FileCheck %s --check-prefix=CHECK-MULTIPLE-DEFS
|
||||
|
||||
# RUN: clang-sycl-linker %t.foo.bc %t.bar.bc -device-libs=%t.libsycl.bc -library-path= -triple=spirv64 --dry-run -o a.spv --print-linked-module 2>&1 | FileCheck %s --check-prefix=CHECK-DEVICE-LIB
|
||||
# RUN: clang-sycl-linker %t.foo.bc %t.bar.bc -device-libs=%t.libLLVMSYCL.bc -library-path= -triple=spirv64 --dry-run -o a.spv --print-linked-module 2>&1 | FileCheck %s --check-prefix=CHECK-DEVICE-LIB
|
||||
|
||||
; CHECK-SIMPLE: define {{.*}}foo_func1{{.*}}
|
||||
; CHECK-SIMPLE: define {{.*}}foo_func2{{.*}}
|
||||
|
||||
25
clang/test/Driver/sycl-offload-jit-unix.cpp
Normal file
25
clang/test/Driver/sycl-offload-jit-unix.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
/// Tests for SYCL offloading JIT that require Unix commands (rm, ln, mkdir, touch)
|
||||
// These tests require a fake install tree with a symlinked clang so that D.Dir points to a
|
||||
// controlled location, allowing us to place a dummy libLLVMSYCL.so where the driver expects it.
|
||||
// UNSUPPORTED: system-windows, system-cygwin
|
||||
|
||||
// Check if path to the SYCL RT is passed to clang-linker-wrapper for SYCL compilation.
|
||||
// The test also checks if SYCL header include paths are added to the SYCL host and device compilation.
|
||||
|
||||
// Check LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON case: library is in lib/<triple>/
|
||||
// RUN: rm -rf %t && mkdir -p %t/bin %t/lib/x86_64-unknown-linux-gnu
|
||||
// RUN: touch %t/lib/x86_64-unknown-linux-gnu/libLLVMSYCL.so
|
||||
// RUN: ln -s %clang %t/bin/clang
|
||||
// RUN: %t/bin/clang -### -no-canonical-prefixes --target=x86_64-unknown-linux-gnu -fsycl %s 2>&1 \
|
||||
// RUN: | FileCheck -check-prefixes=CHECK-LSYCL,CHECK-SYCL-HEADERS-HOST,CHECK-SYCL-HEADERS-DEVICE %s
|
||||
// CHECK-SYCL-HEADERS-DEVICE: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"
|
||||
// CHECK-SYCL-HEADERS-HOST: "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"
|
||||
// CHECK-LSYCL: clang-linker-wrapper{{.*}} "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}x86_64-unknown-linux-gnu{{[/\\]+}}libLLVMSYCL.so"
|
||||
|
||||
// Check LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF case: library is in lib/ (no triple subdir)
|
||||
// RUN: rm -rf %t && mkdir -p %t/bin %t/lib
|
||||
// RUN: touch %t/lib/libLLVMSYCL.so
|
||||
// RUN: ln -s %clang %t/bin/clang
|
||||
// RUN: %t/bin/clang -### -no-canonical-prefixes --target=x86_64-unknown-linux-gnu -fsycl %s 2>&1 \
|
||||
// RUN: | FileCheck -check-prefix=CHECK-LSYCL-FLAT %s
|
||||
// CHECK-LSYCL-FLAT: clang-linker-wrapper{{.*}} "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}libLLVMSYCL.so"
|
||||
@@ -29,13 +29,10 @@
|
||||
// CHK-DEVICE-TRIPLE-SAME: "-O2"
|
||||
// CHK-DEVICE-TRIPLE: llvm-offload-binary{{.*}} "--image=file={{.*}}.bc,triple=spirv64-unknown-unknown,arch=generic,kind=sycl"
|
||||
|
||||
// Check if path to libsycl.so is passed to clang-linker-wrapper tool by default for SYCL compilation.
|
||||
// The test also checks if SYCL header include paths are added to the SYCL host and device compilation.
|
||||
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl %s 2>&1 \
|
||||
// RUN: | FileCheck -check-prefixes=CHECK-LSYCL,CHECK-SYCL-HEADERS-HOST,CHECK-SYCL-HEADERS-DEVICE %s
|
||||
// CHECK-SYCL-HEADERS-DEVICE: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"
|
||||
// CHECK-SYCL-HEADERS-HOST: "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"
|
||||
// CHECK-LSYCL: clang-linker-wrapper{{.*}} "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}libsycl.so"
|
||||
// Check that -fsycl -fno-sycl does not pass libLLVMSYCL.so to the linker.
|
||||
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl -fno-sycl %s 2>&1 \
|
||||
// RUN: | FileCheck -check-prefix=CHECK-NO-SYCL-RT %s
|
||||
// CHECK-NO-SYCL-RT-NOT: libLLVMSYCL.so
|
||||
|
||||
/// Check -fsycl-is-device is passed when compiling for the device.
|
||||
/// Check -fsycl-is-host is passed when compiling for host.
|
||||
|
||||
@@ -116,7 +116,7 @@ add_custom_command(
|
||||
install(DIRECTORY "${LIBSYCL_SOURCE_INCLUDE_DIR}/sycl" DESTINATION ${LIBSYCL_INCLUDE_DIR} COMPONENT sycl-headers)
|
||||
install(DIRECTORY "${LIBSYCL_SOURCE_INCLUDE_DIR}/CL" DESTINATION ${LIBSYCL_INCLUDE_DIR} COMPONENT sycl-headers)
|
||||
|
||||
set(LIBSYCL_LIB_NAME "sycl")
|
||||
set(LIBSYCL_LIB_NAME "LLVMSYCL")
|
||||
set(LIBSYCL_SHARED_OUTPUT_NAME "${LIBSYCL_LIB_NAME}")
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL Windows)
|
||||
if (CMAKE_MSVC_RUNTIME_LIBRARY AND (NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$"))
|
||||
|
||||
@@ -112,6 +112,6 @@ add_sycl_rt_library(${LIBSYCL_LIB_NAME}
|
||||
${LIBSYCL_SOURCES})
|
||||
|
||||
install(TARGETS ${LIBSYCL_RT_LIBS}
|
||||
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT libsycl
|
||||
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT libsycl
|
||||
ARCHIVE DESTINATION ${LIBSYCL_INSTALL_LIBRARY_DIR} COMPONENT libsycl
|
||||
LIBRARY DESTINATION ${LIBSYCL_INSTALL_LIBRARY_DIR} COMPONENT libsycl
|
||||
RUNTIME DESTINATION "bin" COMPONENT libsycl)
|
||||
|
||||
@@ -117,7 +117,7 @@ class test_env:
|
||||
config.substitutions.append(
|
||||
(
|
||||
"%sycl_options",
|
||||
" -lsycl"
|
||||
" -lLLVMSYCL"
|
||||
+ " -isystem "
|
||||
+ config.libsycl_include
|
||||
+ " -isystem "
|
||||
|
||||
@@ -3,7 +3,7 @@ add_executable(sycl-ls sycl-ls.cpp)
|
||||
target_include_directories(sycl-ls SYSTEM PRIVATE ${LLVM_MAIN_INCLUDE_DIR})
|
||||
target_link_libraries(sycl-ls PRIVATE LLVMSupport LLVMObject)
|
||||
|
||||
add_dependencies(sycl-ls sycl)
|
||||
add_dependencies(sycl-ls ${LIBSYCL_LIB_NAME})
|
||||
target_include_directories(sycl-ls PRIVATE ${LIBSYCL_BUILD_INCLUDE_DIR})
|
||||
|
||||
target_link_libraries(sycl-ls
|
||||
|
||||
Reference in New Issue
Block a user