Skip to content

Commit

Permalink
ANN_BENCH (#130)
Browse files Browse the repository at this point in the history
Porting the ANN benchmarks from RAFT.
- [x] Make it build

Sanity check that benchmarks work (runs and gives reasonable recall for Deep-1M dataset)
- [x] cuVS brute force kNN 
- [x] cuVS IVF-Flat
- [x] cuVS IVF-PQ (+ refinement)
- [x] cuVS CAGRA
- [x] cuVS CAGRA-Q (+refinement)
- [x] Faiss GPU/CPU IVF-Flat & IVF-PQ
- [x] HNSW
- [x] CAGRA + HNSW 
- [x] GGNN

NB: the indices built using the old ANN_BENCH in raft tend to crash in cuvs search benchmarks during index deserialization - don't forget to build the indexes anew when testing.

Authors:
  - Artem M. Chirkin (https://github.com/achirkin)
  - Malte Förster (https://github.com/mfoerste4)
  - Tamas Bela Feher (https://github.com/tfeher)
  - Micka (https://github.com/lowener)
  - Corey J. Nolet (https://github.com/cjnolet)

Approvers:
  - Tamas Bela Feher (https://github.com/tfeher)
  - James Lamb (https://github.com/jameslamb)
  - Corey J. Nolet (https://github.com/cjnolet)

URL: #130
  • Loading branch information
achirkin authored Jun 27, 2024
1 parent ebfd068 commit 064a23b
Show file tree
Hide file tree
Showing 52 changed files with 7,868 additions and 98 deletions.
29 changes: 27 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ ARGS=$*
# scripts, and that this script resides in the repo dir!
REPODIR=$(cd $(dirname $0); pwd)

VALIDARGS="clean libcuvs python rust docs tests examples --uninstall -v -g -n --compile-static-lib --allgpuarch --no-nvtx --show_depr_warn --incl-cache-stats --time -h"
HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<tool>] [--limit-tests=<targets>] [--build-metrics=<filename>]
VALIDARGS="clean libcuvs python rust docs tests bench-ann examples --uninstall -v -g -n --compile-static-lib --allgpuarch --no-nvtx --show_depr_warn --incl-cache-stats --time -h"
HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<tool>] [--limit-tests=<targets>] [--limit-bench-ann=<targets>] [--build-metrics=<filename>]
where <target> is:
clean - remove all existing build artifacts and configuration (start over)
libcuvs - build the cuvs C++ code only. Also builds the C-wrapper library
Expand All @@ -28,6 +28,7 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<to
rust - build the cuvs Rust bindings
docs - build the documentation
tests - build the tests
bench-ann - build end-to-end ann benchmarks
examples - build the examples
and <flag> is:
Expand All @@ -37,6 +38,7 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<to
--uninstall - uninstall files for specified targets which were built and installed prior
--compile-static-lib - compile static library for all components
--limit-tests - semicolon-separated list of test executables to compile (e.g. NEIGHBORS_TEST;CLUSTER_TEST)
--limit-bench-ann - semicolon-separated list of ann benchmark executables to compute (e.g. HNSWLIB_ANN_BENCH;RAFT_IVF_PQ_ANN_BENCH)
--allgpuarch - build for all supported GPU architectures
--no-nvtx - disable nvtx (profiling markers), but allow enabling it in downstream projects
--show_depr_warn - show cmake deprecation warnings
Expand Down Expand Up @@ -70,6 +72,7 @@ BUILD_REPORT_METRICS=""
BUILD_REPORT_INCL_CACHE_STATS=OFF

TEST_TARGETS="NEIGHBORS_ANN_CAGRA_TEST"
ANN_BENCH_TARGETS="CUVS_ANN_BENCH_ALL"

CACHE_ARGS=""
NVTX=ON
Expand Down Expand Up @@ -150,6 +153,21 @@ function limitTests {
fi
}

function limitAnnBench {
# Check for option to limit the set of test binaries to build
if [[ -n $(echo $ARGS | { grep -E "\-\-limit\-bench-ann" || true; } ) ]]; then
# There are possible weird edge cases that may cause this regex filter to output nothing and fail silently
# the true pipe will catch any weird edge cases that may happen and will cause the program to fall back
# on the invalid option error
LIMIT_ANN_BENCH_TARGETS=$(echo $ARGS | sed -e 's/.*--limit-bench-ann=//' -e 's/ .*//')
if [[ -n ${LIMIT_ANN_BENCH_TARGETS} ]]; then
# Remove the full LIMIT_TEST_TARGETS argument from list of args so that it passes validArgs function
ARGS=${ARGS//--limit-bench-ann=$LIMIT_ANN_BENCH_TARGETS/}
ANN_BENCH_TARGETS=${LIMIT_ANN_BENCH_TARGETS}
fi
fi
}

function buildMetrics {
# Check for multiple build-metrics options
if [[ $(echo $ARGS | { grep -Eo "\-\-build\-metrics" || true; } | wc -l ) -gt 1 ]]; then
Expand Down Expand Up @@ -179,6 +197,7 @@ if (( ${NUMARGS} != 0 )); then
cmakeArgs
cacheTool
limitTests
limitAnnBench
buildMetrics
for a in ${ARGS}; do
if ! (echo " ${VALIDARGS} " | grep -q " ${a} "); then
Expand Down Expand Up @@ -255,6 +274,11 @@ if hasArg tests || (( ${NUMARGS} == 0 )); then
fi
fi

if hasArg bench-ann || (( ${NUMARGS} == 0 )); then
BUILD_ANN_BENCH=ON
CMAKE_TARGET="${CMAKE_TARGET};${ANN_BENCH_TARGETS}"
fi

if hasArg --no-nvtx; then
NVTX=OFF
fi
Expand Down Expand Up @@ -327,6 +351,7 @@ if (( ${NUMARGS} == 0 )) || hasArg libcuvs || hasArg docs || hasArg tests || has
-DDISABLE_DEPRECATION_WARNINGS=${DISABLE_DEPRECATION_WARNINGS} \
-DBUILD_TESTS=${BUILD_TESTS} \
-DBUILD_C_TESTS=${BUILD_TESTS} \
-DBUILD_ANN_BENCH=${BUILD_ANN_BENCH} \
-DBUILD_CPU_ONLY=${BUILD_CPU_ONLY} \
-DCMAKE_MESSAGE_LOG_LEVEL=${CMAKE_LOG_LEVEL} \
${CACHE_ARGS} \
Expand Down
1 change: 1 addition & 0 deletions conda/environments/all_cuda-118_arch-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies:
- numpy>=1.23,<2.0a0
- numpydoc
- nvcc_linux-aarch64=11.8
- openblas
- pre-commit
- pydata-sphinx-theme
- pylibraft==24.8.*,>=0.0.0a0
Expand Down
1 change: 1 addition & 0 deletions conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies:
- numpy>=1.23,<2.0a0
- numpydoc
- nvcc_linux-64=11.8
- openblas
- pre-commit
- pydata-sphinx-theme
- pylibraft==24.8.*,>=0.0.0a0
Expand Down
1 change: 1 addition & 0 deletions conda/environments/all_cuda-122_arch-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies:
- ninja
- numpy>=1.23,<2.0a0
- numpydoc
- openblas
- pre-commit
- pydata-sphinx-theme
- pylibraft==24.8.*,>=0.0.0a0
Expand Down
1 change: 1 addition & 0 deletions conda/environments/all_cuda-122_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies:
- ninja
- numpy>=1.23,<2.0a0
- numpydoc
- openblas
- pre-commit
- pydata-sphinx-theme
- pylibraft==24.8.*,>=0.0.0a0
Expand Down
2 changes: 1 addition & 1 deletion conda/recipes/libcuvs/build_libcuvs_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Copyright (c) 2022-2024, NVIDIA CORPORATION.

./build.sh tests --allgpuarch --no-nvtx --build-metrics=tests_bench --incl-cache-stats
./build.sh tests bench-ann --allgpuarch --no-nvtx --build-metrics=tests_bench --incl-cache-stats
cmake --install cpp/build --component testing
1 change: 1 addition & 0 deletions conda/recipes/libcuvs/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ outputs:
- libraft ={{ minor_version }}
- {{ pin_subpackage('libcuvs', exact=True) }}
- cuda-version ={{ cuda_version }}
- openblas # required by some CPU algos in benchmarks
{% if cuda_major == "11" %}
- cuda-profiler-api {{ cuda11_cuda_profiler_api_run_version }}
- libcublas {{ cuda11_libcublas_host_version }}
Expand Down
14 changes: 14 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ option(BUILD_SHARED_LIBS "Build cuvs shared libraries" ON)
option(BUILD_TESTS "Build cuvs unit-tests" ON)
option(BUILD_C_LIBRARY "Build raft C API library" OFF)
option(BUILD_C_TESTS "Build raft C API tests" OFF)
option(BUILD_ANN_BENCH "Build cuVS ann benchmarks" OFF)
option(CUDA_ENABLE_KERNELINFO "Enable kernel resource usage info" OFF)
option(CUDA_ENABLE_LINEINFO
"Enable the -lineinfo option for nvcc (useful for cuda-memcheck / profiler)" OFF
Expand Down Expand Up @@ -92,6 +93,7 @@ include(CMakeDependentOption)

message(VERBOSE "cuVS: Build cuVS unit-tests: ${BUILD_TESTS}")
message(VERBOSE "cuVS: Build CPU only components: ${BUILD_CPU_ONLY}")
message(VERBOSE "cuVS: Build ANN benchmarks: ${BUILD_ANN_BENCH}")
message(VERBOSE "cuVS: Enable detection of conda environment for dependencies: ${DETECT_CONDA_ENV}")
message(VERBOSE "cuVS: Disable depreaction warnings " ${DISABLE_DEPRECATION_WARNINGS})
message(VERBOSE "cuVS: Disable OpenMP: ${DISABLE_OPENMP}")
Expand Down Expand Up @@ -184,6 +186,11 @@ endif()

include(cmake/thirdparty/get_cutlass.cmake)

if(BUILD_ANN_BENCH)
include(${rapids-cmake-dir}/cpm/gbench.cmake)
rapids_cpm_gbench(BUILD_STATIC)
endif()

# ##################################################################################################
# * cuvs ---------------------------------------------------------------------

Expand Down Expand Up @@ -663,3 +670,10 @@ if(BUILD_TESTS OR BUILD_C_TESTS)
include(internal/CMakeLists.txt)
include(test/CMakeLists.txt)
endif()

# ##################################################################################################
# * build ann benchmark executable -----------------------------------------------

if(BUILD_ANN_BENCH)
include(bench/ann/CMakeLists.txt)
endif()
Loading

0 comments on commit 064a23b

Please sign in to comment.