Skip to content

softmax is now the slow kernel by 5.8x, and its CHUNK rung is only a quarter of it #76

Closed

Description

@feitreim

Found by #67's agent while fixing layernorm_rows, deliberately not shipped
in #75, and correctly so — softmax.rs's header argues for CHUNK = 32 at
length, and a one-constant probe is not an argument against a written one.
Filing it so the probe is not lost.

The probe

softmax_rows at CHUNK = 16 against its shipped CHUNK = 32, nothing else
changed:

regs frame GB/s
CHUNK = 32, as shipped 66 256 B 950
CHUNK = 16 50 128 B 1185

Half the frame, a quarter more throughput, on a kernel whose arithmetic did not
change.

Why it is worth a ticket

softmax is now the slow kernel in the repository. After #67,
layernorm_rows runs 5539 GB/s where softmax_rows runs 950 — a factor of
5.8, at equal shared memory and the same 6 blocks per SM. Layernorm does
strictly more work per element (two statistics rather than one, plus a gamma
and beta apply), so the ordering is backwards and something is being left on
the floor.

The 16-rung probe is the obvious first suspect but it is not the whole gap: 950
→ 1185 is 1.25×, and the gap is 5.8×. Do not assume closing the rung closes
the difference.
The rest is unexplained and is the more interesting half.

What #67 established that applies here

Scope

  1. Re-run the [32, N] column sweep against softmax_rows at every rung, the
    way layernorm_rows sits at 255 registers with spills and gets 2 blocks/SM where softmax gets 6 #67 did rather than testing two points, and report registers, spill,
    frame, blocks/SM and GB/s per rung. ptxas -v reports what was allocated,
    never what it cost (Is a streamed local-memory band actually slower? ptxas cannot say, and the ladder now makes the question concrete #63) — the GB/s column is the one that decides.
  2. If a rung wins, rewrite softmax.rs's header argument for 32 rather than
    silently changing the constant underneath it. The prose is the reason the
    number is what it is, and a number that no longer matches its argument is
    the GAPS.md §3.2 (Reductions) is stale from before #6 landed #65 failure mode in code.
  3. Then account for the rest of the 5.8×, which is the actual point of this
    issue. softmax already survived one round of this in softmax is latency-bound, not bandwidth-bound: 362 GB/s ceiling and a flat 51us floor #47 and came out
    latency-bound with a flat floor; layernorm_rows sits at 255 registers with spills and gets 2 blocks/SM where softmax gets 6 #67 has since shown that floor is not a
    fixed harness cost (layernorm reaches 8.4 µs where softmax is latency-bound, not bandwidth-bound: 362 GB/s ceiling and a flat 51us floor #47 read softmax's 23 µs
    as the launch itself). So the floor is back on the table as a defect rather
    than a constant.

Acceptance

Same discipline as #67: no throughput claim without the exact check passing at
all six sizes first, and a positive control showing the check fails against a
deliberately broken kernel. softmax already has a reference and a bench row,
so unlike #67 this one starts from a harness that exists.

Related: #47 (softmax's last round, and the 23 µs floor this reopens), #67 (the
finding, and the rung discipline), #63 (allocated is not cost), #60 (the
ladder).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compute

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions