Skip to content

Add implicit conversion from rmm::cuda_stream to cuda::stream_ref - #2326

Merged
rapids-bot[bot] merged 1 commit into
rapidsai:mainfrom
bdice:fix/cuda-stream-ref-conversion
Mar 20, 2026
Merged

rapids-bot[bot] merged 1 commit into
rapidsai:mainfrom
bdice:fix/cuda-stream-ref-conversion

Conversation

@bdice

@bdice bdice commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

Description

rmm::cuda_stream converts to rmm::cuda_stream_view, and rmm::cuda_stream_view converts to cuda::stream_ref, but C++ does not chain two user-defined implicit conversions.

This PR adds a direct operator cuda::stream_ref() to rmm::cuda_stream so it can be passed to CCCL APIs that accept cuda::stream_ref.

This simplifies the ongoing migration to CCCL memory resources. Part of #2011.

Checklist

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

cuda_stream converts to cuda_stream_view, and cuda_stream_view converts
to cuda::stream_ref, but C++ does not chain two user-defined implicit
conversions. Add a direct operator cuda::stream_ref() to cuda_stream so
it can be passed to CCCL APIs that accept cuda::stream_ref.
@bdice
bdice requested a review from a team as a code owner March 20, 2026 22:27
@bdice
bdice requested review from miscco and shrshi March 20, 2026 22:27
@coderabbitai

coderabbitai Bot commented Mar 20, 2026

Copy link
Copy Markdown
📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • CUDA stream objects now support implicit conversion to stream references, enabling usage in additional CUDA API contexts.
  • Tests

    • Added tests to verify stream reference conversion functionality and consistency.
  • Chores

    • Updated copyright year ranges.

Walkthrough

The changes add an implicit conversion operator to rmm::cuda_stream enabling conversion to cuda::stream_ref. The header and implementation files define the operator to return cuda::stream_ref{value()}, while tests verify the conversion behavior and consistency with existing stream conversions.

Changes

