From 46532938434e65604bd481601890152c169e0100 Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Sat, 22 Jan 2022 19:04:11 -0800 Subject: [PATCH] Add option to build faiss and treelite shared libs, inherit common dependencies from raft (#4256) Depends on https://github.com/rapidsai/raft/pull/345, and CI will be blocked until `raft` is removed from `libcumlprims` install export set. Authors: - Paul Taylor (https://github.com/trxcllnt) - Divye Gala (https://github.com/divyegala) - Ashwin Srinath (https://github.com/shwina) - Corey J. Nolet (https://github.com/cjnolet) Approvers: - Corey J. Nolet (https://github.com/cjnolet) URL: https://github.com/rapidsai/cuml/pull/4256 --- build.sh | 59 ++++++++++-------- cpp/CMakeLists.txt | 65 ++++++++++---------- cpp/bench/CMakeLists.txt | 19 +++--- cpp/cmake/thirdparty/get_faiss.cmake | 53 ---------------- cpp/cmake/thirdparty/get_gtest.cmake | 2 +- cpp/cmake/thirdparty/get_raft.cmake | 28 +++++---- cpp/cmake/thirdparty/get_rmm.cmake | 26 -------- cpp/cmake/thirdparty/get_spdlog.cmake | 24 -------- cpp/cmake/thirdparty/get_thrust.cmake | 28 --------- cpp/cmake/thirdparty/get_treelite.cmake | 82 ++++++++++++++++++------- cpp/cmake/versions.json | 9 +++ cpp/test/CMakeLists.txt | 21 +++---- 12 files changed, 169 insertions(+), 247 deletions(-) delete mode 100644 cpp/cmake/thirdparty/get_faiss.cmake delete mode 100644 cpp/cmake/thirdparty/get_rmm.cmake delete mode 100644 cpp/cmake/thirdparty/get_spdlog.cmake delete mode 100644 cpp/cmake/thirdparty/get_thrust.cmake create mode 100644 cpp/cmake/versions.json diff --git a/build.sh b/build.sh index fb077e50ec..04448481c1 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # cuml build script @@ -23,30 +23,32 @@ VALIDFLAGS="-v -g -n --allgpuarch --singlegpu --nolibcumltest --nvtx --show_depr VALIDARGS="${VALIDTARGETS} ${VALIDFLAGS}" HELP="$0 [ ...] [ ...] where is: - clean - remove all existing build artifacts and configuration (start over) - libcuml - build the cuml C++ code only. Also builds the C-wrapper library - around the C++ code. - cuml - build the cuml 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 - prims-bench - build the ml-prims C++ benchmark - cppdocs - build the C++ API doxygen documentation - pydocs - build the general and Python API documentation + clean - remove all existing build artifacts and configuration (start over) + libcuml - build the cuml C++ code only. Also builds the C-wrapper library + around the C++ code. + cuml - build the cuml 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 + prims-bench - build the ml-prims C++ benchmark + cppdocs - build the C++ API doxygen documentation + pydocs - build the general and Python API documentation and is: - -v - verbose build mode - -g - build for debug - -n - no install step - -h - print this text - --allgpuarch - build for all supported GPU architectures - --singlegpu - Build libcuml and cuml without multigpu components - --nolibcumltest - disable building libcuml C++ tests for a faster build - --nvtx - Enable nvtx for profiling support - --show_depr_warn - show cmake deprecation warnings - --codecov - Enable code coverage support by compiling with Cython linetracing - and profiling enabled (WARNING: Impacts performance) - --ccache - Use ccache to cache previous compilations - --nocloneraft - CMake will clone RAFT even if it is in the environment, use this flag to disable that behavior + -v - verbose build mode + -g - build for debug + -n - no install step + -h - print this text + --allgpuarch - build for all supported GPU architectures + --singlegpu - Build libcuml and cuml without multigpu components + --nolibcumltest - disable building libcuml C++ tests for a faster build + --nvtx - Enable nvtx for profiling support + --show_depr_warn - show cmake deprecation warnings + --codecov - Enable code coverage support by compiling with Cython linetracing + and profiling enabled (WARNING: Impacts performance) + --ccache - Use ccache to cache previous compilations + --nocloneraft - CMake will clone RAFT even if it is in the environment, use this flag to disable that behavior + --static-faiss - Force CMake to use the FAISS static libs, cloning and building them if necessary + --static-treelite - Force CMake to use the Treelite static libs, cloning and building them if necessary default action (no args) is to build and install 'libcuml', 'cuml', and 'prims' targets only for the detected GPU arch @@ -77,6 +79,7 @@ BUILD_CUML_STD_COMMS=ON BUILD_CUML_TESTS=ON BUILD_CUML_MG_TESTS=OFF BUILD_STATIC_FAISS=OFF +BUILD_STATIC_TREELITE=OFF CMAKE_LOG_LEVEL=WARNING DISABLE_FORCE_CLONE_RAFT=OFF @@ -194,6 +197,12 @@ while true; do --nocloneraft ) DISABLE_FORCE_CLONE_RAFT=ON ;; + --static-faiss ) + BUILD_STATIC_FAISS=ON + ;; + --static-treelite ) + BUILD_STATIC_TREELITE=ON + ;; --) shift break @@ -245,6 +254,8 @@ if completeBuild || hasArg libcuml || hasArg prims || hasArg bench || hasArg pri -DBUILD_CUML_TESTS=${BUILD_CUML_TESTS} \ -DBUILD_CUML_MPI_COMMS=${BUILD_CUML_MG_TESTS} \ -DBUILD_CUML_MG_TESTS=${BUILD_CUML_MG_TESTS} \ + -DCUML_USE_FAISS_STATIC=${BUILD_STATIC_FAISS} \ + -DCUML_USE_TREELITE_STATIC=${BUILD_STATIC_TREELITE} \ -DDISABLE_FORCE_CLONE_RAFT=${DISABLE_FORCE_CLONE_RAFT} \ -DNVTX=${NVTX} \ -DUSE_CCACHE=${CCACHE} \ diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index ac7e3becf3..3248385a85 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -57,12 +57,13 @@ option(CUDA_ENABLE_KERNEL_INFO "Enable kernel resource usage info" OFF) option(CUDA_ENABLE_LINE_INFO "Enable lineinfo in nvcc" OFF) option(DETECT_CONDA_ENV "Enable detection of conda environment for dependencies" ON) option(DISABLE_DEPRECATION_WARNINGS "Disable depreaction warnings " ON) -option(DISABLE_FORCE_CLONE_RAFT "By default, CPM will clone RAFT even if it's already in the environment. Set to disable that behavior." OFF) option(DISABLE_OPENMP "Disable OpenMP" OFF) option(ENABLE_CUMLPRIMS_MG "Enable algorithms that use libcumlprims_mg" ON) option(NVTX "Enable nvtx markers" OFF) option(SINGLEGPU "Disable all mnmg components and comms libraries" OFF) option(USE_CCACHE "Cache build artifacts with ccache" 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) set(CUML_CPP_ALGORITHMS "ALL" CACHE STRING "Experimental: Choose which algorithms are built into libcuml++.so. Only 'FIL' and 'ALL' are supported right now.") set_property(CACHE CUML_CPP_ALGORITHMS PROPERTY STRINGS "ALL" "FIL") @@ -153,12 +154,12 @@ if(NOT BUILD_CUML_CPP_LIBRARY) endif() if(CUML_CPP_ALGORITHMS STREQUAL "ALL") - set(LINK_FAISS ON) + set(CUML_USE_RAFT_NN ON) elseif(CUML_CPP_ALGORITHMS STREQUAL "FIL") set(SINGLEGPU ON) set(BUILD_CUML_C_LIBRARY OFF) set(BUILD_CUML_EXAMPLES OFF) - set(LINK_FAISS OFF) + set(CUML_USE_RAFT_NN OFF) endif() # SingleGPU build disables cumlprims_mg and comms components @@ -189,16 +190,9 @@ endif() # add third party dependencies using CPM rapids_cpm_init() -include(cmake/thirdparty/get_thrust.cmake) -include(cmake/thirdparty/get_rmm.cmake) - -if(LINK_FAISS) - include(cmake/thirdparty/get_faiss.cmake) -endif() - +include(cmake/thirdparty/get_raft.cmake) include(cmake/thirdparty/get_treelite.cmake) include(cmake/thirdparty/get_gputreeshap.cmake) -include(cmake/thirdparty/get_raft.cmake) if(NOT SINGLEGPU) include(cmake/thirdparty/get_nccl.cmake) @@ -213,7 +207,7 @@ if(BUILD_CUML_TESTS OR BUILD_PRIMS_TESTS) include(cmake/thirdparty/get_gtest.cmake) endif() -if(BUILD_CUML_BENCH) +if(BUILD_CUML_BENCH OR BUILD_CUML_PRIMS_BENCH) include(cmake/thirdparty/get_gbench.cmake) endif() @@ -388,22 +382,13 @@ if(BUILD_CUML_CPP_LIBRARY) target_link_libraries(${CUML_CPP_TARGET} PUBLIC - rmm::rmm - cuml::Thrust raft::raft - raft::raft_nn - raft::raft_distance + raft::nn + raft::distance PRIVATE - CUDA::cublas CUDA::cufft - CUDA::curand - CUDA::cusolver - CUDA::cudart - CUDA::cusparse + ${TREELITE_LIBS} GPUTreeShap::GPUTreeShap - $<$:FAISS::FAISS> - $,treelite::treelite_static,treelite::treelite> - $,treelite::treelite_runtime_static,treelite::treelite_runtime> $<$:OpenMP::OpenMP_CXX> $<$,$>:NCCL::NCCL> $<$:${MPI_CXX_LIBRARIES}> @@ -448,8 +433,6 @@ if(BUILD_CUML_C_LIBRARY) target_link_libraries(${CUML_C_TARGET} PUBLIC ${CUML_CPP_TARGET} - PRIVATE - FAISS::FAISS ) # ensure CUDA symbols aren't relocated to the middle of the debug build binaries @@ -508,14 +491,34 @@ functions that share compatible APIs with other RAPIDS projects. ]=]) -set(code_string +set(code_string ) + +if (TARGET treelite::treelite) + string(APPEND code_string [=[ -thrust_create_target(cuml::Thrust FROM_OPTIONS) +if (TARGET treelite::treelite AND (NOT TARGET treelite)) + add_library(treelite ALIAS treelite::treelite) +endif() +if (TARGET treelite::treelite_runtime AND (NOT TARGET treelite_runtime)) + add_library(treelite_runtime ALIAS treelite::treelite_runtime) +endif() +]=]) +else() + string(APPEND code_string +[=[ +if (TARGET treelite::treelite_static AND (NOT TARGET treelite_static)) + add_library(treelite_static ALIAS treelite::treelite_static) +endif() +if (TARGET treelite::treelite_runtime_static AND (NOT TARGET treelite_runtime_static)) + add_library(treelite_runtime_static ALIAS treelite::treelite_runtime_static) +endif() ]=]) - rapids_export(INSTALL cuml +endif() + +rapids_export(INSTALL cuml EXPORT_SET cuml-exports - GLOBAL_TARGETS cuml + GLOBAL_TARGETS ${CUML_C_TARGET} ${CUML_CPP_TARGET} NAMESPACE cuml:: DOCUMENTATION doc_string FINAL_CODE_BLOCK code_string @@ -526,7 +529,7 @@ thrust_create_target(cuml::Thrust FROM_OPTIONS) rapids_export(BUILD cuml EXPORT_SET cuml-exports - GLOBAL_TARGETS cuml + GLOBAL_TARGETS ${CUML_C_TARGET} ${CUML_CPP_TARGET} NAMESPACE cuml:: DOCUMENTATION doc_string FINAL_CODE_BLOCK code_string diff --git a/cpp/bench/CMakeLists.txt b/cpp/bench/CMakeLists.txt index 5e7afa7a14..6cb2b3a26c 100644 --- a/cpp/bench/CMakeLists.txt +++ b/cpp/bench/CMakeLists.txt @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -44,11 +44,10 @@ if(BUILD_CUML_BENCH) PUBLIC cuml::${CUML_CPP_TARGET} benchmark::benchmark + ${TREELITE_LIBS} raft::raft - raft::raft_nn - raft::raft_distance - $,treelite::treelite_static,treelite::treelite> - $,treelite::treelite_runtime_static,treelite::treelite_runtime> + raft::nn + raft::distance ) target_include_directories(${CUML_CPP_BENCH_TARGET} @@ -85,14 +84,12 @@ if(BUILD_CUML_PRIMS_BENCH) target_link_libraries(${PRIMS_BENCH_TARGET} PUBLIC - cuml - CUDA::cublas + cuml::${CUML_CPP_TARGET} benchmark::benchmark + ${TREELITE_LIBS} raft::raft - raft::raft_nn - raft::raft_distance - $,treelite::treelite_static,treelite::treelite> - $,treelite::treelite_runtime_static,treelite::treelite_runtime> + raft::nn + raft::distance ) target_include_directories(${PRIMS_BENCH_TARGET} diff --git a/cpp/cmake/thirdparty/get_faiss.cmake b/cpp/cmake/thirdparty/get_faiss.cmake deleted file mode 100644 index 8a88f9694e..0000000000 --- a/cpp/cmake/thirdparty/get_faiss.cmake +++ /dev/null @@ -1,53 +0,0 @@ -#============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#============================================================================= - -function(find_and_configure_faiss) - set(oneValueArgs VERSION PINNED_TAG) - cmake_parse_arguments(PKG "${options}" "${oneValueArgs}" - "${multiValueArgs}" ${ARGN} ) - - rapids_find_generate_module(FAISS - HEADER_NAMES faiss/IndexFlat.h - LIBRARY_NAMES faiss - ) - - rapids_cpm_find(FAISS ${PKG_VERSION} - GLOBAL_TARGETS faiss - CPM_ARGS - GIT_REPOSITORY https://github.com/facebookresearch/faiss.git - GIT_TAG ${PKG_PINNED_TAG} - OPTIONS - "FAISS_ENABLE_PYTHON OFF" - "BUILD_SHARED_LIBS OFF" - "CUDAToolkit_ROOT ${CUDAToolkit_LIBRARY_DIR}" - "FAISS_ENABLE_GPU ON" - "BUILD_TESTING OFF" - "CMAKE_MESSAGE_LOG_LEVEL VERBOSE" - ) - - if(FAISS_ADDED) - target_include_directories(faiss INTERFACE $) - endif() - - if(TARGET faiss AND NOT TARGET FAISS::FAISS) - add_library(FAISS::FAISS ALIAS faiss) - endif() - -endfunction() - -find_and_configure_faiss(VERSION 1.7.0 - PINNED_TAG bde7c0027191f29c9dadafe4f6e68ca0ee31fb30 - ) diff --git a/cpp/cmake/thirdparty/get_gtest.cmake b/cpp/cmake/thirdparty/get_gtest.cmake index d72769ff33..cdc2c5d889 100644 --- a/cpp/cmake/thirdparty/get_gtest.cmake +++ b/cpp/cmake/thirdparty/get_gtest.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2022, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/cpp/cmake/thirdparty/get_raft.cmake b/cpp/cmake/thirdparty/get_raft.cmake index c7282899ef..f3815d2b51 100644 --- a/cpp/cmake/thirdparty/get_raft.cmake +++ b/cpp/cmake/thirdparty/get_raft.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2022, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,15 +16,17 @@ function(find_and_configure_raft) - set(oneValueArgs VERSION FORK PINNED_TAG) + set(oneValueArgs VERSION FORK PINNED_TAG USE_RAFT_NN USE_FAISS_STATIC) cmake_parse_arguments(PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - if(DEFINED CPM_raft_SOURCE OR NOT DISABLE_FORCE_CLONE_RAFT) - set(CPM_DL_ALL_CACHE ${CPM_DOWNLOAD_ALL}) - set(CPM_DOWNLOAD_ALL ON) + string(APPEND RAFT_COMPONENTS "distance") + if(PKG_USE_RAFT_NN) + string(APPEND RAFT_COMPONENTS " nn") endif() + message("CUML: raft FIND_PACKAGE_ARGUMENTS COMPONENTS ${RAFT_COMPONENTS}") + rapids_cpm_find(raft ${PKG_VERSION} GLOBAL_TARGETS raft::raft BUILD_EXPORT_SET cuml-exports @@ -33,8 +35,10 @@ function(find_and_configure_raft) GIT_REPOSITORY https://github.com/${PKG_FORK}/raft.git GIT_TAG ${PKG_PINNED_TAG} SOURCE_SUBDIR cpp + FIND_PACKAGE_ARGUMENTS "COMPONENTS ${RAFT_COMPONENTS}" OPTIONS "BUILD_TESTS OFF" + "RAFT_USE_FAISS_STATIC ${PKG_USE_FAISS_STATIC}" "NVTX ${NVTX}" ) @@ -44,10 +48,6 @@ function(find_and_configure_raft) message(VERBOSE "CUML: Using RAFT located in ${raft_DIR}") endif() - if(DEFINED CPM_raft_SOURCE OR NOT DISABLE_FORCE_CLONE_RAFT) - set(CPM_DOWNLOAD_ALL ${CPM_DL_ALL_CACHE}) - endif() - endfunction() set(CUML_MIN_VERSION_raft "${CUML_VERSION_MAJOR}.${CUML_VERSION_MINOR}.00") @@ -57,6 +57,10 @@ set(CUML_BRANCH_VERSION_raft "${CUML_VERSION_MAJOR}.${CUML_VERSION_MINOR}") # To use a different RAFT locally, set the CMake variable # CPM_raft_SOURCE=/path/to/local/raft find_and_configure_raft(VERSION ${CUML_MIN_VERSION_raft} - FORK rapidsai - PINNED_TAG branch-${CUML_BRANCH_VERSION_raft} - ) + # FORK rapidsai + # PINNED_TAG branch-${CUML_BRANCH_VERSION_raft} + FORK robertmaynard + PINNED_TAG refactor_cmake_raft_target_logic + USE_RAFT_NN ${CUML_USE_RAFT_NN} + USE_FAISS_STATIC ${CUML_USE_FAISS_STATIC} + ) diff --git a/cpp/cmake/thirdparty/get_rmm.cmake b/cpp/cmake/thirdparty/get_rmm.cmake deleted file mode 100644 index 325a5b8010..0000000000 --- a/cpp/cmake/thirdparty/get_rmm.cmake +++ /dev/null @@ -1,26 +0,0 @@ -#============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#============================================================================= - -function(find_and_configure_rmm) - - include(${rapids-cmake-dir}/cpm/rmm.cmake) - rapids_cpm_rmm( - BUILD_EXPORT_SET cuml-exports - INSTALL_EXPORT_SET cuml-exports - ) - -endfunction() -find_and_configure_rmm() diff --git a/cpp/cmake/thirdparty/get_spdlog.cmake b/cpp/cmake/thirdparty/get_spdlog.cmake deleted file mode 100644 index bb0fe45dc9..0000000000 --- a/cpp/cmake/thirdparty/get_spdlog.cmake +++ /dev/null @@ -1,24 +0,0 @@ -#============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#============================================================================= - -function(find_and_configure_spdlog) - - include(${rapids-cmake-dir}/cpm/spdlog.cmake) - rapids_cpm_spdlog() - -endfunction() - -find_and_configure_spdlog() diff --git a/cpp/cmake/thirdparty/get_thrust.cmake b/cpp/cmake/thirdparty/get_thrust.cmake deleted file mode 100644 index de56eb93d3..0000000000 --- a/cpp/cmake/thirdparty/get_thrust.cmake +++ /dev/null @@ -1,28 +0,0 @@ -#============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#============================================================================= - -function(find_and_configure_thrust) - include(${rapids-cmake-dir}/cpm/thrust.cmake) - - rapids_cpm_thrust( - NAMESPACE cuml - BUILD_EXPORT_SET cuml-exports - INSTALL_EXPORT_SET cuml-exports - ) - -endfunction() - -find_and_configure_thrust() diff --git a/cpp/cmake/thirdparty/get_treelite.cmake b/cpp/cmake/thirdparty/get_treelite.cmake index 171706ea20..f3d7d7068f 100644 --- a/cpp/cmake/thirdparty/get_treelite.cmake +++ b/cpp/cmake/thirdparty/get_treelite.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2022, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,43 +16,79 @@ function(find_and_configure_treelite) - set(oneValueArgs VERSION PINNED_TAG) + set(oneValueArgs VERSION PINNED_TAG BUILD_STATIC_LIBS) cmake_parse_arguments(PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + if(NOT BUILD_STATIC_LIBS) + list(APPEND TREELITE_LIBS treelite::treelite treelite::treelite_runtime) + else() + list(APPEND TREELITE_LIBS treelite::treelite_static treelite::treelite_runtime_static) + endif() + rapids_cpm_find(Treelite ${PKG_VERSION} - GLOBAL_TARGETS treelite::treelite treelite + GLOBAL_TARGETS ${TREELITE_LIBS} + INSTALL_EXPORT_SET cuml-exports CPM_ARGS - GIT_REPOSITORY https://github.com/dmlc/treelite.git - GIT_TAG ${PKG_PINNED_TAG} + GIT_REPOSITORY https://github.com/dmlc/treelite.git + GIT_TAG ${PKG_PINNED_TAG} OPTIONS "USE_OPENMP ON" - "BUILD_STATIC_LIBS ON" + "BUILD_STATIC_LIBS ${BUILD_STATIC_LIBS}" ) + + list(APPEND TREELITE_LIBS_NO_PREFIX treelite treelite_runtime) + if(Treelite_ADDED AND BUILD_STATIC_LIBS) + list(APPEND TREELITE_LIBS_NO_PREFIX treelite_static treelite_runtime_static) + endif() + set(Treelite_ADDED ${Treelite_ADDED} PARENT_SCOPE) + set(TREELITE_LIBS ${TREELITE_LIBS} PARENT_SCOPE) if(Treelite_ADDED) - target_include_directories(treelite - PUBLIC $ - $) - target_include_directories(treelite_static - PUBLIC $ - $) - target_include_directories(treelite_runtime - PUBLIC $ - $) - target_include_directories(treelite_runtime_static - PUBLIC $ - $) - - if(NOT TARGET treelite::treelite_static) - add_library(treelite::treelite_static ALIAS treelite_static) - add_library(treelite::treelite_runtime_static ALIAS treelite_runtime_static) + if (NOT BUILD_STATIC_LIBS) + target_include_directories(treelite + PUBLIC $ + $) + target_include_directories(treelite_runtime + PUBLIC $ + $) + if(NOT TARGET treelite::treelite) + add_library(treelite::treelite ALIAS treelite) + endif() + if(NOT TARGET treelite::treelite_runtime) + add_library(treelite::treelite_runtime ALIAS treelite_runtime) + endif() + else() + target_include_directories(treelite_static + PUBLIC $ + $) + target_include_directories(treelite_runtime_static + PUBLIC $ + $) + if(NOT TARGET treelite::treelite_static) + add_library(treelite::treelite_static ALIAS treelite_static) + endif() + if(NOT TARGET treelite::treelite_runtime_static) + add_library(treelite::treelite_runtime_static ALIAS treelite_runtime_static) + endif() endif() + + rapids_export(BUILD Treelite + EXPORT_SET TreeliteTargets + GLOBAL_TARGETS ${TREELITE_LIBS_NO_PREFIX} + NAMESPACE treelite::) endif() + # We generate the treelite-config files when we built treelite locally, so always do `find_dependency` + rapids_export_package(BUILD Treelite cuml-exports) + + # Tell cmake where it can find the generated treelite-config.cmake we wrote. + include("${rapids-cmake-dir}/export/find_package_root.cmake") + rapids_export_find_package_root(BUILD Treelite [=[${CMAKE_CURRENT_LIST_DIR}]=] cuml-exports) endfunction() find_and_configure_treelite(VERSION 2.1.0 - PINNED_TAG e5248931c62e3807248e0b150e27b2530a510634) + PINNED_TAG e5248931c62e3807248e0b150e27b2530a510634 + BUILD_STATIC_LIBS ${CUML_USE_TREELITE_STATIC}) diff --git a/cpp/cmake/versions.json b/cpp/cmake/versions.json new file mode 100644 index 0000000000..cca2dd8859 --- /dev/null +++ b/cpp/cmake/versions.json @@ -0,0 +1,9 @@ +{ + "packages" : { + "Thrust" : { + "version" : "1.15.0", + "git_url" : "https://github.com/NVIDIA/thrust.git", + "git_tag" : "${version}" + } + } +} diff --git a/cpp/test/CMakeLists.txt b/cpp/test/CMakeLists.txt index 74f683948e..2b900e4f5d 100644 --- a/cpp/test/CMakeLists.txt +++ b/cpp/test/CMakeLists.txt @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2018-2021, NVIDIA CORPORATION. +# Copyright (c) 2018-2022, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,23 +15,16 @@ #============================================================================= set(COMMON_TEST_LINK_LIBRARIES - CUDA::cublas - CUDA::curand - CUDA::cusolver - CUDA::cudart - CUDA::cusparse CUDA::cufft rmm::rmm raft::raft - raft::raft_nn - raft::raft_distance - $<$:FAISS::FAISS> + raft::nn + raft::distance GTest::gtest GTest::gtest_main OpenMP::OpenMP_CXX Threads::Threads - $,treelite::treelite_static,treelite::treelite> - $,treelite::treelite_runtime_static,treelite::treelite_runtime> + ${TREELITE_LIBS} $ ) @@ -98,7 +91,7 @@ if(BUILD_CUML_TESTS) target_link_libraries(${CUML_CPP_TEST_TARGET} PRIVATE - ${CUML_CPP_TARGET} + cuml::${CUML_CPP_TARGET} $<$:${CUML_C_TARGET}> ${COMMON_TEST_LINK_LIBRARIES} ) @@ -133,7 +126,7 @@ if(BUILD_CUML_MG_TESTS) ) target_link_libraries(${CUML_MG_TEST_TARGET} - ${CUML_CPP_TARGET} + cuml::${CUML_CPP_TARGET} ${COMMON_TEST_LINK_LIBRARIES} NCCL::NCCL ${MPI_CXX_LIBRARIES} @@ -225,7 +218,7 @@ if(BUILD_PRIMS_TESTS) target_link_libraries(${PRIMS_TEST_TARGET} PRIVATE - ${CUML_CPP_TARGET} + cuml::${CUML_CPP_TARGET} ${COMMON_TEST_LINK_LIBRARIES} )