Skip to content

layernorm_rows sits at 255 registers with spills and gets 2 blocks/SM where softmax gets 6 #67

Closed

Description

@feitreim

Surfaced by #47, which made it visible rather than fixing it — the occupancy query it added to examples/src/main.rs now prints this for every kernel.

The numbers

kernel registers occupancy note
softmax_rows 66 / 256 B frame 6 blocks, 24 warps per SM after #47
layernorm_rows 255 + spills 2 blocks per SM at near-identical shared memory

Same shared-memory footprint, three times fewer blocks resident. The occupancy query is register-sensitive, so this is registers doing it, not shared memory.

Why it is worth its own issue

It is the mirror image of the defect #47 just fixed, and the pair makes a nice statement of the real rule. softmax_rows was 39 registers on a 1024-byte frame — too few registers, band spilled to local memory, 2.6x slower than it needed to be. layernorm_rows is 255 with spills — too many, and the cost lands on occupancy instead of on memory traffic. Both are "the band is the wrong shape for the register file"; they just fail in opposite directions.

That also means the fix is probably the same one-constant change: softmax_rows went from [32, 128] to a [32, 32] chunk walk carrying its running statistics across chunks, and layernorm_rows has the same structure — a per-row statistic over a [32, COLUMNS] band. Check the ladder before assuming, though: #60 found [64,64] and [32,128] are both 128 fp32/thread yet differ by 220 registers, so the row extent is not interchangeable with the column extent and M*N predicts nothing.

Acceptance

Note on reading the numbers

Do not treat "fewer registers" as the goal. That heuristic is what hid #47 for as long as it hid — 39 registers looked like the cheapest kernel in the repo. The goal is the band living in registers with the frame at zero, and occupancy high enough to hide what remains.

Related: #47 (the same defect, opposite sign), #60 (the ladder and the frame table), #63 (whether streaming actually costs anything).

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