Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNMG ANN #1993

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3b74685
SNMG ANN
viclafargue Nov 14, 2023
c655d91
Complete main parts and add tests
viclafargue Nov 15, 2023
9aeb456
Debugging
viclafargue Nov 20, 2023
224a59f
Implement search on shards
viclafargue Nov 20, 2023
ebca042
Debugging
viclafargue Nov 23, 2023
8141f72
ANN benchmark integration + offset fix + translations fix
viclafargue Jan 10, 2024
6d29eb1
Adding CAGRA capability
viclafargue Jan 26, 2024
34bb6c4
Testing serialization + use of pre-computed methods
viclafargue Feb 1, 2024
2c3fbc2
Add distribution feature
viclafargue Feb 2, 2024
b5680b2
Merge remote-tracking branch 'origin/branch-24.04' into snmg-ann
viclafargue Mar 26, 2024
4581fbd
SNMG ANN bench update
viclafargue Apr 23, 2024
e3b03b8
OpenMP
viclafargue May 3, 2024
a6707c3
Answering reviews
viclafargue May 6, 2024
4a91a7f
NCCL clique helper
viclafargue May 8, 2024
0a37d63
SNMG ANN IVF-Flat & IVF-PQ bench + fixes
viclafargue May 24, 2024
8417684
Fixes & improvements
viclafargue May 28, 2024
34d4fd3
Setting NCCL init apart for bench
viclafargue May 28, 2024
3f15c43
Mempool + NCCL fix
viclafargue Jun 12, 2024
b77f938
SNMG cagra bench
viclafargue Jun 12, 2024
fc748ae
SNMG CAGRA bench
viclafargue Jun 13, 2024
410562b
Merge branch 'branch-24.08' into snmg-ann
viclafargue Jun 17, 2024
666d47f
Increase search batch size + fix build
viclafargue Jun 17, 2024
1a559a6
mdspan feature for build and extend
viclafargue Jul 8, 2024
11d30da
style fix
viclafargue Jul 8, 2024
9af470e
Merge branch 'branch-24.08' into snmg-ann
viclafargue Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ _text
# clang tooling
compile_commands.json
.clangd/

datasets/
index/
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ INSTALL_TARGET=install
BUILD_REPORT_METRICS=""
BUILD_REPORT_INCL_CACHE_STATS=OFF

TEST_TARGETS="CLUSTER_TEST;CORE_TEST;DISTANCE_TEST;LABEL_TEST;LINALG_TEST;MATRIX_TEST;NEIGHBORS_TEST;NEIGHBORS_ANN_BRUTE_FORCE_TEST;NEIGHBORS_ANN_CAGRA_TEST;NEIGHBORS_ANN_NN_DESCENT_TEST;NEIGHBORS_ANN_IVF_TEST;RANDOM_TEST;SOLVERS_TEST;SPARSE_TEST;SPARSE_DIST_TEST;SPARSE_NEIGHBORS_TEST;STATS_TEST;UTILS_TEST"
TEST_TARGETS="CLUSTER_TEST;CORE_TEST;DISTANCE_TEST;LABEL_TEST;LINALG_TEST;MATRIX_TEST;NEIGHBORS_TEST;NEIGHBORS_ANN_BRUTE_FORCE_TEST;NEIGHBORS_ANN_CAGRA_TEST;NEIGHBORS_ANN_NN_DESCENT_TEST;NEIGHBORS_ANN_IVF_TEST;NEIGHBORS_ANN_MG_TEST;RANDOM_TEST;SOLVERS_TEST;SPARSE_TEST;SPARSE_DIST_TEST;SPARSE_NEIGHBORS_TEST;STATS_TEST;UTILS_TEST"
BENCH_TARGETS="CLUSTER_BENCH;CORE_BENCH;NEIGHBORS_BENCH;DISTANCE_BENCH;LINALG_BENCH;MATRIX_BENCH;SPARSE_BENCH;RANDOM_BENCH"

