Open
Conversation
divyegala
requested changes
Mar 9, 2026
Comment on lines
+514
to
+541
| @@ -532,6 +537,8 @@ class cluster_loader { | |||
| raft::copy(res, cluster_vectors, raft::make_const_mdspan(pinned_cluster)); | |||
| raft::resource::sync_stream(res, stream_); | |||
|
|
|||
| // reset stream back to previous value | |||
| raft::resource::set_cuda_stream(res, stream); | |||
Member
There was a problem hiding this comment.
You can create a new resources object for no cost:
Suggested change
| // For prefetching to overlap with other gpu work | |
| // we need to schedule copies on the provided copy stream stream_ | |
| auto copy_res = raft::resources(stream_); | |
| // htod | |
| auto h_cluster_ids = | |
| raft::make_pinned_vector_view<LabelT, int64_t>(cluster_ids_buf_.data_handle(), size); | |
| @@ -532,6 +537,8 @@ class cluster_loader { | |
| raft::copy(copy_res, cluster_vectors, raft::make_const_mdspan(pinned_cluster)); | |
| raft::resource::sync_stream(res, stream_); |
Contributor
There was a problem hiding this comment.
I vote on this too. Although not very relevant here, another benefit of creating a temporary resources handle is the automatic reset of the changes if an exception is raised. However, I'd like to warn that there are caveats in doing this:
- I'd suggest to use a copy the resources handle rather than creating a new resources handle to inherit all other initialized resources from the current handle.
auto copy_res = raft::resources(res);
raft::resource::set_cuda_stream(res, stream);- Even when you do a copy: if you've used any other not-yet-initialized resources from the
copy_reshandle, it would create those resources on every invocation ofprefetch_cluster, which would incur significant overhead.
Contributor
Author
There was a problem hiding this comment.
Thank you for the comments and info. I now copy the passed resources, set the stream, and use that for scheduling copies
1c03c6f to
22f74e7
Compare
divyegala
approved these changes
Mar 10, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Switching to usage of modern RAFT in cuVS (#1837) introduced a bug where the prefetched gather for AVQ is performed using the stream associated with raft::device_resources rather than the provided stream for copying. This led to two issues:
This PR sets the stream associated with the resource to the copy stream before prefetching, and back when done.