Skip to content

Commit

Permalink
Adding FAISS cpu to raft-ann-bench (#1814)
Browse files Browse the repository at this point in the history
Closes #1813

This PR adds FAISS CPU indexes to the raft-Ann-bench benchmarks, and adjusts the build accordingly. In addition, this PR also updated the FAISS version to include the RAFT-enabled version, which required removing the FAISS conda packages and building FAISS from source.

Authors:
  - Corey J. Nolet (https://github.com/cjnolet)
  - Robert Maynard (https://github.com/robertmaynard)
  - Dante Gama Dessavre (https://github.com/dantegd)

Approvers:
  - Divye Gala (https://github.com/divyegala)
  - Ray Douglass (https://github.com/raydouglass)

URL: #1814
  • Loading branch information
cjnolet authored Oct 10, 2023
1 parent 7561141 commit 99ed345
Show file tree
Hide file tree
Showing 41 changed files with 1,484 additions and 800 deletions.
3 changes: 1 addition & 2 deletions conda/environments/bench_ann_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dependencies:
- cudatoolkit
- cxx-compiler
- cython>=3.0.0
- faiss-proc=*=cuda
- gcc_linux-64=11.*
- glog>=0.6.0
- h5py>=3.8.0
Expand All @@ -30,12 +29,12 @@ dependencies:
- libcusolver=11.4.1.48
- libcusparse-dev=11.7.5.86
- libcusparse=11.7.5.86
- libfaiss>=1.7.1
- matplotlib
- nccl>=2.9.9
- ninja
- nlohmann_json>=3.11.2
- nvcc_linux-64=11.8
- openblas
- pandas
- pyyaml
- rmm==23.12.*
Expand Down
2 changes: 1 addition & 1 deletion conda/recipes/libraft/build_libraft.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
# Copyright (c) 2022-2023, NVIDIA CORPORATION.

./build.sh libraft -v --allgpuarch --compile-lib --build-metrics=compile_lib --incl-cache-stats --no-nvtx
./build.sh libraft --allgpuarch --compile-lib --build-metrics=compile_lib --incl-cache-stats --no-nvtx
2 changes: 1 addition & 1 deletion conda/recipes/libraft/build_libraft_headers.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
# Copyright (c) 2022-2023, NVIDIA CORPORATION.

./build.sh libraft -v --allgpuarch --no-nvtx
./build.sh libraft --allgpuarch --no-nvtx
2 changes: 1 addition & 1 deletion conda/recipes/libraft/build_libraft_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Copyright (c) 2022-2023, NVIDIA CORPORATION.

# Just building template so we verify it uses libraft.so and fail if it doesn't build
./build.sh template -v
./build.sh template
2 changes: 1 addition & 1 deletion conda/recipes/libraft/build_libraft_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Copyright (c) 2022-2023, NVIDIA CORPORATION.

./build.sh tests bench-prims -v --allgpuarch --no-nvtx --build-metrics=tests_bench_prims --incl-cache-stats
./build.sh tests bench-prims --allgpuarch --no-nvtx --build-metrics=tests_bench_prims --incl-cache-stats
cmake --install cpp/build --component testing
3 changes: 1 addition & 2 deletions conda/recipes/raft-ann-bench-cpu/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ requirements:
- pyyaml
- pandas
- benchmark

about:
home: https://rapids.ai/
license: Apache-2.0
summary: libraft ann bench
summary: RAFT ANN CPU benchmarks
2 changes: 1 addition & 1 deletion conda/recipes/raft-ann-bench/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Copyright (c) 2023, NVIDIA CORPORATION.

./build.sh bench-ann -v --allgpuarch --no-nvtx --build-metrics=bench_ann --incl-cache-stats
./build.sh bench-ann --allgpuarch --no-nvtx --build-metrics=bench_ann --incl-cache-stats
cmake --install cpp/build --component ann_bench
3 changes: 0 additions & 3 deletions conda/recipes/raft-ann-bench/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ gtest_version:
glog_version:
- ">=0.6.0"

faiss_version:
- ">=1.7.1"

h5py_version:
- ">=3.8.0"

Expand Down
10 changes: 0 additions & 10 deletions conda/recipes/raft-ann-bench/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ requirements:
{% endif %}
- glog {{ glog_version }}
- nlohmann_json {{ nlohmann_json_version }}
# Temporarily ignore faiss benchmarks on CUDA 12 because packages do not exist yet
{% if cuda_major == "11" %}
- faiss-proc=*=cuda
- libfaiss {{ faiss_version }}
{% endif %}
- h5py {{ h5py_version }}
- benchmark
- matplotlib
Expand All @@ -92,11 +87,6 @@ requirements:
- cudatoolkit
{% endif %}
- glog {{ glog_version }}
# Temporarily ignore faiss benchmarks on CUDA 12 because packages do not exist yet
{% if cuda_major == "11" %}
- faiss-proc=*=cuda
- libfaiss {{ faiss_version }}
{% endif %}
- h5py {{ h5py_version }}
- benchmark
- glog {{ glog_version }}
Expand Down
112 changes: 92 additions & 20 deletions cpp/bench/ann/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
# ##################################################################################################
# * benchmark options ------------------------------------------------------------------------------

option(RAFT_ANN_BENCH_USE_FAISS_BFKNN "Include faiss' brute-force knn algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_USE_FAISS_IVF_FLAT "Include faiss' ivf flat algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_USE_FAISS_IVF_PQ "Include faiss' ivf pq algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_USE_FAISS_GPU_FLAT "Include faiss' brute-force knn algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_USE_FAISS_GPU_IVF_FLAT "Include faiss' ivf flat algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_USE_FAISS_GPU_IVF_PQ "Include faiss' ivf pq algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_USE_FAISS_CPU_FLAT
"Include faiss' cpu brute-force knn algorithm in benchmark" ON
)
option(RAFT_ANN_BENCH_USE_FAISS_CPU_FLAT "Include faiss' cpu brute-force algorithm in benchmark" ON)

option(RAFT_ANN_BENCH_USE_FAISS_CPU_IVF_FLAT "Include faiss' cpu ivf flat algorithm in benchmark"
ON
)
option(RAFT_ANN_BENCH_USE_FAISS_CPU_IVF_PQ "Include faiss' cpu ivf pq algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_USE_RAFT_IVF_FLAT "Include raft's ivf flat algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_USE_RAFT_IVF_PQ "Include raft's ivf pq algorithm in benchmark" ON)
option(RAFT_ANN_BENCH_USE_RAFT_CAGRA "Include raft's CAGRA in benchmark" ON)
Expand All @@ -33,9 +42,15 @@ option(RAFT_ANN_BENCH_SINGLE_EXE
find_package(Threads REQUIRED)

if(BUILD_CPU_ONLY)
set(RAFT_ANN_BENCH_USE_FAISS_BFKNN OFF)
set(RAFT_ANN_BENCH_USE_FAISS_IVF_FLAT OFF)
set(RAFT_ANN_BENCH_USE_FAISS_IVF_PQ OFF)

# Include necessary logging dependencies
include(cmake/thirdparty/get_fmt.cmake)
include(cmake/thirdparty/get_spdlog.cmake)

set(RAFT_FAISS_ENABLE_GPU OFF)
set(RAFT_ANN_BENCH_USE_FAISS_GPU_FLAT OFF)
set(RAFT_ANN_BENCH_USE_FAISS_GPU_IVF_FLAT OFF)
set(RAFT_ANN_BENCH_USE_FAISS_GPU_IVF_PQ OFF)
set(RAFT_ANN_BENCH_USE_RAFT_IVF_FLAT OFF)
set(RAFT_ANN_BENCH_USE_RAFT_IVF_PQ OFF)
set(RAFT_ANN_BENCH_USE_RAFT_CAGRA OFF)
Expand All @@ -44,22 +59,33 @@ else()
# Disable faiss benchmarks on CUDA 12 since faiss is not yet CUDA 12-enabled.
# https://github.com/rapidsai/raft/issues/1627
if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL 12.0.0)
set(RAFT_ANN_BENCH_USE_FAISS_BFKNN OFF)
set(RAFT_ANN_BENCH_USE_FAISS_IVF_FLAT OFF)
set(RAFT_ANN_BENCH_USE_FAISS_IVF_PQ OFF)
set(RAFT_FAISS_ENABLE_GPU OFF)
set(RAFT_ANN_BENCH_USE_FAISS_GPU_FLAT OFF)
set(RAFT_ANN_BENCH_USE_FAISS_GPU_IVF_FLAT OFF)
set(RAFT_ANN_BENCH_USE_FAISS_GPU_IVF_PQ OFF)
set(RAFT_ANN_BENCH_USE_FAISS_CPU_FLAT OFF)
set(RAFT_ANN_BENCH_USE_FAISS_CPU_IVF_PQ OFF)
set(RAFT_ANN_BENCH_USE_FAISS_CPU_IVF_FLAT OFF)
else()
set(RAFT_FAISS_ENABLE_GPU ON)
endif()
endif()

set(RAFT_ANN_BENCH_USE_FAISS OFF)
if(RAFT_ANN_BENCH_USE_FAISS_BFKNN
OR RAFT_ANN_BENCH_USE_FAISS_IVFPQ
OR RAFT_ANN_BENCH_USE_FAISS_IFFLAT
if(RAFT_ANN_BENCH_USE_FAISS_GPU_FLAT
OR RAFT_ANN_BENCH_USE_FAISS_GPU_IVF_PQ
OR RAFT_ANN_BENCH_USE_FAISS_GPU_IVF_FLAT
OR RAFT_ANN_BENCH_USE_FAISS_CPU_FLAT
OR RAFT_ANN_BENCH_USE_FAISS_CPU_IVF_PQ
OR RAFT_ANN_BENCH_USE_FAISS_CPU_IVF_FLAT
)
set(RAFT_ANN_BENCH_USE_FAISS ON)
set(RAFT_USE_FAISS_STATIC ON)
endif()

set(RAFT_ANN_BENCH_USE_RAFT OFF)
if(RAFT_ANN_BENCH_USE_RAFT_IVF_PQ
OR RAFT_ANN_BENCH_USE_RAFT_BRUTE_FORCE
OR RAFT_ANN_BENCH_USE_RAFT_IVF_FLAT
OR RAFT_ANN_BENCH_USE_RAFT_CAGRA
)
Expand All @@ -80,6 +106,12 @@ if(RAFT_ANN_BENCH_USE_GGNN)
endif()

if(RAFT_ANN_BENCH_USE_FAISS)
# We need to ensure that faiss has all the conda
# information. So we currently use the very ugly
# hammer of `link_libraries` to ensure that all
# targets in this directory and the faiss directory
# will have the conda includes/link dirs
link_libraries($<TARGET_NAME_IF_EXISTS:conda_env>)
include(cmake/thirdparty/get_faiss.cmake)
endif()

Expand Down Expand Up @@ -116,14 +148,15 @@ function(ConfigureAnnBench)
${BENCH_NAME}
PRIVATE raft::raft
nlohmann_json::nlohmann_json
$<$<BOOL:${GPU_BUILD}>:$<$<BOOL:${RAFT_ANN_BENCH_USE_MULTIGPU}>:NCCL::NCCL>>
${ConfigureAnnBench_LINKS}
Threads::Threads
$<$<BOOL:${GPU_BUILD}>:${RAFT_CTK_MATH_DEPENDENCIES}>
$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_CXX>
$<TARGET_NAME_IF_EXISTS:conda_env>
-static-libgcc
-static-libstdc++
$<$<BOOL:${BUILD_CPU_ONLY}>:fmt::fmt-header-only>
$<$<BOOL:${BUILD_CPU_ONLY}>:spdlog::spdlog_header_only>
)

set_target_properties(
Expand Down Expand Up @@ -201,6 +234,12 @@ if(RAFT_ANN_BENCH_USE_RAFT_IVF_FLAT)
)
endif()

if(RAFT_ANN_BENCH_USE_RAFT_BRUTE_FORCE)
ConfigureAnnBench(
NAME RAFT_BRUTE_FORCE PATH bench/ann/src/raft/raft_benchmark.cu LINKS raft::compiled
)
endif()

if(RAFT_ANN_BENCH_USE_RAFT_CAGRA)
ConfigureAnnBench(
NAME
Expand All @@ -213,20 +252,52 @@ if(RAFT_ANN_BENCH_USE_RAFT_CAGRA)
)
endif()

if(RAFT_ANN_BENCH_USE_FAISS_IVF_FLAT)
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)
ConfigureAnnBench(
NAME FAISS_CPU_FLAT PATH bench/ann/src/faiss/faiss_cpu_benchmark.cpp LINKS
${RAFT_FAISS_TARGETS}
)
endif()

if(RAFT_ANN_BENCH_USE_FAISS_CPU_IVF_FLAT)
ConfigureAnnBench(
NAME FAISS_CPU_IVF_FLAT PATH bench/ann/src/faiss/faiss_cpu_benchmark.cpp LINKS
${RAFT_FAISS_TARGETS}
)
endif()

if(RAFT_ANN_BENCH_USE_FAISS_CPU_IVF_PQ)
ConfigureAnnBench(
NAME FAISS_IVF_FLAT PATH bench/ann/src/faiss/faiss_benchmark.cu LINKS faiss::faiss
NAME FAISS_CPU_IVF_PQ PATH bench/ann/src/faiss/faiss_cpu_benchmark.cpp LINKS
${RAFT_FAISS_TARGETS}
)
endif()

if(RAFT_ANN_BENCH_USE_FAISS_IVF_PQ)
if(RAFT_ANN_BENCH_USE_FAISS_GPU_IVF_FLAT)
ConfigureAnnBench(
NAME FAISS_IVF_PQ PATH bench/ann/src/faiss/faiss_benchmark.cu LINKS faiss::faiss
NAME FAISS_GPU_IVF_FLAT PATH bench/ann/src/faiss/faiss_gpu_benchmark.cu LINKS
${RAFT_FAISS_TARGETS}
)
endif()

if(RAFT_ANN_BENCH_USE_FAISS_BFKNN)
ConfigureAnnBench(NAME FAISS_BFKNN PATH bench/ann/src/faiss/faiss_benchmark.cu LINKS faiss::faiss)
if(RAFT_ANN_BENCH_USE_FAISS_GPU_IVF_PQ)
ConfigureAnnBench(
NAME FAISS_GPU_IVF_PQ PATH bench/ann/src/faiss/faiss_gpu_benchmark.cu LINKS
${RAFT_FAISS_TARGETS}
)
endif()

if(RAFT_ANN_BENCH_USE_FAISS_GPU_FLAT)
ConfigureAnnBench(
NAME FAISS_GPU_FLAT PATH bench/ann/src/faiss/faiss_gpu_benchmark.cu LINKS ${RAFT_FAISS_TARGETS}
)
endif()

if(RAFT_ANN_BENCH_USE_GGNN)
Expand Down Expand Up @@ -277,7 +348,8 @@ if(RAFT_ANN_BENCH_SINGLE_EXE)
target_compile_definitions(
ANN_BENCH
PRIVATE
$<$<BOOL:${CUDAToolkit_FOUND}>:ANN_BENCH_LINK_CUDART="libcudart.so.${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}.${CUDAToolkit_VERSION_PATCH}">
$<$<BOOL:${CUDAToolkit_FOUND}>:ANN_BENCH_LINK_CUDART="libcudart.so.${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}.${CUDAToolkit_VERSION_PATCH}
">
$<$<BOOL:${NVTX3_HEADERS_FOUND}>:ANN_BENCH_NVTX3_HEADERS_FOUND>
)

Expand Down
Loading

0 comments on commit 99ed345

Please sign in to comment.