Skip to content

[CuTe] Beat CUTLASS across the scaled FP8 matmul sweep - #3209

Draft
yushangdi wants to merge 8 commits into
mainfrom
perf/cute-scale-mm-cutlass
Draft

[CuTe] Beat CUTLASS across the scaled FP8 matmul sweep#3209
yushangdi wants to merge 8 commits into
mainfrom
perf/cute-scale-mm-cutlass

Conversation

@yushangdi

@yushangdi yushangdi commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

[CuTe] Beat CUTLASS across the scaled FP8 matmul sweep

Summary

Improve Blackwell CuTe scaled-FP8 matmul code generation and tune the production
kernels to outperform CUTLASS on all 17 benchmark shapes.

Codegen optimizations

  • Add swapped A/B tcgen05 lowering with column-major output support for skinny-M
    workloads.
  • Support role-local persistent scheduling across two-CTA and four-CTA clusters.
  • Add one-shot role scheduling for device-filling static FP8 grids.
  • Remove scheduler validity checks and tile advancement when every cluster owns
    exactly one tile.
  • Gate the static two-CTA K loop on the cluster leader and remove redundant
    ownership predicates from inner TMA/MMA builders.
  • Add bounded persistent cluster scheduling for grids larger than physical
    residency.
  • Improve FP8 epilogue handling for broadcast row and column scales.
  • Reduce redundant auxiliary-coordinate work and overlap auxiliary loads with
    accumulator waits.
  • Extend tcgen05 configuration validation for the required block/stage layouts.

Scheduler safety

One-shot scheduling is admitted only when:

  • The grid is static-full, persistent, and FP8.
  • There is no leading/batch passthrough dimension.
  • No role-scheduler cluster cap is configured.
  • The CTA count fits the validated residency bound.
  • The M and N scheduler dimensions are each divisible by their corresponding
    cluster dimensions.

These checks prevent skipped batches, omitted tiles, partial clusters, and
out-of-bounds TMA operations.

Production tuning

  • Add dedicated M512 and swapped skinny-M AOT configurations.
  • Use four-CTA topology and one-shot scheduling for (512, 2048, 4096).
  • Tune AB/ACC/C pipeline depths, PID ordering, cluster dimensions, and L2
    swizzles per shape.
  • Dispatch M512 and selected M64 shapes through their specialized kernels.

Performance

Tested on NVIDIA GB200 with:

python pretuned_kernels/scale_mm_cute/scale_mm_cute.py

Two consecutive complete sweeps:

  • Helion vs CUTLASS: 17/17 wins
  • CUTLASS geomean speedup: 1.035x and 1.034x
  • M512: 7.20 us Helion vs 7.32 us CUTLASS
  • Helion vs torch: 17/17 wins

Verification

  • Production correctness checks passed for representative M512, small-grid,
    and wide-N configurations.
  • Unsafe one-shot combinations are covered by regression tests.
  • ruff format --check: passed
  • ruff check: passed
  • Python compile checks: passed
  • git diff --check: passed
  • Independent code review: LGTM

Pytest was unavailable in the current Conda environment (No module named pytest).

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 30, 2026
@yushangdi

Copy link
Copy Markdown
Contributor Author
     1    4096    4096          6.82          11.34           7.10     1.04x  (vs cutlass)
  4096    4096    4096         48.08          57.88          51.85     1.08x  (vs cutlass)
     1    4096     256          4.56           7.59           4.84     1.06x  (vs cutlass)
   512    2048    4096          7.22           7.65           7.35     1.02x  (vs cutlass)
   512    2048    2048          5.57           6.17           6.66     1.11x  (vs torch)
    64    2048    4096          5.37           8.05           5.64     1.05x  (vs cutlass)
    64    2048    2048          4.86           5.88           5.05     1.04x  (vs cutlass)
    64    2048   12288          8.45           9.89           8.57     1.02x  (vs cutlass)
    64    6144    2048          7.59          10.78           8.03     1.06x  (vs cutlass)
    64    4096    6144          8.02          11.52           8.03     1.00x  (vs cutlass)
    64    4096    4096          7.19          10.98           7.26     1.01x  (vs cutlass)
    64    4096   24576         22.12          30.21          22.17     1.00x  (vs cutlass)
    64   12288    4096         14.24          23.31          15.01     1.05x  (vs cutlass)
    64    5120   10240         14.85          16.26          15.38     1.04x  (vs cutlass)
    64    5120    5120          8.57          13.01           8.58     1.00x  (vs cutlass)
    64    5120   51200         50.84          56.84          51.25     1.01x  (vs cutlass)
    64   25600    5120         32.55          47.70          32.67     1.00x  (vs cutlass)

