Skip to content

[CUB] Refactor cub::DeviceRunLengthEncode to always take an environment - #11591

Merged
bernhardmgruber merged 5 commits into
NVIDIA:mainfrom
SamMausberg:refactor/device-rle-env
Nov 3, 2026
Merged

bernhardmgruber merged 5 commits into
NVIDIA:mainfrom
SamMausberg:refactor/device-rle-env

Conversation

@SamMausberg

@SamMausberg SamMausberg commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Part of #9875 (the DeviceRunLengthEncode row).

Replaces the trailing cudaStream_t parameter of the two-phase Encode and NonTrivialRuns overloads with an execution environment (const EnvT& env = {}). The two-phase overloads now go through detail::dispatch_with_env_and_tuning with user-provided storage, so they honor cuda::get_stream and cuda::execution::tune the same way the single-phase overloads do. This follows the pattern of the merged sibling refactors (#9416, #9455 to #9459, #9463, #9464, #9552 to #9555, #11013) and of #11587, #11589 and #11590 for DeviceMergeSort, DeviceMerge and DeviceMemcpy.

The default policy selectors passed by the two-phase overloads are the ones the dispatch layer already defaulted to, so behavior without a tuning in the environment is unchanged. Existing callers keep working: a cudaStream_t, nullptr or literal 0 passed in the last position is accepted (cuda::get_stream handles the first two, the third falls back to the default stream as before). The only caller outside the CUB tests, nvbench_helper/test/gen_entropy.cu, calls the two-phase Encode without a stream argument and is unaffected. The CustomDeviceRunLengthEncode wrapper in the NonTrivialRuns functional test calls detail::rle::dispatch directly and is unaffected too.

The doxygen blocks of the two-phase overloads now document EnvT and env instead of stream.

Tests

Added to cub/test/catch2_test_device_run_length_encode_env.cu, restricted to TEST_LAUNCH == 0 since the two-phase overloads do not go through the launch wrappers:

  • DeviceRunLengthEncode::Encode works with user provided memory and environment and the NonTrivialRuns counterpart. Each runs through test_with_custom_streams for every stream and environment kind the helper covers, checks that the storage query matches the legacy overload, and verifies the encoded runs.
  • DeviceRunLengthEncode::Encode can be tuned with user provided memory and the NonTrivialRuns counterpart, with two block sizes verified via block_size_extracting_constant_iterator.
  • DeviceRunLengthEncode two-phase overloads accept legacy null stream arguments for nullptr and 0.

Run locally on an RTX 5070 Ti (SM 120), CUDA 13.2, gcc 13.3, preset cub-cpp20 with CMAKE_CUDA_ARCHITECTURES=120. All of the following passed:

  • cub.test.device.run_length_encode_env.lid_{0,1,2}
  • cub.test.device.run_length_encode.lid_{0,1,2}
  • cub.test.device.run_length_encode_non_trivial_runs.lid_{0,1,2}
  • cub.test.device.run_length_encode_api.lid_0, cub.test.device.run_length_encode_env_api.lid_0

In addition, the same tree builds with clang 21 as the host compiler under C++17 (preset cub-cpp17, -Werror -Wall -Wextra) with zero warnings, and cub.test.device.run_length_encode_env.lid_{0,1,2}, cub.test.device.run_length_encode_api.lid_0 and cub.test.device.run_length_encode_env_api.lid_0 pass in that configuration too.

pre-commit passes on the changed files. I could not build the MSVC or NVHPC configurations locally.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Developed with Claude Fable 5.1

Fixes: #11702

Part of NVIDIA#9875. Replaces the trailing cudaStream_t parameter of the
two-phase Encode and NonTrivialRuns overloads with an execution
environment. The two-phase overloads now dispatch through
dispatch_with_env_and_tuning, so cuda::get_stream and
cuda::execution::tune are honored like in the single-phase overloads.
Passing a cudaStream_t, nullptr or 0 keeps working.

Adds env tests for the two-phase overloads: per-environment-kind runs
with user provided storage that verify the launch stream, tuning
extraction with two block sizes, and the legacy null-stream arguments.

Developed in combination with Claude Fable 5.1
@SamMausberg
SamMausberg requested a review from a team as a code owner September 22, 2026 15:25
@copy-pr-bot

copy-pr-bot Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Run-length encoding operations now support execution environments for stream selection and tuning customization.
    • Temporary-storage workflows can use these environments for execution.
  • Compatibility
    • Encode continues to accept legacy nullptr and 0 stream arguments.
  • Tests
    • Added coverage for environment-based execution with caller-provided temporary storage, tuning options, and custom streams.

The temporary-storage overloads for DeviceRunLengthEncode::Encode and NonTrivialRuns now accept execution environments instead of CUDA streams. Both use environment-aware dispatch. Tests cover two-phase execution with caller-provided storage, custom streams, legacy nullptr and 0 stream arguments for Encode, and tuned policies.

Changes: Run-length encoding environment support

Layer / File(s) Summary
Two-phase environment dispatch
cub/cub/device/device_run_length_encode.cuh
Encode and NonTrivialRuns accept EnvT and dispatch through dispatch_with_env_and_tuning.
Two-phase API validation
cub/test/catch2_test_device_run_length_encode_env.cu
Tests cover environment-based storage queries and execution, custom streams, legacy stream arguments for Encode, and tuned policies.

Assessment against linked issues

Objective Addressed Explanation
Migrate the two-phase Encode and NonTrivialRuns overloads from cudaStream_t to const Env& [#11702] ✅
Add tests for the new environment overloads [#11702] ✅

Possibly related issues

  • NVIDIA/cccl#9875 — The change is part of the environment-based CUB API migration described by this epic.
  • NVIDIA/cccl#11613 — The issue identifies test-convention findings in the same test file, including custom-stream test checks and launch guards.

Suggested reviewers: bernhardmgruber

Change: Refactor

Merge Risk: Minimal · up to 15856

The two-phase API change has no identified merge-blocking issue; existing non-null stream callers retain their stream behavior.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts ### CodeRabbit Verify
  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: NVIDIA/cccl
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: df6c989
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 3878c4f1-dd6f-4909-80c1-7ae756e9929b
Commits

Reviewing files that changed from the base of the PR and between cd85475 and 1585629.

Files selected for processing: 2
  • cub/cub/device/device_run_length_encode.cuh
  • cub/test/catch2_test_device_run_length_encode_env.cu

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 8 remain after this review.

…de env tests

The two-phase environment tests now go through the shared
test_with_custom_streams helper instead of a local sweep over stream
kinds, and result vectors are created with thrust::no_init.
Comment on lines +453 to +457
// Before the environment parameter, the two-phase overloads took `cudaStream_t stream = nullptr`, so callers passing
// nullptr or a literal 0 for the stream exist. Both must keep compiling and keep running on the default stream.
CUB_TEST_CASE("DeviceRunLengthEncode two-phase overloads accept legacy null stream arguments",
"[run_length_encode][device]",
CUB_SMALL)

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.

Remark: We could have this test for DeviceRunLengthEncode::NonTrivialRuns as well, but I generally don't think this test should be required on every algorithm. nullptr and 0 converting to an env and getting handled was demonstrated, so we don't need to prove it for every algorithm.

@bernhardmgruber

Copy link
Copy Markdown
Contributor

/ok to test 4faed85

@github-actions

This comment has been minimized.

@bernhardmgruber

Copy link
Copy Markdown
Contributor

/ok to test cd85475

@github-actions

This comment has been minimized.

@bernhardmgruber

Copy link
Copy Markdown
Contributor

/ok to test 1585629

@bernhardmgruber
bernhardmgruber enabled auto-merge (squash) November 3, 2026 19:54
@bernhardmgruber
bernhardmgruber merged commit b51a017 into NVIDIA:main Nov 3, 2026
234 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 45m: Pass: 100%/214 | Total: 8d 04h | Max: 2h 44m | Hits: 36%/1240913

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: Done

Development

Successfully merging this pull request may close these issues.

DeviceRunLengthEncode: migrate two-phase overloads to Env

2 participants