Skip to content

Commit

Permalink
Use CUDA math wheels (#5966)
Browse files Browse the repository at this point in the history
Use CUDA math wheels to reduce wheel size by not statically linking CUDA math libraries.

Contributes to rapidsai/build-planning#35

Authors:
  - Kyle Edwards (https://github.com/KyleFromNVIDIA)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #5966
  • Loading branch information
KyleFromNVIDIA authored Aug 15, 2024
1 parent f677791 commit 7df3bbd
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
23 changes: 21 additions & 2 deletions ci/build_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,33 @@ rapids-generate-version > ./VERSION

cd ${package_dir}

SKBUILD_CMAKE_ARGS="-DDETECT_CONDA_ENV=OFF;-DDISABLE_DEPRECATION_WARNINGS=ON;-DCPM_cumlprims_mg_SOURCE=${GITHUB_WORKSPACE}/cumlprims_mg/" \
case "${RAPIDS_CUDA_VERSION}" in
12.*)
EXCLUDE_ARGS=(
--exclude "libcublas.so.12"
--exclude "libcublasLt.so.12"
--exclude "libcufft.so.11"
--exclude "libcurand.so.10"
--exclude "libcusolver.so.11"
--exclude "libcusparse.so.12"
--exclude "libnvJitLink.so.12"
)
EXTRA_CMAKE_ARGS=";-DUSE_CUDA_MATH_WHEELS=ON"
;;
11.*)
EXCLUDE_ARGS=()
EXTRA_CMAKE_ARGS=";-DUSE_CUDA_MATH_WHEELS=OFF"
;;
esac

SKBUILD_CMAKE_ARGS="-DDETECT_CONDA_ENV=OFF;-DDISABLE_DEPRECATION_WARNINGS=ON;-DCPM_cumlprims_mg_SOURCE=${GITHUB_WORKSPACE}/cumlprims_mg/${EXTRA_CMAKE_ARGS}" \
python -m pip wheel . \
-w dist \
-vvv \
--no-deps \
--disable-pip-version-check

mkdir -p final_dist
python -m auditwheel repair -w final_dist dist/*
python -m auditwheel repair -w final_dist "${EXCLUDE_ARGS[@]}" dist/*

RAPIDS_PY_WHEEL_NAME="cuml_${RAPIDS_PY_CUDA_SUFFIX}" rapids-upload-wheels-to-s3 final_dist
21 changes: 21 additions & 0 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ files:
extras:
table: project
includes:
- cuda
- py_run
py_test:
output: pyproject
Expand Down Expand Up @@ -406,6 +407,26 @@ dependencies:
- *libcusolver114
- *libcusparse_dev114
- *libcusparse114
- output_types: pyproject
matrices:
- matrix:
cuda: "12.*"
packages:
- nvidia-cublas-cu12
- nvidia-cufft-cu12
- nvidia-curand-cu12
- nvidia-cusparse-cu12
- nvidia-cusolver-cu12
- matrix:
cuda: "11.*"
packages:
- matrix:
packages:
- nvidia-cublas
- nvidia-cufft
- nvidia-curand
- nvidia-cusparse
- nvidia-cusolver
docs:
common:
- output_types: [conda, requirements]
Expand Down
26 changes: 24 additions & 2 deletions python/cuml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ project(
option(CUML_UNIVERSAL "Build all cuML Python components." ON)
option(FIND_CUML_CPP "Search for existing CUML C++ installations before defaulting to local files" OFF)
option(SINGLEGPU "Disable all mnmg components and comms libraries" OFF)
option(USE_CUDA_MATH_WHEELS "Use the CUDA math wheels instead of the system libraries" OFF)
set(CUML_RAFT_CLONE_ON_PIN OFF)


Expand Down Expand Up @@ -72,8 +73,10 @@ include(rapids-cython-core)

set(CUML_PYTHON_TREELITE_TARGET treelite::treelite)

if(NOT ${CUML_CPU})
if(NOT CUML_CPU)
if(NOT cuml_FOUND)
find_package(CUDAToolkit REQUIRED)

set(BUILD_CUML_TESTS OFF)
set(BUILD_PRIMS_TESTS OFF)
set(BUILD_CUML_C_LIBRARY OFF)
Expand All @@ -85,11 +88,19 @@ if(NOT ${CUML_CPU})

# Statically link dependencies if building wheels
set(CUDA_STATIC_RUNTIME ON)
set(CUDA_STATIC_MATH_LIBRARIES ON)
set(CUML_USE_RAFT_STATIC ON)
set(CUML_USE_FAISS_STATIC ON)
set(CUML_USE_TREELITE_STATIC ON)
set(CUML_USE_CUMLPRIMS_MG_STATIC ON)
# Link to the CUDA wheels with shared libraries for CUDA 12+
if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 12.0)
set(CUDA_STATIC_MATH_LIBRARIES OFF)
else()
if(USE_CUDA_MATH_WHEELS)
message(FATAL_ERROR "Cannot use CUDA math wheels with CUDA < 12.0")
endif()
set(CUDA_STATIC_MATH_LIBRARIES ON)
endif()
# Don't install the static libs into wheels
set(CUML_EXCLUDE_RAFT_FROM_ALL ON)
set(RAFT_EXCLUDE_FAISS_FROM_ALL ON)
Expand All @@ -98,6 +109,17 @@ if(NOT ${CUML_CPU})

add_subdirectory(${CUML_CPP_SRC} cuml-cpp EXCLUDE_FROM_ALL)

if(NOT CUDA_STATIC_MATH_LIBRARIES AND USE_CUDA_MATH_WHEELS)
set_property(TARGET ${CUML_CPP_TARGET} PROPERTY INSTALL_RPATH
"$ORIGIN/../nvidia/cublas/lib"
"$ORIGIN/../nvidia/cufft/lib"
"$ORIGIN/../nvidia/curand/lib"
"$ORIGIN/../nvidia/cusolver/lib"
"$ORIGIN/../nvidia/cusparse/lib"
"$ORIGIN/../nvidia/nvjitlink/lib"
)
endif()

set(cython_lib_dir cuml)
install(TARGETS ${CUML_CPP_TARGET} DESTINATION ${cython_lib_dir})
endif()
Expand Down
5 changes: 5 additions & 0 deletions python/cuml/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ dependencies = [
"dask-cudf==24.10.*,>=0.0.0a0",
"joblib>=0.11",
"numba>=0.57",
"nvidia-cublas",
"nvidia-cufft",
"nvidia-curand",
"nvidia-cusolver",
"nvidia-cusparse",
"packaging",
"pylibraft==24.10.*,>=0.0.0a0",
"raft-dask==24.10.*,>=0.0.0a0",
Expand Down

0 comments on commit 7df3bbd

Please sign in to comment.