Skip to content

[FEA] support of prefiltered brute force#146

Merged
rapids-bot[bot] merged 16 commits into
NVIDIA:branch-24.06from
rhdong:rhdong/prefiltered-bf
May 29, 2024
Merged

[FEA] support of prefiltered brute force#146
rapids-bot[bot] merged 16 commits into
NVIDIA:branch-24.06from
rhdong:rhdong/prefiltered-bf

Conversation

@rhdong

@rhdong rhdong commented May 22, 2024

Copy link
Copy Markdown
Contributor

@rhdong rhdong requested review from a team as code owners May 22, 2024 20:45
@rhdong rhdong requested review from benfred and cjnolet May 22, 2024 20:45
@rhdong rhdong added feature request New feature or request non-breaking Introduces a non-breaking change C++ labels May 22, 2024
Comment thread cpp/src/neighbors/brute_force.cu Outdated
#include <cuvs/core/bitmap.hpp>
#include <cuvs/neighbors/brute_force.hpp>

#include <raft/core/bitset.cuh>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cjnolet @benfred @lowener , I can't remove this inclusion, because it will cause a compilation issue of n_elements of bitset reference but redefinition. I appreciate if you have any idea better to process. Thank you guys!

Copy link
Copy Markdown
Contributor

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.

rhdong added 2 commits May 22, 2024 15:50
This reverts commit 9fbca1a.
Comment thread cpp/src/neighbors/brute_force.cu Outdated
#include <cuvs/core/bitmap.hpp>
#include <cuvs/neighbors/brute_force.hpp>

#include <raft/core/bitset.cuh>

Copy link
Copy Markdown
Contributor

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.

Comment thread cpp/src/neighbors/detail/knn_brute_force.cuh
@rhdong rhdong removed the C++ label May 24, 2024
#include <raft/util/cudart_utils.hpp> // get_device_for_address
#include <raft/util/integer_utils.hpp> // rounding up

#include <cuvs/core/bitmap.hpp>

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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?

Comment thread 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>( \

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread cpp/src/neighbors/detail/knn_utils.cuh Outdated
@@ -0,0 +1,96 @@
/*
* Copyright (c) 2021-2024, NVIDIA CORPORATION.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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);

Copy link
Copy Markdown
Contributor

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.

@rhdong rhdong May 26, 2024

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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,

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

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;

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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(),

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread cpp/test/neighbors/knn_utils.cuh Outdated

#include <memory>

namespace cuvs::spatial::knn {

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@cjnolet

cjnolet commented May 24, 2024

Copy link
Copy Markdown
Contributor

@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,

Copy link
Copy Markdown
Contributor

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.

@cjnolet

cjnolet commented May 29, 2024

Copy link
Copy Markdown
Contributor

/merge

@rapids-bot rapids-bot Bot merged commit c533fe3 into NVIDIA:branch-24.06 May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CMake cpp feature request New feature or request non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants