Skip to content

Commit

Permalink
Use CPMFindPackage to retrieve cumlprims_mg (rapidsai#4649)
Browse files Browse the repository at this point in the history
Depends on rapidsai/raft#583 and rapidsai/cumlprims_mg#86

This PR includes a few fixes to support source-only builds:

1. Use `CPMFindPackage` to get `cumlprims_mg`
  a. This enables building against a local `cumlprims_mg` build (`-D cumlprims_mg_ROOT=/cumlprims_mg/cpp/build`)
2. Explicitly call `find_package(Threads)` to be more resilient to RAFT changes

Authors:
  - Paul Taylor (https://github.com/trxcllnt)

Approvers:
  - Dante Gama Dessavre (https://github.com/dantegd)
  - Robert Maynard (https://github.com/robertmaynard)

URL: rapidsai#4649
  • Loading branch information
trxcllnt authored Mar 25, 2022
1 parent b56823b commit 8bc9fb1
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 54 deletions.
8 changes: 7 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ rapids_cuda_init_architectures(CUML)

project(CUML VERSION 22.04.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 @@ -190,6 +195,8 @@ endif()
# add third party dependencies using CPM
rapids_cpm_init()

find_package(Threads)

include(cmake/thirdparty/get_raft.cmake)

if(LINK_TREELITE)
Expand Down Expand Up @@ -491,7 +498,6 @@ if(BUILD_CUML_CPP_LIBRARY)
target_include_directories(${CUML_CPP_TARGET}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:$<$<BOOL:${ENABLE_CUMLPRIMS_MG}>:${cumlprims_mg_INCLUDE_DIRS}>>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/metrics>
Expand Down
45 changes: 35 additions & 10 deletions cpp/cmake/thirdparty/get_cumlprims_mg.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -14,20 +14,45 @@
# limitations under the License.
#=============================================================================

set(CUML_MIN_VERSION_cumlprims_mg "${CUML_VERSION_MAJOR}.${CUML_VERSION_MINOR}.00")
set(CUML_BRANCH_VERSION_cumlprims_mg "${CUML_VERSION_MAJOR}.${CUML_VERSION_MINOR}")

function(find_and_configure_cumlprims_mg)

if(TARGET cumlprims_mg::cumlprims_mg)
return()
set(oneValueArgs VERSION FORK PINNED_TAG 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)
endif()

rapids_find_generate_module(cumlprims_mg
HEADER_NAMES cumlprims.hpp
LIBRARY_NAMES cumlprims
INCLUDE_SUFFIXES cumlprims
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 [email protected]:${PKG_FORK}/cumlprims_mg.git
GIT_TAG ${PKG_PINNED_TAG}
)

rapids_find_package(cumlprims_mg REQUIRED)

endfunction()

find_and_configure_cumlprims_mg()
###
# Change pinned tag and fork here to test a commit in CI
#
# To use a locally-built cumlprims_mg package, set the CMake variable
# `-D cumlprims_mg_ROOT=/path/to/cumlprims_mg/build`
#
# To use a local clone of cumlprims_mg source and allow CMake to build
# 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}
FORK rapidsai
PINNED_TAG branch-${CUML_BRANCH_VERSION_cumlprims_mg}
# When PINNED_TAG above doesn't match cuml,
# force local cumlprims_mg clone in build directory
# even if it's already installed.
CLONE_ON_PIN ON
)
4 changes: 2 additions & 2 deletions cpp/include/cuml/decomposition/pca_mg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#pragma once

#include <opg/matrix/data.hpp>
#include <opg/matrix/part_descriptor.hpp>
#include <cumlprims/opg/matrix/data.hpp>
#include <cumlprims/opg/matrix/part_descriptor.hpp>

#include "pca.hpp"

Expand Down
6 changes: 3 additions & 3 deletions cpp/include/cuml/decomposition/sign_flip_mg.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
* Copyright (c) 2020-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.
Expand All @@ -16,8 +16,8 @@

#pragma once

#include <opg/matrix/data.hpp>
#include <opg/matrix/part_descriptor.hpp>
#include <cumlprims/opg/matrix/data.hpp>
#include <cumlprims/opg/matrix/part_descriptor.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/cuml/decomposition/tsvd_mg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#pragma once

#include <opg/matrix/data.hpp>
#include <opg/matrix/part_descriptor.hpp>
#include <cumlprims/opg/matrix/data.hpp>
#include <cumlprims/opg/matrix/part_descriptor.hpp>

#include "tsvd.hpp"

Expand Down
6 changes: 3 additions & 3 deletions cpp/include/cuml/linear_model/ols_mg.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
* Copyright (c) 2020-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.
Expand All @@ -17,8 +17,8 @@
#pragma once

#include <cuml/linear_model/glm.hpp>
#include <opg/matrix/data.hpp>
#include <opg/matrix/part_descriptor.hpp>
#include <cumlprims/opg/matrix/data.hpp>
#include <cumlprims/opg/matrix/part_descriptor.hpp>

namespace ML {
namespace OLS {
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/cuml/linear_model/preprocess_mg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#pragma once

#include <opg/matrix/data.hpp>
#include <opg/matrix/part_descriptor.hpp>
#include <cumlprims/opg/matrix/data.hpp>
#include <cumlprims/opg/matrix/part_descriptor.hpp>
#include <raft/comms/comms.hpp>
#include <raft/handle.hpp>

Expand Down
4 changes: 2 additions & 2 deletions cpp/include/cuml/linear_model/ridge_mg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#pragma once

#include <opg/matrix/data.hpp>
#include <opg/matrix/part_descriptor.hpp>
#include <cumlprims/opg/matrix/data.hpp>
#include <cumlprims/opg/matrix/part_descriptor.hpp>

#include "glm.hpp"

Expand Down
6 changes: 3 additions & 3 deletions cpp/include/cuml/neighbors/knn_mg.hpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,8 +19,8 @@
#include <raft/handle.hpp>
#include <vector>

#include <opg/matrix/data.hpp>
#include <opg/matrix/part_descriptor.hpp>
#include <cumlprims/opg/matrix/data.hpp>
#include <cumlprims/opg/matrix/part_descriptor.hpp>

namespace ML {
namespace KNN {
Expand Down
6 changes: 3 additions & 3 deletions cpp/include/cuml/solvers/cd_mg.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
* Copyright (c) 2020-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.
Expand All @@ -17,8 +17,8 @@
#pragma once

#include <cuml/linear_model/glm.hpp>
#include <opg/matrix/data.hpp>
#include <opg/matrix/part_descriptor.hpp>
#include <cumlprims/opg/matrix/data.hpp>
#include <cumlprims/opg/matrix/part_descriptor.hpp>

namespace ML {
namespace CD {
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/glm/ols_mg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <cuml/linear_model/ols_mg.hpp>
#include <cuml/linear_model/preprocess_mg.hpp>

#include <opg/linalg/lstsq.hpp>
#include <opg/stats/mean.hpp>
#include <cumlprims/opg/linalg/lstsq.hpp>
#include <cumlprims/opg/stats/mean.hpp>

#include <raft/comms/comms.hpp>
#include <raft/cuda_utils.cuh>
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/glm/preprocess_mg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

#include <cuml/linear_model/preprocess_mg.hpp>

#include <opg/linalg/norm.hpp>
#include <opg/matrix/math.hpp>
#include <opg/stats/mean.hpp>
#include <opg/stats/mean_center.hpp>
#include <cumlprims/opg/linalg/norm.hpp>
#include <cumlprims/opg/matrix/math.hpp>
#include <cumlprims/opg/stats/mean.hpp>
#include <cumlprims/opg/stats/mean_center.hpp>
#include <raft/comms/comms.hpp>
#include <raft/cuda_utils.cuh>
#include <raft/cudart_utils.h>
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/glm/ridge_mg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include <cuml/linear_model/preprocess_mg.hpp>
#include <cuml/linear_model/ridge_mg.hpp>

#include <opg/linalg/mv_aTb.hpp>
#include <opg/linalg/svd.hpp>
#include <opg/stats/mean.hpp>
#include <cumlprims/opg/linalg/mv_aTb.hpp>
#include <cumlprims/opg/linalg/svd.hpp>
#include <cumlprims/opg/stats/mean.hpp>

#include <raft/comms/comms.hpp>
#include <raft/cuda_utils.cuh>
Expand Down
10 changes: 5 additions & 5 deletions cpp/src/pca/pca_mg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include <cuml/decomposition/pca_mg.hpp>
#include <cuml/decomposition/sign_flip_mg.hpp>

#include <opg/linalg/qr_based_svd.hpp>
#include <opg/matrix/matrix_utils.hpp>
#include <opg/stats/cov.hpp>
#include <opg/stats/mean.hpp>
#include <opg/stats/mean_center.hpp>
#include <cumlprims/opg/linalg/qr_based_svd.hpp>
#include <cumlprims/opg/matrix/matrix_utils.hpp>
#include <cumlprims/opg/stats/cov.hpp>
#include <cumlprims/opg/stats/mean.hpp>
#include <cumlprims/opg/stats/mean_center.hpp>

#include <raft/comms/comms.hpp>
#include <raft/cuda_utils.cuh>
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/solver/cd_mg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#include <functions/softThres.cuh>

#include <opg/linalg/mv_aTb.hpp>
#include <opg/linalg/norm.hpp>
#include <cumlprims/opg/linalg/mv_aTb.hpp>
#include <cumlprims/opg/linalg/norm.hpp>

#include "shuffle.h"
#include <raft/comms/comms.hpp>
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/tsvd/tsvd_mg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include <cuml/decomposition/tsvd.hpp>
#include <cuml/decomposition/tsvd_mg.hpp>

#include <opg/linalg/mm_aTa.hpp>
#include <opg/stats/mean.hpp>
#include <opg/stats/mean_center.hpp>
#include <opg/stats/stddev.hpp>
#include <cumlprims/opg/linalg/mm_aTa.hpp>
#include <cumlprims/opg/stats/mean.hpp>
#include <cumlprims/opg/stats/mean_center.hpp>
#include <cumlprims/opg/stats/stddev.hpp>

#include <raft/comms/comms.hpp>
#include <raft/cuda_utils.cuh>
Expand Down
4 changes: 2 additions & 2 deletions cpp/test/mg/pca.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include "test_opg_utils.h"
#include <cuml/common/logger.hpp>
#include <cuml/decomposition/pca_mg.hpp>
#include <cumlprims/opg/linalg/gemm.hpp>
#include <cumlprims/opg/matrix/matrix_utils.hpp>
#include <gtest/gtest.h>
#include <opg/linalg/gemm.hpp>
#include <opg/matrix/matrix_utils.hpp>
#include <raft/cuda_utils.cuh>
#include <raft/cudart_utils.h>
#include <raft/matrix/matrix.hpp>
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def finalize_options(self):
if (self.singlegpu):
python_exc_list = ["*.dask", "*.dask.*"]
else:
libs.append('cumlprims')
libs.append('cumlprims_mg')
libs.append('nccl')

sys_include = os.path.dirname(sysconfig.get_path("include"))
Expand Down

0 comments on commit 8bc9fb1

Please sign in to comment.