Skip to content

Segmented scan agent with multiple segments per block - #6712

Open
oleksandr-pavlyk wants to merge 43 commits into
NVIDIA:mainfrom
oleksandr-pavlyk:segmented-scan-agent-with-multiple-segments-per-block
Open

oleksandr-pavlyk wants to merge 43 commits into
NVIDIA:mainfrom
oleksandr-pavlyk:segmented-scan-agent-with-multiple-segments-per-block

Conversation

@oleksandr-pavlyk

@oleksandr-pavlyk oleksandr-pavlyk commented Nov 20, 2025 •

Copy link
Copy Markdown
Contributor

Description

Closes #6783
Closes #8424

  • extend agent_segmented_scan with ability to to consume multiple segments per block

    • Introduce new agent template parameter MaxSegmentsPerBlock which controls the size of OffsetT array in shared memory dedicated to storing inclusive-scan of segment sizes. The actual number of segments to process is passed dynamically to consume_ranges method. It can not exceed MaxSegmentsPerBlock, however.
    • Multiple-segments are processed by reconstructing head-flags while loading values using multi_segment_iterator class, which is read- and write- transform iterator.
      • Read transformation reconstructs head-flag and forms value-flag pair, used as AccumT by BlockScan, and
      • write-transform unpacks value-flag pair and only writes the value to the output iterator.
    • Mapping from element_id to segment_id and relative_offset (or rank) is encapsulated into searcher types.
    • Three searcher types are implemented:
      • When segment sizes are all the same, segment_id = element_id / segment_size.
      • Generically, binary search in the array of inclusive-scan of segment sizes is performed. Two implementations (types) are provided:
        • When static bound on array size of known (as it is in our case), branch-less binary search provides best performance
        • When this bound is unknown, cuda::std::upper_bound can be used for larger number of sizes, and linear search using dynamic for-loop for smaller sizes
    • While computing inclusive-scan of segment sizes, we check if all sizes to be processed by block are the same, and use fixed-size searcher, otherwise use branch-less generic searcher.
    • When dynamic number of segments equals 1, simpler consume_range call is made, which does not reconstruct head-flags
  • introduce agent_warp_segmented_scan which closely follows the logic of agent_segmented_scan that computes are block-granularity, but using warps to process given number of segments

    • This agent is advantageous when segment sizes are medium-sized, but not too small.
  • introduce agent_thread_segmented_scan which implement thread-granularity work. Each thread processes requested number of segments.

    • multi-segment iterator here is implemented sequentially, iterating within segment, then over segments.
    • Thread-granularity agent is ideal when segments have only a few elements each.
  • Dispatch layer is modified to take 2 additional parameters (with default values), the number of segments to be processed by a worker (defaults to 1), and the type of worker requested (defaults to block).


This PR implements `cub::detail::segmented_scan::agent_segmented_scan_multiple_segments_per_block`. The agent processes statically known `int SegmentsPerBlock` segments per block in `consume_ranges` method, and implements a tail version as well.

Checklist

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

@copy-pr-bot

copy-pr-bot Bot commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Progress in CCCL Nov 20, 2025
@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-agent-with-multiple-segments-per-block branch 3 times, most recently from 87fccc2 to ea8e25b Compare November 25, 2025 18:09
@oleksandr-pavlyk

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-agent-with-multiple-segments-per-block branch from ea8e25b to 85c74bc Compare November 26, 2025 21:38
@oleksandr-pavlyk

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@oleksandr-pavlyk

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@oleksandr-pavlyk

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-agent-with-multiple-segments-per-block branch from 63b6ae3 to bcf2e58 Compare November 28, 2025 16:31
@oleksandr-pavlyk

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@oleksandr-pavlyk

Copy link
Copy Markdown
Contributor Author

/ok to test

1 similar comment
@oleksandr-pavlyk

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-agent-with-multiple-segments-per-block branch from 10e7ccb to 5aee1ed Compare November 30, 2025 17:38
@oleksandr-pavlyk

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-agent-with-multiple-segments-per-block branch from 5aee1ed to f66ffea Compare December 4, 2025 17:16
@oleksandr-pavlyk

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-agent-with-multiple-segments-per-block branch from f66ffea to 125c54c Compare February 10, 2026 22:36
Exit early if remaining work is out of bound. Clamp amount
of the segments for this thread to process to avoid probing
out of bound.
This is to make it clear that max_segments_per_warp is the natural
kernel tuning parameter. It is independent from max_segments_per_block.
1. Use _CCCL_DEDUCTION_GUIDE_ATTRIBUTES instead of _CCCL_DEVICE
2. Avoid allocating __shared__ temp-storage of empty type.
3. Add assertion that access to input/output offsets in multi-segment
   sequential iterator is done on a non-exhausted iterator.
@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the segmented-scan-agent-with-multiple-segments-per-block branch from e06e119 to 9906f29 Compare July 6, 2026 15:33
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

⏱️ CCCL compile-time benchmark comparison: Public headers compile-time bench

Result: 0 regression row(s), 2 improvement row(s) above threshold.

Run Value
Config public-headers-gcc13
Baseline origin/main
Preset all-dev
Targets cub.headers.base, thrust.cpp.cuda.headers.base, libcudacxx.test.public_headers
GPU / launch args rtx2080 / --cuda 13.3 --host gcc13

Artifacts: reports and traces

Direct file processing

-f file-processing exclusive --sort total

🟢 Direct file processing — Improvements
Rank Improvement impact Selected Δ Baseline Current Event Matched traces
1 0.668807 -0.668807 5.463629 4.794822 Processing Header File: libcudacxx/include/cuda/std/__cccl/prologue.h 554
2 0.219054 -0.219054 1.692802 1.473748 Processing Header File: libcudacxx/include/cuda/std/__cccl/epilogue.h 554

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 41m: Pass: 100%/272 | Total: 3d 14h | Max: 1h 31m | Hits: 83%/229151

See results here.

This branch has not been deployed

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

Labels

None yet

Projects

Status: In Review

6 participants