Skip to content

bench has a denominator: cuBLASLt in-process beside the GEMM, and we are at 0.69 of it (#92) - #96

Merged
feitreim merged 3 commits into
mainfrom
cublaslt-denominator
Jul 28, 2026
Merged

feitreim merged 3 commits into
mainfrom
cublaslt-denominator

Conversation

@feitreim

@feitreim feitreim commented Jul 28, 2026 •

Copy link
Copy Markdown
Owner

Closes #92.

Re-measured after #94. The first version of this PR was timed on a tree
that predated #94's vectorized store_rows, so our column was ~12% low and
the ratio understated by about eight points. Both columns below come from
two complete sweeps of this branch, after #94, each with both sides measured
in the same session
— nothing is hand-patched from another run, which is the
whole point of putting the baseline in the same process.

The answer, in one line

At the two largest sizes this kernel runs at 0.69 of cuBLASLt, reproducing
to about 1%. Below 4096³ the comparison is not stable enough to quote — for a
reason that turned out to be the more interesting finding.

The table

Two complete sweeps of this branch, separate sessions, one B200, driver
580.95.05, cuBLASLt 130000.

shape ours min ms theirs min ms ours TFLOP/s theirs TFLOP/s ours/theirs at median run 2
256x128x256 0.0169 0.0127 1.0 1.3 0.751 0.669 0.454
512x256x256 0.0184 0.0110 3.7 6.1 0.598 0.653 0.484
1024³ 0.0230 0.0134 93.3 160.5 0.581 0.590 0.480
2048³ 0.0376 0.0236 457.3 729.4 0.627 0.623 0.564
4096³ 0.1532 0.0878 896.8 1565.8 0.573 0.585 0.574
8192³ 0.9032 0.6220 1217.4 1767.8 0.689 0.687 0.686
16384³ 6.8477 4.7511 1284.5 1851.4 0.694 0.696 0.685

bench prints the heuristic's pick per row: algorithm id=66 at every size in
both sessions, no split-K, and no workspace used at all despite the 32 MiB
offered. Our own figures reproduce #94 (1217.4 / 1236.0 against its 1223.4).

1. A ratio is less reproducible than either number in it

This is counterintuitive and it should not be a footnote. The instinct — and my
stated reason for sweeping twice — is that run-to-run drift moves both sides
together and cancels. It does not, because the variance here is almost
entirely on the baseline side, so the ratio inherits all of it and adds ours
on top. The split is sharp, and it is by size:

shape ours, run to run theirs, run to run ratio, run to run
256x128x256 3% 77% 0.751 → 0.454
512x256x256 11% 41% 0.598 → 0.484
1024³ 10% 33% 0.581 → 0.480
2048³ 5% 17% 0.627 → 0.564
4096³ 0.6% 0.3% 0.573 → 0.574
8192³ 1.5% 2.0% 0.689 → 0.686
16384³ 0.9% 2.2% 0.694 → 0.685

Only the bottom three rows carry a quotable ratio. The top four are
dominated by cuBLASLt's own variance — its 256x128x256 figure nearly doubles
between sessions — so 0.751 in the table above is noise, not this kernel's
best row. Two digits is all any ratio here supports, and below 4096³ none is.
That is now written into the README beside the table so the next reader is
stopped before they quote three digits.

2. cuBLASLt at 79–84% of dense peak is the calibration this project lacked — and it prices the target

The library measures 1767.8–1892.4 TFLOP/s, i.e. 1.77–1.89 PFLOP/s. That
independently confirms #90's derived 1550–1800 band for this tile "boundary
overlapped and walk L2-aware" from the outside, and shows it was conservative
rather than optimistic — the honest complaint about that derivation was that it
stacked two assumptions and nothing had ever run there. Something has now.

On the target, one correction worth making explicitly. You framed this as
"the stated goal is 2–2.2 PFLOP/s and the vendor library does not reach it".
The only target written down in this repo is #86's: 1.7–1.9 PFLOP/s at bf16
before precision changes
— and cuBLASLt's 1.77–1.89 lands inside that band.
So the written goal is not "most of the way to the library", it is level with
the library
: reaching it means matching a vendor GEMM, not approaching one.
That is materially harder than "48% of peak → 80%" sounds. And a target of 2.0+
is above everything cuBLASLt achieved here, so it would require beating the
vendor on its own part, with nothing measured so far suggesting where that comes
from. Both readings are stated in the README; I did not want to transcribe the
2–2.2 figure without noting the repo says something different.

3. The layout caveat in #92 does not apply

#92 asserts gemm.rs uses encode_bf16_panels. It does not — it builds a TMA
map over a plain packed bf16 [m, k] / [n, k], K contiguous, so both sides
read byte-identical operands and there is no rearrangement on either side to
discount. The descriptor is built once, outside the clock, exactly as cuBLASLt's
layouts and heuristic are.

The real asymmetry is generality: ours computes one form — both operands
K-major, α = 1, β = 0, no epilogue, m % 256 == n % 128 == k % 64 == 0 —
while cuBLASLt takes any of it and picks per shape. So 0.69 is an upper bound
on how well this kernel would stand in for one. cuBLASLt also gets a 32 MiB
workspace it does not spend. All of this prints under the table from bench
itself, not only here, because the output gets pasted into issues.

What it says about the levers — nothing that reorders them

The ratio improves with size in both runs (0.573 → 0.689 → 0.694, reproduced as
0.574 / 0.686 / 0.685). Ragged waves go 76.9% → 92.3% → 99.7% and the per-tile
boundary falls by 4× across those rows; cuBLASLt pays neither. The deficit is
largest where the two known fixed costs are largest — #86's finding from
outside.

It does not follow that #15 and #89 close it: at 8192³ they would have to be
worth the whole 1217 → 1768, and #90's steady state for this tile at this shape
was 1500–1670, under what the library achieves. So there is plausibly a residue
that is the tile (#87). No kernel constant moved in this PR.

Two things to file rather than act on, as agreed: the tile question above,
and whether cuBLASLt also loses 23% to aspect ratio. The latter is deliberately
not measured here — the baseline is on gemm only, since gemm-footprint and
gemm-depth exist to compare the kernel against itself and each extra row
re-stages operands on the host, the long pole at these sizes. It is a one-word
change
, baseline: CUBLASLT on that case, noted in both the code and the
README so whoever picks it up knows.

Linking worked — recorded either way, as #92 asked

cargo oxide shells out to plain cargo and only injects a codegen backend via
RUSTFLAGS, so an ordinary build.rs emitting
cargo:rustc-link-lib=dylib=cublasLt is honoured with nothing special — the
same mechanism cuda-bindings uses upstream for the driver. No fallback to a
separate binary was needed
, so the baseline goes through the same
bench::time, stream, warm-up and min-of-30, and what differs between the two
figures is the code between the two CUDA events.

The check is the load-bearing part

cuBLASLt is column-major and ours is row-major, so what must be asked for is
Ĉ = Cᵀ = B·Aᵀ = (B̂)ᵀ · Â — cuBLASLt's first operand is our b under
CUBLAS_OP_T, its second our a under CUBLAS_OP_N. The operands are swapped
relative to the obvious spelling, and the obvious spelling is not slower and does
not fail: it computes a different matrix at full speed. So gemm::run's
reference comparison was extracted to gemm::check_c and the baseline is checked
by the same function, not a copy — the one edit to gemm.rs, plus
pub(crate) on the two generators and stage.

The comparison stays == rather than a tolerance: operands are small integers,
partial sums stay under 983,040 against fp32's exact 2²⁴, and integer addition in
fp32 below that bound is exact in any order — so whichever tiling or split-K
cuBLASLt picks, the answer is the same integer ours is.

Scope

  • examples/src/cublaslt.rs — new; the FFI, the layout derivation, the fairness
    argument.
  • examples/build.rs, examples/cublaslt_abi.c — new; the link step, and the
    hand-transcribed enum values and struct offsets asserted against the real
    headers under gcc -fsyntax-only, so a wrong constant fails the CPU gate
    rather than a B200 one. It caught nothing, which is the outcome I wanted.
  • examples/src/bench.rs — Baseline on Case, the comparison table, rule 4 in
    the module header. Two type aliases also clear a pre-existing clippy warning.
  • examples/Cargo.toml — cublas feature, off by default.
  • modal_app.py — mounts the two new non-src/ files, runs the ABI check plus a
    feature-on clippy and device build in the CPU gate, and passes
    --features cublas to bench.
  • examples/README.md §7 — the section above, after Two fp32 a store where the layout pairs them, and the boundary intercept says so (#91) #94's.

Verification

  • modal run modal_app.py::build — exit 0 on the rebased tree. Confirms the
    crate still builds with the feature off, and additionally builds and lints
    it with the feature on, linking real libcublasLt.
  • modal run modal_app.py::examples — pass gemm, pass softmax,
    pass layernorm; the check_c extraction changed no result.
  • modal run modal_app.py::bench — two full sweeps after the rebase, both
    exit 0, no row failing its check. Every figure above is measured.
  • Locally: cargo fmt --check both crates, root cargo clippy --all-targets -- -D warnings clean, cargo test 76 + 1.

Every timed figure went through the checked path, cuBLASLt included — there is
still no route in bench that prints a throughput for a launch it did not
verify.

@feitreim feitreim changed the title bench has a denominator: cuBLASLt in-process beside the GEMM, and we are at 44-65% of it (#92) bench has a denominator: cuBLASLt in-process beside the GEMM, and we are at 0.69 of it (#92) Jul 28, 2026
@feitreim
feitreim force-pushed the cublaslt-denominator branch from 8ed7c06 to 6284824 Compare July 28, 2026 20:36
@feitreim
feitreim merged commit 500927c into main Jul 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bench has no denominator: put cuBLASLt beside the GEMM at every size

1 participant