Skip to content

Commit

Permalink
Add wheel builds (#5009)
Browse files Browse the repository at this point in the history
This PR enables building wheels of cuml. I don't expect tests to pass here until the raft wheels PR is merged, but it should be ready for reviews and hopefully CI will provide some useful feedback in the interim.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - Sevag H (https://github.com/sevagh)
  - Paul Taylor (https://github.com/trxcllnt)

Approvers:
  - Joseph (https://github.com/jolorunyomi)
  - Dante Gama Dessavre (https://github.com/dantegd)

URL: #5009
  • Loading branch information
vyasr authored Dec 1, 2022
1 parent 8bdeb2c commit 4b3928b
Show file tree
Hide file tree
Showing 26 changed files with 431 additions and 239 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: cuML wheels

on:
workflow_call:
inputs:
versioneer-override:
type: string
default: ''
build-tag:
type: string
default: ''
branch:
required: true
type: string
date:
required: true
type: string
sha:
required: true
type: string
build-type:
type: string
default: nightly

concurrency:
group: "cuml-${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
cuml-wheel:
uses: rapidsai/shared-action-workflows/.github/workflows/wheels-manylinux.yml@main
with:
repo: rapidsai/cuml

build-type: ${{ inputs.build-type }}
branch: ${{ inputs.branch }}
sha: ${{ inputs.sha }}
date: ${{ inputs.date }}

package-dir: python
package-name: cuml

# Note that this approach to cloning repos obviates any modification to
# the CMake variables in get_cumlprims_mg.cmake since CMake will just use
# the clone as is.
extra-repo: rapidsai/cumlprims_mg
extra-repo-sha: branch-22.12
extra-repo-deploy-key: CUMLPRIMS_SSH_PRIVATE_DEPLOY_KEY

python-package-versioneer-override: ${{ inputs.versioneer-override }}
python-package-build-tag: ${{ inputs.build-tag }}

skbuild-configure-options: "-DCUML_BUILD_WHEELS=ON -DDETECT_CONDA_ENV=OFF -DCPM_cumlprims_mg_SOURCE=/project/cumlprims_mg/"

# Always want to test against latest dask/distributed.
test-before-amd64: "pip install git+https://github.com/dask/dask.git@main git+https://github.com/dask/distributed.git@main git+https://github.com/rapidsai/dask-cuda.git@branch-22.12"
# On arm also need to install cupy from the specific webpage and CMake
# because treelite needs to be compiled (no wheels available for arm).
test-before-arm64: "pip install cupy-cuda11x -f https://pip.cupy.dev/aarch64 && pip install cmake && pip install git+https://github.com/dask/dask.git@main git+https://github.com/dask/distributed.git@main git+https://github.com/rapidsai/dask-cuda.git@branch-22.12"
test-extras: test
test-unittest: "pytest -v ./python/cuml/tests -k 'not test_silhouette_score_batched'"
secrets: inherit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dask-worker-space/
tmp/
.hypothesis
wheels/
wheelhouse/
_skbuild/

## files pickled in notebook when ran during python docstring generation
Expand Down
124 changes: 95 additions & 29 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ rapids_cuda_init_architectures(CUML)

project(CUML VERSION 22.12.00 LANGUAGES CXX CUDA)

# Needed because GoogleBenchmark changes the state of FindThreads.cmake, causing subsequent runs to
# have different values for the `Threads::Threads` target. Setting this flag ensures
# `Threads::Threads` is the same value in first run and subsequent runs.
set(THREADS_PREFER_PTHREAD_FLAG ON)

# Write the version header
rapids_cmake_write_version_file(include/cuml/version_config.hpp)

Expand Down Expand Up @@ -71,6 +66,15 @@ option(CUDA_STATIC_RUNTIME "Statically link the CUDA toolkit runtime and librari
option(CUML_USE_RAFT_STATIC "Build and statically link the RAFT libraries" OFF)
option(CUML_USE_FAISS_STATIC "Build and statically link the FAISS library for nearest neighbors search on GPU" OFF)
option(CUML_USE_TREELITE_STATIC "Build and statically link the treelite library" OFF)
option(CUML_EXPORT_TREELITE_LINKAGE "Whether to publicly or privately link treelite to libcuml++" OFF)
option(CUML_USE_CUMLPRIMS_MG_STATIC "Build and statically link the cumlprims_mg library" OFF)
# The options below allow incorporating libcuml into another build process
# without installing all its components. This is useful if total file size is
# at a premium and we do not expect other consumers to use any APIs of the
# dependency except those that are directly linked to by the dependent library.
option(CUML_EXCLUDE_RAFT_FROM_ALL "Exclude RAFT targets from cuML's 'all' target" OFF)
option(CUML_EXCLUDE_TREELITE_FROM_ALL "Exclude Treelite targets from cuML's 'all' target" OFF)
option(CUML_EXCLUDE_CUMLPRIMS_MG_FROM_ALL "Exclude cumlprims_mg targets from cuML's 'all' target" OFF)
option(CUML_RAFT_CLONE_ON_PIN "Explicitly clone RAFT branch when pinned to non-feature branch" ON)

message(VERBOSE "CUML_CPP: Building libcuml_c shared library. Contains the cuML C API: ${BUILD_CUML_C_LIBRARY}")
Expand Down Expand Up @@ -104,6 +108,13 @@ set(RMM_LOGGING_LEVEL "INFO" CACHE STRING "Choose the logging level.")
set_property(CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF")
message(VERBOSE "CUML_CPP: RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'.")

if(BUILD_CUML_TESTS OR BUILD_PRIMS_TESTS)
# Needed because GoogleBenchmark changes the state of FindThreads.cmake, causing subsequent runs to
# have different values for the `Threads::Threads` target. Setting this flag ensures
# `Threads::Threads` is the same value in first run and subsequent runs.
set(THREADS_PREFER_PTHREAD_FLAG ON)
endif()

##############################################################################
# - Target names -------------------------------------------------------------

Expand Down Expand Up @@ -132,15 +143,7 @@ endif()

set(_ctk_static_suffix "")
if(CUDA_STATIC_RUNTIME)
# If we're statically linking CTK cuBLAS,
# we also want to statically link BLAS
set(BLA_STATIC ON)
set(_ctk_static_suffix "_static")
set(_ctk_static_suffix_cufft "_static_nocallback")
# Control legacy FindCUDA.cmake behavior too
# Remove this after we push it into rapids-cmake:
# https://github.com/rapidsai/rapids-cmake/pull/259
set(CUDA_USE_STATIC_CUDA_RUNTIME ON)
set(_ctk_static_suffix "_static_nocallback")
endif()

if (NOT DISABLE_OPENMP)
Expand Down Expand Up @@ -212,8 +215,11 @@ endif()

# add third party dependencies using CPM
rapids_cpm_init()
rapids_cmake_install_lib_dir(lib_dir)

find_package(Threads)
if(BUILD_CUML_TESTS OR BUILD_PRIMS_TESTS)
find_package(Threads)
endif()

include(cmake/thirdparty/get_raft.cmake)

Expand Down Expand Up @@ -262,6 +268,20 @@ SECTIONS
]=])
endif()

# Copy the interface include directories from INCLUDED_TARGET to TARGET.
# This is necessary when INCLUDED_TARGET was compiled statically but includes
# public APIs that may still require consumers to have the same interface
# headers available.
function(copy_interface_excludes)
set(_options "")
set(_one_value TARGET INCLUDED_TARGET)
set(_multi_value "")
cmake_parse_arguments(_CUML_INCLUDES "${_options}" "${_one_value}"
"${_multi_value}" ${ARGN})
get_target_property(_includes ${_CUML_INCLUDES_INCLUDED_TARGET} INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(${_CUML_INCLUDES_TARGET} PUBLIC ${_includes})
endfunction()

if(BUILD_CUML_CPP_LIBRARY)

# single GPU components
Expand Down Expand Up @@ -534,19 +554,67 @@ if(BUILD_CUML_CPP_LIBRARY)
$<INSTALL_INTERFACE:include>
)

set(_cuml_cpp_public_libs)
set(_cuml_cpp_private_libs)

if(CUML_USE_RAFT_STATIC AND (TARGET raft::raft))
copy_interface_excludes(INCLUDED_TARGET raft::raft TARGET ${CUML_CPP_TARGET})

if(CUML_USE_RAFT_NN AND (TARGET faiss::faiss))
copy_interface_excludes(INCLUDED_TARGET faiss::faiss TARGET ${CUML_CPP_TARGET})
endif()

if(CUML_USE_RAFT_DIST AND (TARGET cuco::cuco))
list(APPEND _cuml_cpp_private_libs cuco::cuco)
endif()
endif()

if(CUML_USE_TREELITE_STATIC AND (TARGET treelite::treelite_static))
# By default, TREELITE_LIBS will contain both treelite::treelite_static and
# treelite::treelite_runtime_static if we are linking statically, but these
# two targets have duplicate symbols so we can only link to one of them.
set(TREELITE_LIBS treelite::treelite_static)

copy_interface_excludes(INCLUDED_TARGET treelite::treelite_static TARGET ${CUML_CPP_TARGET})
elseif(CUML_EXPORT_TREELITE_LINKAGE)
list(APPEND _cuml_cpp_public_libs ${TREELITE_LIBS})
endif()

if(CUML_USE_CUMLPRIMS_MG_STATIC AND (TARGET cumlprims_mg::cumlprims_mg))
copy_interface_excludes(INCLUDED_TARGET cumlprims_mg::cumlprims_mg TARGET ${CUML_CPP_TARGET})
endif()

# These are always private:
list(APPEND _cuml_cpp_private_libs
$<TARGET_NAME_IF_EXISTS:GPUTreeShap::GPUTreeShap>
$<$<BOOL:${LINK_CUFFT}>:CUDA::cufft${_ctk_static_suffix}>
${TREELITE_LIBS}
${OpenMP_CXX_LIB_NAMES}
$<$<OR:$<BOOL:${BUILD_CUML_STD_COMMS}>,$<BOOL:${BUILD_CUML_MPI_COMMS}>>:NCCL::NCCL>
$<$<BOOL:${BUILD_CUML_MPI_COMMS}>:${MPI_CXX_LIBRARIES}>
)

set(_cuml_cpp_libs_var_name "_cuml_cpp_public_libs")
if(CUDA_STATIC_RUNTIME)
set(_cuml_cpp_libs_var_name "_cuml_cpp_private_libs")
# Add CTK include paths because we're going to make our CTK library links private below
target_include_directories(${CUML_CPP_TARGET} SYSTEM PUBLIC ${CUDAToolkit_INCLUDE_DIRS})
endif()

# The visibility of these depend on whether we're linking the CTK statically,
# because cumlprims_mg and cuML inherit their CUDA libs from the raft::raft
# INTERFACE target.
list(APPEND ${_cuml_cpp_libs_var_name}
raft::raft
$<$<BOOL:${CUML_USE_RAFT_NN}>:raft::nn>
$<$<BOOL:${CUML_USE_RAFT_DIST}>:raft::distance>
$<TARGET_NAME_IF_EXISTS:cumlprims_mg::cumlprims_mg>
)

target_link_libraries(${CUML_CPP_TARGET}
PUBLIC
raft::raft
$<$<BOOL:${CUML_USE_RAFT_NN}>:raft::nn>
$<$<BOOL:${CUML_USE_RAFT_DIST}>:raft::distance>
PRIVATE
$<$<BOOL:${LINK_CUFFT}>:CUDA::cufft${_ctk_static_suffix_cufft}>
${TREELITE_LIBS}
$<$<BOOL:${treeshap_algo}>:GPUTreeShap::GPUTreeShap>
${OpenMP_CXX_LIB_NAMES}
$<$<OR:$<BOOL:${BUILD_CUML_STD_COMMS}>,$<BOOL:${BUILD_CUML_MPI_COMMS}>>:NCCL::NCCL>
$<$<BOOL:${BUILD_CUML_MPI_COMMS}>:${MPI_CXX_LIBRARIES}>
$<$<BOOL:${ENABLE_CUMLPRIMS_MG}>:cumlprims_mg::cumlprims_mg>
PUBLIC rmm::rmm
${_cuml_cpp_public_libs}
PRIVATE ${_cuml_cpp_private_libs}
)

# If we export the libdmlc symbols, they can lead to weird crashes with other
Expand All @@ -556,7 +624,6 @@ if(BUILD_CUML_CPP_LIBRARY)
target_link_options(${CUML_CPP_TARGET} PRIVATE "-Wl,--exclude-libs,libprotobuf.a")
# ensure CUDA symbols aren't relocated to the middle of the debug build binaries
target_link_options(${CUML_CPP_TARGET} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/fatbin.ld")

endif()

#############################################################################
Expand Down Expand Up @@ -611,7 +678,6 @@ endif()

# ###################################################################################################
# # - install targets -------------------------------------------------------------------------------
rapids_cmake_install_lib_dir( lib_dir )
include(CPack)

set(CUML_TARGETS ${CUML_CPP_TARGET})
Expand Down
24 changes: 20 additions & 4 deletions cpp/cmake/thirdparty/get_cumlprims_mg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,35 @@ set(CUML_BRANCH_VERSION_cumlprims_mg "${CUML_VERSION_MAJOR}.${CUML_VERSION_MINOR

function(find_and_configure_cumlprims_mg)

set(oneValueArgs VERSION FORK PINNED_TAG CLONE_ON_PIN)
set(oneValueArgs VERSION FORK PINNED_TAG BUILD_STATIC EXCLUDE_FROM_ALL CLONE_ON_PIN)
cmake_parse_arguments(PKG "" "${oneValueArgs}" "" ${ARGN} )

if(PKG_CLONE_ON_PIN AND NOT PKG_PINNED_TAG STREQUAL "branch-${CUML_BRANCH_VERSION_cumlprims_mg}")
message("Pinned tag found: ${PKG_PINNED_TAG}. Cloning cumlprims locally.")
set(CPM_DOWNLOAD_cumlprims_mg ON)
elseif(PKG_BUILD_STATIC AND (NOT CPM_cumlprims_mg_SOURCE))
message(STATUS "CUML: Cloning cumlprims_mg locally to build static libraries.")
set(CPM_DOWNLOAD_cumlprims_mg ON)
endif()

set(CUMLPRIMS_MG_BUILD_SHARED_LIBS ON)
if(PKG_BUILD_STATIC)
set(CUMLPRIMS_MG_BUILD_SHARED_LIBS OFF)
endif()

rapids_cpm_find(cumlprims_mg ${PKG_VERSION}
GLOBAL_TARGETS cumlprims_mg::cumlprims_mg
BUILD_EXPORT_SET cuml-exports
INSTALL_EXPORT_SET cuml-exports
CPM_ARGS
GIT_REPOSITORY git@github.com:${PKG_FORK}/cumlprims_mg.git
GIT_TAG ${PKG_PINNED_TAG}
GIT_REPOSITORY git@github.com:${PKG_FORK}/cumlprims_mg.git
GIT_TAG ${PKG_PINNED_TAG}
EXCLUDE_FROM_ALL ${PKG_EXCLUDE_FROM_ALL}
SOURCE_SUBDIR cpp
OPTIONS
"BUILD_TESTS OFF"
"BUILD_BENCHMARKS OFF"
"BUILD_SHARED_LIBS ${CUMLPRIMS_MG_BUILD_SHARED_LIBS}"
)

endfunction()
Expand All @@ -48,9 +62,11 @@ endfunction()
# cumlprims_mg as part of building cuml itself, set the CMake variable
# `-D CPM_cumlprims_mg_SOURCE=/path/to/cumlprims_mg`
###
find_and_configure_cumlprims_mg(VERSION ${CUML_MIN_VERSION_cumlprims_mg}
find_and_configure_cumlprims_mg(VERSION ${CUML_MIN_VERSION_cumlprims_mg}
FORK rapidsai
PINNED_TAG branch-${CUML_BRANCH_VERSION_cumlprims_mg}
BUILD_STATIC ${CUML_USE_CUMLPRIMS_MG_STATIC}
EXCLUDE_FROM_ALL ${CUML_EXCLUDE_CUMLPRIMS_MG_FROM_ALL}
# When PINNED_TAG above doesn't match cuml,
# force local cumlprims_mg clone in build directory
# even if it's already installed.
Expand Down
Loading

0 comments on commit 4b3928b

Please sign in to comment.