Skip to content

Handle empty RMM buffers without an upstream stream - #1261

Merged
rapids-bot[bot] merged 3 commits into
rapidsai:mainfrom
vyasr:fix-empty-rmm-buffer-stream
Oct 15, 2026
Merged

rapids-bot[bot] merged 3 commits into
rapidsai:mainfrom
vyasr:fix-empty-rmm-buffer-stream

Conversation

@vyasr

@vyasr vyasr commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Adopting a default-constructed or moved-from empty rmm::device_buffer can attempt to record an event on an invalid CUDA stream after rapidsai/rmm#2546. Skip the upstream join only when the buffer has no allocation and carries the invalid-stream sentinel, then assign the requested stream before constructing the rapidsmpf buffer. Valid upstream streams retain their synchronization behavior.

Add a regression test that adopts a default-constructed buffer onto a nondefault stream and waits for its recorded event. This addresses the MetadataMessage.round_trip runtime failure separately from the rattler-build migration in #1258.

Signed-off-by: Vyas Ramasubramani <vyasr@nvidia.com>
@vyasr vyasr added bug Something isn't working non-breaking Introduces a non-breaking change labels Oct 15, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@vyasr

vyasr commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f061499

Follow-up to the fix for empty `rmm::device_buffer`s reporting an invalid
stream after rapidsai/rmm#2546:

- Document in `BufferResource::move()` that an empty buffer without a
  stream (default-constructed or moved-from `rmm::device_buffer`) is not
  synchronized and simply has its stream set to the target stream.
- Simplify the invalid-stream check to `upstream == cuda::invalid_stream`,
  using the comparison operator provided by CCCL.
- Add a regression test for moving a moved-from `rmm::device_buffer`,
  which rapidsai/rmm#2546 documents as a separate case that now reports
  an invalid stream.

Signed-off-by: Peter Andreas Entschev <peter@entschev.com>
@pentschev
pentschev marked this pull request as ready for review October 15, 2026 08:25
@pentschev
pentschev requested a review from a team as a code owner October 15, 2026 08:25

@pentschev pentschev left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @vyasr for getting started with this. I hope you don't mind, I pushed a few changes myself to get this PR merged right away and unblock CI:

  • Document in BufferResource::move() that an empty buffer without a stream (default-constructed or moved-from rmm::device_buffer) is not synchronized and simply has its stream set to the target stream.
  • Simplify the invalid-stream check to upstream == cuda::invalid_stream, using the comparison operator provided by CCCL.
  • Add a regression test for moving a moved-from rmm::device_buffer, which rapidsai/rmm#2546 documents as a separate case that now reports an invalid stream.

EDIT: Moving from an rmm::device_buffer also moves out its memory resource, leaving an empty any_resource, so the subsequent is_host_accessible(data->memory_resource()) call dereferences an empty resource. The test was wrong and is removed now.

@pentschev

Copy link
Copy Markdown
Member

/merge

`BufferResource.MoveMovedFromDeviceBuffer` segfaults in
`BufferResource::move()`. Moving from an `rmm::device_buffer` also moves
out its memory resource (`_mr`), leaving an empty `any_resource`, so the
subsequent `is_host_accessible(data->memory_resource())` call
dereferences an empty resource. This is unrelated to the invalid-stream
change in rapidsai/rmm#2546: moved-from buffers were never valid input
to `BufferResource::move()`.

Remove the test and drop the "moved-from" mentions from the `move()`
docstring and the code comment, which only apply to default-constructed
buffers.

Signed-off-by: Peter Andreas Entschev <peter@entschev.com>
@rapids-bot
rapids-bot Bot merged commit 66576f7 into rapidsai:main Oct 15, 2026
59 checks passed
@vyasr
vyasr deleted the fix-empty-rmm-buffer-stream branch October 15, 2026 16:11
rapids-bot Bot pushed a commit that referenced this pull request Oct 19, 2026
Passing `cuda::invalid_stream` to a buffer factory used to succeed and only fail later, as `cudaErrorInvalidResourceHandle` from a CUDA call far from the cause. The public `HostBuffer::from_rmm_device_buffer` also skipped the stream ordering that `BufferResource::move` does. The buffer factories and `Buffer::rebind_stream` now throw `std::invalid_argument` on an invalid stream. `from_rmm_device_buffer` now orders its stream after the device buffer's pending work. Follow-up to #1261.

- `BufferResource::make_buffer`, `BufferResource::move`, the `HostBuffer` constructors (used by `from_uint8_vector` and `from_owned_vector`), `HostBuffer::from_rmm_device_buffer` and `Buffer::rebind_stream` throw `std::invalid_argument` for `cuda::invalid_stream`.
- `HostBuffer::from_rmm_device_buffer` makes `stream` wait on the device buffer's stream, and frees the memory on the `HostBuffer`'s current stream. Before, memory was freed on the original stream, which could be stale after `rebind_stream`.
- The stream join in `BufferResource::move` and `from_rmm_device_buffer` now just checks `capacity() > 0`. An empty buffer owns no memory, so there's nothing to join. This includes default-constructed buffers, which have no stream.
- Added tests that each entry point throws on an invalid stream, and updated the docstrings.

Authors:
  - Niranda Perera (https://github.com/nirandaperera)

Approvers:
  - Lawrence Mitchell (https://github.com/wence-)
  - Peter Andreas Entschev (https://github.com/pentschev)

URL: #1263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants