-
Notifications
You must be signed in to change notification settings - Fork 232
Roaring Bitmap Filter in CAGRA #2446
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
Open
divyegala
wants to merge
10
commits into
NVIDIA:release/26.10
Choose a base branch
from
divyegala:roaring-filter
base: release/26.10
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f640677
Initial impl
divyegala 3a1f3ca
Merge branch 'main' of https://github.com/rapidsai/cuvs into roaring-…
divyegala 35f50f5
single batch upstream cuco
divyegala 5668d01
just single batch for now
divyegala 2637cf4
reduce surface area
divyegala db29ef9
Merge branch 'main' into roaring-filter
divyegala 1529d8f
Merge branch 'main' into roaring-filter
divyegala b7fcf78
address review
divyegala 90ec178
Merge branch 'roaring-filter' of github.com:divyegala/cuvs into roari…
divyegala 34904d7
Merge remote-tracking branch 'origin/release/26.10' into roaring-filter
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "packages" : { | ||
| "cuco" : { | ||
| "version": "0.0.1", | ||
| "git_url": "https://github.com/NVIDIA/cuCollections.git", | ||
| "git_tag": "9d7c9307395c3b8795d93ad65d0751c98471dde6" | ||
| } | ||
| } | ||
| } | ||
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,135 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cuvs/core/export.hpp> | ||
|
|
||
| #include <raft/core/device_mdspan.hpp> | ||
| #include <raft/core/host_mdspan.hpp> | ||
| #include <raft/core/resources.hpp> | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <memory> | ||
|
|
||
| namespace CUVS_EXPORT cuvs { | ||
| namespace core { | ||
|
|
||
| /** | ||
| * @brief Non-owning device view of one immutable Roaring allowlist. | ||
| * | ||
| * The view contains an opaque pointer to an already initialized device-side cuCollections | ||
| * reference plus immutable shape and cardinality metadata. Creating or copying it is O(1) and | ||
| * performs no allocation, parsing, kernel launch, or synchronization. The owning | ||
| * @ref roaring_allowlist must outlive the view and every operation that uses it. | ||
| */ | ||
| class CUVS_EXPORT roaring_allowlist_view { | ||
| public: | ||
| roaring_allowlist_view() = default; | ||
|
|
||
| [[nodiscard]] std::size_t dataset_rows() const noexcept { return dataset_rows_; } | ||
| [[nodiscard]] std::size_t cardinality() const noexcept { return cardinality_; } | ||
| [[nodiscard]] bool empty() const noexcept { return cardinality_ == 0; } | ||
| [[nodiscard]] bool valid() const noexcept { return valid_; } | ||
|
|
||
| /** @brief Opaque device pointer to the initialized cuCollections reference, or null if empty. */ | ||
| [[nodiscard]] void const* device_reference() const noexcept { return device_reference_; } | ||
|
|
||
| private: | ||
| friend class roaring_allowlist; | ||
|
|
||
| roaring_allowlist_view(void const* device_reference, | ||
| std::size_t dataset_rows, | ||
| std::size_t cardinality) noexcept | ||
| : device_reference_(device_reference), | ||
| dataset_rows_(dataset_rows), | ||
| cardinality_(cardinality), | ||
| valid_(true) | ||
| { | ||
| } | ||
|
|
||
| void const* device_reference_{}; | ||
| std::size_t dataset_rows_{}; | ||
| std::size_t cardinality_{}; | ||
| bool valid_{}; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Owning immutable exact Roaring allowlist over CAGRA dataset-row IDs. | ||
| * | ||
| * Build an allowlist through @ref from_ids, then pass its zero-copy @ref view to a | ||
| * cuvs::neighbors::filtering::roaring_filter. A filter maps one such view to each query; owners | ||
| * remain independent and can therefore be reused across filters and queries. | ||
| * | ||
| * Construction sorts IDs on the GPU unless @p pre_sorted is true. Setting @p pre_sorted promises | ||
| * that IDs are already in strictly increasing order; this promise is not verified. IDs must be | ||
| * unique and smaller than @p dataset_rows. The encoded bytes and the initialized | ||
| * cuco::experimental::roaring_bitmap_ref<uint32_t> are retained on the device. Creating a view | ||
| * never copies or reparses them, and CAGRA search performs no Roaring initialization. | ||
| * | ||
| * ID-based construction emits the standard portable 32-bit Roaring array and bitmap container | ||
| * forms. Each ID is partitioned by its high 16 bits; the low 16 bits are stored as an array for at | ||
| * most 4,096 values in a partition and as an 8 KiB bitmap otherwise. | ||
| * | ||
| * @see https://github.com/RoaringBitmap/RoaringFormatSpec | ||
| * @see https://github.com/NVIDIA/cuCollections/pull/839 | ||
| */ | ||
| class CUVS_EXPORT roaring_allowlist { | ||
| private: | ||
| struct impl; | ||
|
|
||
| public: | ||
| using key_type = std::uint32_t; | ||
|
|
||
| /** | ||
| * @brief Build one allowlist from host IDs. | ||
| * | ||
| * Host IDs are copied to the construction stream and then use the same device builder as the | ||
| * device overload. IDs must be smaller than dataset_rows; this precondition is not checked. | ||
| * Empty input is valid and rejects every candidate. | ||
| */ | ||
| static roaring_allowlist from_ids(raft::resources const& res, | ||
| std::size_t dataset_rows, | ||
| raft::host_vector_view<const key_type, std::int64_t> ids, | ||
| bool pre_sorted = false); | ||
|
|
||
| /** | ||
| * @brief Build one allowlist from device IDs. | ||
| * | ||
| * The input must remain valid until the construction stream reaches the enqueued work. IDs must | ||
| * be smaller than dataset_rows; this precondition is not checked. | ||
| * Temporary memory is O(cardinality + container count); no dataset-sized dense bitmap is used. | ||
| */ | ||
| static roaring_allowlist from_ids(raft::resources const& res, | ||
| std::size_t dataset_rows, | ||
| raft::device_vector_view<const key_type, std::int64_t> ids, | ||
| bool pre_sorted = false); | ||
|
|
||
| ~roaring_allowlist(); | ||
|
|
||
| roaring_allowlist(roaring_allowlist const&) = delete; | ||
| roaring_allowlist& operator=(roaring_allowlist const&) = delete; | ||
| roaring_allowlist(roaring_allowlist&&) noexcept; | ||
| roaring_allowlist& operator=(roaring_allowlist&&) noexcept; | ||
|
|
||
| [[nodiscard]] std::size_t dataset_rows() const noexcept; | ||
| [[nodiscard]] std::size_t cardinality() const noexcept; | ||
| [[nodiscard]] bool empty() const noexcept; | ||
|
|
||
| /** @brief Total device bytes retained by the encoded allowlist and initialized reference. */ | ||
| [[nodiscard]] std::size_t size_bytes() const noexcept; | ||
|
|
||
| /** @brief Return a zero-copy view. */ | ||
| [[nodiscard]] roaring_allowlist_view view() const noexcept; | ||
|
|
||
| private: | ||
| explicit roaring_allowlist(std::unique_ptr<impl> impl) noexcept; | ||
|
|
||
| std::unique_ptr<impl> impl_; | ||
| }; | ||
|
|
||
| } // namespace core | ||
| } // namespace CUVS_EXPORT cuvs |
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
Oops, something went wrong.
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.