Skip to content

Commit 1d6e8da

Browse files
Use CUDA math wheels (#298)
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: - James Lamb (https://github.com/jameslamb) - Robert Maynard (https://github.com/robertmaynard) - Bradley Dice (https://github.com/bdice) URL: #298
1 parent 934645c commit 1d6e8da

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

ci/build_wheel.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,26 @@ rapids-generate-version > ./VERSION
1616

1717
cd "${package_dir}"
1818

19+
case "${RAPIDS_CUDA_VERSION}" in
20+
12.*)
21+
EXCLUDE_ARGS=(
22+
--exclude "libcublas.so.12"
23+
--exclude "libcublasLt.so.12"
24+
--exclude "libcurand.so.10"
25+
--exclude "libcusolver.so.11"
26+
--exclude "libcusparse.so.12"
27+
--exclude "libnvJitLink.so.12"
28+
)
29+
;;
30+
11.*)
31+
EXCLUDE_ARGS=()
32+
;;
33+
esac
34+
1935
# Hardcode the output dir
2036
python -m pip wheel . -w dist -vvv --no-deps --disable-pip-version-check
2137

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

2541
RAPIDS_PY_WHEEL_NAME="${underscore_package_name}_${RAPIDS_PY_CUDA_SUFFIX}" rapids-upload-wheels-to-s3 final_dist

ci/build_wheel_cuvs.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33

44
set -euo pipefail
55

6+
case "${RAPIDS_CUDA_VERSION}" in
7+
12.*)
8+
EXTRA_CMAKE_ARGS=";-DUSE_CUDA_MATH_WHEELS=ON"
9+
;;
10+
11.*)
11+
EXTRA_CMAKE_ARGS=";-DUSE_CUDA_MATH_WHEELS=OFF"
12+
;;
13+
esac
14+
615
# Set up skbuild options. Enable sccache in skbuild config options
7-
export SKBUILD_CMAKE_ARGS="-DDETECT_CONDA_ENV=OFF -DFIND_CUVS_CPP=OFF"
16+
export SKBUILD_CMAKE_ARGS="-DDETECT_CONDA_ENV=OFF;-DFIND_CUVS_CPP=OFF${EXTRA_CMAKE_ARGS}"
817

918
ci/build_wheel.sh cuvs python/cuvs

dependencies.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ files:
7878
extras:
7979
table: project
8080
includes:
81+
- cuda_wheels
8182
- run_py_cuvs
8283
py_test_py_cuvs:
8384
output: pyproject
@@ -310,6 +311,36 @@ dependencies:
310311
- *libcusolver114
311312
- *libcusparse_dev114
312313
- *libcusparse114
314+
cuda_wheels:
315+
specific:
316+
- output_types: pyproject
317+
matrices:
318+
- matrix:
319+
cuda: "12.*"
320+
use_cuda_wheels: "true"
321+
packages:
322+
- nvidia-cublas-cu12
323+
- nvidia-curand-cu12
324+
- nvidia-cusolver-cu12
325+
- nvidia-cusparse-cu12
326+
# CUDA 11 does not provide wheels, so use the system libraries instead
327+
- matrix:
328+
cuda: "11.*"
329+
use_cuda_wheels: "true"
330+
packages:
331+
# if use_cuda_wheels=false is provided, do not add dependencies on any CUDA wheels
332+
# (e.g. for DLFW and pip devcontainers)
333+
- matrix:
334+
use_cuda_wheels: "false"
335+
packages:
336+
# if no matching matrix selectors passed, list the unsuffixed packages
337+
# (just as a source of documentation, as this populates pyproject.toml in source control)
338+
- matrix:
339+
packages:
340+
- nvidia-cublas
341+
- nvidia-curand
342+
- nvidia-cusolver
343+
- nvidia-cusparse
313344

314345
cupy:
315346
common:

python/cuvs/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ project(
3737
option(FIND_CUVS_CPP "Search for existing CUVS C++ installations before defaulting to local files"
3838
OFF
3939
)
40+
option(USE_CUDA_MATH_WHEELS "Use the CUDA math wheels instead of the system libraries" OFF)
4041

4142
message(
4243
"CUVS_PY: Searching for existing cuVS C/C++ installations before defaulting to local files: ${FIND_CUVS_CPP}"
@@ -62,6 +63,8 @@ else()
6263
endif()
6364

6465
if(NOT cuvs_FOUND)
66+
find_package(CUDAToolkit REQUIRED)
67+
6568
set(BUILD_TESTS OFF)
6669
set(BUILD_C_LIBRARY ON)
6770

@@ -70,8 +73,26 @@ if(NOT cuvs_FOUND)
7073
set(CUDA_STATIC_MATH_LIBRARIES ON)
7174
set(CUVS_USE_RAFT_STATIC ON)
7275

76+
if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 12.0)
77+
set(CUDA_STATIC_MATH_LIBRARIES OFF)
78+
elseif(USE_CUDA_MATH_WHEELS)
79+
message(FATAL_ERROR "Cannot use CUDA math wheels with CUDA < 12.0")
80+
endif()
81+
7382
add_subdirectory(../../cpp cuvs-cpp EXCLUDE_FROM_ALL)
7483

84+
if(NOT CUDA_STATIC_MATH_LIBRARIES AND USE_CUDA_MATH_WHEELS)
85+
set(rpaths
86+
"$ORIGIN/../nvidia/cublas/lib"
87+
"$ORIGIN/../nvidia/curand/lib"
88+
"$ORIGIN/../nvidia/cusolver/lib"
89+
"$ORIGIN/../nvidia/cusparse/lib"
90+
"$ORIGIN/../nvidia/nvjitlink/lib"
91+
)
92+
set_property(TARGET cuvs PROPERTY INSTALL_RPATH ${rpaths} APPEND)
93+
set_property(TARGET cuvs_c PROPERTY INSTALL_RPATH ${rpaths} APPEND)
94+
endif()
95+
7596
set(cython_lib_dir cuvs)
7697
install(TARGETS cuvs cuvs_c DESTINATION ${cython_lib_dir})
7798
endif()

python/cuvs/pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ requires-python = ">=3.9"
3333
dependencies = [
3434
"cuda-python",
3535
"numpy>=1.23,<2.0a0",
36+
"nvidia-cublas",
37+
"nvidia-curand",
38+
"nvidia-cusolver",
39+
"nvidia-cusparse",
3640
"pylibraft==24.10.*,>=0.0.0a0",
3741
] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`.
3842
classifiers = [
@@ -128,7 +132,7 @@ requires = [
128132
] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`.
129133
build-backend = "scikit_build_core.build"
130134
dependencies-file = "../../dependencies.yaml"
131-
matrix-entry = "cuda_suffixed=true"
135+
matrix-entry = "cuda_suffixed=true;use_cuda_wheels=true"
132136

133137
[tool.pytest.ini_options]
134138
filterwarnings = [

0 commit comments

Comments
 (0)