Skip to content

Segmented scan tests to use cuda buffer - #11374

Closed
oleksandr-pavlyk wants to merge 28 commits into
NVIDIA:mainfrom
oleksandr-pavlyk:segmented-scan-tests-to-use-cuda-buffer
Closed

oleksandr-pavlyk wants to merge 28 commits into
NVIDIA:mainfrom
oleksandr-pavlyk:segmented-scan-tests-to-use-cuda-buffer

Conversation

@oleksandr-pavlyk

@oleksandr-pavlyk oleksandr-pavlyk commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR contains the final portion split from #10898.

It migrates the six CUB segmented-scan test suites from c2h::host_vector and c2h::device_vector to cuda::host_buffer and cuda::device_buffer backed by C2H checked memory resources.

CUB segmented-scan implementation is not changed.

The changes in this PR:

  • Migrate all six segmented-scan test suites from C2H vectors to cuda::device_buffer and cuda::host_buffer.
  • Add shared segmented-scan utilities for buffer construction, host/device copies, reference scans, and result matching.
  • Propagate explicit streams through test setup, CUB launches, copies, and result verification.
  • Extend the launch-test helper to accept stream-like arguments while preserving host, device-side, and CUDA graph launch coverage.
  • Add buffer-returning uniform-offset generators and validate offset sizes before allocation.
  • Keep large-buffer comparison diagnostics bounded to fixed storage while preserving total mismatch reporting.
  • Restore explicit vector-size checking in the C2H matcher.
  • Update the launch-wrapper testing documentation and add regression coverage for the supporting utilities.
  • Also small cleanup: Guard main-only Catch2 and generator includes with C2H_CONFIG_MAIN.

closes #11373

gated by #11344

Checklist

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

@oleksandr-pavlyk
oleksandr-pavlyk requested review from a team as code owners September 13, 2026 11:17
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Sep 13, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Sep 13, 2026
@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-tests-to-use-cuda-buffer branch from f2a2931 to df5f8d7 Compare September 13, 2026 11:24
@coderabbitai

coderabbitai Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: NVIDIA/cccl
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 7bf3883
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: e22ed726-09fa-430e-b947-1b9e45a4eb99
Commits

Reviewing files that changed from the base of the PR and between d2db03d and b7b08e2.

Files selected for processing: 2
  • c2h/include/c2h/buffer_generators.cuh
  • cub/test/catch2_test_launch_helper.h
Files skipped from review as they are similar to previous changes: 1
  • c2h/include/c2h/buffer_generators.cuh

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

📝 Summary

Summary by CodeRabbit

  • New Features
    • Uniform segment offsets can now be generated on a specified non-default CUDA stream or directly into resizable device and host/device buffers.
    • Added utilities for copying device-buffer data to host and comparing device buffers with expected values.
    • Host buffers can now be created with values initialized at allocation.
  • Bug Fixes
    • Offset generation now validates requested capacity and rejects invalid sizes before allocation.
    • Buffer comparisons now require matching sizes and report a bounded set of mismatches.
  • Documentation
    • Clarified stream handling for host, graph, and device launches.

The PR adds checked, stream-aware uniform-offset generation and C2H buffer utilities. It migrates segmented-scan tests to CUDA buffers and explicit streams. It also updates launch wrappers and adds shared scan-reference and numeric test helpers.

Changes: C2H buffer and generator utilities

Layer / File(s) Summary
Buffer operations and comparison
c2h/include/c2h/buffer_utils.cuh, c2h/include/c2h/catch2_test_helper.h, c2h/include/c2h/checked_memory_resource.cuh, c2h/include/c2h/device_and_stream.h, c2h/include/c2h/buffer_generators.cuh, cub/test/catch2_test_c2h_buffers.cu
Adds device-to-host copy and comparison helpers, bounded mismatch reporting, initialized host-buffer creation, customizable device buffers, and buffer tests.
Checked uniform-offset generation
c2h/include/c2h/generator_common.h, c2h/include/c2h/vector_generators.h, c2h/generators_uniform_offsets.cu, c2h/include/c2h/buffer_generators.cuh, cub/test/catch2_test_c2h_buffers.cu
Validates offset counts and destination capacity. Adds stream-based generation and resizable device-buffer and paired-buffer APIs.
Generator and shared test support
c2h/generators_gen_values.cu, c2h/include/c2h/detail/generators.cuh, cub/test/catch2_test_scan_reference.cuh, cub/test/catch2_test_device_scan.cuh, cub/test/catch2_test_numeric_helpers.cuh, cub/test/catch2_test_device_reduce.cuh
Moves value-generation implementation into the detail header. Adds shared scan references and numeric helpers for extended, custom, and vector types.

Segmented-scan test migration

Layer / File(s) Summary
Test utilities and reference functions
cub/test/catch2_test_device_segmented_scan_utils.cuh, cub/test/catch2_test_scan_reference.cuh, cub/test/catch2_test_device_scan.cuh
Adds scan test type aliases, host-buffer generation and copy helpers, and shared exclusive and inclusive scan references.
Core scan tests
cub/test/catch2_test_device_segmented_scan.cu
Uses CUDA host/device buffers and explicit streams for scan calls and result checks.
API and environment tests
cub/test/catch2_test_device_segmented_scan_api.cu, cub/test/catch2_test_device_segmented_scan_env.cu, cub/test/catch2_test_device_segmented_scan_env_api.cu
Uses CUDA buffers and stream-bearing environments for scan, tuning, queued setup, overload resolution, and result comparisons.
Multi-segment and noncommutative tests
cub/test/catch2_test_device_segmented_scan_multi_segment.cu, cub/test/catch2_test_device_segmented_scan_noncommutative.cu
Uses explicit streams and CUDA buffers for dispatch, test data, expected results, and output checks.

Launch-helper stream support

Layer / File(s) Summary
Stream-aware launch helpers and tests
cub/test/catch2_test_launch_helper.h, cub/test/catch2_test_launch_wrapper.cu, cub/test/catch2_test_memory_resources.h, docs/cub/developer/test_overview.rst
Updates host, graph, device, and environment launch paths to handle streams and stream-associated buffers. Adds stream-forwarding tests and documents launch behavior. The device-side memory resource now supports a null allocation counter.

Assessment against linked issues

Objective Addressed Explanation
Migrate segmented-scan tests to CUDA buffer containers with checked memory resources instead of C2H host and device vectors [11373] ✅

Possibly related issues

Priority: Normal

Change: Refactor

Merge Risk: Minimal · up to b7b08

The reviewed changes preserve buffer, stream, and graph-capture behavior without introducing a concrete correctness or availability risk.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

coderabbitai[bot]

This comment was marked as outdated.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-tests-to-use-cuda-buffer branch from df5f8d7 to 2103b66 Compare September 13, 2026 11:54
coderabbitai[bot]

This comment was marked as resolved.

@github-actions

This comment has been minimized.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-tests-to-use-cuda-buffer branch from 2103b66 to 452f928 Compare September 13, 2026 17:39
@github-actions

This comment has been minimized.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-tests-to-use-cuda-buffer branch from 452f928 to 9d76f67 Compare September 13, 2026 19:49
@github-actions

This comment has been minimized.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-tests-to-use-cuda-buffer branch from 9d76f67 to 9adb174 Compare September 15, 2026 17:31
coderabbitai[bot]

This comment was marked as resolved.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-tests-to-use-cuda-buffer branch 2 times, most recently from 114d31b to 0173bae Compare September 15, 2026 18:20
@github-actions

This comment has been minimized.

@coderabbitai coderabbitai Bot mentioned this pull request Oct 5, 2026
2 tasks done
  - Migrated all six segmented-scan test suites to cuda::device_buffer/cuda::host_buffer
    created using c2h::make_device_buffer and c2h::make_host_buffer which used
    checked allocator memory resources
  - Added shared CUDA and segmented-scan test utilities
  - Added stream-aware launch-helper support and coverage
  - Added uniform-offset buffer generators and pre-allocation size validation
  - Updated C2H generator tests and CUB testing documentation
…rage

Track the total mismatch count while retaining only the first and last
five mismatches needed for diagnostics. This avoids allocating temporary
host storage proportional to the compared range size in segmented-scan
tests.

