Skip to content

Conversation

@bdice
Copy link
Contributor

@bdice bdice commented Nov 26, 2025

Description

allocate_sync promises that the returned pointer is immediately valid on all streams. However, the previous implementation only allocated on the default stream without synchronizing it. This caused race conditions when using non-blocking streams, as the allocation might not be visible to other streams.

This fix adds a synchronization of the default stream after allocation to ensure the pointer is immediately valid on all streams, including non-blocking streams.

Closes #2156.

Checklist

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

…eams.

`allocate_sync` promises that the returned pointer is immediately valid on all streams. However, the previous implementation only allocated on the default stream without synchronizing it. This caused race conditions when using non-blocking streams, as the allocation might not be visible to other streams.

This fix adds a synchronization of the default stream after allocation to ensure the pointer is immediately valid on all streams, including non-blocking streams.

Closes rapidsai#2156.
@bdice bdice requested a review from a team as a code owner November 26, 2025 01:15
@bdice bdice requested review from miscco and wence- November 26, 2025 01:15
@bdice bdice added bug Something isn't working non-breaking Non-breaking change labels Nov 26, 2025
@bdice bdice self-assigned this Nov 26, 2025
@bdice bdice moved this to In Progress in RMM Project Board Nov 26, 2025
Comment on lines +101 to 103
* The returned pointer is immediately valid on all streams.
*
* @throws rmm::bad_alloc When the requested `bytes` cannot be allocated.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a note to deallocate_sync that "All stream-ordered work on ptr must be complete before calling this function otherwise behavior is undefined"?

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 Non-breaking change

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

[BUG] cuda_async_memory_resource.allocate_sync doesn't

2 participants