Skip to content

Env passthrough 4/4 - #9065

Merged
bernhardmgruber merged 9 commits into
NVIDIA:mainfrom
gonidelis:env_passthrough_4
May 20, 2026
Merged

bernhardmgruber merged 9 commits into
NVIDIA:mainfrom
gonidelis:env_passthrough_4

Conversation

@gonidelis

@gonidelis gonidelis commented May 19, 2026 •

Copy link
Copy Markdown
Member

closes #8175

examines

  • DeviceMergeSort
  • DeviceHistogram
  • DeviceScan
  • DeviceSegmentedScan

ambiguities found. important to backport.

DeviceTopK is still open so we cannot examine it here in order not to create conflicts.

@gonidelis
gonidelis requested a review from a team as a code owner May 19, 2026 03:52
@gonidelis
gonidelis requested a review from srinivasyadav18 May 19, 2026 03:52
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 19, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 19, 2026
@coderabbitai

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c313795a-d37c-4d12-b3a5-9761ca9e3345

📥 Commits

Reviewing files that changed from the base of the PR and between 8e34fbc and c574e39.

📒 Files selected for processing (5)
  • cub/cub/device/device_scan.cuh
  • cub/test/catch2_test_device_histogram_api.cu
  • cub/test/catch2_test_device_merge_sort_api.cu
  • cub/test/catch2_test_device_scan_api.cu
  • cub/test/catch2_test_device_segmented_scan_api.cu
🚧 Files skipped from review as they are similar to previous changes (5)
  • cub/test/catch2_test_device_merge_sort_api.cu
  • cub/test/catch2_test_device_histogram_api.cu
  • cub/test/catch2_test_device_scan_api.cu
  • cub/test/catch2_test_device_segmented_scan_api.cu
  • cub/cub/device/device_scan.cuh

📝 Walkthrough

Summary by CodeRabbit

  • Documentation

    • Enhanced documentation for histogram, scan, and segmented scan operations with improved parameter descriptions and formatting.
  • Bug Fixes

    • Added template constraints to histogram and scan APIs to prevent invalid type combinations and improve compile-time error detection.
  • Tests

    • Expanded test coverage for non-environment API overloads across histogram, merge sort, scan, and segmented scan operations.
    • Simplified environment-based API tests to directly accept stream references without intermediate wrapper construction.

Walkthrough

This PR refines CUB device APIs across histogram, merge sort, scan, and segmented scan: tightening SFINAE constraints on exclusive/inclusive scan env overloads to improve overload resolution, shifting all environment tests from wrapped env to direct stream_ref passing, adding comprehensive non-env API test coverage via new Catch2 files, and refining documentation/test data consistency.

Changes

Environment API Pattern and Constraint Refinements

Layer / File(s) Summary
Scan SFINAE constraints on env overloads
cub/cub/device/device_scan.cuh
ExclusiveScan (both init forms) now exclude size_t output iterators and require integral NumItemsT; InclusiveScan (env) now requires integral NumItemsT to tighten overload resolution.
Histogram environment parameter: direct stream_ref passing
cub/test/catch2_test_device_histogram_env_api.cu
All histogram env API tests updated to pass cuda::stream_ref directly instead of wrapping in cuda::std::execution::env; all 8 variants (HistogramEven/Range, MultiHistogramEven/Range × 1D/2D) adjusted.
Scan environment parameter: direct stream_ref passing
cub/test/catch2_test_device_scan_env_api.cu
ExclusiveScan with FutureValue, InclusiveScan, and InclusiveScanInit env tests updated to pass cuda::stream_ref directly, removing intermediate env wrapping.
Scan-by-key environment parameter: direct stream_ref and sync points
cub/test/catch2_test_device_scan_by_key_env_api.cu
All four scan-by-key env tests updated to pass cuda::stream_ref directly with stream.sync() calls before assertions to ensure queued work completes.
Histogram documentation clarifications
cub/cub/device/device_histogram.cuh
Refined parameter descriptions for bin boundary semantics, per-channel clarity, and level array boundary specifications in env-based overloads.
Segmented scan documentation formatting
cub/cub/device/device_segmented_scan.cuh
Restructured Doxygen/Sphinx markup for offset parameters, preconditions sections, and in-place constraint bullets across 14 env-based overload documentation blocks.
Scan-by-key documentation snippet separators
cub/cub/device/device_scan.cuh
Updated 4 comment markers in scan-by-key environment API documentation sections for consistent formatting.

Non-Environment and Updated Environment Test Coverage

Layer / File(s) Summary
Histogram non-env API test coverage
cub/test/catch2_test_device_histogram_api.cu
New test file with 8 Catch2 tests covering HistogramEven, HistogramRange, MultiHistogramEven, MultiHistogramRange (1D/2D variants) using device vectors and nullptr temp storage queries.
Merge sort non-env API test coverage and env updates
cub/test/catch2_test_device_merge_sort_api.cu, cub/test/catch2_test_device_merge_sort_env_api.cu
New non-env test file with 7 tests for SortPairs, SortPairsCopy, SortKeys, SortKeysCopy, and stable variants; env tests updated with duplicate-key test data, stream.sync() calls after copy variants, and new SortPairs test with greater comparator.
Scan non-env API test coverage
cub/test/catch2_test_device_scan_api.cu
New test file with 16 Catch2 tests covering exclusive/inclusive sum/scan (including FutureValue form), ScanInit, and all *ByKey variants using size-1 device vectors and nullptr temp storage.
Segmented scan non-env API test coverage and env operator updates
cub/test/catch2_test_device_segmented_scan_api.cu, cub/test/catch2_test_device_segmented_scan_env_api.cu
New non-env test file with 10 tests for exclusive/inclusive segmented sum/scan/init (2-offset and 3-offset forms); env tests refactored to use cuda::maximum<> operator with updated initializers and expected outputs matching maximum-reduction semantics.

Assessment against linked issues

Objective Addressed Explanation
Verify constraints on all env overloads are as strict as necessary [#8175-6] ✅
Use stream_ref explicitly as last argument in env_api tests, not through environment wrap [#8175-9] ✅
Verify where stream.sync() is needed before assertions [#8175-7] ❓ stream.sync() added to merge sort and scan-by-key env tests, but consistency across all env tests should be verified for completeness.
Each non-env overload has corresponding env overload (histogram, scan, merge sort, segmented scan subset) [#8175-1] ✅
Documentation for env-overloads follows consistent style [#8175-3] ❓ Histogram and segmented scan docs updated, but style consistency across all device APIs and comparison with non-env counterpart docs warrants verification.

Out-of-scope changes

Code Change Explanation
Test data operator switch from plus to maximum (catch2_test_device_segmented_scan_env_api.cu, multiple ranges) This appears to be a functional test data update rather than API constraint/pattern refinement. Unclear if this change is part of the stated objectives or a separate test fix; unclear whether test expectations align with the new operator semantics.

suggestion: The PR successfully implements environment parameter pattern unification (stream_ref direct passing) across histogram, scan, and scan-by-key env tests, but review should verify that stream.sync() placement is complete and correct across all async dispatch paths. Merge sort copy variants and segmented scan tests have it; check scan env tests for consistency.

important: The SFINAE constraints on ExclusiveScan env overloads now exclude size_t output iterators. This is a breaking change for any code passing size_t* as output; verify that no test or internal code path depends on that overload signature and that error messages guide users to the correct overload.

important: Segmented scan env tests switched from plus to maximum operator with new test data {3, 1, 4, 1, 5, 9, 2, 6} and different initializers/expected outputs. Confirm that this change is intentional and does not mask a regression in the original plus-based semantics; if it is a functional fix, document the issue it resolves.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (4)
cub/test/catch2_test_device_histogram_api.cu (1)

17-123: ⚡ Quick win

suggestion: Capture the return value of each cub::DeviceHistogram::* query call and assert cudaSuccess (or REQUIRE(status == cudaSuccess)). Right now Lines 17-123 ignore status, so these tests can pass even if the API dispatch/query path fails.

As per coding guidelines: cub/**/*: Focus on algorithm correctness, temporary-storage protocol, dispatch/policy selection, stream behavior, CUDA error handling, synchronization, memory access safety, performance regressions, and test coverage.

cub/test/catch2_test_device_merge_sort_api.cu (1)

15-75: ⚡ Quick win

suggestion: Store and assert the cudaError_t from each cub::DeviceMergeSort::* invocation. Lines 15-75 currently drop status codes, which weakens these tests to compile-only coverage instead of validating runtime API query success.

As per coding guidelines: cub/**/*: Focus on algorithm correctness, temporary-storage protocol, dispatch/policy selection, stream behavior, CUDA error handling, synchronization, memory access safety, performance regressions, and test coverage.

cub/test/catch2_test_device_scan_api.cu (1)

42-168: ⚡ Quick win

suggestion: Add cudaError_t status = ...; REQUIRE(status == cudaSuccess); for each newly added non-env cub::DeviceScan::* call in Lines 42-168. Ignoring statuses here makes failures on overload resolution/dispatch path invisible to the test suite.

As per coding guidelines: cub/**/*: Focus on algorithm correctness, temporary-storage protocol, dispatch/policy selection, stream behavior, CUDA error handling, synchronization, memory access safety, performance regressions, and test coverage.

cub/test/catch2_test_device_segmented_scan_api.cu (1)

417-576: ⚡ Quick win

suggestion: Capture and assert the return status for each non-env cub::DeviceSegmentedScan::* call. Lines 417-576 currently ignore cudaError_t, so runtime query-path regressions won’t fail these tests.

As per coding guidelines: cub/**/*: Focus on algorithm correctness, temporary-storage protocol, dispatch/policy selection, stream behavior, CUDA error handling, synchronization, memory access safety, performance regressions, and test coverage.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a533ea8a-ba38-483e-96aa-e0f6bda0f087

📥 Commits

Reviewing files that changed from the base of the PR and between 9378ff3 and 8e34fbc.

📒 Files selected for processing (13)
  • cub/cub/device/device_histogram.cuh
  • cub/cub/device/device_merge_sort.cuh
  • cub/cub/device/device_scan.cuh
  • cub/cub/device/device_segmented_scan.cuh
  • cub/test/catch2_test_device_histogram_api.cu
  • cub/test/catch2_test_device_histogram_env_api.cu
  • cub/test/catch2_test_device_merge_sort_api.cu
  • cub/test/catch2_test_device_merge_sort_env_api.cu
  • cub/test/catch2_test_device_scan_api.cu
  • cub/test/catch2_test_device_scan_by_key_env_api.cu
  • cub/test/catch2_test_device_scan_env_api.cu
  • cub/test/catch2_test_device_segmented_scan_api.cu
  • cub/test/catch2_test_device_segmented_scan_env_api.cu
💤 Files with no reviewable changes (1)
  • cub/cub/device/device_merge_sort.cuh

@github-actions

This comment has been minimized.

Comment thread cub/cub/device/device_merge_sort.cuh Resolved
Comment thread cub/cub/device/device_scan.cuh Resolved
Comment thread cub/test/catch2_test_device_scan_api.cu Resolved
@gonidelis gonidelis changed the title Env passthrough 4 Env passthrough 4/4 May 19, 2026
@gonidelis
gonidelis requested a review from bernhardmgruber May 19, 2026 21:38
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 25m: Pass: 100%/283 | Total: 11d 02h | Max: 2h 25m | Hits: 21%/904039

See results here.

Comment on lines +12 to +19
C2H_TEST("cub::DeviceHistogram::HistogramEven non-env overload is not ambiguous", "[histogram][device]")
{
thrust::device_vector<int> samples(1);
thrust::device_vector<int> histogram(1);
size_t temp_storage_bytes = 0;
cub::DeviceHistogram::HistogramEven(
nullptr, temp_storage_bytes, samples.begin(), thrust::raw_pointer_cast(histogram.data()), 2, 0, 10, 1);
}

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.

May need to be revisited depending on the outcome of #9078

@bernhardmgruber
bernhardmgruber merged commit eed8d77 into NVIDIA:main May 20, 2026
307 of 308 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Successfully created backport PR for branch/3.4.x:

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

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Final passthrough for all env APIs

2 participants