Skip to content

Use cudaStream_t instead of cuda_stream_view in pylibcudf Cython#22368

Open
vyasr wants to merge 18 commits intorapidsai:mainfrom
vyasr:feat/cy_raw_cudastream
Open

Use cudaStream_t instead of cuda_stream_view in pylibcudf Cython#22368
vyasr wants to merge 18 commits intorapidsai:mainfrom
vyasr:feat/cy_raw_cudastream

Conversation

@vyasr
Copy link
Copy Markdown
Contributor

@vyasr vyasr commented May 4, 2026

Description

Contributes to rapidsai/rmm#2359

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@vyasr vyasr self-assigned this May 4, 2026
@vyasr vyasr requested a review from a team as a code owner May 4, 2026 20:04
@vyasr vyasr requested review from Matt711 and galipremsagar May 4, 2026 20:04
@vyasr vyasr added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels May 4, 2026
@github-actions github-actions Bot added Python Affects Python cuDF API. pylibcudf Issues specific to the pylibcudf package labels May 4, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python May 4, 2026
@vyasr vyasr force-pushed the feat/cy_raw_cudastream branch from 14dc2de to 4de0682 Compare May 4, 2026 20:07
@vyasr vyasr requested review from a team as code owners May 4, 2026 20:07
@github-actions github-actions Bot added libcudf Affects libcudf (C++/CUDA) code. CMake CMake build issue Java Affects Java cuDF API. cudf.pandas Issues specific to cudf.pandas cudf-polars Issues specific to cudf-polars labels May 4, 2026
@vyasr vyasr force-pushed the feat/cy_raw_cudastream branch from 4de0682 to 508f091 Compare May 4, 2026 20:09
@rapidsai rapidsai deleted a comment from copy-pr-bot Bot May 4, 2026
@vyasr vyasr removed request for a team, karthikeyann, msarahan and mythrocks May 4, 2026 20:10
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.

Just commenting here as a signpost, this file has actual C++ in it. Looks fine to me.

Comment on lines +53 to +55
if isinstance(stream, Stream):
return <Stream>stream
return Stream(stream) # Handles __cuda_stream__ protocol
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.

If there's something here that you think should be upstreamed (ha) to RMM, I'm open to it.

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.

Nah nothing worth upstreaming. We could simplify this code further by removing the second if and just delegating to the the Stream constructor, at which point we'd have the same semantics at the small extra cost of creating a new Stream object pointing to the same underlying cudaStream_t and owner. I don't think it really matters either way though.

@vyasr vyasr force-pushed the feat/cy_raw_cudastream branch from 51bc52f to db5faa4 Compare May 5, 2026 00:12
…nd stream test marker

- Fix self.stream -> self._stream in ChunkedParquetReader.read_chunk()
- Mark test_join_streams_type_error with uses_custom_stream to skip in
  stream-testing mode (uses protocol object with default stream pointer)
Copy link
Copy Markdown
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

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

Question: I note all the Stream stream parameters in the cpdef functions change to object stream. Is that actually a type change? If yes, should we update the typestubs appropriately?

Comment on lines +13 to +24
#include <cudf/detail/utilities/stream_pool.hpp>
#include <cudf/utilities/span.hpp>
#include <rmm/cuda_stream_view.hpp>
#include <vector>

void join_streams_wrapper(
cudf::host_span<cudaStream_t const> streams,
cudaStream_t stream
) {
std::vector<rmm::cuda_stream_view> stream_views(streams.begin(), streams.end());
cudf::detail::join_streams(stream_views, stream);
}
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.

Suggested change
#include <cudf/detail/utilities/stream_pool.hpp>
#include <cudf/utilities/span.hpp>
#include <rmm/cuda_stream_view.hpp>
#include <vector>
void join_streams_wrapper(
cudf::host_span<cudaStream_t const> streams,
cudaStream_t stream
) {
std::vector<rmm::cuda_stream_view> stream_views(streams.begin(), streams.end());
cudf::detail::join_streams(stream_views, stream);
}
#include <cudf/detail/utilities/stream_pool.hpp>
#include <cudf/utilities/span.hpp>
#include <rmm/cuda_stream_view.hpp>
#include <vector>
namespace {
void join_streams_wrapper(
cudf::host_span<cudaStream_t const> streams,
cudaStream_t stream
) {
std::vector<rmm::cuda_stream_view> stream_views(streams.begin(), streams.end());
cudf::detail::join_streams(stream_views, stream);
}
}

I think,

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.

@vyasr vyasr requested a review from wence- May 5, 2026 18:07
vyasr added 2 commits May 5, 2026 11:39
Introduce HasCudaStream Protocol and CudaStreamLike type alias in
utils.pyi to reflect that stream parameters now accept any object
implementing the __cuda_stream__ protocol, not just rmm Stream objects.

Update all .pyi files to use CudaStreamLike | None instead of
Stream | None for stream parameters.
@vyasr
Copy link
Copy Markdown
Contributor Author

vyasr commented May 5, 2026

Question: I note all the Stream stream parameters in the cpdef functions change to object stream. Is that actually a type change? If yes, should we update the typestubs appropriately?

Good call. Yes it is a meaningful change. I've added a new protocol for the type.

vyasr added 2 commits May 5, 2026 12:12
The pylibcudf join_streams stub now expects list[CudaStreamLike] due to
the __cuda_stream__ protocol support. Update join_cuda_streams and
get_joined_cuda_stream parameter types from Sequence[Stream] to
Sequence[CudaStreamLike] to satisfy mypy's list invariance check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CMake CMake build issue cudf.pandas Issues specific to cudf.pandas cudf-polars Issues specific to cudf-polars improvement Improvement / enhancement to an existing function Java Affects Java cuDF API. libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change pylibcudf Issues specific to the pylibcudf package Python Affects Python cuDF API.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants