Skip to content

Conversation

@pciolkosz
Copy link
Contributor

We have the legacy non-stream ordered memory resources, but we don't have a way to use them in a buffer type.
While we could add a synchronous_buffer type along with async_buffer we currently have, this approach has a number of issues:

  • In a lot of cases user would like to initialize the synchronous_buffer and most likely that would be a stream ordered initialization. It makes no difference if the allocation was stream ordered or not, after the initialization is submitted into a stream the buffer has a dependency on that stream and it would be nice if we could express that in the buffer type, like we do in async_buffer
  • Conversion from async_buffer to synchronous_buffer (and back?) on synchronization or launching new stream ordered work is not the most convenient. Instead [cudax] Make stream in async_buffer optional #6416 makes the stream in async_buffer optional, so you can add and remove stream dependency from async_buffer easily.

The direction we would like to take instead is to rename async_buffer to just buffer and make it work with legacy resources. This PR adds synchronous_resource_adapter, which is a generic utility wrapper that can extend synchronous_resource to a full resource. It forwards allocate_sync and deallocate_sync to the wrapper resource, while for allocate and deallocate, it forwards it if possible, otherwise uses the _sync variants. In order to make deallocate correct it also synchronizes the stream in case forwarding was not possible. The adapter is generic and will work for any custom synchronous_resource.

This PR also makes async_buffer automatically apply the added adapter to a resource used to create a buffer if it does not have the stream ordered allocation/deallocation. This way legacy resources can be used with that type just like the memory pools.

After this and #6416 is merged a future change will rename async_buffer to just buffer

@pciolkosz pciolkosz requested review from a team as code owners October 31, 2025 23:41
@pciolkosz pciolkosz requested a review from ericniebler October 31, 2025 23:41
@github-project-automation github-project-automation bot moved this to Todo in CCCL Oct 31, 2025
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Oct 31, 2025
@github-actions

This comment has been minimized.

@pciolkosz pciolkosz force-pushed the add_synchronous_resource_adapter_and_use_it_in_async_buffer branch 2 times, most recently from 9169f81 to 29e3ddf Compare November 3, 2025 18:56
@github-actions

This comment has been minimized.

@pciolkosz pciolkosz force-pushed the add_synchronous_resource_adapter_and_use_it_in_async_buffer branch from 29e3ddf to 9d8784f Compare November 3, 2025 23:26
@github-actions

This comment has been minimized.

@pciolkosz pciolkosz requested a review from davebayer November 4, 2025 00:52
@github-actions

This comment has been minimized.

Comment on lines +43 to +44
template <class _Resource>
struct synchronous_resource_adapter : ::cuda::mr::__copy_default_queries<_Resource>
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: should the adapter own the resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it should, otherwise you run into lifetime issues

@github-actions

This comment has been minimized.

@pciolkosz pciolkosz force-pushed the add_synchronous_resource_adapter_and_use_it_in_async_buffer branch from 8e34cb5 to 8b1b323 Compare November 7, 2025 00:28
@github-actions

This comment has been minimized.

@davebayer
Copy link
Contributor

pre-commit.ci autofix

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

NVIDIA#6352)

* Add pointer attributes fallback to async buffer initialization

* Add else branch instead of return because of MSVC

* Fix format

* Update cudax/include/cuda/experimental/__container/async_buffer.cuh

Co-authored-by: David Bayer <[email protected]>

* Fix format

---------

Co-authored-by: David Bayer <[email protected]>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 14m: Pass: 100%/120 | Total: 2d 15h | Max: 1h 33m | Hits: 87%/229477

See results here.

@pciolkosz pciolkosz merged commit e3b5adc into NVIDIA:main Nov 13, 2025
132 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants