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

Replace faiss bfKnn #1202

Merged
merged 92 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
57cfa20
Replace faiss bfKnn
benfred Jan 27, 2023
984c641
Merge branch 'branch-23.02' into bfknn
benfred Jan 27, 2023
805abc7
fix merge
benfred Jan 27, 2023
3e21478
Merge branch 'branch-23.02' into bfknn
cjnolet Jan 27, 2023
74bd44f
Fix bug with col_tiles < K
benfred Jan 27, 2023
c69054d
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred Jan 27, 2023
1d9581b
Include metric_arg in bfknn
benfred Jan 30, 2023
b4cf88c
speedup compile times
benfred Jan 30, 2023
98ffb70
Merge branch 'branch-23.02' into bfknn
benfred Jan 31, 2023
5442d31
Suggestions from code review
benfred Jan 31, 2023
0f5d206
fixes
benfred Jan 31, 2023
cb2b750
Merge branch 'branch-23.04' into bfknn
benfred Feb 3, 2023
e870eb3
use pairwise_distance specialization to speed up compile times
benfred Feb 7, 2023
cd84397
Merge branch 'branch-23.04' into bfknn
benfred Feb 7, 2023
8445aed
Use distance specializations
benfred Feb 7, 2023
e87633a
Merge branch 'branch-23.04' into bfknn
cjnolet Feb 9, 2023
52bf729
Merge branch 'branch-23.04' into bfknn
benfred Feb 11, 2023
d97ddb8
Merge branch 'branch-23.04' into bfknn
cjnolet Feb 11, 2023
5905b2d
use specializations in RBC code
benfred Feb 14, 2023
d905266
Merge branch 'branch-23.04' into bfknn
benfred Feb 14, 2023
8eaba84
use pw specializations in rbc
benfred Feb 14, 2023
fe728e9
use matrix::select_k in bfknn call
benfred Feb 14, 2023
96e05e1
expose bf detail specialization
benfred Feb 15, 2023
59060b2
Revert "use pw specializations in rbc"
benfred Feb 15, 2023
c734bac
Add tests for other metrics
benfred Feb 15, 2023
c65e4bb
Fix parameter order
benfred Feb 16, 2023
3830e53
Fix Lp distance
benfred Feb 17, 2023
3f0b9a7
Revert "use matrix::select_k in bfknn call"
benfred Feb 17, 2023
3900570
re-enable failing tests
benfred Feb 17, 2023
8e71915
fix cosine/innerproduct in bfknn
benfred Feb 17, 2023
f806bf6
Test JensenShannon distance
benfred Feb 17, 2023
3315dca
support k up to 2048 in faiss select
benfred Feb 18, 2023
1b6eda2
Merge remote-tracking branch 'origin/branch-23.04' into bfknn
benfred Feb 18, 2023
a83bef3
cmake format
benfred Feb 18, 2023
3b811a1
support k up to 2048 in faiss select
benfred Feb 18, 2023
9a19456
Merge branch 'branch-23.04' into faiss_largek
cjnolet Feb 18, 2023
c39dc65
style
benfred Feb 18, 2023
c60e17f
Merge branch 'faiss_largek' of github.com:benfred/raft into faiss_largek
benfred Feb 18, 2023
2752294
code review suggestions
benfred Feb 18, 2023
84f7a42
Merge remote-tracking branch 'bf/faiss_largek' into bfknn
benfred Feb 18, 2023
901b898
Merge branch 'branch-23.04' into bfknn
cjnolet Feb 20, 2023
1548a78
Remove ENABLE_NN_DEPENDENCIES option
benfred Feb 21, 2023
3fdc712
Merge branch 'branch-23.04' into bfknn
benfred Feb 21, 2023
31c9cf2
temporarily re-add faiss build targets
benfred Feb 21, 2023
f7fd6a7
couple more files to re-add faiss
benfred Feb 21, 2023
37d66d2
re-add faiss_mr
benfred Feb 22, 2023
a61c92f
explicitly include faiss_mr
benfred Feb 23, 2023
dbd31b2
Allow col_major input to bfknn
benfred Feb 24, 2023
fddecc3
fix faiss queryempty test
benfred Feb 24, 2023
4687144
exclude LP from fused
benfred Feb 27, 2023
bd3ff51
Merge branch 'branch-23.04' into bfknn
benfred Feb 27, 2023
06c8674
use metric processor for cosine/correlation
benfred Feb 27, 2023
b44d15c
exclude cosine
benfred Feb 28, 2023
5a582cd
Merge branch 'branch-23.04' into bfknn
benfred Mar 1, 2023
eb0271a
avoid l2expanded distance
benfred Mar 1, 2023
616455c
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred Mar 1, 2023
4c41c63
Expanded L2 Changes
benfred Mar 6, 2023
cdf1962
correct for small instabilities in l2sqrtexpanded distance
benfred Mar 7, 2023
6a1e2d8
warp divergence
benfred Mar 7, 2023
1e2817c
clamp to 0
benfred Mar 7, 2023
4b56fac
threshold
benfred Mar 7, 2023
4b41e2c
Transpose for fusedl2knn as well
benfred Mar 8, 2023
455c952
fix
benfred Mar 8, 2023
df46b65
Fix stream handling on col-major inputs
benfred Mar 8, 2023
97a3c01
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred Mar 8, 2023
105bc96
Merge branch 'branch-23.04' into bfknn
benfred Mar 9, 2023
2828c3b
Merge branch 'branch-23.04' into bfknn
benfred Mar 9, 2023
6e45267
Merge branch 'branch-23.04' into bfknn
benfred Mar 11, 2023
28ebeef
fix build for missing symbols
benfred Mar 13, 2023
9917324
Merge branch 'branch-23.04' into bfknn
cjnolet Mar 13, 2023
65d7725
code review feedback
benfred Mar 14, 2023
e41ff88
matrix::fill and linalg::map_offset
benfred Mar 14, 2023
5eb7d22
build fix
benfred Mar 14, 2023
e36d089
fix
benfred Mar 14, 2023
50e366f
Merge branch 'branch-23.04' into bfknn
benfred Mar 14, 2023
e8f9c55
move faiss_select into raft::neighbors namespace
benfred Mar 14, 2023
9f211a0
move knn_merge parts to its own file
benfred Mar 14, 2023
9cbac3c
Merge branch 'branch-23.04' into bfknn
cjnolet Mar 14, 2023
0667526
Merge remote-tracking branch 'origin/branch-23.04' into bfknn
benfred Mar 15, 2023
9593ae1
Use stream pool
benfred Mar 15, 2023
76d2b19
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred Mar 15, 2023
97753b0
use right handle for transpose
benfred Mar 15, 2023
a534538
set blas stream
benfred Mar 15, 2023
237b7e1
error handling
benfred Mar 15, 2023
07290bc
try to isolate stream failure
benfred Mar 16, 2023
2671a0e
Move transpose code out of loop
benfred Mar 16, 2023
7e0bb9b
fix
benfred Mar 16, 2023
b4c3284
try transpose inside streampool again
benfred Mar 16, 2023
92d82db
one more try with cublasSetStream
benfred Mar 17, 2023
c84e560
Merge branch 'branch-23.04' into bfknn
benfred Mar 17, 2023
21a1953
fix
benfred Mar 17, 2023
80fb76c
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred Mar 17, 2023
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
8 changes: 1 addition & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ARGS=$*
# script, and that this script resides in the repo dir!
REPODIR=$(cd $(dirname $0); pwd)