The new implementation keeps only the information printed on failure:

 - The first five mismatches go into first_mismatches.
 - The most recent five go into last_mismatches.
 - Additional mismatches overwrite the oldest trailing entry using a circular index.
 - A final rotation restores chronological order.
 - total_mismatches is still counted exactly.
 - The three good values preceding the first mismatch are still retained.

For example, with mismatches at indices 0–11, the result stores:

  First: 0, 1, 2, 3, 4
  Last:  7, 8, 9, 10, 11
  Total: 12

The diagnostic output remains the same, but auxiliary mismatch storage changes from
being proportional to the input size—O(N)—to a fixed maximum of ten records, O(1).

This matters because segmented-scan tests can compare very large
buffers close to the configured memory limit.
Require equal vector sizes in addition to zero element mismatches. This
prevents an empty actual vector from matching a nonempty expected vector.

Also added a regression test covering an empty actual vector against a
nonempty expected vector in cub/test/catch2_test_c2h_buffers.cu
Added tests for passing owning cuda::stream argument.

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

Blocking, until above feedback is addressed.

@github-project-automation github-project-automation Bot moved this from In Review to In Progress in CCCL Oct 21, 2026
This is still flat, all changes together, but it should be much closer
to the desired shape and validates that it all sits together before
I start splitting it all up

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

Actionable comments posted: 3

🧹 Nitpick comments: 5
c2h/include/c2h/buffer_utils.cuh: 1

59-59: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

suggestion: Complete the documented function contracts. Add //! @param[in/out/in,out] entries for every parameter of copy_to_host and read_single. Add //! @return for read_single. As per coding guidelines, “Documented functions must include //! @brief, //! @param[in/out/in,out] for every parameter, and //! @return for non-void functions.”

Also applies to: 87-87

Source: Coding guidelines

c2h/include/c2h/checked_memory_resource.cuh: 1

234-234: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

suggestion: Complete the new overload’s documentation. Add //! @param[in] entries for stream, device, num_items, and value. Add //! @return for the initialized host buffer. As per coding guidelines, “Documented functions must include //! @brief, //! @param[in/out/in,out] for every parameter, and //! @return for non-void functions.”

Source: Coding guidelines

c2h/include/c2h/device_and_stream.h: 2

30-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

suggestion: Make default_stream_ref constexpr. The function only constructs a null handle. Its cuda::stream_ref constructor is constexpr. (raw.githubusercontent.com) As per coding guidelines, “Use constexpr for functions that do not depend on run-time features, such as pointers.”

Source: Coding guidelines


27-27: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

suggestion: Use the required function documentation format. Replace the plain comment with //! @brief and add //! @return for the stream reference. As per coding guidelines, “Documented functions must include //! @brief, //! @param[in/out/in,out] for every parameter, and //! @return for non-void functions.”

Source: Coding guidelines

cub/test/catch2_test_device_segmented_scan_env_api.cu: 1

28-36: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

suggestion: Use public CUDA APIs in the extracted examples.

The documentation extracts these regions. The markers include c2h::make_device_buffer, while the device declaration is outside the markers. Define the device inside each example and use cuda::make_device_buffer for the documented setup. Do not move the buffers outside the markers because the extracted scan calls use them.


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: NVIDIA/cccl
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 7bf3883
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: c879fbb5-9245-4c0f-9d3b-e489749b7575
📥 Commits

Reviewing files that changed from the base of the PR and between d96f34d and 674c24b.

📒 Files selected for processing: 16
  • c2h/generators_gen_values.cu
  • c2h/generators_uniform_offsets.cu
  • c2h/include/c2h/buffer_utils.cuh
  • c2h/include/c2h/checked_memory_resource.cuh
  • c2h/include/c2h/detail/generators.cuh
  • c2h/include/c2h/device_and_stream.h
  • cub/test/catch2_test_c2h_buffers.cu
  • cub/test/catch2_test_device_segmented_scan.cu
  • cub/test/catch2_test_device_segmented_scan_api.cu
  • cub/test/catch2_test_device_segmented_scan_env.cu
  • cub/test/catch2_test_device_segmented_scan_env_api.cu
  • cub/test/catch2_test_device_segmented_scan_multi_segment.cu
  • cub/test/catch2_test_device_segmented_scan_noncommutative.cu
  • cub/test/catch2_test_device_segmented_scan_utils.cuh
  • cub/test/catch2_test_launch_helper.h
  • cub/test/catch2_test_launch_wrapper.cu
