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
def persistent_topk_block(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 block-wide bitonic top-k for total_seq_len score rows.
For N β€ PERSISTENT_TOPK_MAX_N (= 2048) a single block sorts the whole row.
For N > PERSISTENT_TOPK_MAX_N a streaming variant folds _TILE-wide tiles
into a running top-_TILE champion; this requires K β€ PERSISTENT_TOPK_MAX_N
(the champion width). Call sites needing K > PERSISTENT_TOPK_MAX_N must
use topk_gpu.
Each row of N float32 scores yields the K highest-scoring column indices
(as int32) in descending score order in out_idxs.
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 (one block per row).
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!