Skip to content

Commit

Permalink
Enable cuml-cpu nightly (#5585)
Browse files Browse the repository at this point in the history
PR Adds changes necessary to produce cum-cpu nightly packages. PR accomplishes this by: 

- [x] Using CMake conditional compiling
- [x] Using Cython IF compilation temporarily. This will be changed for separating the C++ calls from the Python code, similar to pylibraft. 
- [x] Adding new conda recipe. 

Two follow ups from this are:

- [ ] Doc and notebook updates
- [ ] Additional models added

Authors:
  - Dante Gama Dessavre (https://github.com/dantegd)

Approvers:
  - William Hicks (https://github.com/wphicks)
  - Ray Douglass (https://github.com/raydouglass)
  - Corey J. Nolet (https://github.com/cjnolet)

URL: #5585
  • Loading branch information
dantegd authored Sep 27, 2023
1 parent 4f0f0f3 commit 3e5c8e9
Show file tree
Hide file tree
Showing 53 changed files with 3,058 additions and 2,893 deletions.
9 changes: 8 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ARGS=$*
# script, and that this script resides in the repo dir!
REPODIR=$(cd $(dirname $0); pwd)

VALIDTARGETS="clean libcuml cuml cpp-mgtests prims bench prims-bench cppdocs pydocs"
VALIDTARGETS="clean libcuml cuml cuml-cpu cpp-mgtests prims bench prims-bench cppdocs pydocs"
VALIDFLAGS="-v -g -n --allgpuarch --singlegpu --nolibcumltest --nvtx --show_depr_warn --codecov --ccache --configure-only -h --help "
VALIDARGS="${VALIDTARGETS} ${VALIDFLAGS}"
HELP="$0 [<target> ...] [<flag> ...]
Expand All @@ -27,6 +27,7 @@ HELP="$0 [<target> ...] [<flag> ...]
libcuml - build the cuml C++ code only. Also builds the C-wrapper library
around the C++ code.
cuml - build the cuml Python package
cuml-cpu - build the cuml CPU Python package
cpp-mgtests - build libcuml mnmg tests. Builds MPI communicator, adding MPI as dependency.
prims - build the ml-prims tests
bench - build the libcuml C++ benchmark
Expand Down Expand Up @@ -294,3 +295,9 @@ if (! hasArg --configure-only) && (completeBuild || hasArg cuml || hasArg pydocs
make html
fi
fi

if hasArg cuml-cpu; then
SKBUILD_CONFIGURE_OPTIONS="-DCUML_CPU=ON -DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE" \
SKBUILD_BUILD_OPTIONS="-j${PARALLEL_LEVEL}" \
python -m pip install --no-build-isolation --no-deps -v ${REPODIR}/python
fi
9 changes: 9 additions & 0 deletions ci/build_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ rapids-conda-retry mambabuild \
--channel "${CPP_CHANNEL}" \
conda/recipes/cuml

# Build cuml-cpu only in CUDA 11 jobs since it only depends on python
# version
RAPIDS_CUDA_MAJOR="${RAPIDS_CUDA_VERSION%%.*}"
if [[ ${RAPIDS_CUDA_MAJOR} == "11" ]]; then
rapids-conda-retry mambabuild \
--no-test \
conda/recipes/cuml-cpu
fi

rapids-upload-conda-to-s3 python
5 changes: 5 additions & 0 deletions conda/recipes/cuml-cpu/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# Copyright (c) 2023, NVIDIA CORPORATION.

# This assumes the script is executed from the root of the repo directory
./build.sh cuml-cpu -v
11 changes: 11 additions & 0 deletions conda/recipes/cuml-cpu/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
c_compiler_version:
- 11

cxx_compiler_version:
- 11

cmake_version:
- ">=3.26.4"

sysroot_version:
- "=2.17"
50 changes: 50 additions & 0 deletions conda/recipes/cuml-cpu/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) 2023, NVIDIA CORPORATION.

# Usage:
# conda build . -c conda-forge -c numba -c rapidsai -c pytorch
{% set version = environ.get('GIT_DESCRIBE_TAG', '0.0.0.dev').lstrip('v') + environ.get('VERSION_SUFFIX', '') %}
{% set py_version = environ['CONDA_PY'] %}
{% set date_string = environ['RAPIDS_DATE_STRING'] %}

package:
name: cuml-cpu
version: {{ version }}

source:
git_url: ../../..

build:
number: {{ GIT_DESCRIBE_NUMBER }}
string: py{{ py_version }}_{{ date_string }}_{{ GIT_DESCRIBE_HASH }}_{{ GIT_DESCRIBE_NUMBER }}
script_env:
- VERSION_SUFFIX

requirements:
build:
- cmake {{ cmake_version }}
- {{ compiler('c') }}
- {{ compiler('cxx') }}
- sysroot_{{ target_platform }} {{ sysroot_version }}
- ninja
host:
- python x.x
- setuptools
- scikit-build>=0.13.1
- cython>=3.0.0
run:
- python x.x
- numpy
- scikit-learn=1.2
- hdbscan<=0.8.30
- umap-learn=0.5.3
- nvtx

tests: # [linux64]
imports: # [linux64]
- cuml-cpu # [linux64]

about:
home: http://rapids.ai/
license: Apache-2.0
# license_file: LICENSE
summary: cuML-CPU library
5 changes: 1 addition & 4 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,7 @@ Quasi-Newton
:members:

Support Vector Machines
------------------------

.. autoclass:: cuml.svm.SVC
:members:
-----------------------

.. autoclass:: cuml.svm.SVR
:members:
Expand Down
124 changes: 80 additions & 44 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ include(../fetch_rapids.cmake)

set(CUML_VERSION 23.10.00)

# We always need CUDA for cuML because the raft dependency brings in a
# header-only cuco dependency that enables CUDA unconditionally.
include(rapids-cuda)
rapids_cuda_init_architectures(cuml-python)
option(CUML_CPU "Build only cuML CPU Python components." OFF)
set(language_list "C;CXX")

if(NOT CUML_CPU)
# We always need CUDA for cuML GPU because the raft dependency brings in a
# header-only cuco dependency that enables CUDA unconditionally.
include(rapids-cuda)
rapids_cuda_init_architectures(cuml-python)
list(APPEND language_list "CUDA")
endif()

project(
cuml-python
Expand All @@ -30,14 +36,12 @@ project(
# language to be enabled here. The test project that is built in scikit-build to verify
# various linking options for the python library is hardcoded to build with C, so until
# that is fixed we need to keep C.
C CXX CUDA
${language_list}
)

################################################################################
# - User Options --------------------------------------------------------------
option(CUML_UNIVERSAL "Build all cuML Python components." ON)
option(CUML_CPU "Build only cuML CPU Python components." OFF)
option(CUML_GPU "Build only cuML GPU Python components. Not supported yet, defaulting to CUML_UNIVERSAL" OFF)
option(FIND_CUML_CPP "Search for existing CUML C++ installations before defaulting to local files" OFF)
option(CUML_BUILD_WHEELS "Whether this build is generating a Python wheel." OFF)
option(SINGLEGPU "Disable all mnmg components and comms libraries" OFF)
Expand All @@ -47,11 +51,11 @@ set(CUML_RAFT_CLONE_ON_PIN OFF)

# todo: use CMAKE_MESSAGE_CONTEXT for prefix for logging.
# https://github.com/rapidsai/cuml/issues/4843
message(VERBOSE "CUML_PY: Build only cuML CPU Python components.: ${CUML_CPU}")
message(VERBOSE "CUML_PY: Searching for existing CUML C++ installations before defaulting to local files: ${FIND_CUML_CPP}")
message(VERBOSE "CUML_PY: Disabling all mnmg components and comms libraries: ${SINGLEGPU}")

set(CUML_ALGORITHMS "ALL" CACHE STRING "Experimental: Choose which algorithms are built into libcuml++.so. Can specify individual algorithms or groups in a semicolon-separated list.")
message(VERBOSE "CUML_PY: Building cuML with algorithms: '${CUML_ALGORITHMS}'.")
set(CUML_ALGORITHMS "ALL" CACHE STRING "Choose which algorithms are built cuML. Can specify individual algorithms or groups in a semicolon-separated list.")

set(CUML_CPP_TARGET "cuml++")
set(CUML_CPP_SRC "../cpp")
Expand Down Expand Up @@ -80,48 +84,68 @@ else()
set(CUML_PYTHON_TREELITE_TARGET treelite::treelite)
endif()

if(NOT cuml_FOUND)
set(BUILD_CUML_TESTS OFF)
set(BUILD_PRIMS_TESTS OFF)
set(BUILD_CUML_C_LIBRARY OFF)
set(BUILD_CUML_EXAMPLES OFF)
set(BUILD_CUML_BENCH OFF)
set(BUILD_CUML_PRIMS_BENCH OFF)
set(CUML_EXPORT_TREELITE_LINKAGE ON)

set(_exclude_from_all "")
if(CUML_BUILD_WHEELS)
# Statically link dependencies if building wheels
set(CUDA_STATIC_RUNTIME 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)
# Don't install the static libs into wheels
set(CUML_EXCLUDE_RAFT_FROM_ALL ON)
set(RAFT_EXCLUDE_FAISS_FROM_ALL ON)
set(CUML_EXCLUDE_TREELITE_FROM_ALL ON)
set(CUML_EXCLUDE_CUMLPRIMS_MG_FROM_ALL ON)

# Don't install the cuML C++ targets into wheels
set(_exclude_from_all EXCLUDE_FROM_ALL)
if(NOT ${CUML_CPU})
if(NOT cuml_FOUND)
set(BUILD_CUML_TESTS OFF)
set(BUILD_PRIMS_TESTS OFF)
set(BUILD_CUML_C_LIBRARY OFF)
set(BUILD_CUML_EXAMPLES OFF)
set(BUILD_CUML_BENCH OFF)
set(BUILD_CUML_PRIMS_BENCH OFF)
set(CUML_EXPORT_TREELITE_LINKAGE ON)

set(_exclude_from_all "")
if(CUML_BUILD_WHEELS)
# Statically link dependencies if building wheels
set(CUDA_STATIC_RUNTIME 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)
# Don't install the static libs into wheels
set(CUML_EXCLUDE_RAFT_FROM_ALL ON)
set(RAFT_EXCLUDE_FAISS_FROM_ALL ON)
set(CUML_EXCLUDE_TREELITE_FROM_ALL ON)
set(CUML_EXCLUDE_CUMLPRIMS_MG_FROM_ALL ON)

# Don't install the cuML C++ targets into wheels
set(_exclude_from_all EXCLUDE_FROM_ALL)
endif()

add_subdirectory(../cpp cuml-cpp ${_exclude_from_all})

set(cython_lib_dir cuml)
install(TARGETS ${CUML_CPP_TARGET} DESTINATION ${cython_lib_dir})
endif()

add_subdirectory(../cpp cuml-cpp ${_exclude_from_all})

set(cython_lib_dir cuml)
install(TARGETS ${CUML_CPP_TARGET} DESTINATION ${cython_lib_dir})
endif()

if(CUML_CPU)
set(CUML_UNIVERSAL OFF)
set(SINGLEGPU ON)

set(CUML_ALGORITHMS "linearregression")
endif()
list(APPEND CUML_ALGORITHMS "pca")
list(APPEND CUML_ALGORITHMS "tsvd")
list(APPEND CUML_ALGORITHMS "elasticnet")
list(APPEND CUML_ALGORITHMS "logisticregression")
list(APPEND CUML_ALGORITHMS "ridge")
list(APPEND CUML_ALGORITHMS "lasso")
list(APPEND CUML_ALGORITHMS "umap")
list(APPEND CUML_ALGORITHMS "knn")
list(APPEND CUML_ALGORITHMS "hdbscan")

# this won't be needed when we add CPU libcuml++ (FIL)
set(cuml_sg_libraries "")

list(APPEND CYTHON_FLAGS
"--compile-time-env GPUBUILD=0")
else()
set(cuml_sg_libraries cuml::${CUML_CPP_TARGET})
set(cuml_mg_libraries cuml::${CUML_CPP_TARGET})

set(cuml_sg_libraries cuml::${CUML_CPP_TARGET})
set(cuml_mg_libraries cuml::${CUML_CPP_TARGET})
list(APPEND CYTHON_FLAGS
"--compile-time-env GPUBUILD=1")
endif()

if(NOT SINGLEGPU)
include("${CUML_CPP_SRC}/cmake/thirdparty/get_cumlprims_mg.cmake")
Expand All @@ -131,9 +155,21 @@ if(NOT SINGLEGPU)
)
endif()

rapids_cython_init()
################################################################################
# - Build Cython artifacts -----------------------------------------------------

include("${CUML_CPP_SRC}/cmake/modules/ConfigureAlgorithms.cmake")
include(cmake/ConfigureCythonAlgorithms.cmake)

if(${CUML_CPU})
# libcuml requires metrics built if HDSCAN is built, which is not the case
# for cuml-cpu
unset(metrics_algo)
endif()

message(VERBOSE "CUML_PY: Building cuML with algorithms: '${CUML_ALGORITHMS}'.")

include(cmake/ConfigureAlgorithmsHelpers.cmake)
rapids_cython_init()

add_subdirectory(cuml/common)
add_subdirectory(cuml/internals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@


function(add_module_gpu_default FILENAME)
set (extra_args ${ARGN})
list(LENGTH extra_args extra_count)
if (${extra_count} GREATER 0 OR
${CUML_UNIVERSAL} OR
${CUML_GPU})
list(APPEND cython_sources
${FILENAME})
set (cython_sources ${cython_sources} PARENT_SCOPE)
endif()
endfunction()


function(add_module_universal_default FILENAME)
set (extra_args ${ARGN})
list(LENGTH extra_args extra_count)
if (${extra_count} GREATER 0 OR
Expand Down
Loading

0 comments on commit 3e5c8e9

Please sign in to comment.