Skip to content
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

[SuiteSparse_GPU] Update products to only contain GPU libraries #7803

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 0 additions & 2 deletions S/SuiteSparse/SuiteSparse@7/build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ include("../common.jl")
name = "SuiteSparse"
version = v"7.4.0"

sources = suitesparse_sources(version)

sources = suitesparse_sources(version)
push!(sources, DirectorySource("./bundled"))

Expand Down
105 changes: 50 additions & 55 deletions S/SuiteSparse/SuiteSparse_GPU@7/build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ include("../common.jl")
using Base.BinaryPlatforms: arch, os

name = "SuiteSparse_GPU"
version = v"7.3.0"
version = v"7.4.0"

sources = suitesparse_sources(version)
push!(sources, DirectorySource("./bundled"))

const YGGDRASIL_DIR = "../../.."
include(joinpath(YGGDRASIL_DIR, "fancy_toys.jl"))
Expand All @@ -18,6 +19,17 @@ cd $WORKSPACE/srcdir/SuiteSparse
# Needs cmake >= 3.22 provided by jll
apk del cmake

# Apply upstream patch to fix BLAS calls (backported from 7.5.0 dev branch)
atomic_patch -p1 ${WORKSPACE}/srcdir/patches/blas_suffix.patch

# Ensure CUDA is on the path
export CUDA_HOME=${WORKSPACE}/destdir/cuda;
export PATH=$PATH:$CUDA_HOME/bin
export CUDACXX=$CUDA_HOME/bin/nvcc

# nvcc thinks the libraries are located inside lib64, but the SDK actually has them in lib
ln -s ${CUDA_HOME}/lib ${CUDA_HOME}/lib64

# Disable OpenMP as it will probably interfere with blas threads and Julia threads
FLAGS+=(INSTALL="${prefix}" INSTALL_LIB="${libdir}" INSTALL_INCLUDE="${prefix}/include" CFOPENMP=)

Expand All @@ -38,59 +50,45 @@ fi
if [[ ${nbits} == 64 ]]; then
CMAKE_OPTIONS=(
-DBLAS64_SUFFIX="_64"
-DALLOW_64BIT_BLAS=YES
-DSUITESPARSE_USE_64BIT_BLAS=YES
)
else
CMAKE_OPTIONS=(
-DALLOW_64BIT_BLAS=NO
-DSUITESPARSE_USE_64BIT_BLAS=NO
)
fi

for proj in SuiteSparse_config SuiteSparse_GPURuntime GPUQREngine CHOLMOD SPQR; do
cd ${proj}/build
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${prefix} \
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
-DENABLE_CUDA=1 \
-DNFORTRAN=1 \
-DNOPENMP=1 \
-DNSTATIC=1 \
-DBLAS_FOUND=1 \
-DBLAS_LIBRARIES="${libdir}/lib${BLAS_NAME}.${dlext}" \
-DBLAS_LINKER_FLAGS="${BLAS_NAME}" \
-DBLAS_UNDERSCORE=ON \
-DBLA_VENDOR="${BLAS_NAME}" \
-DLAPACK_FOUND=1 \
-DLAPACK_LIBRARIES="${libdir}/lib${BLAS_NAME}.${dlext}" \
-DLAPACK_LINKER_FLAGS="${BLAS_NAME}" \
"${CMAKE_OPTIONS[@]}"
make -j${nproc}
make install
cd ../..
done

# For now, we'll have to adjust the name of the Lbt library on macOS and FreeBSD.
# Eventually, this should be fixed upstream
if [[ ${target} == *-apple-* ]] || [[ ${target} == *freebsd* ]]; then
echo "-- Modifying library name for Lbt"

for nm in libcholmod libspqr; do
# Figure out what version it probably latched on to:
if [[ ${target} == *-apple-* ]]; then
LBT_LINK=$(otool -L ${libdir}/${nm}.dylib | grep lib${BLAS_NAME} | awk '{ print $1 }')
install_name_tool -change ${LBT_LINK} @rpath/lib${BLAS_NAME}.dylib ${libdir}/${nm}.dylib
elif [[ ${target} == *freebsd* ]]; then
LBT_LINK=$(readelf -d ${libdir}/${nm}.so | grep lib${BLAS_NAME} | sed -e 's/.*\[\(.*\)\].*/\1/')
patchelf --replace-needed ${LBT_LINK} lib${BLAS_NAME}.so ${libdir}/${nm}.so
fi
done
fi

# Delete the extra soversion libraries built. https://github.com/JuliaPackaging/Yggdrasil/issues/7
if [[ "${target}" == *-mingw* ]]; then
rm -f ${libdir}/lib*.*.${dlext}
rm -f ${libdir}/lib*.*.*.${dlext}
fi
PROJECTS_TO_BUILD="cholmod;spqr"

cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${prefix} \
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
-DCMAKE_RELEASE_POSTFIX="_cuda" \
-DBUILD_STATIC_LIBS=OFF \
-DBUILD_TESTING=OFF \
-DSUITESPARSE_ENABLE_PROJECTS=${PROJECTS_TO_BUILD} \
-DSUITESPARSE_DEMOS=OFF \
-DSUITESPARSE_USE_STRICT=ON \
-DSUITESPARSE_USE_CUDA=ON \
-DSUITESPARSE_USE_FORTRAN=OFF \
-DSUITESPARSE_USE_OPENMP=OFF \
-DSUITESPARSE_USE_SYSTEM_SUITESPARSE_CONFIG=ON \
-DSUITESPARSE_USE_SYSTEM_AMD=ON \
-DSUITESPARSE_USE_SYSTEM_COLAMD=ON \
-DSUITESPARSE_USE_SYSTEM_CAMD=ON \
-DSUITESPARSE_USE_SYSTEM_CCOLAMD=ON \
-DCHOLMOD_PARTITION=ON \
-DBLAS_FOUND=1 \
-DBLAS_LIBRARIES="${libdir}/lib${BLAS_NAME}.${dlext}" \
-DBLAS_LINKER_FLAGS="${BLAS_NAME}" \
-DBLA_VENDOR="${BLAS_NAME}" \
-DLAPACK_LIBRARIES="${libdir}/lib${BLAS_NAME}.${dlext}" \
-DLAPACK_LINKER_FLAGS="${BLAS_NAME}" \
"${CMAKE_OPTIONS[@]}" \
.

make -j${nproc}
make install

install_license LICENSE.txt
"""
Expand All @@ -99,22 +97,19 @@ install_license LICENSE.txt
platforms = CUDA.supported_platforms()
filter!(p -> arch(p) == "x86_64", platforms)

# Add products
push!(products, LibraryProduct("libgpuqrengine", :libgpuqrengine))
push!(products, LibraryProduct("libsuitesparse_gpuruntime", :libsuitesparse_gpuruntime))

# Add dependency on SuiteSparse_jll
push!(dependencies, Dependency("SuiteSparse_jll"))

# build SuiteSparse_GPU for all supported CUDA toolkits
for platform in platforms
should_build_platform(triplet(platform)) || continue

cuda_deps = CUDA.required_dependencies(platform)
# Need the static SDK to let CMake detect the compiler properly
cuda_deps = CUDA.required_dependencies(platform, static_sdk=true)

build_tarballs(ARGS, name, version, sources, script, [platform],
products, [dependencies; cuda_deps]; lazy_artifacts=true,
julia_compat="1.10",preferred_gcc_version=v"9",
gpu_products, [dependencies; cuda_deps]; lazy_artifacts=true,
julia_compat="1.11",preferred_gcc_version=v"9",
augment_platform_block=CUDA.augment,
skip_audit=true, dont_dlopen=true)
end
40 changes: 40 additions & 0 deletions S/SuiteSparse/SuiteSparse_GPU@7/bundled/patches/blas_suffix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
From b936940aab08dc4bc60ccf2b9daec2105a960ad4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Markus=20M=C3=BCtzel?= <[email protected]>
Date: Mon, 1 Jan 2024 13:00:17 +0100
Subject: [PATCH] Add preprocessor definitions also with user-supplied
BLAS_LIBRARIES

---
SuiteSparse_config/cmake_modules/SuiteSparseBLAS.cmake | 4 ++--
SuiteSparse_config/cmake_modules/SuiteSparseBLAS64.cmake | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/SuiteSparse_config/cmake_modules/SuiteSparseBLAS.cmake b/SuiteSparse_config/cmake_modules/SuiteSparseBLAS.cmake
index ca241472d..be7cd2e73 100644
--- a/SuiteSparse_config/cmake_modules/SuiteSparseBLAS.cmake
+++ b/SuiteSparse_config/cmake_modules/SuiteSparseBLAS.cmake
@@ -36,9 +36,9 @@ if ( DEFINED BLAS_LIBRARIES OR DEFINED BLAS_INCLUDE_DIRS )
# User supplied variables for libraries and/or include directories.
# Use them as-is.
if ( SUITESPARSE_USE_64BIT_BLAS )
- set ( SuiteSparse_BLAS_integer "int64_t" )
+ include ( SuiteSparseBLAS64 )
else ( )
- set ( SuiteSparse_BLAS_integer "int32_t" )
+ include ( SuiteSparseBLAS32 )
endif ( )
return ( )
endif ( )
diff --git a/SuiteSparse_config/cmake_modules/SuiteSparseBLAS64.cmake b/SuiteSparse_config/cmake_modules/SuiteSparseBLAS64.cmake
index 744aaef91..1a5c63690 100644
--- a/SuiteSparse_config/cmake_modules/SuiteSparseBLAS64.cmake
+++ b/SuiteSparse_config/cmake_modules/SuiteSparseBLAS64.cmake
@@ -37,7 +37,7 @@ set ( SuiteSparse_BLAS_integer "int64_t" )
# https://github.com/spack/spack/blob/develop/var/spack/repos/builtin/packages/suite-sparse/package.py

if ( DEFINED BLAS64_SUFFIX )
- # append BLAS64_SUFFIX to each BLAS and LAPACK name
+ # append BLAS64_SUFFIX to each BLAS and LAPACK function name
string ( FIND ${BLAS64_SUFFIX} "_" HAS_UNDERSCORE )
message ( STATUS "BLAS64_suffix: ${BLAS64_SUFFIX}" )
if ( HAS_UNDERSCORE EQUAL -1 )
8 changes: 8 additions & 0 deletions S/SuiteSparse/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ products = [
LibraryProduct("libspqr", :libspqr),
]

# Products for the GPU builds of SuiteSparse
gpu_products = [
LibraryProduct("libcholmod_cuda", :libcholmod),
LibraryProduct("libspqr_cuda", :libspqr),
LibraryProduct("libgpuqrengine_cuda", :libgpuqrengine),
LibraryProduct("libsuitesparse_gpuruntime_cuda", :libsuitesparse_gpuruntime),
]

# Dependencies that must be installed before this package can be built
dependencies = [
Dependency("libblastrampoline_jll"; compat="5.8.0"),
Expand Down