From afdeda99a197b2bfd40321a9aff4ce444245e6af Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Wed, 16 Jun 2021 09:29:39 -0500 Subject: [PATCH] Promote `trustworthiness_score` to public header, add missing includes, update dependencies (#3968) * Updates dask/distributed versions to match cuDF (https://github.com/rapidsai/cudf/pull/8458) * Updates to Thrust v1.12.0 to align with cuDF and cuGraph * Don't include the src and src_prims directories in `cuml::cuml++` target's public include paths * Add missing `` and `` include directives * Promote `trustworthiness_score` to public `cuml/metrics/metrics.hpp` header and update Cython * Compile Cython with `-std=c++17` * Remove `-Wstrict-prototypes` Cython warning * Fixes linker error in debug builds * Fixes #3885 Authors: - Paul Taylor (https://github.com/trxcllnt) Approvers: - Dante Gama Dessavre (https://github.com/dantegd) - AJ Schmidt (https://github.com/ajschmidt8) URL: https://github.com/rapidsai/cuml/pull/3968 --- conda/environments/cuml_dev_cuda11.0.yml | 4 ++++ conda/environments/cuml_dev_cuda11.2.yml | 4 ++++ conda/recipes/cuml/meta.yaml | 6 ++--- cpp/CMakeLists.txt | 20 ++++++++++++++-- cpp/cmake/thirdparty/get_thrust.cmake | 2 +- cpp/include/cuml/manifold/umap.hpp | 3 +++ cpp/include/cuml/metrics/metrics.hpp | 21 +++++++++++++++++ cpp/src/metrics/trustworthiness.cu | 20 +++++++++------- cpp/src/metrics/trustworthiness.cuh | 30 ------------------------ cpp/src/metrics/trustworthiness_c.h | 30 ------------------------ cpp/src/svm/workingset.cuh | 4 ++-- cpp/src/tsa/auto_arima.cuh | 6 +++-- cpp/test/sg/trustworthiness_test.cu | 5 +++- cpp/test/sg/tsne_test.cu | 5 ++-- cpp/test/sg/umap_parametrizable_test.cu | 3 ++- python/cuml/metrics/trustworthiness.pyx | 2 +- python/setup.py | 10 +++++++- 17 files changed, 91 insertions(+), 84 deletions(-) delete mode 100644 cpp/src/metrics/trustworthiness.cuh delete mode 100644 cpp/src/metrics/trustworthiness_c.h diff --git a/conda/environments/cuml_dev_cuda11.0.yml b/conda/environments/cuml_dev_cuda11.0.yml index 55157accbc..a4ef7e67cf 100644 --- a/conda/environments/cuml_dev_cuda11.0.yml +++ b/conda/environments/cuml_dev_cuda11.0.yml @@ -23,6 +23,10 @@ dependencies: - umap-learn - scikit-learn=0.23.1 - treelite=1.3.0 +- statsmodels +- seaborn +- hdbscan +- nltk - pip - pip: - sphinx_markdown_tables diff --git a/conda/environments/cuml_dev_cuda11.2.yml b/conda/environments/cuml_dev_cuda11.2.yml index 1d41be917e..1b4ed6ef39 100644 --- a/conda/environments/cuml_dev_cuda11.2.yml +++ b/conda/environments/cuml_dev_cuda11.2.yml @@ -23,6 +23,10 @@ dependencies: - umap-learn - scikit-learn=0.23.1 - treelite=1.3.0 +- statsmodels +- seaborn +- hdbscan +- nltk - pip - pip: - sphinx_markdown_tables diff --git a/conda/recipes/cuml/meta.yaml b/conda/recipes/cuml/meta.yaml index 98cdf171cc..73ab6b9034 100644 --- a/conda/recipes/cuml/meta.yaml +++ b/conda/recipes/cuml/meta.yaml @@ -27,7 +27,7 @@ requirements: - python x.x - setuptools - cython>=0.29,<0.30 - - cmake>=3.14 + - cmake>=3.20.1 - treelite=1.3.0 - cudf {{ minor_version }} - libcuml={{ version }} @@ -46,8 +46,8 @@ requirements: - nccl>=2.9.9 - ucx-py 0.21 - ucx-proc=*=gpu - - dask>=2.12.0 - - distributed>=2.12.0 + - dask>=2021.6.0 + - distributed>=2021.6.0 - joblib >=0.11 - {{ pin_compatible('cudatoolkit', max_pin='x.x') }} diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 6bd281ef08..5b4d359509 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -206,6 +206,17 @@ endif() ############################################################################## # - build libcuml++ shared library ------------------------------------------- +if(BUILD_CUML_C_LIBRARY OR BUILD_CUML_CPP_LIBRARY) + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/fatbin.ld" +[=[ +SECTIONS +{ +.nvFatBinSegment : { *(.nvFatBinSegment) } +.nv_fatbin : { *(.nv_fatbin) } +} +]=]) +endif() + if(BUILD_CUML_CPP_LIBRARY) # single GPU components @@ -309,11 +320,11 @@ if(BUILD_CUML_CPP_LIBRARY) target_include_directories(${CUML_CPP_TARGET} PUBLIC $ - $ - $ $:${cumlprims_mg_INCLUDE_DIRS}>> $<$:${Treelite_SOURCE_DIR}/include> PRIVATE + $ + $ $<$,$>:${NCCL_INCLUDE_DIRS}> $<$:${MPI_CXX_INCLUDE_PATH}> INTERFACE @@ -347,6 +358,8 @@ if(BUILD_CUML_CPP_LIBRARY) target_link_options(${CUML_CPP_TARGET} PRIVATE "-Wl,--exclude-libs,libdmlc.a") # same as above, but for protobuf 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(BUILD_CUML_CPP_LIBRARY) @@ -382,6 +395,9 @@ if(BUILD_CUML_C_LIBRARY) FAISS::FAISS ) + # ensure CUDA symbols aren't relocated to the middle of the debug build binaries + target_link_options(${CUML_C_TARGET} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/fatbin.ld") + endif() ############################################################################## diff --git a/cpp/cmake/thirdparty/get_thrust.cmake b/cpp/cmake/thirdparty/get_thrust.cmake index 5fc088fc94..e5b824a3b9 100644 --- a/cpp/cmake/thirdparty/get_thrust.cmake +++ b/cpp/cmake/thirdparty/get_thrust.cmake @@ -26,4 +26,4 @@ function(find_and_configure_thrust VERSION) endfunction() -find_and_configure_thrust(1.10.0) +find_and_configure_thrust(1.12.0) diff --git a/cpp/include/cuml/manifold/umap.hpp b/cpp/include/cuml/manifold/umap.hpp index b4754c0bee..4e5a1a3113 100644 --- a/cpp/include/cuml/manifold/umap.hpp +++ b/cpp/include/cuml/manifold/umap.hpp @@ -16,6 +16,9 @@ #pragma once +#include +#include + namespace raft { class handle_t; } diff --git a/cpp/include/cuml/metrics/metrics.hpp b/cpp/include/cuml/metrics/metrics.hpp index ce3a294691..5afa93dc5d 100644 --- a/cpp/include/cuml/metrics/metrics.hpp +++ b/cpp/include/cuml/metrics/metrics.hpp @@ -18,6 +18,8 @@ #include +#include + namespace raft { class handle_t; } @@ -337,5 +339,24 @@ void pairwiseDistance_sparse(const raft::handle_t &handle, float *x, float *y, raft::distance::DistanceType metric, float metric_arg); +/** + * @brief Compute the trustworthiness score + * + * @param h Raft handle + * @param X Data in original dimension + * @param X_embedded Data in target dimension (embedding) + * @param n Number of samples + * @param m Number of features in high/original dimension + * @param d Number of features in low/embedded dimension + * @param n_neighbors Number of neighbors considered by trustworthiness score + * @param batchSize Batch size + * @tparam distance_type: Distance type to consider + * @return Trustworthiness score + */ +template +double trustworthiness_score(const raft::handle_t &h, const math_t *X, + math_t *X_embedded, int n, int m, int d, + int n_neighbors, int batchSize = 512); + } // namespace Metrics } // namespace ML diff --git a/cpp/src/metrics/trustworthiness.cu b/cpp/src/metrics/trustworthiness.cu index 629d33cb27..de8212cf94 100644 --- a/cpp/src/metrics/trustworthiness.cu +++ b/cpp/src/metrics/trustworthiness.cu @@ -15,6 +15,9 @@ */ #include + +#include + #include #include @@ -23,14 +26,15 @@ namespace Metrics { /** * @brief Compute the trustworthiness score - * @param h: Raft handle - * @param X[in]: Data in original dimension - * @param X_embedded[in]: Data in target dimension (embedding) - * @param n[in]: Number of samples - * @param m[in]: Number of features in high/original dimension - * @param d[in]: Number of features in low/embedded dimension - * @param n_neighbors[in]: Number of neighbors considered by - * trustworthiness score + * + * @param h Raft handle + * @param X Data in original dimension + * @param X_embedded Data in target dimension (embedding) + * @param n Number of samples + * @param m Number of features in high/original dimension + * @param d Number of features in low/embedded dimension + * @param n_neighbors Number of neighbors considered by trustworthiness score + * @param batchSize Batch size * @tparam distance_type: Distance type to consider * @return Trustworthiness score */ diff --git a/cpp/src/metrics/trustworthiness.cuh b/cpp/src/metrics/trustworthiness.cuh deleted file mode 100644 index 3527969f3f..0000000000 --- a/cpp/src/metrics/trustworthiness.cuh +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2018-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. - */ - -#pragma once - -#include -#include - -namespace ML { -namespace Metrics { - -template -double trustworthiness_score(const raft::handle_t& h, const math_t* X, - math_t* X_embedded, int n, int m, int d, - int n_neighbors, int batchSize = 512); -} -} // namespace ML diff --git a/cpp/src/metrics/trustworthiness_c.h b/cpp/src/metrics/trustworthiness_c.h deleted file mode 100644 index ac1c345825..0000000000 --- a/cpp/src/metrics/trustworthiness_c.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2018-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. - */ - -#pragma once - -#include - -namespace ML { -namespace Metrics { - -template -double trustworthiness_score(const raft::handle_t& h, const math_t* X, - math_t* X_embedded, int n, int m, int d, - int n_neighbors, int batchSize); - -} -} // namespace ML diff --git a/cpp/src/svm/workingset.cuh b/cpp/src/svm/workingset.cuh index e083147106..6272e462fb 100644 --- a/cpp/src/svm/workingset.cuh +++ b/cpp/src/svm/workingset.cuh @@ -343,8 +343,8 @@ class WorkingSet { // Determine temporary device storage requirements for cub size_t cub_bytes2 = 0; cub::DeviceRadixSort::SortPairs( - NULL, cub_bytes, f_idx.data(), f_idx_sorted.data(), f_sorted.data(), - f_sorted.data(), n_train, 0, 8 * sizeof(int), stream); + NULL, cub_bytes, f_sorted.data(), f_sorted.data(), f_idx.data(), + f_idx_sorted.data(), n_train, 0, 8 * sizeof(math_t), stream); cub::DeviceSelect::If(NULL, cub_bytes2, f_idx.data(), f_idx.data(), d_num_selected, n_train, dummy_select_op, stream); cub_bytes = max(cub_bytes, cub_bytes2); diff --git a/cpp/src/tsa/auto_arima.cuh b/cpp/src/tsa/auto_arima.cuh index 6b15784a77..9a76fb18d0 100644 --- a/cpp/src/tsa/auto_arima.cuh +++ b/cpp/src/tsa/auto_arima.cuh @@ -49,7 +49,8 @@ void cumulative_sum_helper( std::shared_ptr allocator, cudaStream_t stream) { // Determine temporary storage size size_t temp_storage_bytes = 0; - cub::DeviceScan::InclusiveSum(NULL, temp_storage_bytes, mask, cumul, + cub::DeviceScan::InclusiveSum(NULL, temp_storage_bytes, + reinterpret_cast(mask), cumul, mask_size, stream); // Allocate temporary storage @@ -58,7 +59,8 @@ void cumulative_sum_helper( void* d_temp_storage = (void*)temp_storage.data(); // Execute the scan - cub::DeviceScan::InclusiveSum(d_temp_storage, temp_storage_bytes, mask, cumul, + cub::DeviceScan::InclusiveSum(d_temp_storage, temp_storage_bytes, + reinterpret_cast(mask), cumul, mask_size, stream); } diff --git a/cpp/test/sg/trustworthiness_test.cu b/cpp/test/sg/trustworthiness_test.cu index 6b49b4e864..8c08cd11b3 100644 --- a/cpp/test/sg/trustworthiness_test.cu +++ b/cpp/test/sg/trustworthiness_test.cu @@ -14,9 +14,12 @@ * limitations under the License. */ +#include + +#include + #include #include -#include #include #include diff --git a/cpp/test/sg/tsne_test.cu b/cpp/test/sg/tsne_test.cu index cc5d15f865..233ebccfb7 100644 --- a/cpp/test/sg/tsne_test.cu +++ b/cpp/test/sg/tsne_test.cu @@ -15,6 +15,8 @@ */ #include +#include + #include #include #include @@ -26,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -174,4 +175,4 @@ TEST_P(TSNETestF, Result) { assert_score(knn_score_fft, "knn_fft\n", trustworthiness_threshold); } -INSTANTIATE_TEST_CASE_P(TSNETests, TSNETestF, ::testing::ValuesIn(inputs)); \ No newline at end of file +INSTANTIATE_TEST_CASE_P(TSNETests, TSNETestF, ::testing::ValuesIn(inputs)); diff --git a/cpp/test/sg/umap_parametrizable_test.cu b/cpp/test/sg/umap_parametrizable_test.cu index 7c41c11f87..f38962f1d8 100644 --- a/cpp/test/sg/umap_parametrizable_test.cu +++ b/cpp/test/sg/umap_parametrizable_test.cu @@ -14,6 +14,8 @@ * limitations under the License. */ +#include + #include #include #include @@ -27,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/python/cuml/metrics/trustworthiness.pyx b/python/cuml/metrics/trustworthiness.pyx index e77cfd2be5..9bb907f81d 100644 --- a/python/cuml/metrics/trustworthiness.pyx +++ b/python/cuml/metrics/trustworthiness.pyx @@ -33,7 +33,7 @@ cdef extern from "raft/linalg/distance_type.h" namespace "raft::distance": ctypedef int DistanceType ctypedef DistanceType euclidean "(raft::distance::DistanceType)5" -cdef extern from "metrics/trustworthiness_c.h" namespace "ML::Metrics": +cdef extern from "cuml/metrics/metrics.hpp" namespace "ML::Metrics": cdef double trustworthiness_score[T, DistanceType](const handle_t& h, T* X, diff --git a/python/setup.py b/python/setup.py index 21525ba67c..4853a5c639 100644 --- a/python/setup.py +++ b/python/setup.py @@ -190,7 +190,7 @@ def finalize_options(self): ], libraries=libs, language='c++', - extra_compile_args=['-std=c++14']) + extra_compile_args=['-std=c++17']) ] self.distribution.ext_modules = extensions @@ -207,6 +207,14 @@ class cuml_build_ext(cython_build_ext, object): boolean_options = ["singlegpu"] + cython_build_ext.boolean_options + def build_extensions(self): + try: + # Silence the '-Wstrict-prototypes' warning + self.compiler.compiler_so.remove("-Wstrict-prototypes") + except Exception: + pass + cython_build_ext.build_extensions(self) + def initialize_options(self): self.singlegpu = None