CACHE_ARGS=""
Expand Down Expand Up @@ -326,6 +326,7 @@ if hasArg tests || (( ${NUMARGS} == 0 )); then
$CMAKE_TARGET == *"NEIGHBORS_ANN_BRUTE_FORCE_TEST"* || \
$CMAKE_TARGET == *"NEIGHBORS_ANN_CAGRA_TEST"* || \
$CMAKE_TARGET == *"NEIGHBORS_ANN_IVF_TEST"* || \
$CMAKE_TARGET == *"NEIGHBORS_ANN_MG_TEST"* || \
$CMAKE_TARGET == *"NEIGHBORS_ANN_NN_DESCENT_TEST"* || \
$CMAKE_TARGET == *"NEIGHBORS_TEST"* || \
$CMAKE_TARGET == *"SPARSE_DIST_TEST" || \
Expand Down
53 changes: 53 additions & 0 deletions cpp/bench/ann/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ option(RAFT_ANN_BENCH_USE_RAFT_IVF_PQ "Include raft's ivf pq algorithm in benchm
option(RAFT_ANN_BENCH_USE_RAFT_CAGRA "Include raft's CAGRA in benchmark" ON)
option(RAFT_ANN_BENCH_USE_RAFT_BRUTE_FORCE "Include raft's brute force knn in benchmark" ON)
option(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB "Include raft's CAGRA in benchmark" ON)
option(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_FLAT "Include raft's MG ANN IVF-FLAT in benchmark" ON)
option(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_PQ "Include raft's MG ANN IVF-PQ in benchmark" ON)
option(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA "Include raft's MG ANN CAGRA in benchmark" ON)
option(RAFT_ANN_BENCH_USE_HNSWLIB "Include hnsw algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_USE_GGNN "Include ggnn algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_SINGLE_EXE
Expand All @@ -57,6 +60,9 @@ if(BUILD_CPU_ONLY)
set(RAFT_ANN_BENCH_USE_RAFT_CAGRA OFF)
set(RAFT_ANN_BENCH_USE_RAFT_BRUTE_FORCE OFF)
set(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB OFF)
set(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_FLAT OFF)
set(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_PQ OFF)
set(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA OFF)
set(RAFT_ANN_BENCH_USE_GGNN OFF)
endif()

Expand All @@ -66,6 +72,9 @@ if(RAFT_ANN_BENCH_USE_RAFT_IVF_PQ
OR RAFT_ANN_BENCH_USE_RAFT_IVF_FLAT
OR RAFT_ANN_BENCH_USE_RAFT_CAGRA
OR RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB
OR RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_FLAT
OR RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_PQ
OR RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA
)
set(RAFT_ANN_BENCH_USE_RAFT ON)
endif()
Expand Down Expand Up @@ -252,6 +261,50 @@ if(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB)
)
endif()

if(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_FLAT)
ConfigureAnnBench(
NAME
RAFT_ANN_MG_IVF_FLAT
PATH
src/raft/raft_benchmark.cu
src/raft/raft_ann_mg_ivf_flat.cu
LINKS
raft::compiled
ucp ucs ucxx nccl
)
endif()

if(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_PQ)
ConfigureAnnBench(
NAME
RAFT_ANN_MG_IVF_PQ
PATH
src/raft/raft_benchmark.cu
src/raft/raft_ann_mg_ivf_pq.cu
LINKS
raft::compiled
ucp ucs ucxx nccl
)
endif()

if(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA)
ConfigureAnnBench(
NAME
RAFT_ANN_MG_CAGRA
PATH
src/raft/raft_benchmark.cu
src/raft/raft_ann_mg_cagra.cu
LINKS
raft::compiled
ucp ucs ucxx nccl
)
endif()

set(RAFT_FAISS_TARGETS faiss::faiss)
if(TARGET faiss::faiss_avx2)
set(RAFT_FAISS_TARGETS faiss::faiss_avx2)
endif()

message("RAFT_FAISS_TARGETS: ${RAFT_FAISS_TARGETS}")
message("CUDAToolkit_LIBRARY_DIR: ${CUDAToolkit_LIBRARY_DIR}")
if(RAFT_ANN_BENCH_USE_FAISS_CPU_FLAT)
Expand Down
1 change: 1 addition & 0 deletions cpp/bench/ann/src/common/benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <numeric>
#include <sstream>
#include <string>
#include <thread>
#include <vector>

namespace raft::bench::ann {
Expand Down
60 changes: 54 additions & 6 deletions cpp/bench/ann/src/raft/raft_ann_bench_param_parser.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
* Copyright (c) 2024, 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,15 +30,16 @@ extern template class raft::bench::ann::RaftIvfFlatGpu<uint8_t, int64_t>;
extern template class raft::bench::ann::RaftIvfFlatGpu<int8_t, int64_t>;
#endif
#if defined(RAFT_ANN_BENCH_USE_RAFT_IVF_PQ) || defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA) || \
defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB)
defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB) || defined(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA)
#include "raft_ivf_pq_wrapper.h"
#endif
#ifdef RAFT_ANN_BENCH_USE_RAFT_IVF_PQ
extern template class raft::bench::ann::RaftIvfPQ<float, int64_t>;
extern template class raft::bench::ann::RaftIvfPQ<uint8_t, int64_t>;
extern template class raft::bench::ann::RaftIvfPQ<int8_t, int64_t>;
#endif
#if defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA) || defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB)
#if defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA) || defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB) || \
defined(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA)
#include "raft_cagra_wrapper.h"
#endif
#ifdef RAFT_ANN_BENCH_USE_RAFT_CAGRA
Expand All @@ -47,11 +48,33 @@ extern template class raft::bench::ann::RaftCagra<half, uint32_t>;
extern template class raft::bench::ann::RaftCagra<uint8_t, uint32_t>;
extern template class raft::bench::ann::RaftCagra<int8_t, uint32_t>;
#endif
#ifdef RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_FLAT
#include "raft_ann_mg_ivf_flat_wrapper.hpp"
extern template class raft::bench::ann::RaftAnnMG_IvfFlat<float, int64_t>;
extern template class raft::bench::ann::RaftAnnMG_IvfFlat<uint8_t, int64_t>;
extern template class raft::bench::ann::RaftAnnMG_IvfFlat<int8_t, int64_t>;
#endif
#ifdef RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_PQ
#include "raft_ann_mg_ivf_pq_wrapper.hpp"
extern template class raft::bench::ann::RaftAnnMG_IvfPq<float, int64_t>;
extern template class raft::bench::ann::RaftAnnMG_IvfPq<uint8_t, int64_t>;
extern template class raft::bench::ann::RaftAnnMG_IvfPq<int8_t, int64_t>;
#endif
#ifdef RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA
#include "raft_ann_mg_cagra_wrapper.hpp"
extern template class raft::bench::ann::RaftAnnMG_Cagra<float, uint32_t>;
extern template class raft::bench::ann::RaftAnnMG_Cagra<uint8_t, uint32_t>;
extern template class raft::bench::ann::RaftAnnMG_Cagra<int8_t, uint32_t>;
#endif