Cohort / File(s) Summary
Core Implementation
cpp/include/rmm/cuda_stream.hpp, cpp/src/cuda_stream.cpp
Added implicit conversion operator operator cuda::stream_ref() const noexcept to rmm::cuda_stream class. Header declares the operator; source implements it to return cuda::stream_ref{value()}. Copyright year updated to 2026 in header.
Tests
cpp/tests/cuda_stream_tests.cpp
Added include <cuda/stream_ref> and two new test cases (ImplicitConversionToStreamRef and StreamRefConsistentWithView) to verify implicit conversion to cuda::stream_ref and consistency with stream view conversions. Copyright year updated to 2026.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding an implicit conversion operator from rmm::cuda_stream to cuda::stream_ref.
Description check ✅ Passed The description clearly explains the motivation, implementation, and relationship to existing code, providing relevant context for the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cpp/include/rmm/cuda_stream.hpp`:
- Around line 102-107: The header adds a second implicit conversion operator
(operator cuda::stream_ref() const noexcept) alongside operator
cuda_stream_view(), which could be perceived as a breaking change; update the
API docs and the inline comment for both operator cuda_stream_view() and
operator cuda::stream_ref() to state compatibility impact explicitly (confirming
that no functions in the codebase accept both types and therefore no overload
ambiguity exists), and, if this change is considered potentially breaking for
downstream users, add a deprecation/migration note and recommended migration
steps (or annotate the older operator with deprecation guidance) so callers know
which conversion to prefer; ensure the class-level and function-level comments
include the migration guidance and the exact symbols (operator cuda_stream_view
and operator cuda::stream_ref) so reviewers and users can find and act on them.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9f18eb2f-a6ec-47c9-a8a9-bb146a748b9f

📥 Commits

Reviewing files that changed from the base of the PR and between 86a91a3 and 0e39d3f.

📒 Files selected for processing (3)
  • cpp/include/rmm/cuda_stream.hpp
  • cpp/src/cuda_stream.cpp
  • cpp/tests/cuda_stream_tests.cpp

Comment thread cpp/include/rmm/cuda_stream.hpp Resolved
@bdice bdice self-assigned this Mar 20, 2026
@bdice bdice added feature request New feature or request non-breaking Non-breaking change labels Mar 20, 2026
@bdice bdice moved this to In Progress in RMM Project Board Mar 20, 2026
@bdice bdice mentioned this pull request Mar 20, 2026
51 tasks done
@bdice

bdice commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator Author

/merge

@rapids-bot
rapids-bot Bot merged commit 1bef459 into rapidsai:main Mar 20, 2026
81 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in RMM Project Board Mar 20, 2026
@bdice bdice changed the title Add implicit conversion from cuda_stream to cuda::stream_ref Add implicit conversion from rmm::cuda_stream to cuda::stream_ref Mar 20, 2026
@bdice bdice mentioned this pull request Mar 21, 2026
3 tasks done
rapids-bot Bot pushed a commit to NVIDIA/cudf that referenced this pull request Mar 21, 2026
This fixes an ambiguous stream constructor error. RMM added a new conversion from `rmm::cuda_stream` to `cuda::stream_ref` in rapidsai/rmm#2326, creating the ambiguity.

```
FAILED: CMakeFiles/cudf_identify_stream_usage_mode_cudf.dir/tests/utilities/identify_stream_usage.cpp.o
/usr/bin/sccache /home/coder/.conda/envs/rapids/bin/x86_64-conda-linux-gnu-c++ -DCCCL_DISABLE_PDL -DCUB_DISABLE_NAMESPACE_MAGIC -DCUB_IGNORE_NAMESPACE_MAGIC_ERROR -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA -DTHRUST_DISABLE_ABI_NAMESPACE -DTHRUST_HOST_SYSTEM=THRUST_HOST_SYSTEM_CPP -DTHRUST_IGNORE_ABI_NAMESPACE_ERROR -Dcudf_identify_stream_usage_mode_cudf_EXPORTS -I/home/coder/cudf/cpp/include -I/home/coder/cudf/cpp/build/conda/cuda-13.1/release/_deps/cccl-src/lib/cmake/thrust/../../../thrust -I/home/coder/cudf/cpp/build/conda/cuda-13.1/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include -I/home/coder/cudf/cpp/build/conda/cuda-13.1/release/_deps/cccl-src/lib/cmake/cub/../../../cub -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/coder/.conda/envs/rapids/include  -I/home/coder/.conda/envs/rapids/targets/x86_64-linux/include -I/home/coder/.conda/envs/rapids/targets/x86_64-linux/include/cccl -O3 -DNDEBUG -std=gnu++20 -fPIC -Wall -Werror -Wno-unknown-pragmas -Wno-error=deprecated-declarations -MD -MT CMakeFiles/cudf_identify_stream_usage_mode_cudf.dir/tests/utilities/identify_stream_usage.cpp.o -MF CMakeFiles/cudf_identify_stream_usage_mode_cudf.dir/tests/utilities/identify_stream_usage.cpp.o.d -o CMakeFiles/cudf_identify_stream_usage_mode_cudf.dir/tests/utilities/identify_stream_usage.cpp.o -c /home/coder/cudf/cpp/tests/utilities/identify_stream_usage.cpp
/home/coder/cudf/cpp/tests/utilities/identify_stream_usage.cpp: In function 'const rmm::cuda_stream_view cudf::get_default_stream()':
/home/coder/cudf/cpp/tests/utilities/identify_stream_usage.cpp:54:17: error: conversion from '<brace-enclosed initializer list>' to 'const rmm::cuda_stream_view' is ambiguous
   54 |   return {stream};
      |                 ^
In file included from /home/coder/.conda/envs/rapids/include/rmm/device_buffer.hpp:8,
                 from /home/coder/cudf/cpp/include/cudf/utilities/span.hpp:11,
                 from /home/coder/cudf/cpp/include/cudf/detail/utilities/stream_pool.hpp:9,
                 from /home/coder/cudf/cpp/tests/utilities/identify_stream_usage.cpp:6:
/home/coder/.conda/envs/rapids/include/rmm/cuda_stream_view.hpp:55:3: note: candidate: 'rmm::cuda_stream_view::cuda_stream_view(cuda::__4::stream_ref)'
   55 |   cuda_stream_view(cuda::stream_ref stream) noexcept;
      |   ^~~~~~~~~~~~~~~~
/home/coder/.conda/envs/rapids/include/rmm/cuda_stream_view.hpp:33:3: note: candidate: 'constexpr rmm::cuda_stream_view::cuda_stream_view(rmm::cuda_stream_view&&)'
   33 |   cuda_stream_view(cuda_stream_view&&)      = default;  ///< @default_move_constructor
      |   ^~~~~~~~~~~~~~~~
/home/coder/.conda/envs/rapids/include/rmm/cuda_stream_view.hpp:32:3: note: candidate: 'constexpr rmm::cuda_stream_view::cuda_stream_view(const rmm::cuda_stream_view&)'
   32 |   cuda_stream_view(cuda_stream_view const&) = default;  ///< @default_copy_constructor
      |   ^~~~~~~~~~~~~~~~
```

Authors:
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - Nghia Truong (https://github.com/ttnghia)
  - David Wendt (https://github.com/davidwendt)
  - Shruti Shivakumar (https://github.com/shrshi)

URL: #21881
@bdice bdice mentioned this pull request Mar 31, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request non-breaking Non-breaking change

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants