Repository navigation
Description
We decided a while back on Slack that in order to solve the problem of querying the temporary storage size of CUB APIs that take an environment and have no equivalent non-env overload, we should just replace all cudaStream_t parameters in public device-scope APIs by a const Env& parameter and add the additional environment handling (excluding temporary storage allocation). This would result in every CUB API to have two flavors:
struct DeviceAlg {
// two-phase overload, user must handle temp storage allocation
template <..., typename Env>
static cudaError_t Algorithm(void* ts_ptr, size_t& ts_size, ..., const Env& env);
// single-phase overload, handles temp storage allocation itself
template <..., typename Env>
static cudaError_t Algorithm(..., const Env& env);
}This change is transparent to users, since a passed cudaStream_t (or a type convertible to that) will be handled appropriately by the stream query of the environment.
This work has already begun, but was mostly driven by needs in PSTL to query the temporary storage to combine that storage with further allocations (like an output parameter). See also #9328 and the following PRs:
- [CUB] Refactor
DeviceReduce::Arg{Min, Max}to always take an environment #9403 - [CUB] Refactor
DeviceCopyto always take an environment #9416 - [CUB] Refactor
DeviceAdjacentDifference::SubtractLeftto always take an environment #9418 - [CUB] Refactor
DeviceAdjacentDifference::SubtractRightto always take an environment #9419 - [CUB] Refactor
DeviceSelect::Flaggedto always take an environment #9455 - [CUB] Refactor
cub::DeviceSelect::Ifto always take an environment #9456 - [CUB] Refactor
DeviceSelect::FlaggedIfto always take an environment #9457 - [CUB] Refactor
DeviceSelect::Uniqueto always take an environment #9458 - [CUB] Refactor
DeviceHistogram::MultiHistogramEvento always take an environment #9552 - [CUB] Refactor
DeviceHistogram::HistogramEvento always take an environment #9553 - [CUB] Refactor
DeviceHistogram::MultiHistogramRangeto always take an environment #9554 - [CUB] Refactor
DeviceHistogram::HistogramRangeto always take an environment #9555 - Refactor
device_adjacent_difference::dispatchto take a tuning #9454 - [CUB] Refactor
dispatch_streaming_arg_reduceto take a tuning environment #9660 - [PSTL] Use env based overload for
DeviceFindIf#9318 - Use environment based CUB APIs when possible in PSTL #8526
- [CUB] Refactor
DeviceSelect::UniqueByKeyto always take an environment #9459 - [CUB] Refactor
DevicePartition::Flaggedto always take an environment #9463 - [CUB] Refactor
DevicePartition::Ifto always take an environment #9464 - [CUB] Refactor
DeviceSelect::Uniqueto always take an environment #9386 - [CUB] Refactor
DeviceSelect::UniqueByKeyto always take an environment #9387 - [CUB] Refactor
DeviceSelect::Flaggedto always take an environment #9388 - [CUB] Refactor
DeviceSelect::FlaggedIfto always take an environment #9389 - [CUB] Refactor
DeviceSelect::Ifto always take an environment #9391 - [CUB] Refactor
DevicePartition::Ifto always take an environment #9393 - [CUB] Refactor
DevicePartition::Flaggedto always take an environment #9396 - [CUB] Refactor
DevicePartition::Flaggedto always take an environment #9462
However, we should complete this work. There are sub issues for the currently missing overloads that still have a cudaStream_t.
Here is a guide on what kind of testing to add: https://nvidia.github.io/cccl/unstable/cub/developer/test_overview.html#testing-environment-aware-api-overloads
After all sub issues have been resolved, there are a couple of cleanup actions:
- Make sure all documentation is consistent, notably mention that the env ignores the memory resource on all two-step APIs
Sub-issues
Collapse Sub-issuesSub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
bernhardmgruber commentedon Jul 15, 2026
@miscco I just assigned this to you, since you already started, but anyone can work on this. If you already have a good prompt, consider posting it here.
macdonaldezra commentedon Aug 17, 2026
Any interest in some contributions for these missing overloads? If that's of interest, I can put together a PR for the DeviceFor overloads.
miscco commentedon Aug 18, 2026
Contributions are always welcome, but be aware that this is a nontrivial issue. There will be dragons
nfcalabria commentedon Aug 28, 2026
I'd like to work on
DeviceFind::LowerBoundSortedValuesandDeviceFind::UpperBoundSortedValues.Please let me know if these methods are already being worked on.
SamMausberg commentedon Sep 22, 2026
Opened PRs for four more rows: DeviceMergeSort (#11587), DeviceMerge (#11589), DeviceMemcpy (#11590) and DeviceRunLengthEncode (#11591). Each follows the pattern of the merged DeviceCopy/DeviceSelect/DeviceFor refactors and adds two-phase env tests (stream routing, tuning extraction, legacy null-stream arguments).
[CUB] Refactor cub::DeviceMergeSort to always take an environment
[CUB] Refactor cub::DeviceMergeSort to always take an environment
[-]Refactor CUB device-scope APIs to take an environment instead of `cudaStream_t`[/-][+][EPIC] Refactor CUB device-scope APIs to take an environment instead of `cudaStream_t`[/+]11 remaining items
SamMausberg commentedon Sep 29, 2026
Thanks, Bernhard. Especially for the help with the fixes and for making it so easy. Happy to contribute more in the future.
bernhardmgruber commentedon Sep 29, 2026
I am happy to receive those PRs since it addresses an important API gap. Thank you for the help! I guess it should get smoother with each PR!