#ifdef RAFT_ANN_BENCH_USE_RAFT_IVF_FLAT
#if defined(RAFT_ANN_BENCH_USE_RAFT_IVF_FLAT) || defined(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_FLAT)
template <typename T, typename IdxT>
void parse_build_param(const nlohmann::json& conf,
#ifdef RAFT_ANN_BENCH_USE_RAFT_IVF_FLAT
typename raft::bench::ann::RaftIvfFlatGpu<T, IdxT>::BuildParam& param)
#else
typename raft::bench::ann::RaftAnnMG_IvfFlat<T, IdxT>::BuildParam& param)
#endif
{
param.n_lists = conf.at("nlist");
if (conf.contains("niter")) { param.kmeans_n_iters = conf.at("niter"); }
Expand All @@ -60,17 +83,26 @@ void parse_build_param(const nlohmann::json& conf,

template <typename T, typename IdxT>
void parse_search_param(const nlohmann::json& conf,
#ifdef RAFT_ANN_BENCH_USE_RAFT_IVF_FLAT
typename raft::bench::ann::RaftIvfFlatGpu<T, IdxT>::SearchParam& param)
#else
typename raft::bench::ann::RaftAnnMG_IvfFlat<T, IdxT>::SearchParam& param)
#endif
{
param.ivf_flat_params.n_probes = conf.at("nprobe");
}
#endif

#if defined(RAFT_ANN_BENCH_USE_RAFT_IVF_PQ) || defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA) || \
defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB)
defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB) || \
defined(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_PQ) || defined(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA)
template <typename T, typename IdxT>
void parse_build_param(const nlohmann::json& conf,
#ifdef RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_PQ
typename raft::bench::ann::RaftAnnMG_IvfPq<T, IdxT>::BuildParam& param)
#else
typename raft::bench::ann::RaftIvfPQ<T, IdxT>::BuildParam& param)
#endif
{
if (conf.contains("nlist")) { param.n_lists = conf.at("nlist"); }
if (conf.contains("niter")) { param.kmeans_n_iters = conf.at("niter"); }
Expand All @@ -92,7 +124,11 @@ void parse_build_param(const nlohmann::json& conf,

template <typename T, typename IdxT>
void parse_search_param(const nlohmann::json& conf,
#ifdef RAFT_ANN_BENCH_USE_RAFT_ANN_MG_IVF_PQ
typename raft::bench::ann::RaftAnnMG_IvfPq<T, IdxT>::SearchParam& param)
#else
typename raft::bench::ann::RaftIvfPQ<T, IdxT>::SearchParam& param)
#endif
{
if (conf.contains("nprobe")) { param.pq_param.n_probes = conf.at("nprobe"); }
if (conf.contains("internalDistanceDtype")) {
Expand Down Expand Up @@ -133,7 +169,8 @@ void parse_search_param(const nlohmann::json& conf,
}
#endif

#if defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA) || defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB)
#if defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA) || defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB) || \
defined(RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA)
template <typename T, typename IdxT>
void parse_build_param(const nlohmann::json& conf,
raft::neighbors::experimental::nn_descent::index_params& param)
Expand Down Expand Up @@ -180,7 +217,11 @@ nlohmann::json collect_conf_with_prefix(const nlohmann::json& conf,

template <typename T, typename IdxT>
void parse_build_param(const nlohmann::json& conf,
#ifdef RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA
typename raft::bench::ann::RaftAnnMG_Cagra<T, IdxT>::BuildParam& param)
#else
typename raft::bench::ann::RaftCagra<T, IdxT>::BuildParam& param)
#endif
{
if (conf.contains("graph_degree")) {
param.cagra_params.graph_degree = conf.at("graph_degree");
Expand Down Expand Up @@ -244,7 +285,11 @@ raft::bench::ann::AllocatorType parse_allocator(std::string mem_type)

template <typename T, typename IdxT>
void parse_search_param(const nlohmann::json& conf,
#ifdef RAFT_ANN_BENCH_USE_RAFT_ANN_MG_CAGRA
typename raft::bench::ann::RaftAnnMG_Cagra<T, IdxT>::SearchParam& param)
#else
typename raft::bench::ann::RaftCagra<T, IdxT>::SearchParam& param)
#endif
{
if (conf.contains("itopk")) { param.p.itopk_size = conf.at("itopk"); }
if (conf.contains("search_width")) { param.p.search_width = conf.at("search_width"); }
Expand All @@ -263,12 +308,15 @@ void parse_search_param(const nlohmann::json& conf,
THROW("Invalid value for algo: %s", tmp.c_str());
}
}

#if defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA) || defined(RAFT_ANN_BENCH_USE_RAFT_CAGRA_HNSWLIB)
if (conf.contains("graph_memory_type")) {
param.graph_mem = parse_allocator(conf.at("graph_memory_type"));
}
if (conf.contains("internal_dataset_memory_type")) {
param.dataset_mem = parse_allocator(conf.at("internal_dataset_memory_type"));
}
#endif
// Same ratio as in IVF-PQ
param.refine_ratio = conf.value("refine_ratio", 1.0f);
}
Expand Down
28 changes: 28 additions & 0 deletions cpp/bench/ann/src/raft/raft_ann_mg_cagra.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024, 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 "raft_ann_mg_cagra_wrapper.hpp"

#include <raft/comms/std_comms.hpp>
#include <raft/neighbors/ann_mg_helpers.cuh>

namespace raft::bench::ann {

template class RaftAnnMG_Cagra<float, uint32_t>;
template class RaftAnnMG_Cagra<uint8_t, uint32_t>;
template class RaftAnnMG_Cagra<int8_t, uint32_t>;

} // namespace raft::bench::ann
Loading
Loading