Skip to content
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] Add support for bitmap_view & the API of bitmap_to_csr #2109

Merged
merged 30 commits into from
Mar 21, 2024

Conversation

rhdong
Copy link
Member

@rhdong rhdong commented Jan 23, 2024

Authors:

Approvers:

- This PR is one part of the Feature of [FEA] Pre-filtered brute-force KNN rapidsai#1969

Authors:
  - James Rong (https://github.com/rhdong)

Approvers:
  - Ben Frederickson (https://github.com/benfred)
  - Micka (https://github.com/lowener)
  - Corey J. Nolet (https://github.com/cjnolet)
@rhdong rhdong requested review from a team as code owners January 23, 2024 02:44
@rhdong rhdong added enhancement New feature or request 3 - Ready for Review feature request New feature or request non-breaking Non-breaking change and removed cpp CMake labels Jan 23, 2024
@rhdong rhdong requested review from benfred, cjnolet and lowener January 23, 2024 02:45
@rhdong rhdong changed the base branch from branch-24.02 to branch-24.04 January 25, 2024 21:58
Copy link
Contributor

@lowener lowener left a comment

Choose a reason for hiding this comment

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

bitmap_to_csr is allocating too much memory

cpp/include/raft/sparse/convert/csr.cuh Outdated Show resolved Hide resolved
cpp/include/raft/sparse/convert/csr.cuh Outdated Show resolved Hide resolved
cpp/include/raft/sparse/convert/detail/bitmap_to_csr.cuh Outdated Show resolved Hide resolved
@rhdong rhdong requested a review from lowener February 26, 2024 19:13
@rhdong rhdong requested a review from lowener March 5, 2024 22:17
@rhdong
Copy link
Member Author

rhdong commented Mar 5, 2024

Hi @lowener , thank you for your valuable review. I accepted all your review comments and modified the code. Please help review again when you feel convenient; thank you!

@rhdong
Copy link
Member Author

rhdong commented Mar 7, 2024

Hi @lowener, I accepted all your review comments(3rd round) and modified the code. Please help review again when you feel convenient; thank you!

@rhdong
Copy link
Member Author

rhdong commented Mar 11, 2024

Heloo @lowener, I accepted all your review comments(4th round) and modified the code. Please help review again when you feel convenient; thank you!

Comment on lines 163 to 166
// Ensure the HBM allocated for CSR values is sufficient to handle all non-zero bitmap bits.
// An assert will trigger if the allocated HBM is insufficient when `NDEBUG` isn't defined.
// Note: Assertion is active only if `NDEBUG` is undefined.
if (lane_id == 0) { assert(nnz < indptr[num_rows]); }
Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @cjnolet, as per Michael's recommendation, I'd like you to review it here. There is a trade-off for checking if the nnz of CSR is equal to the non-zero bits number of the bitmap. Option 1: checking outside the kernel by using the RAFT_EXPECTS, but we had to sync stream explicitly, which may potentially break the effort of end-users on building a pipeline to improve end-2-end performance with multi-stream in the complex industry scenarios; Option 2: use assert in the kernel and reuse the indptr[num_rows] as the non-zero bits number of bitmap, but this solution may disable by #define NDEBUG. The current implementation is Option 2. Thank you!

template <typename bitmap_t, typename index_t, typename value_t, typename nnz_t>
void bitmap_to_csr(raft::resources const& handle,
raft::core::bitmap_view<bitmap_t, index_t> bitmap,
raft::device_csr_matrix_view<value_t, index_t, index_t, nnz_t> csr)
Copy link
Member

Choose a reason for hiding this comment

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

Our sparse APIs discern between strucure owning and structure preserving. The former means that the nnz is not yet known when the user creates the object. The latter means that nnz is known upon creation and any processing functions do not have the freedom to change it. One of the reasons we discern between these two is so that upon invoking a function, the user knows whether the function is supposed to compute the sparsity in addition to populating the resulting non-zero weights/elements. It doesn't look like we make that distinction here, yet we are calculating and computing the sparsity in the implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does it mean we should calculate/get the nnz of bitmap and reallocate/allocate values by it for csr in the API?

auto bitmap =
raft::core::bitmap_view<bitmap_t, index_t>(bitmap_d.data(), params.n_rows, params.n_cols);

auto csr_view = raft::make_device_compressed_structure_view<index_t, index_t, index_t>(
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't have to know the sparsity of the CSR when we call bitmap_to_csr. To provide a good user experienc, we should accept a structure-owning CSR so we can count the number of nonzeros in the bitmap view for the user and then initialize the csr w/ the sparsity. Please see the device_sparsity_owning_csr_matrix_view and the initialize_sparsity method.

* @param[in] bitmap input raft::bitmap_view
* @param[out] csr output raft::device_csr_matrix_view
* @param[in] handle RAFT handle
* @param[in] bitmap input raft::bitmap_view
Copy link
Member

Choose a reason for hiding this comment

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

In and out are already specified on the param so we shouldn't need to duplicate those in the description. Can you please expand the descriptions, though? Instead of just "handle" and "raft::bitmap_view", it would be helpful to explain their purpose.

Also, please don't include "reference type" in the description. The caller doesn't have to care that it's a reference type. That's automatic when they pass in the argument.

Copy link
Member

@cjnolet cjnolet Mar 14, 2024

Choose a reason for hiding this comment

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

I think we should still be accepting device_structure_owning_csr_matrix here unless we intend to explicitly support both. If a user passes in a structure-preserving csr matrix, they will end up getting an error when you try to initialize the sparsity.

EDIT: Nevermind. I see where you are supporting both below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Make sense.

@rhdong rhdong requested a review from cjnolet March 16, 2024 05:04
@rhdong
Copy link
Member Author

rhdong commented Mar 16, 2024

Hey @cjnolet, I responded to all your comments, and all checks have been passed. Thank you!

@cjnolet
Copy link
Member

cjnolet commented Mar 21, 2024

/merge

@rapids-bot rapids-bot bot merged commit fd91efb into rapidsai:branch-24.04 Mar 21, 2024
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review CMake cpp enhancement New feature or request feature request New feature or request non-breaking Non-breaking change
Projects
Development

Successfully merging this pull request may close these issues.

3 participants