Skip to content

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

Closed

Description

@feitreim

bench reports the GEMM at 1081 TFLOP/s at 8192³ and 1117–1179 at
16384³
(#86). Those are numbers without a denominator. Against a dense bf16
peak of roughly 2.25 PFLOP/s they are about half, but "half of a spec sheet" is
not the comparison anyone actually wants: what matters is how far this sits from
a tuned library on the same device, the same shapes and the same day.

Wanted: a cuBLASLt baseline as another column of bench, so every future
GEMM change carries the ratio rather than an absolute that has to be
re-contextualized each time. That is the point — a permanent denominator, not a
one-off measurement.

Everything needed is already here

  • The Modal image is nvidia/cuda:13.0.0-devel-ubuntu24.04, a devel image,
    so cublasLt.h and libcublasLt.so are present.
  • Upstream cuda-oxide ships a working precedent at
    crates/rustc-codegen-cuda/examples/gemm_sol/bench/cublaslt_bench.c (158
    lines) with a build.sh, invoked from that example's main.rs. Read it — it
    has the descriptor, layout, preference and heuristic calls already worked out.

Prefer FFI over upstream's separate C binary

Upstream compiles a C file and shells out to it. Do it as direct extern "C"
declarations from the examples crate instead
, unless that proves impossible.
The reason is not tidiness: a subprocess measures on its own stream, in its own
process, with its own timing loop, and the comparison is then between two
harnesses as much as between two kernels. In-process, the baseline goes through
the same Timings path, the same stream and the same min-of-N as ours does,
and the only difference left is the kernel.

It is roughly ten functions and a few opaque handle types. If linking
libcublasLt through cargo-oxide's link step turns out not to work, say so
precisely and fall back to upstream's pattern — that failure is itself worth
recording.

Configuration, which must match ours exactly

examples/src/gemm.rs is bf16 A and B, fp32 C, C row-major with ldc. So:
CUDA_R_16BF operands, CUBLAS_COMPUTE_32F, CUDA_R_32F output. Upstream's C
file uses a 2-byte output; do not copy that.

Fairness, which is the whole difficulty

  1. Check the baseline, do not just time it. bench.rs has no path that
    prints a throughput for a launch it did not verify, and cuBLASLt must not be
    the exception. Run its output against the same CPU reference. This is not
    ceremony: the live trap here is CUBLAS_OP_T/CUBLAS_OP_N and the leading
    dimensions, where a wrong setting computes a different GEMM quickly and you
    report a bogus baseline that makes us look good or bad for no reason.
  2. Layout. Ours needs encode_bf16_panels; cuBLASLt wants plain
    row/column-major. Each should get its preferred layout prepared once,
    outside the timed region
    — that is fair. But state the caveat plainly:
    our kernel requires a non-standard input layout, and in a real pipeline
    producing it is not free. Do not bury that.
  3. Workspace. cuBLASLt takes one (upstream uses 32 MiB); ours takes none.
    Say so, and say whether its allocation is inside or outside the timed region.
  4. Report the chosen algorithm if cublasLtMatmulAlgoGetHeuristic's result
    can be identified. A baseline nobody can reproduce is worth much less.
  5. Same sizes as GEMM_SIZES, including 16384³. Report both min and median if
    the harness has them — 16384³ has 5.5% cross-run spread (What binds the GEMM at 1081 TFLOP/s, and does the curve flatten at 16384 cubed #86), so a single
    min could flatter either side.

Scope

  • The baseline behind a cargo feature, defaulted off, so tier 1 CI (no CUDA
    toolkit, no cuBLAS) is unaffected and the examples crate still builds for
    anyone without it.
  • A bench column, plus the ratio.
  • Do not tune our kernel in this PR. If the comparison suggests something,
    file it.

Acceptance

modal run modal_app.py::bench prints ours, cuBLASLt, and the ratio at every
size, with both checked against the CPU reference first. A number that makes us
look bad is the expected outcome and must be reported as measured — the value of
this issue is the denominator, not the verdict.

Related: #86 (the measurements wanting a denominator, and the depth sweep), #87,
#89, #15 (the levers this will price).

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