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

Build C++ wheel #2251

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b72d69e
Add libraft package
vyasr Mar 29, 2024
6d2c8cc
Update dependencies.yaml
vyasr Mar 29, 2024
34899d5
Get libraft building
vyasr Mar 29, 2024
83fd2d5
Add libraft as dependency
vyasr Mar 29, 2024
2277659
Make librmm a runtime dependency of libraft
vyasr Mar 29, 2024
0f5606f
Change pylibraft to use libraft wheel
vyasr Mar 30, 2024
57a48d1
Don't error
vyasr Mar 30, 2024
82b0289
Fix name
vyasr Mar 30, 2024
64c4596
Remove RPATH hacking in favor of dynamic loading.
vyasr Mar 31, 2024
8cd54e6
Remove now extraneous ASSOCIATED_TARGETS
vyasr Mar 31, 2024
f5de64b
Make loading the library opt-in rather than automatic on import
vyasr Mar 31, 2024
4cdb805
Support disabling the static library build
vyasr Apr 1, 2024
b68fbc6
Add build in CI
vyasr Apr 1, 2024
cd3bd40
WAR dependencies
vyasr Apr 1, 2024
0daba29
Combine Python wheel building steps
vyasr Apr 1, 2024
38b5be2
Temporarily disable raft-dask builds since the package hasn't been up…
vyasr Apr 1, 2024
3d12d54
Pull rmm from the PR
vyasr Apr 1, 2024
f7b5098
Fix GHA
vyasr Apr 1, 2024
6e1ed98
Disambiguate dists
vyasr Apr 1, 2024
1b82456
Download librmm for the libraft build
vyasr Apr 1, 2024
f7425a5
Fix rmm artifact name
vyasr Apr 1, 2024
a107fa5
Bug
vyasr Apr 1, 2024
5e60fb0
Fix variable
vyasr Apr 1, 2024
d0b54fe
Fix find links
vyasr Apr 2, 2024
d1ba3f5
Make wheel py3
vyasr Apr 2, 2024
555fb31
Fix sed
vyasr Apr 2, 2024
81003c9
Exclude libraft.so from auditwheel
vyasr Apr 2, 2024
dddd49a
Make libraft a runtime dependency of the wheel
vyasr Apr 2, 2024
05aee04
Also download libraft wheel
vyasr Apr 2, 2024
14d2f5e
Also add the rmm wheelhouse
vyasr Apr 2, 2024
b8fdf4e
Specify py version for libraft download
vyasr Apr 2, 2024
036a105
Specify version correctly...
vyasr Apr 2, 2024
a6f20a0
Update to use latest tools
vyasr Apr 2, 2024
e34366b
typo
vyasr Apr 2, 2024
4be1c58
Get rid of extension
vyasr Apr 2, 2024
63833b3
Specify the wheel name to get
vyasr Apr 2, 2024
fefc447
Add missing underscore
vyasr Apr 2, 2024
7d003ea
Specify var in command
vyasr Apr 3, 2024
d8eb7a9
Move all exports out of conditional
vyasr Apr 3, 2024
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
27 changes: 14 additions & 13 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
- conda-python-build
- conda-python-tests
- docs-build
- wheel-build-pylibraft
- wheel-build-cpp
- wheel-build-python
- wheel-tests-pylibraft
- wheel-build-raft-dask
- wheel-tests-raft-dask
- devcontainer
secrets: inherit
Expand Down Expand Up @@ -74,29 +74,30 @@ jobs:
arch: "amd64"
container_image: "rapidsai/ci-conda:latest"
run_script: "ci/build_docs.sh"
wheel-build-pylibraft:
wheel-build-cpp:
needs: checks
secrets: inherit
uses: rapidsai/shared-workflows/.github/workflows/wheels-build.yaml@branch-24.06
with:
matrix_filter: group_by([.ARCH, (.CUDA_VER|split(".")|map(tonumber)|.[0])]) | map(max_by(.PY_VER|split(".")|map(tonumber)))
build_type: pull-request
script: ci/build_wheel_pylibraft.sh
wheel-tests-pylibraft:
needs: wheel-build-pylibraft
script: ci/build_wheel_cpp.sh
wheel-build-python:
needs: wheel-build-cpp
secrets: inherit
uses: rapidsai/shared-workflows/.github/workflows/wheels-test.yaml@branch-24.06
uses: rapidsai/shared-workflows/.github/workflows/wheels-build.yaml@branch-24.06
with:
build_type: pull-request
script: ci/test_wheel_pylibraft.sh
wheel-build-raft-dask:
needs: wheel-tests-pylibraft
script: ci/build_wheel_python.sh
wheel-tests-pylibraft:
needs: wheel-build-python
secrets: inherit
uses: rapidsai/shared-workflows/.github/workflows/wheels-build.yaml@branch-24.06
uses: rapidsai/shared-workflows/.github/workflows/wheels-test.yaml@branch-24.06
with:
build_type: pull-request
script: "ci/build_wheel_raft_dask.sh"
script: ci/test_wheel_pylibraft.sh
wheel-tests-raft-dask:
needs: wheel-build-raft-dask
needs: wheel-build-python
secrets: inherit
uses: rapidsai/shared-workflows/.github/workflows/wheels-test.yaml@branch-24.06
with:
Expand Down
35 changes: 14 additions & 21 deletions ci/build_wheel.sh → ci/build_wheel_cpp.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/bin/bash
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2024, NVIDIA CORPORATION.

