-
Notifications
You must be signed in to change notification settings - Fork 72
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
[FEA] support of prefiltered brute force #146
[FEA] support of prefiltered brute force #146
Conversation
rhdong
commented
May 22, 2024
- The PR is one part of prefiltered brute force and should work with the PR of raft: [FEA] support of prefiltered brute force raft#2294
cpp/src/neighbors/brute_force.cu
Outdated
#include <cuvs/neighbors/brute_force.hpp> | ||
|
||
#include <raft/core/bitset.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.
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.
The include of the bitmap.cuh should be where n_elements
is called, in cpp/src/neighbors/detail/knn_brute_force.cuh
.
This reverts commit 9fbca1a.
cpp/src/neighbors/brute_force.cu
Outdated
#include <cuvs/neighbors/brute_force.hpp> | ||
|
||
#include <raft/core/bitset.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.
The include of the bitmap.cuh should be where n_elements
is called, in cpp/src/neighbors/detail/knn_brute_force.cuh
.
@@ -25,6 +25,7 @@ | |||
#include <raft/util/cudart_utils.hpp> // get_device_for_address | |||
#include <raft/util/integer_utils.hpp> // rounding up | |||
|
|||
#include <cuvs/core/bitmap.hpp> |
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.
The bitset header is included here because the bitset struct prototype is being defined here. I don't see anything being defined for the bitmap here, though.
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.
Mainly for reducing the number of the include files in the cuvs/neighbors/brute_force.hpp
and other files need cuvs::core::bitmap_view
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 be including what we use and not relying on transitivity here. Ultimately, this creates a lot of confusion for future developers. If bitmap is being explicitly required in parts of the public APIs, it should be getting included there and not here. Also, why aren't we including the bitmap here, defining it here, and compiling it in src/ like bitset is doing?
cpp/src/neighbors/brute_force.cu
Outdated
if (!sample_filter.has_value()) { \ | ||
detail::brute_force_search<T, int64_t>(res, idx, queries, neighbors, distances); \ | ||
} else { \ | ||
detail::brute_force_search<T, int64_t>( \ |
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 was a little confused on the reasoning for this overload at first. Could we maybe name the second one brute_force_search_filtered
?
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.
Done
@@ -0,0 +1,96 @@ | |||
/* | |||
* Copyright (c) 2021-2024, NVIDIA CORPORATION. |
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.
Since this is a new file, please only use the 2024 year. I've missed this a couple of times in my PR, but best to fix it where it's noticed.
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.
Done
@@ -0,0 +1,95 @@ | |||
/* | |||
* Copyright (c) 2023-2024, NVIDIA CORPORATION. |
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.
Since this is a new file, please use only 2024 year.
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.
Done
auto filter_view = | ||
raft::make_device_vector_view<const BitmapT, IdxT>(filter.data(), filter.n_elements()); | ||
|
||
raft::detail::popc(res, filter_view, n_queries * n_dataset, nnz_view); |
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 never be calling into raft detail APIs in cuvs.
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.
Totally agree! I've noticed this, but as you know, just for so tight schedule to split the raft internal calling to cuVS
(I suppose public API needs more regular test/benchmark code, at that time, I had to make it in first). I will fix it ASAP: #158
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.
Thanks for creating an issue for this. Can you please reference a link to the github issue in a comment on this line of code so we don't lose sight of it? Then we can merge this in.
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.
Sure!
raft::make_host_scalar_view<T>(&alpha), | ||
raft::make_host_scalar_view<T>(&beta)); | ||
} else { | ||
raft::sparse::distance::detail::faster_dot_on_csr(res, |
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 never be calling into RAFT detail APIs in cuvs. If you think about the reason why we separate public from details APIs, it's so that each library can put forth a contract that they make guarantees not to break across versions while still hosting internal implementation-specific code that makes no such guarantees. If we're invoking detail APIs from RAFT within cuVS then we're going to end up either 1) making breakig changes those detail APIs and not realizing we just broke cuVS downstream, or 2) never being able to make changes to detail APIs because they need to maintain the same guarantees as public APIs.
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.
This needs to be fixed, but RAFT is in code freeze. What I think you should do to fix this is to create a GIthub issue in cuVS to describe the issue, then add comments in all the places in this PR that you are calling into RAFT detail APIs and reference the Github issue there.
After you do that and address the other PR review feedback, we can merge this PR into 24.06 but you'll need to open up a RAFT PR to immediately expose all of these APIs publicly in RAFT and then open up a PR to invoke the public APIs in cuVS (target both to 24.08 since it's too late to make raft changes for 24.06).
Of course, if you've already exposed these APIs publicly in RAFT and calling into detail was just an oversight, then they could simply be fixed in this PR. The general rule of thumb for detail APIs even within a library is that you should expose any functions publicly if you are going to invoke them across namespace separate namespace boundaries. Obvously that's more simple to do for a header-only library like RAFT than it is for a library where all public APIs are strictly compiled like cuVS, but we should be striving to reduce the amount of inter-namespace calls into detail APIs as possible so we can maintain our public API contracts.
|
||
void random_array(value_t* array, size_t size) | ||
{ | ||
std::random_device rd; |
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.
please generate a raft::random::rectangular_rmat
for the bitmap. This is the only way we can test variable degree distributions, which is what we're likely to encounter in practice.
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.
Will be fixed in the next commit
|
||
brute_force::search(handle, dataset, queries, out_idx, out_val, std::make_optional(filter)); | ||
|
||
ASSERT_TRUE(cuvs::spatial::knn::devArrMatchKnnPair(out_idx_expected_d.data(), |
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.
raft::spatial::knn
is deprecated and I'd prefer to not to transfer that over to cuVS. Please rename this namespace to cuvs::neighbors
so it's consistent with all the other nearest neighbors stuff.
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.
Done
cpp/test/neighbors/knn_utils.cuh
Outdated
|
||
#include <memory> | ||
|
||
namespace cuvs::spatial::knn { |
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.
Please rename this to cuvs::neighbors
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.
Done
@rhdong this also needs to be exposed through the Python API. |
raft::make_host_scalar_view<T>(&alpha), | ||
raft::make_host_scalar_view<T>(&beta)); | ||
} else { | ||
raft::sparse::distance::detail::faster_dot_on_csr(res, |
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.
Thanks for creating an issue to fix this. Let's get this C++ side merged in. Can you please reference the github issue in a comment just abov ethis line of code so that we don't lose sight of it? Then we can get this merged in.
/merge |
- The PR is one part of prefiltered brute force and should work with the PR of raft: rapidsai/raft#2294 Authors: - rhdong (https://github.com/rhdong) Approvers: - Corey J. Nolet (https://github.com/cjnolet) URL: rapidsai/cuvs#146