Skip to content

[libcu++] Add make_device_buffer, make_pinned_buffer, and make_managed_buffer#8250

Open
pciolkosz wants to merge 2 commits intoNVIDIA:mainfrom
pciolkosz:more_make_buffer_functions
Open

[libcu++] Add make_device_buffer, make_pinned_buffer, and make_managed_buffer#8250
pciolkosz wants to merge 2 commits intoNVIDIA:mainfrom
pciolkosz:more_make_buffer_functions

Conversation

@pciolkosz
Copy link
Copy Markdown
Contributor

This PR adds make_device/managed/pinned_buffer as a shorthand for make_buffer with device/managed/pinned_default_memory_pool.

Also fly-by fix to add _CCCL_HOST_API to make_buffer.

Closes #8240

@pciolkosz pciolkosz requested a review from a team as a code owner March 31, 2026 22:06
@pciolkosz pciolkosz requested a review from davebayer March 31, 2026 22:06
@github-project-automation github-project-automation bot moved this to Todo in CCCL Mar 31, 2026
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Mar 31, 2026
@github-actions

This comment has been minimized.

//! @param __stream The stream used for allocation.
//! @param __device The device whose default memory pool will be used.
template <class _Tp, class _Env = ::cuda::std::execution::env<>>
_CCCL_HOST_API auto make_device_buffer(stream_ref __stream, device_ref __device, const _Env& __env = {})
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.

I believe there was another PR with a similar question: Is the device argument obolete given that stream and device must match?

If so should we verify that

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.

The stream and device doesn't need to match. Stream is used for sequencing and device argument selects the device where the memory should reside.

We could provide another overload where the device is taken from the stream, it might be a good idea. I was a bit hesitant, because the pinned and managed variants only take a stream and the device variant not taking an explicit device could make it seem like the pinned and managed variants also are localized to the stream's device, where its not the case. I am 50/50 on this right now, but we can always add another overload later

//! @param __stream The stream used for allocation and copy.
//! @param __range The input range to be copied into the buffer.
template <class _Tp, class _Range, class _Env = ::cuda::std::execution::env<>>
_CCCL_HOST_API auto make_pinned_buffer(stream_ref __stream, _Range&& __range, const _Env& __env = {})
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.

Critical: None of those APIs is constrained. We really need to add some constraints to disambiguate the different overloads

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.

I wanted to avoid repeating all the constraints, but you are right they could be ambiguous. I reworked these wrappers to just blindly forward arguments to make_buffer, the error message will be marginally worse, but at least we don't need to list all those overloads.
This approach doesn't work with the initializer_list overload, but I am questioning if its needed at all and maybe we should just deprecate it

Convenience wrappers around make_buffer that use the default memory pools:
- make_device_buffer: uses device_default_memory_pool(device_ref)
- make_pinned_buffer: uses pinned_default_memory_pool() (CTK 12.9+)
- make_managed_buffer: uses managed_default_memory_pool() (CTK 13.0+)

They forward arguments to make_buffer
@pciolkosz pciolkosz force-pushed the more_make_buffer_functions branch from 7353175 to 2abd228 Compare April 1, 2026 20:22
@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

🥳 CI Workflow Results

🟩 Finished in 4h 05m: Pass: 100%/99 | Total: 1d 00h | Max: 3h 41m | Hits: 99%/258072

See results here.

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

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

Add convenience functions for make_buffer to provide a shorthand for usage of the default mempools

2 participants