set -euo pipefail

package_name=$1
package_dir=$2
underscore_package_name=$(echo "${package_name}" | tr "-" "_")
package_name="libraft"
package_dir="python/libraft"

if [[ ! -d "/tmp/gha-tools" ]]; then
git clone https://github.com/msarahan/gha-tools.git -b get-pr-wheel-artifact /tmp/gha-tools
fi
export PATH="/tmp/gha-tools/tools:${PATH}"

source rapids-configure-sccache
source rapids-date-string
Expand All @@ -15,13 +19,15 @@ git_commit=$(git rev-parse HEAD)

RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen ${RAPIDS_CUDA_VERSION})"

librmm_wheelhouse=$(RAPIDS_PY_WHEEL_NAME="librmm_${RAPIDS_PY_CUDA_SUFFIX}" rapids-get-pr-wheel-artifact rmm 1512 cpp)

# This is the version of the suffix with a preceding hyphen. It's used
# everywhere except in the final wheel name.
PACKAGE_CUDA_SUFFIX="-${RAPIDS_PY_CUDA_SUFFIX}"

# Patch project metadata files to include the CUDA version suffix and version override.
pyproject_file="${package_dir}/pyproject.toml"
version_file="${package_dir}/${underscore_package_name}/_version.py"
version_file="${package_dir}/${package_name}/_version.py"

sed -i "s/name = \"${package_name}\"/name = \"${package_name}${PACKAGE_CUDA_SUFFIX}\"/g" ${pyproject_file}
echo "${version}" > VERSION
Expand All @@ -36,26 +42,13 @@ if ! rapids-is-release-build; then
alpha_spec=',>=0.0.0a0'
fi

if [[ ${package_name} == "raft-dask" ]]; then
sed -r -i "s/pylibraft==(.*)\"/pylibraft${PACKAGE_CUDA_SUFFIX}==\1${alpha_spec}\"/g" ${pyproject_file}
sed -r -i "s/ucx-py==(.*)\"/ucx-py${PACKAGE_CUDA_SUFFIX}==\1${alpha_spec}\"/g" ${pyproject_file}
sed -r -i "s/rapids-dask-dependency==(.*)\"/rapids-dask-dependency==\1${alpha_spec}\"/g" ${pyproject_file}
sed -r -i "s/dask-cuda==(.*)\"/dask-cuda==\1${alpha_spec}\"/g" ${pyproject_file}
else
sed -r -i "s/rmm(.*)\"/rmm${PACKAGE_CUDA_SUFFIX}\1${alpha_spec}\"/g" ${pyproject_file}
fi

if [[ $PACKAGE_CUDA_SUFFIX == "-cu12" ]]; then
sed -i "s/cuda-python[<=>\.,0-9a]*/cuda-python>=12.0,<13.0a0/g" ${pyproject_file}
sed -i "s/cupy-cuda11x/cupy-cuda12x/g" ${pyproject_file}
fi
sed -r -i "s/librmm(.*)\"/librmm${PACKAGE_CUDA_SUFFIX}\1${alpha_spec}\"/g" ${pyproject_file}

cd "${package_dir}"

# Hardcode the output dir
python -m pip wheel . -w dist -vvv --no-deps --disable-pip-version-check
PIP_FIND_LINKS="${librmm_wheelhouse}" 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/*

RAPIDS_PY_WHEEL_NAME="${underscore_package_name}_${RAPIDS_PY_CUDA_SUFFIX}" rapids-upload-wheels-to-s3 final_dist
RAPIDS_PY_WHEEL_NAME="${package_name}_${RAPIDS_PY_CUDA_SUFFIX}" rapids-upload-wheels-to-s3 cpp final_dist
9 changes: 0 additions & 9 deletions ci/build_wheel_pylibraft.sh

This file was deleted.

96 changes: 96 additions & 0 deletions ci/build_wheel_python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash
# Copyright (c) 2023-2024, NVIDIA CORPORATION.

set -euo pipefail

if [[ ! -d "/tmp/gha-tools" ]]; then
git clone https://github.com/msarahan/gha-tools.git -b get-pr-wheel-artifact /tmp/gha-tools
fi
export PATH="/tmp/gha-tools/tools:${PATH}"

source rapids-configure-sccache
source rapids-date-string

version=$(rapids-generate-version)
git_commit=$(git rev-parse HEAD)

RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen ${RAPIDS_CUDA_VERSION})"
RAPIDS_PY_WHEEL_NAME="libraft_${RAPIDS_PY_CUDA_SUFFIX}" rapids-download-wheels-from-s3 cpp /tmp/libraft_dist

# This is the version of the suffix with a preceding hyphen. It's used
# everywhere except in the final wheel name.
PACKAGE_CUDA_SUFFIX="-${RAPIDS_PY_CUDA_SUFFIX}"

echo "${version}" > VERSION
# For nightlies we want to ensure that we're pulling in alphas as well. The
# easiest way to do so is to augment the spec with a constraint containing a
# min alpha version that doesn't affect the version bounds but does allow usage
# of alpha versions for that dependency without --pre
alpha_spec=''
if ! rapids-is-release-build; then
alpha_spec=',>=0.0.0a0'
fi


###############################################
# Build pylibraft

librmm_wheelhouse=$(RAPIDS_PY_WHEEL_NAME="librmm_${RAPIDS_PY_CUDA_SUFFIX}" rapids-get-pr-wheel-artifact rmm 1512 cpp)

package_name="pylibraft"
package_dir="python/pylibraft"

pyproject_file="${package_dir}/pyproject.toml"
version_file="${package_dir}/${package_name}/_version.py"

sed -i "s/name = \"${package_name}\"/name = \"${package_name}${PACKAGE_CUDA_SUFFIX}\"/g" ${pyproject_file}
sed -i "/^__git_commit__ / s/= .*/= \"${git_commit}\"/g" ${version_file}

sed -r -i "s/rmm(.*)\"/rmm${PACKAGE_CUDA_SUFFIX}\1${alpha_spec}\"/g" ${pyproject_file}
sed -r -i "s/libraft==(.*)\"/libraft${PACKAGE_CUDA_SUFFIX}==\1${alpha_spec}\"/g" ${pyproject_file}
if [[ $PACKAGE_CUDA_SUFFIX == "-cu12" ]]; then
sed -i "s/cuda-python[<=>\.,0-9a]*/cuda-python>=12.0,<13.0a0/g" ${pyproject_file}
sed -i "s/cupy-cuda11x/cupy-cuda12x/g" ${pyproject_file}
fi

pushd "${package_dir}"

PIP_FIND_LINKS="/tmp/libraft_dist ${librmm_wheelhouse}" python -m pip wheel . -w pylibraft_dist -vvv --no-deps --disable-pip-version-check

