For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo function
persistent_topk_block_split
def persistent_topk_block_split(ctx: DeviceContext, in_scores: Pointer[Float32, ImmutAnyOrigin, _safe=False], out_idxs: Pointer[Int32, MutAnyOrigin, _safe=False], N: Int, K: Int, total_seq_len: Int)
Launch bitonic top-k, splitting the N dimension when rows under-fill GPU.
Same contract and output as persistent_topk_block. When the row count is
small relative to the SM count and N spans many tiles (the long-context
decode regime β a handful of blocks would otherwise each fold the whole row
serially), the streaming fold is split across rows * S blocks (phase 1),
each producing a sorted top-_TILE partial, then merged per row (phase 2).
All other shapes fall back to persistent_topk_block unchanged.
Args:
- βctx (
DeviceContext): Device context. - βin_scores (
Pointer[Float32, ImmutAnyOrigin, _safe=False]): Flat score buffer[total_seq_len Γ N]row-major. - βout_idxs (
Pointer[Int32, MutAnyOrigin, _safe=False]): Output buffer[total_seq_len Γ K]row-major (int32). - βN (
Int): Score columns per token. - βK (
Int): Top-k count per token (β€ N, and β€ PERSISTENT_TOPK_MAX_N when N > 2048). - βtotal_seq_len (
Int): Number of rows.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!