Skip to content

[EPIC] Refactor CUB device-scope APIs to take an environment instead of cudaStream_t #9875

Closed
19 of 19 issues completed

Description

@bernhardmgruber

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:

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

Sub-issues

19 of 19 Issues completed
Loading 19 sub-issues

Activity

  1. bernhardmgruber commented on Jul 15, 2026

    @bernhardmgruber
    ContributorAuthor

    @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.

  2. added
    help wanted
    on Jul 15, 2026
  3. macdonaldezra commented on Aug 17, 2026

    @macdonaldezra
    Contributor

    Any interest in some contributions for these missing overloads? If that's of interest, I can put together a PR for the DeviceFor overloads.

  4. miscco commented on Aug 18, 2026

    @miscco
    Contributor

    Contributions are always welcome, but be aware that this is a nontrivial issue. There will be dragons

  5. nfcalabria commented on Aug 28, 2026

    @nfcalabria
    Contributor

    I'd like to work on DeviceFind::LowerBoundSortedValues and DeviceFind::UpperBoundSortedValues.

    Please let me know if these methods are already being worked on.

  6. SamMausberg commented on Sep 22, 2026

    @SamMausberg
    Contributor

    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).

  7. changed the title [-]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`[/+] on Sep 29, 2026
  8. 11 remaining items

  9. SamMausberg commented on Sep 29, 2026

    @SamMausberg
    Contributor

    I had claude create sub issues for all the open algorithms now. @SamMausberg I linked your 4 PRs to those issues.

    Thanks, Bernhard. Especially for the help with the fixes and for making it so easy. Happy to contribute more in the future.

  10. bernhardmgruber commented on Sep 29, 2026

    @bernhardmgruber
    ContributorAuthor

    Thanks, Bernhard. Especially for the help with the fixes and for making it so easy. Happy to contribute more in the future.

    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!

  11. moved this from Todo to In Progress in CCCLon Nov 18, 2026
  12. moved this from In Progress to In Review in CCCLon Nov 18, 2026
  13. moved this from In Review to Done in CCCLon Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

help wanted

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions