A row of logits is half a megabyte, so the kernel is not bandwidth-bound and the cost is in how many passes you make over it. Why a full sort does far more work than the question asks, the two shapes that fit small and large k, and the four-pass radix select with a reference that matches a sort exactly.
Select the top k logits from a 128,000-token vocabulary on the GPU. What shape does the kernel take and why not just sort?
A row of logits is half a megabyte, so the kernel is not bandwidth-bound and the cost is in how many passes you make over it. Why a full sort does far more work than the question asks, the two shapes that fit small and large k, and the four-pass radix select with a reference that matches a sort exactly.
Updated Sep 2026 · Grounded in real AI infrastructure interview loops and written to a senior-engineer editorial bar, with every number worked and every diagram hand-built.
The concepts behind this question
Ranked by how closely each one overlaps this question's topic, so the first card is the thing to read if the answer above moved too fast.
Scored on rejecting a full sort with a reason, on choosing the structure from the size of k, on the per-block-then-merge shape for small k, and on knowing the radix select is a fixed number of passes regardless of vocabulary size.
No comments yet — be the first to share your approach.