mkdir -p pylibraft_final_dist
python -m auditwheel repair -w pylibraft_final_dist --exclude libraft.so pylibraft_dist/*

RAPIDS_PY_WHEEL_NAME="${package_name}_${RAPIDS_PY_CUDA_SUFFIX}" rapids-upload-wheels-to-s3 python pylibraft_final_dist

popd


################################################
## Build raft-dask
#
#package_name=raft-dask
#package_dir=python/raft-dask
#underscore_package_name=$(echo "${package_name}" | tr "-" "_")
#
#pyproject_file="${package_dir}/pyproject.toml"
#version_file="${package_dir}/${underscore_package_name}/_version.py"
#
#sed -i "s/name = \"${package_name}\"/name = \"${package_name}${PACKAGE_CUDA_SUFFIX}\"/g" ${pyproject_file}
#sed -i "/^__git_commit__ / s/= .*/= \"${git_commit}\"/g" ${version_file}
#
#sed -r -i "s/libraft(.*)\"/libraft${PACKAGE_CUDA_SUFFIX}\1${alpha_spec}\"/g" ${pyproject_file}
#sed -r -i "s/pylibraft==(.*)\"/pylibraft${PACKAGE_CUDA_SUFFIX}==\1${alpha_spec}\"/g" ${pyproject_file}
#sed -r -i "s/ucx-py==(.*)\"/ucx-py${PACKAGE_CUDA_SUFFIX}==\1${alpha_spec}\"/g" ${pyproject_file}
#sed -r -i "s/rapids-dask-dependency==(.*)\"/rapids-dask-dependency==\1${alpha_spec}\"/g" ${pyproject_file}
#sed -r -i "s/dask-cuda==(.*)\"/dask-cuda==\1${alpha_spec}\"/g" ${pyproject_file}
#
#pushd "${package_dir}"
#
#PIP_FIND_LINKS="../pylibraft/pylibraft_dist /tmp/libraft_dist" python -m pip wheel . -w raft_dask_dist -vvv --no-deps --disable-pip-version-check
#
#mkdir -p raft_dask_final_dist
#python -m auditwheel repair -w raft_dask_final_dist --exclude libraft.so raft_dask_dist/*
#
#RAPIDS_PY_WHEEL_NAME="${underscore_package_name}_${RAPIDS_PY_CUDA_SUFFIX}" rapids-upload-wheels-to-s3 raft_dask_final_dist
#
#popd
9 changes: 0 additions & 9 deletions ci/build_wheel_raft_dask.sh

This file was deleted.

14 changes: 11 additions & 3 deletions ci/test_wheel_pylibraft.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#!/bin/bash
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.

set -euo pipefail

if [[ ! -d "/tmp/gha-tools" ]]; then
git clone https://github.com/msarahan/gha-tools.git -b get-pr-wheel-artifact /tmp/gha-tools
fi
export PATH="/tmp/gha-tools/tools:${PATH}"

mkdir -p ./dist
RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen ${RAPIDS_CUDA_VERSION})"
RAPIDS_PY_WHEEL_NAME="pylibraft_${RAPIDS_PY_CUDA_SUFFIX}" rapids-download-wheels-from-s3 ./dist
RAPIDS_PY_WHEEL_NAME="libraft_${RAPIDS_PY_CUDA_SUFFIX}" rapids-download-wheels-from-s3 cpp ./dist
RAPIDS_PY_WHEEL_NAME="pylibraft_${RAPIDS_PY_CUDA_SUFFIX}" rapids-download-wheels-from-s3 python ./dist

librmm_wheelhouse=$(RAPIDS_PY_WHEEL_NAME="librmm_${RAPIDS_PY_CUDA_SUFFIX}" rapids-get-pr-wheel-artifact rmm 1512 cpp)

# echo to expand wildcard before adding `[extra]` requires for pip
python -m pip install $(echo ./dist/pylibraft*.whl)[test]
python -m pip install $(echo ./dist/pylibraft*.whl)[test] --find-links ./dist --find-links ${librmm_wheelhouse}

# Run smoke tests for aarch64 pull requests
if [[ "$(arch)" == "aarch64" && "${RAPIDS_BUILD_TYPE}" == "pull-request" ]]; then
Expand Down
74 changes: 48 additions & 26 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ if((BUILD_TESTS
)
set(RAFT_COMPILE_LIBRARY_DEFAULT ON)
endif()
option(RAFT_COMPILE_LIBRARY "Enable building raft shared library instantiations"
option(RAFT_COMPILE_LIBRARY "Enable building raft library instantiations"
${RAFT_COMPILE_LIBRARY_DEFAULT}
)
option(RAFT_COMPILE_DYNAMIC_ONLY "Only build the static library and skip the
static library. Has no effect if RAFT_COMPILE_LIBRARY is OFF" OFF)

if(BUILD_CPU_ONLY)
set(BUILD_SHARED_LIBS OFF)
Expand Down Expand Up @@ -582,17 +584,25 @@ if(RAFT_COMPILE_LIBRARY)
)

add_library(raft_lib SHARED $<TARGET_OBJECTS:raft_objs>)
add_library(raft_lib_static STATIC $<TARGET_OBJECTS:raft_objs>)
if(NOT RAFT_COMPILE_DYNAMIC_ONLY)
add_library(raft_lib_static STATIC $<TARGET_OBJECTS:raft_objs>)
endif()

set(raft_lib_targets raft_lib)
if(NOT RAFT_COMPILE_DYNAMIC_ONLY)
list(APPEND raft_lib_targets raft_lib_static)
endif()

set_target_properties(
raft_lib raft_lib_static
${raft_lib_targets}
PROPERTIES OUTPUT_NAME raft
BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
INTERFACE_POSITION_INDEPENDENT_CODE ON
)

foreach(target raft_lib raft_lib_static raft_objs)
list(APPEND raft_lib_targets raft_objs)
foreach(target IN LISTS raft_lib_targets)
target_link_libraries(
${target}
PUBLIC raft::raft
Expand All @@ -617,21 +627,23 @@ target_link_libraries(raft_compiled INTERFACE raft::raft $<TARGET_NAME_IF_EXISTS
# ##################################################################################################
# * raft_compiled_static----------------------------------------------------------------------------

add_library(raft_compiled_static INTERFACE)

if(TARGET raft_compiled_static AND (NOT TARGET raft::compiled_static))
add_library(raft::compiled_static ALIAS raft_compiled_static)
endif()
set_target_properties(raft_compiled_static PROPERTIES EXPORT_NAME compiled_static)

if(TARGET raft_lib_static AND (NOT TARGET raft::raft_lib_static))
add_library(raft::raft_lib_static ALIAS raft_lib_static)
if(NOT RAFT_COMPILE_DYNAMIC_ONLY)
add_library(raft_compiled_static INTERFACE)

if(TARGET raft_compiled_static AND (NOT TARGET raft::compiled_static))
add_library(raft::compiled_static ALIAS raft_compiled_static)
endif()
set_target_properties(raft_compiled_static PROPERTIES EXPORT_NAME compiled_static)

if(TARGET raft_lib_static AND (NOT TARGET raft::raft_lib_static))
add_library(raft::raft_lib_static ALIAS raft_lib_static)
endif()

target_link_libraries(
raft_compiled_static INTERFACE raft::raft $<TARGET_NAME_IF_EXISTS:raft::raft_lib_static>
)
endif()

target_link_libraries(
raft_compiled_static INTERFACE raft::raft $<TARGET_NAME_IF_EXISTS:raft::raft_lib_static>
)

# ##################################################################################################
# * raft_distributed -------------------------------------------------------------------------------
add_library(raft_distributed INTERFACE)
Expand Down Expand Up @@ -670,8 +682,12 @@ install(
EXPORT raft-exports
)

set(raft_compiled_install_targets raft_compiled)
if(NOT RAFT_COMPILE_DYNAMIC_ONLY)
list(APPEND raft_compiled_install_targets raft_compiled_static)
endif()
install(
TARGETS raft_compiled raft_compiled_static
TARGETS ${raft_compiled_install_targets}
DESTINATION ${lib_dir}
COMPONENT raft
EXPORT raft-compiled-exports
Expand All @@ -684,12 +700,14 @@ if(TARGET raft_lib)
COMPONENT compiled
EXPORT raft-compiled-lib-exports
)
install(
TARGETS raft_lib_static
DESTINATION ${lib_dir}
COMPONENT compiled-static
EXPORT raft-compiled-static-lib-exports
)
if(NOT RAFT_COMPILE_DYNAMIC_ONLY)
install(
TARGETS raft_lib_static
DESTINATION ${lib_dir}
COMPONENT compiled-static
EXPORT raft-compiled-static-lib-exports
)
endif()
install(
DIRECTORY include/raft_runtime
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
Expand Down Expand Up @@ -760,8 +778,12 @@ endif()
set(raft_components compiled distributed)
set(raft_export_sets raft-compiled-exports raft-distributed-exports)
if(TARGET raft_lib)
list(APPEND raft_components compiled compiled-static)
list(APPEND raft_export_sets raft-compiled-lib-exports raft-compiled-static-lib-exports)
list(APPEND raft_components compiled)
list(APPEND raft_export_sets raft-compiled-lib-exports)
if(NOT RAFT_COMPILE_DYNAMIC_ONLY)
list(APPEND raft_components compiled-static)
list(APPEND raft_export_sets raft-compiled-static-lib-exports)
endif()
endif()

string(
Expand Down
Loading
Loading