Skip to content

gemm_cg2 is three registers from losing a third of its occupancy, and nothing is watching #95

Closed

Description

@feitreim

#94 vectorized store_rows/load_rows and took gemm_cg2 from 40 registers
to 167
, with zero spill and an unchanged frame. It is a clear net win —
8192³ went 1076 → 1223 TFLOP/s and occupancy did not move — but it spent almost
all of a budget nobody was tracking.

At 128 threads against a 64 K register file:

registers CTAs/SM
≤ 128 4
≤ 170 3
≤ 256 2

gemm_cg2 is at 167. Three registers of headroom. The 171st register costs
a third of the kernel's occupancy.

Why this is a live risk rather than a curiosity

#84 measured the GEMM at 3 CTAs/SM, capped by its 73792 B shared plan. Registers
were nowhere near binding at 40, so nothing in the repo watches them. They are
now the joint binding constraint, and four in-flight or queued changes all add
live state to this kernel:

Any one of them can silently cross 170. The failure mode is not a build error or
a wrong number: it is a third of the occupancy, showing up as a throughput
regression that looks like the feature was a bad idea. That is expensive to
diagnose and easy to misattribute — and #47, #63, #67, #76 and now #94 are five
occasions where a register count did not mean what someone assumed it meant.

The cause of the jump is unestablished, and that is stated honestly

#94's agent hypothesized the inline asm's memory clobber, measured it, and was
wrong
— deleting both clobbers gives byte-identical counts. So this issue is
not "undo the regression"; the registers may well be buying the speed. It is
"make the cliff visible".

Worth a look anyway: 4x the registers for a change that only alters how stores
are issued is surprising, and if the extra state is incidental rather than
load-bearing then there is headroom to reclaim for free.

Scope

  1. Make the cliff checked rather than remembered. modal_app.py::regcount
    already prints registers per entry function and runs CPU-only on every PR
    through tier 2. A threshold that fails the run when a named kernel crosses
    its occupancy step would catch this at the cheapest gate available, before a
    B200 is ever booked. Prefer that to a const assert, since the count is a
    ptxas output and not something the type system can see.
  2. Express the threshold as the occupancy step, not as a magic 170 — derive it
    from threads and the register file so it stays right if THREADS changes.
  3. Do not gate on an exact count, which would fail on every incidental
    codegen wobble. Gate on the step.
  4. Then investigate whether the 40 → 167 jump is load-bearing. Report what
    the extra live state is; if some is incidental, reclaiming it is free
    headroom for lcsf and the rest of the prototype layer #15, Sweep the GEMM's pair tile and pipeline depth: [256,256] at three stages should dominate on paper #87 and Cluster Launch Control: hardware work-stealing exists in cuda-oxide and pipeline::run schedules statically #88.

Acceptance

A tier-2 gate that fails when a kernel's register count would cost it a CTA per
SM, with the step derived rather than hardcoded, and a positive control showing
it fires — deliberately inflate a kernel past its step and watch the gate go
red. Same discipline as #67 and #76: a check nobody has seen fail is not
a check.

Related: #94 (the jump and the win), #84 (the residency census and why shared
memory was the only cap anyone was watching), #63, #15, #87, #88.

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