Skip to content

Commit

Permalink
Enable building static libs (rapidsai#4673)
Browse files Browse the repository at this point in the history
This PR allows building libcuml++ static libs via CMake option `-DBUILD_SHARED_LIBS=ON|OFF`.

~I was seeing a linker error due to not having `-fPIC` enabled, but I wouldn't have expected this to affect static libs. I'll investigate some more and turn it off if possible, but for now `-fPIC` is enabled.~

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

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

URL: rapidsai#4673
  • Loading branch information
trxcllnt authored May 10, 2022
1 parent 3060322 commit 61524d7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
11 changes: 9 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
##############################################################################
# - User Options ------------------------------------------------------------

option(BUILD_SHARED_LIBS "Build cuML shared libraries" ON)
option(BUILD_CUML_C_LIBRARY "Build libcuml_c shared library. Contains the cuML C API" ON)
option(BUILD_CUML_CPP_LIBRARY "Build libcuml shared library" ON)
option(BUILD_CUML_TESTS "Build cuML algorithm tests" ON)
Expand Down Expand Up @@ -205,6 +206,11 @@ endif()

if(all_algo OR treeshap_algo)
include(cmake/thirdparty/get_gputreeshap.cmake)
# Workaround until https://github.com/rapidsai/rapids-cmake/issues/176 is resolved
if(NOT BUILD_SHARED_LIBS)
rapids_export_package(BUILD GPUTreeShap cuml-exports)
rapids_export_package(INSTALL GPUTreeShap cuml-exports)
endif()
endif()

if(NOT SINGLEGPU)
Expand Down Expand Up @@ -242,7 +248,7 @@ if(BUILD_CUML_CPP_LIBRARY)

# single GPU components
# common components
add_library(${CUML_CPP_TARGET} SHARED
add_library(${CUML_CPP_TARGET}
src/common/logger.cpp)

if(all_algo OR arima_algo)
Expand Down Expand Up @@ -480,6 +486,7 @@ if(BUILD_CUML_CPP_LIBRARY)
CXX_STANDARD_REQUIRED ON
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
)

Expand Down Expand Up @@ -537,7 +544,7 @@ endif()
# - build libcuml C shared library -------------------------------------------

if(BUILD_CUML_C_LIBRARY)
add_library(${CUML_C_TARGET} SHARED
add_library(${CUML_C_TARGET}
src/common/cumlHandle.cpp
src/common/cuml_api.cpp
src/dbscan/dbscan_api.cpp
Expand Down
39 changes: 38 additions & 1 deletion cpp/cmake/thirdparty/get_gputreeshap.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 Down Expand Up @@ -27,6 +27,43 @@ function(find_and_configure_gputreeshap)
GIT_TAG ${PKG_PINNED_TAG}
)

if (GPUTreeShap_ADDED)
include(GNUInstallDirs)
install(TARGETS GPUTreeShap
EXPORT gputreeshap-exports)

# clear out incorrect INTERFACE_SOURCES
set_target_properties(GPUTreeShap PROPERTIES INTERFACE_SOURCES "")
get_target_property(all_includes GPUTreeShap INTERFACE_INCLUDE_DIRECTORIES)
# clear out incorrect INTERFACE_INCLUDE_DIRECTORIES
set_target_properties(GPUTreeShap PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
# set INTERFACE_INCLUDE_DIRECTORIES appropriately
target_include_directories(GPUTreeShap INTERFACE
$<BUILD_INTERFACE:${all_includes}>
$<INSTALL_INTERFACE:${CMAKE_INCLUDE_DIR}>)

# generate gputreeshap-targets.cmake for install dir
rapids_export(INSTALL GPUTreeShap
EXPORT_SET gputreeshap-exports
GLOBAL_TARGETS GPUTreeShap
NAMESPACE GPUTreeShap::)

# generate gputreeshap-targets.cmake for binary dir
rapids_export(BUILD GPUTreeShap
EXPORT_SET gputreeshap-exports
GLOBAL_TARGETS GPUTreeShap
NAMESPACE GPUTreeShap::)

endif()

# do `find_dependency(GPUTreeShap) in build and install`
rapids_export_package(BUILD GPUTreeShap cuml-exports)
rapids_export_package(INSTALL GPUTreeShap cuml-exports)

# Tell cmake where it can find the generated gputreeshap-config.cmake we wrote.
include("${rapids-cmake-dir}/export/find_package_root.cmake")
rapids_export_find_package_root(BUILD GPUTreeShap [=[${CMAKE_CURRENT_LIST_DIR}]=] cuml-exports)

set(GPUTreeShap_ADDED ${GPUTreeShap_ADDED} PARENT_SCOPE)

endfunction()
Expand Down
7 changes: 5 additions & 2 deletions cpp/include/cuml/manifold/common.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 Down Expand Up @@ -30,7 +30,10 @@ typedef int knn_indices_sparse_t;
*/
template <typename value_idx, typename value_t>
struct knn_graph {
knn_graph(value_idx n_rows_, int n_neighbors_) : n_rows(n_rows_), n_neighbors(n_neighbors_) {}
knn_graph(value_idx n_rows_, int n_neighbors_)
: n_rows(n_rows_), n_neighbors(n_neighbors_), knn_indices{nullptr}, knn_dists{nullptr}
{
}

knn_graph(value_idx n_rows_, int n_neighbors_, value_idx* knn_indices_, value_t* knn_dists_)
: n_rows(n_rows_), n_neighbors(n_neighbors_), knn_indices(knn_indices_), knn_dists(knn_dists_)
Expand Down

0 comments on commit 61524d7

Please sign in to comment.