VALIDARGS="clean libraft pylibraft raft-dask docs tests bench clean --uninstall -v -g -n --compile-libs --compile-nn --compile-dist --allgpuarch --no-nvtx --show_depr_warn -h --buildfaiss --minimal-deps"
VALIDARGS="clean libraft pylibraft raft-dask docs tests bench clean --uninstall -v -g -n --compile-libs --compile-nn --compile-dist --allgpuarch --no-nvtx --show_depr_warn -h --minimal-deps"
HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<tool>] [--limit-tests=<targets>] [--limit-bench=<targets>]
where <target> is:
clean - remove all existing build artifacts and configuration (start over)
Expand All @@ -45,7 +45,6 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<to
--limit-tests - semicolon-separated list of test executables to compile (e.g. NEIGHBORS_TEST;CLUSTER_TEST)
--limit-bench - semicolon-separated list of benchmark executables to compute (e.g. NEIGHBORS_BENCH;CLUSTER_BENCH)
--allgpuarch - build for all supported GPU architectures
--buildfaiss - build faiss statically into raft
--no-nvtx - disable nvtx (profiling markers), but allow enabling it in downstream projects
--show_depr_warn - show cmake deprecation warnings
--cmake-args=\\\"<args>\\\" - pass arbitrary list of CMake configuration options (escape all quotes in argument)
Expand All @@ -68,7 +67,6 @@ BUILD_ALL_GPU_ARCH=0
BUILD_TESTS=OFF
BUILD_TYPE=Release
BUILD_BENCH=OFF
BUILD_STATIC_FAISS=OFF
COMPILE_LIBRARIES=OFF
COMPILE_NN_LIBRARY=OFF
COMPILE_DIST_LIBRARY=OFF
Expand Down Expand Up @@ -335,9 +333,6 @@ if hasArg bench || (( ${NUMARGS} == 0 )); then