💤 Files with no reviewable changes: 1
  • c2h/generators_gen_values.cu

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

Comment thread c2h/include/c2h/buffer_utils.cuh Resolved
Comment thread cub/test/catch2_test_launch_wrapper.cu Resolved
custom_type_t<Policies> can be padded so we need to fully initialize
all bytes of this type before filling it up with a `min` value.
@github-actions

This comment has been minimized.

@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
c2h/include/c2h/buffer_generators.cuh: 1

51-52: Trivial · Maintainability & Code Quality · Quick win

suggestion: Restore the required function documentation tags. These changed comments document functions with plain // text. Add //! @brief and a //! @param[in/out/in,out] entry for each parameter. Add //! @return to the non-void functions. As per coding guidelines: “Documented functions must include //! @brief, //! @param[in/out/in,out] for every parameter, and //! @return for non-void functions.”

Also applies to: 78-80, 91-93, 113-113, 121-123, 141-143, 156-158, 176-178

Source: Coding guidelines

c2h/include/c2h/buffer_utils.cuh: 1

60-61: Trivial · Maintainability & Code Quality · Quick win

suggestion: Document these helpers with the required API tags. The new comments document copy_to_host and read_single without //! @brief or parameter entries. read_single also needs //! @return. As per coding guidelines: “Documented functions must include //! @brief, //! @param[in/out/in,out] for every parameter, and //! @return for non-void functions.”

Also applies to: 90-91

Source: Coding guidelines

c2h/include/c2h/detail/current_device.cuh: 1

12-15: Trivial · Maintainability & Code Quality · Quick win

suggestion: Keep assert_current_device documentation in the required format. Replace the plain comments with //! @brief and //! @param[in] device. As per coding guidelines: “Documented functions must include //! @brief, //! @param[in/out/in,out] for every parameter, and //! @return for non-void functions.”

Source: Coding guidelines

c2h/include/c2h/device_and_stream.h: 1

30-30: Trivial · Maintainability & Code Quality · Quick win

suggestion: Add the required tags to default_stream_ref documentation. Its plain comments document a non-void function. Use //! @brief and //! @return. As per coding guidelines: “Documented functions must include //! @brief, //! @param[in/out,in,out] for every parameter, and //! @return for non-void functions.”

Source: Coding guidelines


Review info
Run configuration
  • Source mode: Auto
  • Repository: NVIDIA/cccl
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 7bf3883
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 55d06e4f-67e5-43e1-97f0-b236ef2c0742
Commits

Reviewing files that changed from the base of the PR and between 674c24b and d2db03d.

Files selected for processing: 9
  • c2h/include/c2h/buffer_generators.cuh
  • c2h/include/c2h/buffer_utils.cuh
  • c2h/include/c2h/checked_memory_resource.cuh
  • c2h/include/c2h/detail/current_device.cuh
  • c2h/include/c2h/device_and_stream.h
  • cub/test/catch2_test_c2h_buffers.cu
  • cub/test/catch2_test_device_segmented_scan_api.cu
  • cub/test/catch2_test_launch_helper.h
  • cub/test/catch2_test_launch_wrapper.cu
Files skipped from review as they are similar to previous changes: 2
  • c2h/include/c2h/checked_memory_resource.cuh
  • cub/test/catch2_test_device_segmented_scan_api.cu

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

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 7h 06m: Pass: 100%/187 | Total: 8d 23h | Max: 2h 56m | Hits: 39%/538559

See results here.

@oleksandr-pavlyk

Copy link
Copy Markdown
Contributor Author

This PR has been split into smaller, more focused PRs. The PR to change non-API tests for DeviceSegmentedScan to use cuda::buffer is #12495 .

Closing this PR now.

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.

[Task] Open PR with last shard of 10898 which modifies segmented test scan tests

4 participants