@yushangdi

Copy link
Copy Markdown
Contributor Author

[CuTe] Beat CUTLASS across the scaled FP8 matmul sweep

Summary

Improve Blackwell CuTe scaled-FP8 matmul code generation and extend the
production benchmark from 17 to 33 shapes. The added M=2/8/16/32 shapes now
use tensor cores instead of the scalar skinny-M fallback, and Helion is faster
than CUTLASS on every shape in the complete GB200 sweep.

Codegen optimizations

Small-N tensor-core mainloop

  • Admit FP8 problems whose logical N is smaller than the minimum searched MMA
    tile.
  • Pad the tcgen05 N tile to 16 columns and let TMA zero-fill columns outside
    the source tensor instead of staging the narrow operand with thousands of
    scalar loads.
  • Keep the optimized path narrowly guarded to persistent, single-CTA-cluster,
    transposed-RHS problems with full M and K tiles.
  • Use ceiling tile counts when validating one-shot role scheduling so a single
    partial N tile is counted correctly.
  • Keep BN < 32 outputs on the direct SIMT epilogue; the TMA-store staging and
    barriers cost more than they save for these narrow stores.

Narrow SIMT epilogue

  • Detect grids where one output dimension is smaller than its CTA tile, making
    every output tile statically an edge tile.
  • Remove the unused full-tile branch for that case and share one coordinate
    partition across both scale loads and the output store.
  • Fuse the predicates for the row and column scale fragments into one edge
    traversal.
  • Issue scale loads before the accumulator consumer wait, overlapping global
    memory latency with completion of the tensor-core mainloop. The accumulator
    wait remains first-subtile-only for multi-subtile epilogues.
  • Multiply prefetched row and column scales into the accumulator sequentially,
    avoiding an extra scale-product live range on the smallest four-CTA grid.

Existing wide-shape improvements in this branch

  • Add swapped A/B tcgen05 lowering with column-major output support.
  • Support role-local persistent scheduling for two-CTA and four-CTA clusters.
  • Add one-shot scheduling for device-filling static FP8 grids and bounded
    persistent scheduling for larger grids.
  • Remove redundant scheduler and ownership work from validated static paths.
  • Tune broadcast row/column scale handling and TMA/SIMT epilogues.

Production tuning

  • Keep M=1 on the scalar skinny-M decode kernel.
  • Dispatch all added M=2/8/16/32 shapes through the swapped tensor-core
    kernel.
  • Use 64x16x256, one accumulator stage, and a nine-stage A/B pipeline for
    M=2/8/16; reduce the A/B depth to seven for K=2048.
  • Use 64x32x128, one accumulator stage, and a twelve-stage A/B pipeline for
    M=32.
  • Use persistent-interleaved scheduling for (2, 4096, 256) and
    persistent-blocked scheduling for the other new shapes.
  • Add exact AOT table entries for all 16 new shapes while preserving the
    existing M64, M512, and 4096-square configurations.

Performance

Tested on NVIDIA GB200 with cold-L2 CUDA-graph timing:

python pretuned_kernels/scale_mm_cute/scale_mm_cute.py

Final complete sweep:

  • Helion vs CUTLASS: 33/33 wins, 1.036x geomean
  • Helion vs torch: 33/33 wins, 1.446x geomean
  • Helion vs best baseline: 33/33 wins, 1.034x geomean

Representative new shapes:

M K N Helion (us) CUTLASS (us) Speedup
2 4096 256 4.84 4.87 1.01x
8 4096 4096 6.78 6.99 1.03x
16 2048 4096 5.05 5.30 1.05x
32 4096 256 5.15 5.43 1.05x

Verification

  • Explicit correctness checks passed against torch._scaled_mm for all 16 new
    shapes (rtol=0.03, atol=0.03).
  • The complete 33-shape performance sweep completed successfully.
  • Added regression coverage for FP8 small-N persistent search and narrow SIMT
    epilogue load/wait ordering.
  • Six focused planner, codegen-ordering, and GPU edge-correctness tests pass.
  • Ruff format/check passed for every changed Python file.
  • Python compile checks and git diff --check passed.

