-
Notifications
You must be signed in to change notification settings - Fork 428
Implement Segmented TopK using Thread-Block-Clusters #9224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pauleonix
wants to merge
130
commits into
NVIDIA:main
Choose a base branch
from
pauleonix:cluster-topk-poc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
130 commits
Select commit
Hold shift + click to select a range
5c45cdd
Simple cluster
gevtushenko ef0c358
Early
gevtushenko f7b8359
Coop
gevtushenko 55bdf24
Larger tile
gevtushenko ba545e3
Refactor test
gevtushenko fd2f4f3
Working on atomic
gevtushenko 01c6838
Bench
gevtushenko 82eae9a
Force atoms
gevtushenko 34e3ab9
Early exit
gevtushenko 00bc1e2
Late entry
gevtushenko b36aa62
Bound search
gevtushenko 2477d87
Remove restriction of one bucket per thread
pauleonix dc1c00d
Remove experimental atomic backend
pauleonix 784416a
Local atomic output index accumulation
pauleonix 5ea4399
Fix race introduced with early exit
pauleonix 8657a21
Add scan-then-reduce path
pauleonix f8442af
Make cluster size dynamic
pauleonix c03daaf
Increase tile size using smem
pauleonix 082c3df
Improve dispatch and naming
pauleonix 0b8111d
Handle very big segments by repeated streaming
pauleonix 8e29b29
Fix variable benchmark
pauleonix 69e7932
Manually tune for B200
pauleonix c95a1b4
Clean up chunking
pauleonix c24d75e
Get rid of local memory and generic atomics
pauleonix b2b4494
Fix deadlocks
pauleonix e56abb0
Fix smem alignment to match gmem alignment
pauleonix 68eca9a
Use blocked chunks
pauleonix 0fa088f
Merge branch 'main' into cluster-topk-poc
pauleonix 50abf59
Implement determinism
pauleonix 6313b02
Add value handling
pauleonix aa96a9a
Make streaming decision more flexible
pauleonix 406f4c8
Hide streaming latency behind resident work
pauleonix 34e22a7
Fix non-deterministic key-value case
pauleonix 0f60524
Apply latency hiding to non-deterministic filter
pauleonix f830031
Avoid inflating the number of streamed chunks
pauleonix cb52dac
Optimize histogram loop
pauleonix 338784c
Improve non-TMA fallback path and its testing
pauleonix 9a23a33
Clean up
pauleonix 4883221
Move hardware constants to appropriate header
pauleonix 986dff5
Merge branch 'main' into cluster-topk-poc
pauleonix 34b613a
Fix races due to missplaced histogram resets
pauleonix 9fc8e46
Add special handling for head/tail storage
pauleonix 4bedd27
Wire up determinism/tie-breaking requirements
pauleonix 57a5385
Improve tuning parameters (unrolling)
pauleonix 5c211da
Improve dispatch by minimizing waves
pauleonix f98b50c
Optimize single CTA case
pauleonix ca10336
Prefer single-CTA when possible
pauleonix 347fd7f
Prefer single-CTA only up to a tunable threshold
pauleonix 488f0a3
Dynamically shrink clusters to single CTA
pauleonix c8f3e05
Disregard CTAs with less chunks than threshold
pauleonix 8acc49c
Add fast path for k > segment size
pauleonix 9268c5b
Symmetrize prefer-large-index perf
pauleonix d28d69e
Improve histogram unrolling
pauleonix 8e7e0b6
Revert "Improve histogram unrolling"
pauleonix 13fb7e3
Clamp unrolling for small segments
pauleonix e448787
Also clamp unrolling of the k>=segment_size path
pauleonix 0bc7b85
Add histogram unrolling experiment
pauleonix 04e7f65
Do another histogram unrolling experiment
pauleonix b269e7a
Clean up unrolling experiments
pauleonix bc4bfd3
Improve mbarrier/bulk copy codegen
pauleonix 2f398aa
Parallelize mbarrier init
pauleonix aa33341
Fix deterministic filter not using pipeline
pauleonix dcc39e4
Improve early exit
pauleonix 4069a2d
Reduce filter-scans on deterministic path
pauleonix 9fd05c3
Parallelize inter-CTA scan atomics
pauleonix 431a5f3
Move from pull-based broadcast to push-based
pauleonix 982d48c
Revert "Move from pull-based broadcast to push-based"
pauleonix ac0c6a1
Subdivide first resident chunk for better ramp-up
pauleonix 94205d1
Revert "Subdivide first resident chunk for better ramp-up"
pauleonix 204cfc5
Reduce early exit checking
pauleonix db38b62
Simplify tail handling
pauleonix 7a47139
Replace cg with PTX
pauleonix 1a8e1bb
Avoid bulk copy when ct max seg size is small
pauleonix 0b26e44
Revert "Avoid bulk copy when ct max seg size is small"
pauleonix 94d5a64
Clean up big nested lambdas
pauleonix 5e6c265
Merge branch 'main' into cluster-topk-poc
pauleonix 43cbd1f
Unify backends into one dispatch/tuning/kernel
pauleonix b943a0c
Update tests to use the unified interface
pauleonix 592279d
Update benchmarks to use the unified interface
pauleonix d26c7b8
Avoid re-repriming streamer for filter
pauleonix e381495
Move CDP kernel to kernel header
pauleonix 53d7350
Remove dead code and avoid repetition
pauleonix ac027d2
Add emit_back_one function to avoid repetition
pauleonix 692f05c
Add sink removing repetition from write_selected[_idx]
pauleonix d651595
Clean up variable/function naming
pauleonix d38bf56
Trim comments a little
pauleonix 88cee8d
Split up long functions
pauleonix d0458bf
Split up more long functions
pauleonix 19a9cae
Use ceil_div and clamp
pauleonix 75a88a8
Use I32 offsets instead of U32
pauleonix ac18c38
Go back to unsigned offsets in the agent
pauleonix 40144aa
Go back to unsigned integers for indices internally
pauleonix 44e2a43
Improve latency hiding via split-barrier
pauleonix e9ed894
Clean up
pauleonix 45b80d2
Revert unnecessary changes to API tests.
pauleonix 7e51a28
Remove redundant helper
pauleonix fe003da
Add defensive asserts
pauleonix fbeddc5
Move barriers up the call chain
pauleonix 7148ce4
Use member variables to avoid many arguments
pauleonix 0a35ad7
Flatten overflow streamer into agent
pauleonix c95ef85
Flatten deterministic filter class into agent
pauleonix 545c8f5
Flatten write_nondeterministic_topk lambda
pauleonix 63a7faf
Avoid bool/enum arrays
pauleonix 302b852
Flatten emit_[arrival|indexed] lambdas
pauleonix 71dfeb0
Unify candidate and selected path
pauleonix 7dc3284
Unify det and non-det filters
pauleonix f0d1799
Prime output rank counters with offsets
pauleonix 22d9ee9
Split scan atomics since 64b ones seem to spin
pauleonix dab7483
Try to fix non-det perf regression from unification
pauleonix dadf4e9
Try to use striped loads in the deterministic filter
pauleonix 6b9eeae
Use elected leader thread also outside TMA
pauleonix 1866bc8
More clean up
pauleonix 65390a6
Make sure no unrolling decision is left to the compiler
pauleonix 355e107
Revert forcing nounroll for some loops due to perf
pauleonix 960d6a2
Flatten more lambdas
pauleonix cf4272d
Improve TMA latency hiding
pauleonix d7fe9c2
Hopefully revert perf regression from previous commit
pauleonix c9f0878
Improve testing
pauleonix 10391be
Try fixing perf regression again
pauleonix b9a790f
Next try
pauleonix cc12760
Cut out dead streaming prime call
pauleonix a92bdd3
Clean up
pauleonix 9abc4ef
First pass opimization
pauleonix 983a8aa
Fix pipeline ordering
pauleonix ad6ddc3
Revert .clangd change
pauleonix 240dcd3
Merge branch 'main' into cluster-topk-poc
pauleonix 1f9d81b
Implement CodeRabbit feedback
pauleonix 563d246
Remove dead legacy dispatch functions
pauleonix fc46a4a
Make CUB_DISABLE_TOPK_UNSUPPORTED_ARCH_ASSERR public
pauleonix 5d86cdc
Fix issues with Clang as host compiler
pauleonix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
cub/benchmarks/bench/segmented_topk/variable/indexed.cluster.cu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| // Cluster-backend variable-segment indexed (arg-top-k) benchmark. A base build runs the library's production | ||
| // (automatic) selector; a tuning variant forces the cluster backend and sweeps its per-block knobs plus the | ||
| // determinism / tie-break requirement. The baseline backend is benchmarked separately in the plain `indexed.cu`. | ||
|
|
||
| // %RANGE% TUNE_CLUSTER_THREADS_PER_BLOCK tpb 128:1024:32 | ||
| // %RANGE% TUNE_CLUSTER_MIN_BLOCKS_PER_SM mbs 1:2:1 | ||
| // %RANGE% TUNE_CLUSTER_MIN_CHUNKS_PER_BLOCK mcb 1:2:1 | ||
| // %RANGE% TUNE_CLUSTER_CHUNK_KIB ckib 8:32:1 | ||
| // %RANGE% TUNE_CLUSTER_LOAD_ALIGN_BYTES_POW2 la 4:7:1 | ||
| // %RANGE% TUNE_CLUSTER_PIPELINE_STAGES ps 2:16:1 | ||
| // %RANGE% TUNE_CLUSTER_BITS_PER_PASS bpp 8:11:1 | ||
| // %RANGE% TUNE_CLUSTER_HIST_IPT hipt 1:24:1 | ||
| // %RANGE% TUNE_CLUSTER_TIEBREAK_IPT tipt 1:24:1 | ||
| // %RANGE% TUNE_CLUSTER_COPY_IPT cipt 1:24:1 | ||
| // %RANGE% TUNE_REQUIREMENT req 0:2:1 | ||
|
|
||
| #ifndef TUNE_BACKEND | ||
| # if TUNE_BASE | ||
| # define TUNE_BACKEND 2 // automatic: the library's production selector, for base/benchmark builds | ||
| # else | ||
| # define TUNE_BACKEND 1 // cluster: the backend this file tunes | ||
| # endif | ||
| #endif | ||
|
|
||
| #ifndef TUNE_REQUIREMENT | ||
| # define TUNE_REQUIREMENT 1 // deterministic + prefer-smaller-index (forward): the safe, least-surprising default | ||
| #endif | ||
|
|
||
| #include "indexed_common.cuh" | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.