You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEA]: Design single-stage mr-based API for CUB #2523
Is your feature request related to a problem? Please describe.
It's not uncommon for users to define a macro that queries temporary storage required by CUB algorithm, allocates that storage using cudaMemcpyAsync, invokes the algorithm, and then frees the storage. This essentially makes the two-stage CUB API a single-stage one while preserving asynchrony. This approach leads to less verbose API, and addresses issues associated with mismatching parameters at query and execution stages. We should have a standard solution.
Describe the solution you'd like
We should consider memory resource-based API for CUB. That'd allow users to customize temporary storage allocation when needed and take advantage of asynchronous memory managemenet by default. Something along the lines of:
[FEA] Implement single-stage MR-based API for CUB (#2523)
- Introduced a memory resource-based API for CUB.
- Eliminated the need for two-step (query + execution) calls.
- Enabled asynchronous memory allocation with cudax::mr::async_resource{}.
- Improved usability while maintaining backward compatibility.
@NailaRais the interface that you've specified looks great! We've just discussed the interface with the team. A few conclusions below:
New interface should accept stream first, then memory resource. We expect the need of changing the stream to be more frequent than changing the default memory resource behavior. This is confirmed by precedent of libcudf ordering stream and memory resource this way.
New interface should accept memory resource type as a template parameter to avoid any performance overhead caused by indirect calls coming from the type erasure.
We should be careful not to create ambiguity with existing overloads (probably SFINAE-out on size_t& as the second parameter).
Memory resources are experimental, so we might want to hide the new interface behind the LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE macro for now.
As to the implementation, it'll be tracked by a separate issue. @NailaRais it looks like you have an implementation for reduction. We'll split the work into sub-issues soon. Let us know if you'd like to contribute new API for reduction.
@NailaRais the interface that you've specified looks great! We've just discussed the interface with the team. A few conclusions below:
New interface should accept stream first, then memory resource. We expect the need of changing the stream to be more frequent than changing the default memory resource behavior. This is confirmed by precedent of libcudf ordering stream and memory resource this way.
New interface should accept memory resource type as a template parameter to avoid any performance overhead caused by indirect calls coming from the type erasure.
We should be careful not to create ambiguity with existing overloads (probably SFINAE-out on size_t& as the second parameter).
Memory resources are experimental, so we might want to hide the new interface behind the LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE macro for now.
As to the implementation, it'll be tracked by a separate issue. @NailaRais it looks like you have an implementation for reduction. We'll split the work into sub-issues soon. Let us know if you'd like to contribute new API for reduction.
Hi @gevtushenko
Thank you for reviewing my proposal and for the detailed feedback! I appreciate the insights from the team discussion.
Here’s how I plan to incorporate the suggested improvements:
Reordering parameters – I will update the interface to accept the stream first, followed by the memory resource, ensuring consistency with libcudf conventions.
Template-based memory resource – I'll modify the implementation to take the memory resource type as a template parameter, avoiding any potential performance overhead due to type erasure.
Overload ambiguity handling – I’ll ensure that existing overloads are not affected by using SFINAE to avoid conflicts (e.g., handling size_t& as the second parameter).
Hiding the interface behind the experimental macro – Since memory resources are still experimental, I will wrap the new API behind LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE to align with best practices.
I’d be happy to contribute the new API for reduction as part of the upcoming sub-issues.
Looking forward to your thoughts!
Best,
Naila Rais
Activity
NailaRais commentedon Feb 4, 2025
How about this?
gevtushenko commentedon Feb 18, 2025
@NailaRais the interface that you've specified looks great! We've just discussed the interface with the team. A few conclusions below:
size_t&as the second parameter).LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCEmacro for now.As to the implementation, it'll be tracked by a separate issue. @NailaRais it looks like you have an implementation for reduction. We'll split the work into sub-issues soon. Let us know if you'd like to contribute new API for reduction.
NailaRais commentedon Feb 20, 2025
@gevtushenko