-
Notifications
You must be signed in to change notification settings - Fork 228
libraft and pylibraft API for CAGRA build and HNSW search
#2022
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
Merged
rapids-bot
merged 42 commits into
rapidsai:branch-24.02
from
divyegala:cagra_hnswlib_pylibraft
Jan 26, 2024
Merged
Changes from 25 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
c60ae05
hnswlib serialize python API
divyegala 7f04f97
fix typo, refactor cython
divyegala 4b2b2c6
add cpp index and python load,search methods with runtime API
divyegala c62c8e3
Merge remote-tracking branch 'upstream/branch-24.02' into cagra_hnswl…
divyegala 92e5717
add static_assert guard for (u)int hnswlib serialize
divyegala 7f78851
passing float tests
divyegala 29f0774
fix docs
divyegala e2e1fc3
try to write in native dtype
divyegala b8a4c50
update mypy, solve error
divyegala e02a0e3
attempt to use rapids_cpm_find for hnswlib
divyegala 54106a1
rework to not expose hnswlib headers in runtime API
divyegala ebdce10
readd copyright check
divyegala c29313a
Merge remote-tracking branch 'upstream/branch-24.02' into cagra_hnswl…
divyegala 1da21e4
print binary dir
divyegala e5cd5f6
address review
divyegala 460bc98
address review, enable int8 in hnswlib
divyegala ce1108a
Merge remote-tracking branch 'upstream/branch-24.02' into cagra_hnswl…
divyegala fdc015f
missed template
divyegala 211ba39
fix docs
divyegala 466e141
move serialize back to cagra::
divyegala d3fad16
use unique_ptr for deserialization
divyegala e4e635f
add composite function from_cagra
divyegala ad0a25f
fix ann-bench compiler error
divyegala 397176e
update docs from review
divyegala 114d176
Merge branch 'branch-24.02' into cagra_hnswlib_pylibraft
cjnolet 691d254
Merge branch 'branch-24.02' into cagra_hnswlib_pylibraft
vyasr c30671b
Fix some style
vyasr 44c88e7
Get wheel builds to compile
vyasr 304ae7a
fix docs
divyegala d10bb4f
Export hnswlib dependency in raft
vyasr 1d8e804
fix doc again
divyegala 05bc41b
Merge remote-tracking branch 'origin/cagra_hnswlib_pylibraft' into ca…
divyegala 306de24
Merge branch 'branch-24.02' into cagra_hnswlib_pylibraft
divyegala ae543e7
Specify the hnswlib version in the export
vyasr ad05438
more doc fixes
divyegala d8a3e06
Merge branch 'cagra_hnswlib_pylibraft' of github.com:divyegala/raft i…
divyegala 94d08cd
hopefully final doc fix
divyegala 54bf32c
style fix
divyegala 8e8549b
Merge branch 'branch-24.02' into cagra_hnswlib_pylibraft
divyegala aa16015
merging upstream
divyegala e62d3bc
Merge remote-tracking branch 'origin/cagra_hnswlib_pylibraft' into ca…
divyegala 1897cf7
pre commit fixes
divyegala 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,82 @@ | ||
| /* | ||
| * Copyright (c) 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. | ||
| * 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "hnsw_types.hpp" | ||
|
|
||
| #include <cstdint> | ||
| #include <raft/core/host_mdspan.hpp> | ||
| #include <raft/core/resources.hpp> | ||
|
|
||
| #include <omp.h> | ||
|
|
||
| #include <hnswlib.h> | ||
|
|
||
| namespace raft::neighbors::hnsw::detail { | ||
|
|
||
| template <typename T> | ||
| void get_search_knn_results(hnswlib::HierarchicalNSW<typename hnsw_dist_t<T>::type> const* idx, | ||
| const T* query, | ||
| int k, | ||
| uint64_t* indices, | ||
| float* distances) | ||
| { | ||
| auto result = idx->searchKnn(query, k); | ||
| assert(result.size() >= static_cast<size_t>(k)); | ||
|
|
||
| for (int i = k - 1; i >= 0; --i) { | ||
| indices[i] = result.top().second; | ||
| distances[i] = result.top().first; | ||
| result.pop(); | ||
| } | ||
| } | ||
|
|
||
| template <typename T> | ||
| void search(raft::resources const& res, | ||
| const search_params& params, | ||
| const index<T>& idx, | ||
| raft::host_matrix_view<const T, int64_t, row_major> queries, | ||
| raft::host_matrix_view<uint64_t, int64_t, row_major> neighbors, | ||
| raft::host_matrix_view<float, int64_t, row_major> distances) | ||
| { | ||
| auto const* hnswlib_index = | ||
| reinterpret_cast<hnswlib::HierarchicalNSW<typename hnsw_dist_t<T>::type> const*>( | ||
| idx.get_index()); | ||
|
|
||
| // when num_threads == 0, automatically maximize parallelism | ||
| if (params.num_threads) { | ||
| #pragma omp parallel for num_threads(params.num_threads) | ||
| for (int64_t i = 0; i < queries.extent(0); ++i) { | ||
| get_search_knn_results(hnswlib_index, | ||
| queries.data_handle() + i * queries.extent(1), | ||
| neighbors.extent(1), | ||
| neighbors.data_handle() + i * neighbors.extent(1), | ||
| distances.data_handle() + i * distances.extent(1)); | ||
| } | ||
| } else { | ||
| #pragma omp parallel for | ||
| for (int64_t i = 0; i < queries.extent(0); ++i) { | ||
| get_search_knn_results(hnswlib_index, | ||
| queries.data_handle() + i * queries.extent(1), | ||
| neighbors.extent(1), | ||
| neighbors.data_handle() + i * neighbors.extent(1), | ||
| distances.data_handle() + i * distances.extent(1)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } // namespace raft::neighbors::hnsw::detail |
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.
Uh oh!
There was an error while loading. Please reload this page.