interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

Experiment: fuse greedy lm-head selection into the BF16 GEMV epilogue without materializing full logits

Open · #72 · open 2026-10-24 17:49 UTC

Imported from GitHub aien-dev/CUDApp#72, by drakestapleton

drakestapleton wrote on 2026-10-24 17:49 UTC

Problem, ownership and deduplication

The graph already has GPU argmax and a one-command-list token path. This proposal does not recreate either. At main 22e9d9bad9b9238996b05b68dfd73e4036ed354f, record_final L353–366 emits BF16 lm-head into full FP32 logits, then argmax stage 0 over logits, then indexed argmax stage 1. BF16 epilogue L234–247 has each finished dot product in registers immediately before its global store. Greedy end_token reads only the selected token (L370–382); diagnostic/readback API can request complete logits (L400–407).

Related but different: Core #624 connects eligible greedy HTTP requests to the already-existing GPU token, eliminating host logit readback. Omega #558 tunes large 27B weight GEMVs; it does not eliminate the GPU logit intermediate. Coordinate with those owners and CUDApp #5/#16/#17/#19/#54/#57. Main, issue/PR inventory and relevant integration branch inspected; no equivalent lm-head/argmax fusion issue found.

Narrow candidate and counted work

For an explicitly token-only greedy mode, preserve each BF16 dot product/reduction and retain a (max_value, lowest_original_index) pair per warp/CTA across its row loop. Write one pair per GEMV CTA and use one ordered final reduction kernel. No grid-wide spin, no changed weight representation. Full-logit sampling, log-probabilities and diagnostic modes continue to choose the qualified materializing algorithm; callers must not receive stale logits from a token-only execution.

Let V=vocabulary, H=hidden dimension, A=2048 (current argmax span), C=ceil(V/A), Vp=A*C, and G=GEMV CTA count. Current logits boundary alone writes 4V and reads 4Vp bytes. Current first argmax writes 8C pair bytes. Fused GEMV writes 8G pair bytes instead, removing one launch/barrier; the second reduction can initially remain unchanged. Therefore the directly eliminated logical global traffic is 4V+4Vp+8(C-G) bytes, excluding the unchanged fixed-size final reduction, padding initialization, and optional future improvements. Example only: V=131072,H=2048,G=96 gives 1,048,320 B removed, nominal service term 3.840 microseconds at 273 GB/s.

The main work is unchanged: dense BF16 weights are 2VH bytes and dot products approximately 2VH FLOPs (plus reductions). For that example, weights alone are 536,870,912 B, ideal uncached streaming floor 1.967 ms at 273 GB/s. Therefore this is a small memory-traffic saving, potentially useful for launch/selection latency; it is not a large lm-head bandwidth acceleration. Count effective C2C service separately, with rate unknown. Register/shared-memory growth can lose more time than the removed boundary saves.

Correctness and applicability

  • Declare token-only versus full-logit output capability explicitly; arbitrary sampler closures, temperature changes, top-k/top-p, penalties, logprob requests and callbacks cannot silently qualify as greedy.
  • Preserve BF16 decode, per-row FP32 FFMA/reduction sequence, tie-to-lowest-original-index semantics, finite/nonfinite input policy, padding/tails, and supported row/CTA shapes. Existing tie rule is in argmax L303–355.
  • Bound CTA/warp partial capacity. Keep final reduction ordered after all producers, retain uncertainty latch/lifetimes, and keep host-polled token/completion buffers uncached under the platform contract. Unknown aliases remain dependent.
  • Do not change FP precision or introduce atomic floating reductions to get the claimed fusion. Any numerical relaxation is a different experiment with #16 acceptance.

Acceptance and controls

  • Reproduce baseline+candidate from pinned source/compiler/kernel/model/config identities in seeded .om; independent byte validation and simulator/native checks remain separate.
  • Compare selected token AND winning logit against the unfused materializing graph for supported shapes, multiple iterations, exact ties, near-ties, extreme finite values, tail/padding, and whatever nonfinite domain is admitted. Wrong index/tie handling, dropped last row, premature partial reuse, and omitted producer-to-reducer ordering are negative controls.
  • Prove at the API trace level that token-only mode performs no full-logit store/readback and cannot later return a stale diagnostic vector; full-logit and non-greedy modes retain their existing behavior and sampling receipts.
  • Paired warm/cold and repeated-session tests on actual GB10 through #17 report kernel/graph/HTTP p50/p95 as applicable, allocations, registers/declared registers/spills, shared bytes, launches/barriers, estimated logical bytes versus measured counters, and instrumentation cost. Freeze minimum benefit and regression limits before final comparison; preserve no-gain outcomes.
  • Keep opt-in until final integrated consumer gates pass; no live restart, driver switch, unreserved GPU run or deployment follows from this issue. Unsupported hardware/consumer evidence remains NOT_RUN; a reproducible no-go is a valid experimental outcome.

Status

Static opportunity only. No implementation, model run, speedup or energy result is claimed.

No comments.

Sign in to comment