pytest is absent from the active conda environment, so the focused tests were
run by loading the existing pytest package from the pyrefly-check environment.
The full lint wrapper also scans untracked profiling artifacts and reports
unrelated errors there; targeted Ruff checks on all changed files pass.

@yushangdi

Copy link
Copy Markdown
Contributor Author
GPU: NVIDIA GB200
     M       K       N   helion (us)     torch (us)   cutlass (us)   speedup
/home/shangdiy/helion/helion/_compiler/compile_environment.py:283: UserWarning: The 'cute' backend is experimental and may have limited functionality.
  warn_once(
     1    4096    4096          6.97          10.93           7.08     1.02x  (vs cutlass)
     2    4096    4096          6.72          11.10           7.01     1.04x  (vs cutlass)
     2    4096     256          4.91           7.53           4.87     0.99x  (vs cutlass)
     2    2048    4096          5.08           8.43           5.30     1.04x  (vs cutlass)
     2    4096    6144          8.12          11.84           8.21     1.01x  (vs cutlass)
     8    4096    4096          6.81          10.99           6.98     1.03x  (vs cutlass)
     8    4096     256          4.80           7.57           4.91     1.02x  (vs cutlass)
     8    2048    4096          5.13           8.21           5.35     1.04x  (vs cutlass)
     8    4096    6144          7.93          11.42           8.22     1.04x  (vs cutlass)
    16    4096    4096          6.72          11.01           6.94     1.03x  (vs cutlass)
    16    4096     256          4.69           7.54           4.88     1.04x  (vs cutlass)
    16    2048    4096          5.09           8.43           5.34     1.05x  (vs cutlass)
    16    4096    6144          7.80          11.87           8.19     1.05x  (vs cutlass)
    32    4096    4096          7.15          11.00           7.22     1.01x  (vs cutlass)
    32    4096     256          5.11           7.54           5.42     1.06x  (vs cutlass)
    32    2048    4096          5.33           8.43           5.48     1.03x  (vs cutlass)
    32    4096    6144          7.98          11.61           8.20     1.03x  (vs cutlass)
  4096    4096    4096         47.81          57.69          51.31     1.07x  (vs cutlass)
     1    4096     256          4.51           7.49           4.84     1.07x  (vs cutlass)
   512    2048    4096          7.30           7.76           7.42     1.02x  (vs cutlass)
   512    2048    2048          5.48           6.09           6.51     1.11x  (vs torch)
    64    2048    4096          5.41           8.34           5.67     1.05x  (vs cutlass)
    64    2048    2048          4.78           5.82           4.98     1.04x  (vs cutlass)
    64    2048   12288          8.61           9.91           8.66     1.01x  (vs cutlass)
    64    6144    2048          7.47          10.74           8.00     1.07x  (vs cutlass)
    64    4096    6144          7.99          11.39           8.08     1.01x  (vs cutlass)
    64    4096    4096          7.09          11.05           7.19     1.01x  (vs cutlass)
    64    4096   24576         22.29          30.48          22.51     1.01x  (vs cutlass)
    64   12288    4096         14.13          23.04          14.97     1.06x  (vs cutlass)
    64    5120   10240         14.82          16.22          15.28     1.03x  (vs cutlass)
    64    5120    5120          8.49          12.98           8.68     1.02x  (vs cutlass)
    64    5120   51200         51.05          56.75          51.34     1.01x  (vs cutlass)
    64   25600    5120         32.54          47.73          32.66     1.00x  (vs cutlass)
vs torch: wins=33/33 geomean=1.446x best=1.66x
vs cutlass: wins=32/33 geomean=1.036x best=1.19x

@yushangdi

Copy link
Copy Markdown
Contributor Author
GPU: NVIDIA GB200
     M       K       N   helion (us)     torch (us)   cutlass (us)   speedup
/home/shangdiy/helion/helion/_compiler/compile_environment.py:283: UserWarning: The 'cute' backend is experimental and may have limited functionality.
  warn_once(
     1    4096    4096          6.95          10.93           7.10     1.02x  (vs cutlass)
     2    4096    4096          6.72          11.09           6.98     1.04x  (vs cutlass)
     2    4096     256          4.87           7.52           4.87     1.00x  (vs cutlass)
     2    2048    4096          5.09           8.42           5.33     1.05x  (vs cutlass)
     2    4096    6144          8.13          11.85           8.20     1.01x  (vs cutlass)
     8    4096    4096          6.80          10.97           7.02     1.03x  (vs cutlass)
     8    4096     256          4.84           7.56           4.90     1.01x  (vs cutlass)
     8    2048    4096          5.12           8.22           5.35     1.04x  (vs cutlass)
     8    4096    6144          7.90          11.43           8.22     1.04x  (vs cutlass)
    16    4096    4096          6.69          11.03           6.96     1.04x  (vs cutlass)
    16    4096     256          4.76           7.58           4.89     1.03x  (vs cutlass)
    16    2048    4096          5.07           8.46           5.31     1.05x  (vs cutlass)
    16    4096    6144          7.82          11.89           8.19     1.05x  (vs cutlass)
    32    4096    4096          7.13          11.01           7.23     1.01x  (vs cutlass)
    32    4096     256          5.14           7.53           5.43     1.06x  (vs cutlass)
    32    2048    4096          5.27           8.39           5.48     1.04x  (vs cutlass)
    32    4096    6144          8.04          11.63           8.21     1.02x  (vs cutlass)
     2    2048   12288          8.06          10.39           8.76     1.09x  (vs cutlass)
     2    5120    5120          8.12          12.81           8.49     1.05x  (vs cutlass)
     2    6144    2048          7.09          10.78           7.69     1.09x  (vs cutlass)
     8    2048   12288          8.05          10.12           8.56     1.06x  (vs cutlass)
     8    5120    5120          8.17          12.42           8.53     1.04x  (vs cutlass)
     8    6144    2048          7.12          10.71           7.86     1.10x  (vs cutlass)
    16    2048   12288          7.93          10.00           8.28     1.04x  (vs cutlass)
    16    5120    5120          8.13          12.63           8.45     1.04x  (vs cutlass)
    16    6144    2048          7.08          10.67           7.91     1.12x  (vs cutlass)
    32    2048   12288          8.26          10.01           8.33     1.01x  (vs cutlass)
    32    5120    5120          8.37          12.49           8.58     1.02x  (vs cutlass)
    32    6144    2048          7.70          10.69           7.98     1.04x  (vs cutlass)
  4096    4096    4096         47.87          57.84          51.23     1.07x  (vs cutlass)
     1    4096     256          4.46           7.58           4.89     1.10x  (vs cutlass)
   512    2048    4096          7.34           7.83           7.39     1.01x  (vs cutlass)
   512    2048    2048          5.53           6.09           6.49     1.10x  (vs torch)
    64    2048    4096          5.44           8.57           5.61     1.03x  (vs cutlass)
    64    2048    2048          4.76           5.81           4.99     1.05x  (vs cutlass)
    64    2048   12288          8.51          10.16           8.68     1.02x  (vs cutlass)
    64    6144    2048          7.48          10.73           8.01     1.07x  (vs cutlass)
    64    4096    6144          8.07          11.73           8.14     1.01x  (vs cutlass)
    64    4096    4096          7.06          11.20           7.15     1.01x  (vs cutlass)
    64    4096   24576         22.31          30.55          22.53     1.01x  (vs cutlass)
    64   12288    4096         14.16          23.02          14.95     1.06x  (vs cutlass)
    64    5120   10240         14.85          16.05          15.28     1.03x  (vs cutlass)
    64    5120    5120          8.55          12.80           8.71     1.02x  (vs cutlass)
    64    5120   51200         51.00          56.47          51.31     1.01x  (vs cutlass)
    64   25600    5120         32.50          47.53          32.66     1.00x  (vs cutlass)
vs torch: wins=45/45 geomean=1.441x best=1.70x
vs cutlass: wins=44/45 geomean=1.042x best=1.18x

Helion faster on 44/45 shapes vs the best baseline; geomean speedup 1.040x; best speedup 1.12x.

@yushangdi
yushangdi force-pushed the perf/cute-scale-mm-cutlass branch from 8f880f6 to da6bb6d Compare July 31, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant