Skip to content

flash_forward's 1 CTA/SM may be the query rather than the hardware — the GEMM's is not real #78

Closed

Description

@feitreim

#74 established, with a control rather than an inference, that a CTA touching
tcgen05.alloc is charged the SM's entire tensor memory
— 1 block per SM at
32 columns exactly as at 512, against 32/32/16/8 for the byte-identical kernel
with the allocator deleted. device-tests' tmem occupancy ladder is the
measurement and it is in tree.

That closed #74. What it opens is bigger than the kernel it was found in.

The consequence, which is a library-wide fact and not a flash detail

For any tcgen05 kernel, occupancy is warps per CTA. Nothing else is a
lever. At 1 block/SM the CTA's own width is the SM's occupancy, so the three
things this repo has reached for so far do not apply:

flash_forward runs 4 warps against its own max_threads_per_block of 512,
and against the 32 the control probe holds. The GEMM is the other tcgen05
entry and the occupancy query cannot describe it — a #[cluster_launch] kernel
takes a different path — so whether the GEMM is in the same position is not
currently known
, and finding out is part of this.

Why this is not a tuning constant

QUERIES / 32 is where flash's 4 warps come from: one warp per 32 accumulator
rows. Raising the warp count means a different decomposition, not a bigger
number — a producer/consumer split with warps dedicated to TMA issue and to MMA
issue, which is the shape a tcgen05 kernel is supposed to have and the shape
ThunderKittens' own attention kernels use. That is a design to price, not an
edit to make.

Scope

  1. Establish whether the GEMM is also at 1 CTA/SM. The occupancy query will not
    answer for a #[cluster_launch] kernel, so this needs another route — a
    non-cluster probe with the same TMEM shape, or reading it off a timed run.
    Do this first: if the GEMM is unaffected the rest is narrower than it
    looks, and if it is affected then every tcgen05 kernel in this repo has an
    occupancy ceiling nobody has priced.
  2. Price the warp count on the control ladder before touching a real kernel.
    The probe in device-tests already sweeps block width; extend it to hold
    TMEM and vary warps, so the shape of the curve is known independently of any
    kernel's decomposition.
  3. Only then propose a decomposition for flash_forward. It has no launcher
    and no CPU reference
    , so a rewrite cannot currently be checked — see layernorm_rows sits at 255 registers with spills and gets 2 blocks/SM where softmax gets 6 #67,
    where the harness had to come first and the fix turned on a rung the ladder
    did not predict. Adding the launcher and reference is plausibly its own issue
    and plausibly the prerequisite for this one.

Acceptance

A number for what warps per CTA buys on a tcgen05 kernel, measured on the
control rather than argued from the ISA. No claim about flash_forward being
faster without a CPU reference in front of it and a positive control behind it
(#67's discipline: an error class built as a real kernel, with predicted and
observed wrong-cell counts).

Related: #74 (the finding and the control), #70 (the shared plan is not the
lever), #47 and #67 (what an occupancy ceiling costs when nothing is in flight),
#63 (allocated is not cost).

Activity

  1. added
    area:compute
    on Jul 28, 2026
  2. feitreim commented on Jul 28, 2026

    @feitreim
    OwnerAuthor

    Step 1 has an answer already, from #51, and it goes against this issue's premise. The GEMM is not at 1 CTA/SM.

    #51 ported gemm.rs to pipeline::run and swept the grid cap on a B200. Min ms over 30 timed launches at 8192³:

    grid ms TFLOP/s
    launch per tile (uncapped) 1.0169 1081
    cap 74 clusters — one cluster per SM 2.1036 523
    cap 148 clusters — two per SM 1.2130 906

    Capping the grid at one cluster per SM costs 2.07×. That is only possible if more than one cluster is actually resident per SM. If the hardware could hold just one, the uncapped grid's surplus clusters would queue behind the resident ones and the total work would take the same time — the cap would be free. It is not free; it is a factor of two.

    So extrapolating #77 to the GEMM is false by at least 2×, and this issue's framing — "for any tcgen05 kernel, warps per CTA is the only occupancy lever" — is wrong as stated. I wrote it; the correction is mine, not #51's.

    What #77 actually established, restated precisely

    #77's control is sound and nothing here contradicts it. What it measured is that cuOccupancyMaxActiveBlocksPerMultiprocessor returns 1 for any kernel containing a tcgen05.alloc, at every column count and every block width, against 32/32/16/8 for the byte-identical kernel without one. That is a fact about the query.

    Whether the query's 1 describes hardware residency is a separate claim, and #51's timing is the first evidence either way. It says no — at least for a #[cluster_launch] kernel using alloc_cluster.

    Two candidate reasons, neither tested:

    1. The query cannot describe a cluster launch at all (it takes a block shape and no cluster), so its answer for gemm was never meaningful — but note the query was never asked about gemm; The 1 CTA/SM is tcgen05 itself, and a smaller TMEM allocation buys nothing (#74) #77 measured flash_forward and a synthetic probe, both plain #[kernel]s.
    2. alloc_cluster (cta_group::2) charges TMEM differently from alloc_block, so a pair splits the SM's tensor memory rather than each rank claiming all of it. This would make the two kernels genuinely different, and The 1 CTA/SM is tcgen05 itself, and a smaller TMEM allocation buys nothing (#74) #77's control used alloc_block.

    If (2) holds, flash_forward may be at 1 CTA/SM for real while the GEMM is not, and the two need separate answers rather than one rule.

    Revised scope

    1. Establish whether the GEMM is at 1 CTA/SM. Answered: it is not. Keep the table above as the evidence.
    2. Determine whether flash_forward's 1 is real residency or only the query's answer. This is now the load-bearing question and it did not exist before. The query cannot be trusted as residency for at least one kernel here, so a timed probe is needed — the same shape as pipeline::run cannot schedule a cluster: work items are blockIdx.x-strided #51's grid-cap sweep, on a kernel where capping the grid is possible.
    3. Extend The 1 CTA/SM is tcgen05 itself, and a smaller TMEM allocation buys nothing (#74) #77's tmem occupancy ladder to price alloc_cluster beside alloc_block. If the pair splits the allocation, that is the whole explanation and it belongs in src/tmem.rs's docs.
    4. Only then ask what warps per CTA buys, and only for whichever kernels turn out to be genuinely capped.

    The warps-per-CTA question is still worth answering — flash_forward runs 4 warps against its own max_threads_per_block of 512 — but it is no longer established that it is the only lever, and it should not be pursued on the strength of a query result that has now been shown not to predict residency once.

    Related: #77 (the query finding, which stands), #51 (the timing that limits its reach), #74, #70.

  3. changed the title [-]For a tcgen05 kernel, warps per CTA is the only occupancy lever left — and nobody has priced it[/-] [+]flash_forward's 1 CTA/SM may be the query rather than the hardware — the GEMM's is not real[/+] on Jul 28, 2026
  4. feitreim commented on Jul 28, 2026

    @feitreim
    OwnerAuthor

    Step 1 now has a number, not just a refutation: the GEMM's residency is 3 CTAs/SM, measured by bisecting the grid cap on a clock (#83).

    Min ms at 8192³, B200, 148 SMs, 30 timed launches:

    launch per tile cap 74 (1/SM) cap 148 (2/SM) cap 222 (3/SM)
    1.0204 2.1036 1.2130 1.0217

    The curve stops at 222. So residency is three, and #77's figure extrapolated to this kernel would have said one — wrong by 3×, and wrong in the direction that costs 2× if you build a grid on it.

    This also supersedes the provisional conclusion in #80 and its closing comment here. #80 measured caps 74 and 148 only, found the persistent GEMM 2.07× slower, and named cap 222 as the unmeasured point that would decide it. The Modal spend limit is what stopped it being taken. It came back a dead heat — 1076 vs 1077 TFLOP/s — so the GEMM now runs on pipeline::run, and the entire effect was the grid cap rather than anything about persistence.

    The method is the transferable part. For a #[cluster_launch] kernel the occupancy query is not merely unreliable, it is inapplicable — it takes a block shape and no cluster, which is why main.rs prints cluster in that row. A grid-cap sweep on a clock is currently the only residency probe available for such a kernel, and it works by bisection: cap the grid at k CTAs per SM and find where the time stops improving.

    What remains open here is unchanged and is the interesting half: flash_forward is a plain #[kernel], so the query does apply to it, and whether its 1 is real residency or only the query's answer is still unknown. The GEMM result does not settle it, because the two kernels allocate TMEM differently — alloc_cluster versus alloc_block — which is the leading hypothesis for why they differ and is exactly what the in-flight work on this issue is pricing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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