fi

if hasArg --buildfaiss; then
BUILD_STATIC_FAISS=ON
fi
if hasArg --no-nvtx; then
NVTX=OFF
fi
Expand Down Expand Up @@ -407,7 +402,6 @@ if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || has
-DCMAKE_MESSAGE_LOG_LEVEL=${CMAKE_LOG_LEVEL} \
-DRAFT_COMPILE_NN_LIBRARY=${COMPILE_NN_LIBRARY} \
-DRAFT_COMPILE_DIST_LIBRARY=${COMPILE_DIST_LIBRARY} \
-DRAFT_USE_FAISS_STATIC=${BUILD_STATIC_FAISS} \
-DRAFT_ENABLE_thrust_DEPENDENCY=${ENABLE_thrust_DEPENDENCY} \
${CACHE_ARGS} \
${EXTRA_CMAKE_ARGS}
Expand Down
2 changes: 0 additions & 2 deletions conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dependencies:
- dask>=2022.12.0
- distributed>=2022.12.0
- doxygen>=1.8.20
- faiss-proc=*=cuda
- gcc_linux-64=9
- libcublas-dev=11.11.3.6
- libcublas=11.11.3.6
Expand All @@ -32,7 +31,6 @@ dependencies:
- libcusolver=11.4.1.48
- libcusparse-dev=11.7.5.86
- libcusparse=11.7.5.86
- libfaiss>=1.7.1=cuda*
- ninja
- pytest
- pytest-cov
Expand Down
3 changes: 0 additions & 3 deletions conda/recipes/libraft/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ nccl_version:
gtest_version:
- "=1.10.0"

libfaiss_version:
- "1.7.2 *_cuda"

# The CTK libraries below are missing from the conda-forge::cudatoolkit
# package. The "*_host_*" version specifiers correspond to `11.8` packages and the
# "*_run_*" version specifiers correspond to `11.x` packages.
Expand Down
6 changes: 1 addition & 5 deletions conda/recipes/libraft/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2022-2023, NVIDIA CORPORATION.

