# Batched GEMM with static FP8 output (`batched_gemm_static_fp8_quant`) | ServingStudio Kernel Library

Multiply one query and weight pair per attention head and write the product as FP8 under one static scale, in one launch.

MLA query absorption maps each head's query into the compressed KV space (C\[b\] = A\[b\] · W_UK\[b\]); an FP8 sparse-attention kernel then reads that latent query as FP8 E4M3 with one static per-tensor scale. This kind computes the product with FP32 accumulation, rounds it to bf16 as the unfused torch.bmm output would be stored, multiplies by 1/scale, clamps to ±448 and writes FP8 E4M3, token-major (\[m, num_batches, n\]). It replaces a bf16 batched GEMM plus a static FP8 quant launch, and is bit-identical to that pair.

Category: GEMM. Interactive page: https://servingstudio.cs.washington.edu/kernels.html?kind=batched_gemm_static_fp8_quant. All kernel kinds: https://servingstudio.cs.washington.edu/kernels.md.

## Formula

- `C[t, b, n] = fp8(clamp(bf16(Σ_k A[b, t, k] · W[b, k, n]) · (1/scale), ±448))`
- `TFLOPS = 2·num_batches·m·n·k / time`
- `GB/s = num_batches·(2·m·k + 2·k·n + m·n) / time`

## How it is measured

GPU kernel time from CUPTI activity records, averaged over repeated launches in one capture. The L2 cache is flushed before each launch, so the numbers are cold-cache times. One launch per call; warm-up calls run first. Before timing, the FP8 output is checked byte for byte against vLLM's unfused pair (torch.bmm into the bf16 latent query, then the static scaled_fp8_quant), and against a Torch float32 reference within one FP8 code.

## Caveats

- The cuda_tcgen05 backend has its head geometry compiled in (64 heads, k = 256, n = 512) and refuses any other. It reads the weight pre-transposed to a K-major \[num_batches·n, k\] copy, a layout change made once when the weights load.
- The cuda_tcgen05 backend has three tile configurations; each row is the fastest of them at that m, as an autotuned launch would pick.

## Arguments

| Argument | Type | Unit | Meaning |
| --- | --- | --- | --- |
| `num_batches` | number | heads | Attention heads multiplied independently on this GPU. |
| `m` | number | tokens | Token rows per attention head. |
| `n` | number | elements | Output features per attention head. |
| `k` | number | elements | Input features per attention head. |
| `dtype` | dtype |  | Element type of both inputs (bf16). The output is always FP8 E4M3. |

## Metrics

- Time (`time_ms`, ms)
- Throughput (`tflops`, TFLOPS)
- Memory bandwidth (`memory_bandwidth_gbps`, GB/s)
- Energy (`energy_j`, J)

## Backends

- `cuda_tcgen05`: A repo-vendored CUDA kernel: TMA loads, tcgen05 MMA into TMEM (one CTA per 128-token tile, head and n chunk, two CTAs per SM), and an epilogue that rounds to bf16, scales, clamps and stores FP8. dtypes `bf16`, SM targets `sm_100a`, GPUs B200-SXM-180GB, GB200-Superchip.

## Measured rows

68 rows in all.

| GPU | Backend | Precision | Rows |
| --- | --- | --- | --- |
| NVIDIA B200 | `cuda_tcgen05` | `bf16` | 68 |

## Used by these deployments

- [GLM-5.3-Flash NVFP4: ServingStudio design: DP attention, KDA TP groups, fused EP MoE, DFlash speculative decoding](https://servingstudio.cs.washington.edu/models/GLM-5.3-Flash-NVFP4/glm53_flash_nvfp4_dp_attn_kda_tp_fused_ep_moe_dflash2.md) (`GLM-5.3-Flash-NVFP4/glm53_flash_nvfp4_dp_attn_kda_tp_fused_ep_moe_dflash2`)

## API

- This kind: https://servingstudio.cs.washington.edu/api/public/v1/kernels/batched_gemm_static_fp8_quant
- Measured rows: https://servingstudio.cs.washington.edu/api/public/v1/kernels/batched_gemm_static_fp8_quant/rows (filter by any column, such as `?gpu=NVIDIA%20H200`; `format=csv` for CSV)
- Configs the public deployments ask of it: https://servingstudio.cs.washington.edu/api/public/v1/kernels/batched_gemm_static_fp8_quant/configs

---

This page as Markdown: https://servingstudio.cs.washington.edu/kernels/batched_gemm_static_fp8_quant.md. A guide to the whole site for AI agents: [llms.txt](https://servingstudio.cs.washington.edu/llms.txt).
