Skip to content

reg.rs says the measurement does not favour the SFU exp2, on a register count; timed, it is 2.7x #81

Closed

Description

@feitreim

Found by #76 and deliberately not taken there, because the file it is about was
not the file that issue was fixing.

src/reg.rs's module header says the measurement does not favour the SFU
exp2 over the FMA polynomial. The evidence behind that sentence is a register
count on softmax_probe_128 — and nothing else. #76 timed it on a real kernel:

at CHUNK = 16, 8192 blocks regs frame GB/s
exp2 — the FMA polynomial 50 128 1178
exp2_hw — one ex2.approx.f32 48 0 3153

2.7×, and it is the largest single term in softmax's 4.6× improvement. At
that kernel's shipped shape the two spellings are 32 registers and a zero frame
either way, so the register column does not distinguish them at all — and
where it did, it pointed the wrong way. That is the fourth time in this
repository the register column has ordered time backwards (#47, #63, #67, #76).

The cost is a clamp, a shift-trick split and a degree-3 minimax evaluated
twice per element
over 128 elements a thread, against one SFU instruction.

And the accuracy argument does not defend it either

The SFU is good to roughly 2⁻²² where the polynomial's own bound is 7.5e-5, and
softmax's exactness check measures a worst relative error of 1.97e-3 either
way
— the two are indistinguishable at the tolerance, because what dominates
is the bf16 round-trip and not the transcendental. So the polynomial is paying
2.7× for precision that nothing downstream can observe.

Scope

  1. Correct src/reg.rs's header. It is a claim about a measurement, made on
    a measurement that could not see the thing it is claiming about. This is the
    GAPS.md §3.2 (Reductions) is stale from before #6 landed #65 failure mode living in library docs rather than in GAPS.md: prose that
    nobody re-reads, contradicted by no commit message. softmax.rs and
    examples/README.md currently state the contradiction rather than resolve
    it, which was the right call for softmax is now the slow kernel by 5.8x, and its CHUNK rung is only a quarter of it #76 and is not a resting place.
  2. Decide what the default should be, and say why in the doc rather than
    leaving both spellings with equal billing. Note the header also claims
    ex2.approx serializes in some chain schedules — if that is load-bearing it
    needs a probe of its own; if it is inherited from FA4 lore, say so.
  3. flash_forward still calls the polynomial in its inner loop, twice per
    element per tile, which is where it would cost the most. It has no launcher
    and no CPU reference, so a numerics change there cannot currently be
    checked
    — do not make it blind. Either sequence this behind flash's
    harness, or land the reg.rs correction and leave flash explicitly marked.
  4. If the default changes, sweep the kernels that call it rather than assuming
    the 2.7× transfers. layernorm_rows sits at 255 registers with spills and gets 2 blocks/SM where softmax gets 6 #67 and softmax is now the slow kernel by 5.8x, and its CHUNK rung is only a quarter of it #76 both found the ladder does not answer for a
    kernel that has to be built.

Acceptance

The doc says what the measurement says, and the measurement is timed rather than
counted. Any kernel change carries a check in front of it and a positive control
behind it (#67/#76 discipline).

Related: #76 (the measurement), #63 (ptxas reports what was allocated, never
what it cost), #65 (unchecked prose rots), #47.

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