# Usage:
# conda build . -c conda-forge -c nvidia -c rapidsai
Expand Down Expand Up @@ -126,7 +126,6 @@ outputs:
host:
- {{ pin_subpackage('libraft-headers', exact=True) }}
- cuda-profiler-api {{ cuda_profiler_api_host_version }}
- faiss-proc=*=cuda
- lapack
- libcublas {{ libcublas_host_version }}
- libcublas-dev {{ libcublas_host_version }}
Expand All @@ -136,10 +135,7 @@ outputs:
- libcusolver-dev {{ libcusolver_host_version }}
- libcusparse {{ libcusparse_host_version }}
- libcusparse-dev {{ libcusparse_host_version }}
- libfaiss {{ libfaiss_version }}
run:
- faiss-proc=*=cuda
- libfaiss {{ libfaiss_version }}
- {{ pin_subpackage('libraft-headers', exact=True) }}
about:
home: https://rapids.ai/
Expand Down
28 changes: 6 additions & 22 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ option(
option(RAFT_COMPILE_DIST_LIBRARY "Enable building raft distant shared library instantiations"
${RAFT_COMPILE_LIBRARIES}
)
option(RAFT_ENABLE_NN_DEPENDENCIES "Search for raft::nn dependencies like faiss"
${RAFT_COMPILE_LIBRARIES}
)
option(RAFT_ENABLE_NN_DEPENDENCIES "Search for raft::nn dependencies" ${RAFT_COMPILE_LIBRARIES})

option(RAFT_ENABLE_thrust_DEPENDENCY "Enable Thrust dependency" ON)

Expand All @@ -83,16 +81,7 @@ if(BUILD_TESTS AND NOT RAFT_ENABLE_thrust_DEPENDENCY)
set(RAFT_ENABLE_thrust_DEPENDENCY ON)
endif()

option(RAFT_EXCLUDE_FAISS_FROM_ALL "Exclude FAISS targets from RAFT's 'all' target" ON)

include(CMakeDependentOption)
cmake_dependent_option(
RAFT_USE_FAISS_STATIC
"Build and statically link the FAISS library for nearest neighbors search on GPU"
ON
RAFT_COMPILE_LIBRARIES
OFF
)

message(VERBOSE "RAFT: Building optional components: ${raft_FIND_COMPONENTS}")
message(VERBOSE "RAFT: Build RAFT unit-tests: ${BUILD_TESTS}")
Expand Down Expand Up @@ -177,7 +166,6 @@ rapids_cpm_init()
# thrust before rmm/cuco so we get the right version of thrust/cub
include(cmake/thirdparty/get_thrust.cmake)
include(cmake/thirdparty/get_rmm.cmake)
include(cmake/thirdparty/get_faiss.cmake)
include(cmake/thirdparty/get_cutlass.cmake)

if(RAFT_ENABLE_cuco_DEPENDENCY)
Expand Down Expand Up @@ -303,7 +291,6 @@ if(RAFT_COMPILE_DIST_LIBRARY)
src/distance/distance/specializations/detail/chebyshev.cu
src/distance/distance/specializations/detail/correlation.cu
src/distance/distance/specializations/detail/cosine.cu
src/distance/distance/specializations/detail/cosine.cu
src/distance/distance/specializations/detail/hamming_unexpanded.cu
src/distance/distance/specializations/detail/hellinger_expanded.cu
src/distance/distance/specializations/detail/jensen_shannon_float_float_float_int.cu
Expand Down Expand Up @@ -427,7 +414,10 @@ if(RAFT_COMPILE_NN_LIBRARY)
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
src/nn/specializations/knn_long_float_int.cu
src/nn/specializations/knn_long_float_uint.cu
src/nn/specializations/knn_uint_float_int.cu
src/nn/specializations/knn_uint_float_uint.cu
)
set_target_properties(
raft_nn_lib
Expand All @@ -444,7 +434,7 @@ if(RAFT_COMPILE_NN_LIBRARY)

target_link_libraries(
raft_nn_lib
PUBLIC faiss::faiss raft::raft
PUBLIC raft::raft
PRIVATE nvidia::cutlass::cutlass
)
target_compile_options(
Expand Down Expand Up @@ -652,12 +642,6 @@ endif()

if(nn IN_LIST raft_FIND_COMPONENTS)
enable_language(CUDA)

if(TARGET faiss AND (NOT TARGET faiss::faiss))
add_library(faiss::faiss ALIAS faiss)
elseif(TARGET faiss::faiss AND (NOT TARGET faiss))
add_library(faiss ALIAS faiss::faiss)
endif()
endif()
]=]
)
Expand Down
2 changes: 1 addition & 1 deletion cpp/bench/distance/distance_common.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-2023, 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
89 changes: 0 additions & 89 deletions cpp/cmake/thirdparty/get_faiss.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion cpp/include/raft/matrix/detail/select_radix.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-2023, 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
56 changes: 0 additions & 56 deletions cpp/include/raft/spatial/knn/detail/common_faiss.h

This file was deleted.

52 changes: 52 additions & 0 deletions cpp/include/raft/spatial/knn/detail/faiss_select/DistanceUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file thirdparty/LICENSES/LICENSE.faiss
*/

#pragma once

namespace raft::spatial::knn::detail::faiss_select {
// If the inner size (dim) of the vectors is small, we want a larger query tile
// size, like 1024
inline void chooseTileSize(size_t numQueries,
size_t numCentroids,
size_t dim,
size_t elementSize,
size_t totalMem,
size_t& tileRows,
size_t& tileCols)
{
// The matrix multiplication should be large enough to be efficient, but if
// it is too large, we seem to lose efficiency as opposed to
// double-streaming. Each tile size here defines 1/2 of the memory use due
// to double streaming. We ignore available temporary memory, as that is
// adjusted independently by the user and can thus meet these requirements
// (or not). For <= 4 GB GPUs, prefer 512 MB of usage. For <= 8 GB GPUs,
// prefer 768 MB of usage. Otherwise, prefer 1 GB of usage.
size_t targetUsage = 0;

if (totalMem <= ((size_t)4) * 1024 * 1024 * 1024) {
targetUsage = 512 * 1024 * 1024;
} else if (totalMem <= ((size_t)8) * 1024 * 1024 * 1024) {
targetUsage = 768 * 1024 * 1024;
} else {
targetUsage = 1024 * 1024 * 1024;
}

targetUsage /= 2 * elementSize;

// 512 seems to be a batch size sweetspot for float32.
// If we are on float16, increase to 512.
// If the k size (vec dim) of the matrix multiplication is small (<= 32),
// increase to 1024.
size_t preferredTileRows = 512;
if (dim <= 32) { preferredTileRows = 1024; }

tileRows = std::min(preferredTileRows, numQueries);

// tileCols is the remainder size
tileCols = std::min(targetUsage / preferredTileRows, numCentroids);
}
} // namespace raft::spatial::knn::detail::faiss_select
Loading