-
Notifications
You must be signed in to change notification settings - Fork 197
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
Replace faiss bfKnn #1202
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
57cfa20
Replace faiss bfKnn
benfred 984c641
Merge branch 'branch-23.02' into bfknn
benfred 805abc7
fix merge
benfred 3e21478
Merge branch 'branch-23.02' into bfknn
cjnolet 74bd44f
Fix bug with col_tiles < K
benfred c69054d
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred 1d9581b
Include metric_arg in bfknn
benfred b4cf88c
speedup compile times
benfred 98ffb70
Merge branch 'branch-23.02' into bfknn
benfred 5442d31
Suggestions from code review
benfred 0f5d206
fixes
benfred cb2b750
Merge branch 'branch-23.04' into bfknn
benfred e870eb3
use pairwise_distance specialization to speed up compile times
benfred cd84397
Merge branch 'branch-23.04' into bfknn
benfred 8445aed
Use distance specializations
benfred e87633a
Merge branch 'branch-23.04' into bfknn
cjnolet 52bf729
Merge branch 'branch-23.04' into bfknn
benfred d97ddb8
Merge branch 'branch-23.04' into bfknn
cjnolet 5905b2d
use specializations in RBC code
benfred d905266
Merge branch 'branch-23.04' into bfknn
benfred 8eaba84
use pw specializations in rbc
benfred fe728e9
use matrix::select_k in bfknn call
benfred 96e05e1
expose bf detail specialization
benfred 59060b2
Revert "use pw specializations in rbc"
benfred c734bac
Add tests for other metrics
benfred c65e4bb
Fix parameter order
benfred 3830e53
Fix Lp distance
benfred 3f0b9a7
Revert "use matrix::select_k in bfknn call"
benfred 3900570
re-enable failing tests
benfred 8e71915
fix cosine/innerproduct in bfknn
benfred f806bf6
Test JensenShannon distance
benfred 3315dca
support k up to 2048 in faiss select
benfred 1b6eda2
Merge remote-tracking branch 'origin/branch-23.04' into bfknn
benfred a83bef3
cmake format
benfred 3b811a1
support k up to 2048 in faiss select
benfred 9a19456
Merge branch 'branch-23.04' into faiss_largek
cjnolet c39dc65
style
benfred c60e17f
Merge branch 'faiss_largek' of github.com:benfred/raft into faiss_largek
benfred 2752294
code review suggestions
benfred 84f7a42
Merge remote-tracking branch 'bf/faiss_largek' into bfknn
benfred 901b898
Merge branch 'branch-23.04' into bfknn
cjnolet 1548a78
Remove ENABLE_NN_DEPENDENCIES option
benfred 3fdc712
Merge branch 'branch-23.04' into bfknn
benfred 31c9cf2
temporarily re-add faiss build targets
benfred f7fd6a7
couple more files to re-add faiss
benfred 37d66d2
re-add faiss_mr
benfred a61c92f
explicitly include faiss_mr
benfred dbd31b2
Allow col_major input to bfknn
benfred fddecc3
fix faiss queryempty test
benfred 4687144
exclude LP from fused
benfred bd3ff51
Merge branch 'branch-23.04' into bfknn
benfred 06c8674
use metric processor for cosine/correlation
benfred b44d15c
exclude cosine
benfred 5a582cd
Merge branch 'branch-23.04' into bfknn
benfred eb0271a
avoid l2expanded distance
benfred 616455c
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred 4c41c63
Expanded L2 Changes
benfred cdf1962
correct for small instabilities in l2sqrtexpanded distance
benfred 6a1e2d8
warp divergence
benfred 1e2817c
clamp to 0
benfred 4b56fac
threshold
benfred 4b41e2c
Transpose for fusedl2knn as well
benfred 455c952
fix
benfred df46b65
Fix stream handling on col-major inputs
benfred 97a3c01
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred 105bc96
Merge branch 'branch-23.04' into bfknn
benfred 2828c3b
Merge branch 'branch-23.04' into bfknn
benfred 6e45267
Merge branch 'branch-23.04' into bfknn
benfred 28ebeef
fix build for missing symbols
benfred 9917324
Merge branch 'branch-23.04' into bfknn
cjnolet 65d7725
code review feedback
benfred e41ff88
matrix::fill and linalg::map_offset
benfred 5eb7d22
build fix
benfred e36d089
fix
benfred 50e366f
Merge branch 'branch-23.04' into bfknn
benfred e8f9c55
move faiss_select into raft::neighbors namespace
benfred 9f211a0
move knn_merge parts to its own file
benfred 9cbac3c
Merge branch 'branch-23.04' into bfknn
cjnolet 0667526
Merge remote-tracking branch 'origin/branch-23.04' into bfknn
benfred 9593ae1
Use stream pool
benfred 76d2b19
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred 97753b0
use right handle for transpose
benfred a534538
set blas stream
benfred 237b7e1
error handling
benfred 07290bc
try to isolate stream failure
benfred 2671a0e
Move transpose code out of loop
benfred 7e0bb9b
fix
benfred b4c3284
try transpose inside streampool again
benfred 92d82db
one more try with cublasSetStream
benfred c84e560
Merge branch 'branch-23.04' into bfknn
benfred 21a1953
fix
benfred 80fb76c
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
cpp/include/raft/neighbors/detail/faiss_select/DistanceUtils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::neighbors::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::neighbors::detail::faiss_select |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make a note to eventually get these out of this file. These are k-selection specific helpers that really belong in
raft/matrix/select_k.cuh
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved these to neighbors/detail/knn_merge_parts.cuh for now -