From 964eebf9442b130bd540409c8738081e955db061 Mon Sep 17 00:00:00 2001 From: "Corey J. Nolet" Date: Mon, 24 Jan 2022 19:13:50 -0500 Subject: [PATCH 1/5] Splitting fused l2 knn specializations --- README.md | 2 +- cpp/CMakeLists.txt | 5 +- cpp/src/nn/specializations/fused_l2_knn.cu | 80 ------------------- .../fused_l2_knn_int_float_false.cu | 41 ++++++++++ .../fused_l2_knn_int_float_true.cu | 40 ++++++++++ .../fused_l2_knn_long_float_false.cu | 40 ++++++++++ .../fused_l2_knn_long_float_true.cu | 40 ++++++++++ 7 files changed, 166 insertions(+), 82 deletions(-) delete mode 100644 cpp/src/nn/specializations/fused_l2_knn.cu create mode 100644 cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu create mode 100644 cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu create mode 100644 cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu create mode 100644 cpp/src/nn/specializations/fused_l2_knn_long_float_true.cu diff --git a/README.md b/README.md index c0eeab75e5..45cbee9fe2 100755 --- a/README.md +++ b/README.md @@ -63,6 +63,6 @@ The folder structure mirrors other RAPIDS repos (cuDF, cuML, cuGraph...), with t - `ci`: Scripts for running CI in PRs - `conda`: conda recipes and development conda environments -- `cpp`: Source code for all C++ code. The code is currently header-only, therefore it is in the `include` folder (with no `src`). +- `cpp`: Source code for all C++ code. Headers are in the `include` folder and compiled template specializations for the shared libraries are in `src`. - `docs`: Source code and scripts for building library documentation - `python`: Source code for all Python source code. diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index f3a0f2d554..6aafa39d97 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -203,7 +203,10 @@ if(RAFT_COMPILE_LIBRARIES) add_library(raft_nn_lib SHARED src/nn/specializations/ball_cover.cu src/nn/specializations/detail/ball_cover_lowdim.cu - src/nn/specializations/fused_l2_knn.cu + src/nn/specializations/fused_l2_knn_long_float_true.cu + src/nn/specializations/fused_l2_knn_long_float_false.cu + src/nn/specializations/fused_l2_knn_int_float_true.cu + src/nn/specializations/fused_l2_knn_int_float_false.cu src/nn/specializations/knn.cu ) set_target_properties(raft_nn_lib PROPERTIES OUTPUT_NAME raft_nn) diff --git a/cpp/src/nn/specializations/fused_l2_knn.cu b/cpp/src/nn/specializations/fused_l2_knn.cu deleted file mode 100644 index 26aa7069e9..0000000000 --- a/cpp/src/nn/specializations/fused_l2_knn.cu +++ /dev/null @@ -1,80 +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. - */ - -#include -#include - -namespace raft { -namespace spatial { -namespace knn { -namespace detail { - -template void fusedL2Knn(size_t D, - long* out_inds, - float* out_dists, - const float* index, - const float* query, - size_t n_index_rows, - size_t n_query_rows, - int k, - bool rowMajorIndex, - bool rowMajorQuery, - cudaStream_t stream, - raft::distance::DistanceType metric); - -template void fusedL2Knn(size_t D, - long* out_inds, - float* out_dists, - const float* index, - const float* query, - size_t n_index_rows, - size_t n_query_rows, - int k, - bool rowMajorIndex, - bool rowMajorQuery, - cudaStream_t stream, - raft::distance::DistanceType metric); - -template void fusedL2Knn(size_t D, - int* out_inds, - float* out_dists, - const float* index, - const float* query, - size_t n_index_rows, - size_t n_query_rows, - int k, - bool rowMajorIndex, - bool rowMajorQuery, - cudaStream_t stream, - raft::distance::DistanceType metric); - -template void fusedL2Knn(size_t D, - int* out_inds, - float* out_dists, - const float* index, - const float* query, - size_t n_index_rows, - size_t n_query_rows, - int k, - bool rowMajorIndex, - bool rowMajorQuery, - cudaStream_t stream, - raft::distance::DistanceType metric); - -}; // namespace detail -}; // namespace knn -}; // namespace spatial -}; // namespace raft diff --git a/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu b/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu new file mode 100644 index 0000000000..61f23c8e4b --- /dev/null +++ b/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#include +#include + +namespace raft { + namespace spatial { + namespace knn { + namespace detail { + + template void fusedL2Knn(size_t D, + int* out_inds, + float* out_dists, + const float* index, + const float* query, + size_t n_index_rows, + size_t n_query_rows, + int k, + bool rowMajorIndex, + bool rowMajorQuery, + cudaStream_t stream, + raft::distance::DistanceType metric); + + }; // namespace detail + }; // namespace knn + }; // namespace spatial +}; // namespace raft diff --git a/cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu b/cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu new file mode 100644 index 0000000000..3ea3160776 --- /dev/null +++ b/cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#include +#include + +namespace raft { + namespace spatial { + namespace knn { + namespace detail { + template void fusedL2Knn(size_t D, + int* out_inds, + float* out_dists, + const float* index, + const float* query, + size_t n_index_rows, + size_t n_query_rows, + int k, + bool rowMajorIndex, + bool rowMajorQuery, + cudaStream_t stream, + raft::distance::DistanceType metric); + + }; // namespace detail + }; // namespace knn + }; // namespace spatial +}; // namespace raft diff --git a/cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu b/cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu new file mode 100644 index 0000000000..fac9e1f035 --- /dev/null +++ b/cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#include +#include + +namespace raft { + namespace spatial { + namespace knn { + namespace detail { + + template void fusedL2Knn(size_t D, + long* out_inds, + float* out_dists, + const float* index, + const float* query, + size_t n_index_rows, + size_t n_query_rows, + int k, + bool rowMajorIndex, + bool rowMajorQuery, + cudaStream_t stream, + raft::distance::DistanceType metric); + }; // namespace detail + }; // namespace knn + }; // namespace spatial +}; // namespace raft diff --git a/cpp/src/nn/specializations/fused_l2_knn_long_float_true.cu b/cpp/src/nn/specializations/fused_l2_knn_long_float_true.cu new file mode 100644 index 0000000000..ba846d5e24 --- /dev/null +++ b/cpp/src/nn/specializations/fused_l2_knn_long_float_true.cu @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#include +#include + +namespace raft { +namespace spatial { +namespace knn { +namespace detail { + +template void fusedL2Knn(size_t D, + long* out_inds, + float* out_dists, + const float* index, + const float* query, + size_t n_index_rows, + size_t n_query_rows, + int k, + bool rowMajorIndex, + bool rowMajorQuery, + cudaStream_t stream, + raft::distance::DistanceType metric); +}; // namespace detail +}; // namespace knn +}; // namespace spatial +}; // namespace raft From 5e228e7d34da0ae8aa5b5c2d567fa8f1fb2be967 Mon Sep 17 00:00:00 2001 From: "Corey J. Nolet" Date: Mon, 24 Jan 2022 19:19:35 -0500 Subject: [PATCH 2/5] Updating year --- cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu | 2 +- cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu | 2 +- cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu | 2 +- cpp/src/nn/specializations/fused_l2_knn_long_float_true.cu | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu b/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu index 61f23c8e4b..00d4dc28ac 100644 --- a/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu +++ b/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 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/src/nn/specializations/fused_l2_knn_int_float_true.cu b/cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu index 3ea3160776..ccf06e63a9 100644 --- a/cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu +++ b/cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 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/src/nn/specializations/fused_l2_knn_long_float_false.cu b/cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu index fac9e1f035..ba22f9e7dc 100644 --- a/cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu +++ b/cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 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/src/nn/specializations/fused_l2_knn_long_float_true.cu b/cpp/src/nn/specializations/fused_l2_knn_long_float_true.cu index ba846d5e24..379c24bf36 100644 --- a/cpp/src/nn/specializations/fused_l2_knn_long_float_true.cu +++ b/cpp/src/nn/specializations/fused_l2_knn_long_float_true.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 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. From 6091eba1c9a6c37a280fa94fd23cf73b44049204 Mon Sep 17 00:00:00 2001 From: "Corey J. Nolet" Date: Mon, 24 Jan 2022 19:26:38 -0500 Subject: [PATCH 3/5] Fixing style --- .../fused_l2_knn_int_float_false.cu | 36 +++++++++---------- .../fused_l2_knn_int_float_true.cu | 36 +++++++++---------- .../fused_l2_knn_long_float_false.cu | 36 +++++++++---------- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu b/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu index 00d4dc28ac..7d1747cfc3 100644 --- a/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu +++ b/cpp/src/nn/specializations/fused_l2_knn_int_float_false.cu @@ -18,24 +18,24 @@ #include namespace raft { - namespace spatial { - namespace knn { - namespace detail { +namespace spatial { +namespace knn { +namespace detail { - template void fusedL2Knn(size_t D, - int* out_inds, - float* out_dists, - const float* index, - const float* query, - size_t n_index_rows, - size_t n_query_rows, - int k, - bool rowMajorIndex, - bool rowMajorQuery, - cudaStream_t stream, - raft::distance::DistanceType metric); +template void fusedL2Knn(size_t D, + int* out_inds, + float* out_dists, + const float* index, + const float* query, + size_t n_index_rows, + size_t n_query_rows, + int k, + bool rowMajorIndex, + bool rowMajorQuery, + cudaStream_t stream, + raft::distance::DistanceType metric); - }; // namespace detail - }; // namespace knn - }; // namespace spatial +}; // namespace detail +}; // namespace knn +}; // namespace spatial }; // namespace raft diff --git a/cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu b/cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu index ccf06e63a9..d6748a0e4a 100644 --- a/cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu +++ b/cpp/src/nn/specializations/fused_l2_knn_int_float_true.cu @@ -18,23 +18,23 @@ #include namespace raft { - namespace spatial { - namespace knn { - namespace detail { - template void fusedL2Knn(size_t D, - int* out_inds, - float* out_dists, - const float* index, - const float* query, - size_t n_index_rows, - size_t n_query_rows, - int k, - bool rowMajorIndex, - bool rowMajorQuery, - cudaStream_t stream, - raft::distance::DistanceType metric); +namespace spatial { +namespace knn { +namespace detail { +template void fusedL2Knn(size_t D, + int* out_inds, + float* out_dists, + const float* index, + const float* query, + size_t n_index_rows, + size_t n_query_rows, + int k, + bool rowMajorIndex, + bool rowMajorQuery, + cudaStream_t stream, + raft::distance::DistanceType metric); - }; // namespace detail - }; // namespace knn - }; // namespace spatial +}; // namespace detail +}; // namespace knn +}; // namespace spatial }; // namespace raft diff --git a/cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu b/cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu index ba22f9e7dc..b96bb8987e 100644 --- a/cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu +++ b/cpp/src/nn/specializations/fused_l2_knn_long_float_false.cu @@ -18,23 +18,23 @@ #include namespace raft { - namespace spatial { - namespace knn { - namespace detail { +namespace spatial { +namespace knn { +namespace detail { - template void fusedL2Knn(size_t D, - long* out_inds, - float* out_dists, - const float* index, - const float* query, - size_t n_index_rows, - size_t n_query_rows, - int k, - bool rowMajorIndex, - bool rowMajorQuery, - cudaStream_t stream, - raft::distance::DistanceType metric); - }; // namespace detail - }; // namespace knn - }; // namespace spatial +template void fusedL2Knn(size_t D, + long* out_inds, + float* out_dists, + const float* index, + const float* query, + size_t n_index_rows, + size_t n_query_rows, + int k, + bool rowMajorIndex, + bool rowMajorQuery, + cudaStream_t stream, + raft::distance::DistanceType metric); +}; // namespace detail +}; // namespace knn +}; // namespace spatial }; // namespace raft From c17ec126eb5054daa621d038d99362c0eaaa5936 Mon Sep 17 00:00:00 2001 From: "Corey J. Nolet" Date: Tue, 25 Jan 2022 12:17:43 -0500 Subject: [PATCH 4/5] Updates to build.sh --- build.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/build.sh b/build.sh index 1346270e45..c1a4169fa0 100755 --- a/build.sh +++ b/build.sh @@ -18,7 +18,7 @@ ARGS=$* # script, and that this script resides in the repo dir! REPODIR=$(cd $(dirname $0); pwd) -VALIDARGS="clean libraft pyraft docs -v -g --compilelibs --allgpuarch --nvtx --show_depr_warn -h --buildgtest --buildfaiss" +VALIDARGS="clean libraft pyraft docs -v -g --compilelibs --allgpuarch --nvtx --show_depr_warn -h --nogtest --buildfaiss" HELP="$0 [ ...] [ ...] where is: clean - remove all existing build artifacts and configuration (start over) @@ -33,6 +33,7 @@ HELP="$0 [ ...] [ ...] --compilelibs - compile shared libraries --allgpuarch - build for all supported GPU architectures --buildfaiss - build faiss statically into raft + --nogtest - do not build google tests for libraft --nvtx - Enable nvtx for profiling support --show_depr_warn - show cmake deprecation warnings -h - print this text @@ -49,10 +50,10 @@ BUILD_DIRS="${CPP_RAFT_BUILD_DIR} ${PY_RAFT_BUILD_DIR} ${PYTHON_DEPS_CLONE}" CMAKE_LOG_LEVEL="" VERBOSE_FLAG="" BUILD_ALL_GPU_ARCH=0 -BUILD_TESTS=ON +BUILD_TESTS=YES BUILD_STATIC_FAISS=OFF -COMPILE_LIBRARIES=OFF -ENABLE_NN_DEPENDENCIES=ON +COMPILE_LIBRARIES=${BUILD_TESTS} +ENABLE_NN_DEPENDENCIES=${BUILD_TESTS} SINGLEGPU="" NVTX=OFF CLEAN=0 @@ -97,18 +98,20 @@ if hasArg -g; then BUILD_TYPE=Debug fi -if hasArg --compilelibs; then - COMPILE_LIBRARIES=ON -fi - if hasArg --allgpuarch; then BUILD_ALL_GPU_ARCH=1 fi -if hasArg --buildgtest; then - BUILD_GTEST=ON +if hasArg --nogtest; then + BUILD_TESTS=OFF + COMPILE_LIBRARIES=${BUILD_TESTS} + ENABLE_NN_DEPENDENCIES=${BUILD_TESTS} +fi +if hasArg --compilelibs; then + COMPILE_LIBRARIES=ON + ENABLE_NN_DEPENDENCIES=ON fi if hasArg --buildfaiss; then - BUILD_STATIC_FAISS=ON + BUILD_STATIC_FAISS=ON fi if hasArg --singlegpu; then SINGLEGPU="--singlegpu" From be89a07096ba5aa2f3db61522bd8a92cdd2473ad Mon Sep 17 00:00:00 2001 From: "Corey J. Nolet" Date: Tue, 25 Jan 2022 12:35:05 -0500 Subject: [PATCH 5/5] More updates --- build.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index c1a4169fa0..c13bd70342 100755 --- a/build.sh +++ b/build.sh @@ -57,7 +57,8 @@ ENABLE_NN_DEPENDENCIES=${BUILD_TESTS} SINGLEGPU="" NVTX=OFF CLEAN=0 -BUILD_DISABLE_DEPRECATION_WARNING=ON +DISABLE_DEPRECATION_WARNINGS=ON +CMAKE_TARGET="" # Set defaults for vars that may not have been defined externally # FIXME: if INSTALL_PREFIX is not set, check PREFIX, then check @@ -103,8 +104,8 @@ if hasArg --allgpuarch; then fi if hasArg --nogtest; then BUILD_TESTS=OFF - COMPILE_LIBRARIES=${BUILD_TESTS} - ENABLE_NN_DEPENDENCIES=${BUILD_TESTS} + COMPILE_LIBRARIES=OFF + ENABLE_NN_DEPENDENCIES=OFF fi if hasArg --compilelibs; then COMPILE_LIBRARIES=ON @@ -120,7 +121,7 @@ if hasArg --nvtx; then NVTX=ON fi if hasArg --show_depr_warn; then - BUILD_DISABLE_DEPRECATION_WARNING=OFF + DISABLE_DEPRECATION_WARNINGS=OFF fi if hasArg clean; then CLEAN=1 @@ -163,14 +164,14 @@ if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs; then -DRAFT_COMPILE_LIBRARIES=${COMPILE_LIBRARIES} \ -DRAFT_ENABLE_NN_DEPENDENCIES=${ENABLE_NN_DEPENDENCIES} \ -DNVTX=${NVTX} \ - -DDISABLE_DEPRECATION_WARNING=${BUILD_DISABLE_DEPRECATION_WARNING} \ + -DDISABLE_DEPRECATION_WARNINGS=${DISABLE_DEPRECATION_WARNINGS} \ -DBUILD_TESTS=${BUILD_TESTS} \ -DRAFT_USE_FAISS_STATIC=${BUILD_STATIC_FAISS} \ .. if (( ${NUMARGS} == 0 )) || hasArg libraft; then # Run all c++ targets at once - cmake --build ${CPP_RAFT_BUILD_DIR} -j${PARALLEL_LEVEL} ${VERBOSE_FLAG} + cmake --build ${CPP_RAFT_BUILD_DIR} -j${PARALLEL_LEVEL} ${VERBOSE_FLAG} ${CMAKE_TARGET} fi fi