KernelBench hard deprecated · RTX PRO 6000

FP8 GEMM Grok 4.5

33.7%geomean peak fraction across shapes

manually audited: clean

Clean rerun of the contaminated sibling 20260708_132148 (0.4146, excluded: that run executed on the host and read fable's CUTLASS SM120 solution and glm-5.2's pad-cache trick from the shared outputs/runs archive). This rerun ran in a container with the archive unmounted, and the transcript confirms independent work end to end: zero references to fable, glm, other run ids, outputs/runs paths, the leaderboard, or incumbent scores. The kernel is a genuine pure-Triton fp8xfp8 tensor-core GEMM (TMA descriptors + tl.dot, fp32 accum, fused per-channel weight_scale, bf16 out), no torch._scaled_mm, no output caching, no check.py sniffing. 0.3367 is the honest archive-blind score; per-shape 0.6036 / 0.4757 / 0.0680 (skinny bandwidth-wall, same as every model) / 0.6578.

harnessgrokagent session23mtotal wall23mcheck8sbenchmark5soutput tokens—gpu-lock wait0sgpu-lock held14sregimecompute

Per-shape vs governing ceilingeach shape graded against whichever binds — fp8 compute or HBM bandwidth

4096×4096×40960.228 ms60.4%604 TFLOPS · 60% of 1,000 TF fp8 peak · also 0.29 TB/s (16% of HBM)
4096×4096×41270.291 ms47.6%476 TFLOPS · 48% of 1,000 TF fp8 peak · also 0.23 TB/s (13% of HBM)
32×8192×81920.063 ms6.8%1.08 TB/s · 60% of 1.8 TB/s HBM · also 68 TFLOPS (7% of compute)
4096×14336×40960.731 ms65.8%658 TFLOPS · 66% of 1,000 TF fp8 peak · also 0.26 TB/s (15% of HBM)

compute-bound memory-bound · bar + right column = official fraction of the ceiling (the geomean input)

geomean(60.4% · 47.6% · 6.8% · 65.8%) = 33.7%

Kernel source (redacted)
"""FP8 e4m3 GEMM via Triton TMA + tl.dot (fp8 x fp8 -> fp32 acc) + per-channel scale.

Genuine tensor-core path: Triton lowers tl.dot on float8e4nv to e4m3 tensor-core MMA.
"""
from __future__ import annotations

import torch
import torch.nn as nn
import triton
import triton.language as tl
from triton.tools.tensor_descriptor import TensorDescriptor

E4M3_MAX = 448.0


@triton.jit
def _fp8_gemm_tma_kernel(
    a_desc,
    b_desc,
    c_ptr,
    scale_ptr,
    M,
    N,
    K,
    stride_cm,
    stride_cn,
    BLOCK_M: tl.constexpr,
    BLOCK_N: tl.constexpr,
    BLOCK_K: tl.constexpr,
    GROUP_M: tl.constexpr,
):
    pid = tl.program_id(0)
    num_pid_m = tl.cdiv(M, BLOCK_M)
    num_pid_n = tl.cdiv(N, BLOCK_N)
    num_pid_in_group = GROUP_M * num_pid_n
    group_id = pid // num_pid_in_group
    first_pid_m = group_id * GROUP_M
    group_size_m = min(num_pid_m - first_pid_m, GROUP_M)
    pid_m = first_pid_m + ((pid % num_pid_in_group) % group_size_m)
    pid_n = (pid % num_pid_in_group) // group_size_m

    offs_am = pid_m * BLOCK_M
    offs_bn = pid_n * BLOCK_N

    acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
    for k in range(0, tl.cdiv(K, BLOCK_K)):
        a = a_desc.load([offs_am, k * BLOCK_K])
        b = b_desc.load([offs_bn, k * BLOCK_K])
        acc = tl.dot(a, b.T, acc)

    offs_m = offs_am + tl.arange(0, BLOCK_M)
    offs_n = offs_bn + tl.arange(0, BLOCK_N)
    scales = tl.load(scale_ptr + offs_n, mask=offs_n < N, other=0.0)
    acc = acc * scales[None, :]
    c = acc.to(tl.bfloat16)
    mask = (offs_m[:, None] < M) & (offs_n[None, :] < N)
    tl.store(c_ptr + offs_m[:, None] * stride_cm + offs_n[None, :] * stride_cn, c, mask=mask)


def _pick_config(M: int, N: int, K: int):
    """(BLOCK_M, BLOCK_N, BLOCK_K, num_warps, num_stages, GROUP_M).

    Tuned under L2-cold timing to match the scoring harness.
    """
    if M <= 32:
        # Skinny-M / decode: BM=16 doubles CTA count vs BM=32 for better SM fill
        return 16, 128, 256, 4, 3, 1
    if M <= 64:
        return 64, 128, 128, 4, 4, 4
    # Large compute-bound tiles
    if K % 128 == 0:
        return 128, 128, 128, 4, 2, 16
    return 128, 128, 64, 4, 3, 8


class Model(nn.Module):
    """y = ((x @ w.T) * weight_scale).to(bf16).

    x: fp8_e4m3 (M, K).  w: fp8_e4m3 (N, K) normalized to the e4m3 range.
    weight_scale: (N,) per-output-channel dequant scale.
    """

    def __init__(self, M: int, N: int, K: int):
        super().__init__()
        self.M, self.N, self.K = M, N, K
        w = torch.empty(N, K, dtype=torch.bfloat16)
        nn.init.normal_(w, std=0.02)
        s = (w.float().abs().amax(dim=1, keepdim=True) / E4M3_MAX).clamp(min=1e-12)
        w_fp8 = (w.float() / s).to(torch.float8_e4m3fn)
        self.register_buffer("weight", w_fp8)
        self.register_buffer("weight_scale", s.squeeze(1).to(torch.float32))
        # Per-model pad buffers (not in state_dict). Weight is re-copied every
        # call so numeric-stress in-place mutations stay correct.
        self._a_pad: torch.Tensor | None = None
        self._b_pad: torch.Tensor | None = None
        self._cfg = _pick_config(M, N, K)
        self._K_use = (K + 15) // 16 * 16

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        a = x if x.is_contiguous() else x.contiguous()
        b = self.weight
        scale = self.weight_scale
        M, K = a.shape
        N = b.shape[0]

        BLOCK_M, BLOCK_N, BLOCK_K, num_warps, num_stages, GROUP_M = self._cfg
        K_use = self._K_use

        if K_use != K:
            if self._a_pad is None:
                self._a_pad = torch.zeros(M, K_use, device=a.device, dtype=a.dtype)
                self._b_pad = torch.zeros(N, K_use, device=b.device, dtype=b.dtype)
            self._a_pad[:, :K].copy_(a)
            self._b_pad[:, :K].copy_(b)
            a_use, b_use = self._a_pad, self._b_pad
        else:
            a_use, b_use = a, b

        c = torch.empty((M, N), device=a.device, dtype=torch.bfloat16)
        grid = (triton.cdiv(M, BLOCK_M) * triton.cdiv(N, BLOCK_N),)
        a_desc = TensorDescriptor.from_tensor(a_use, [BLOCK_M, BLOCK_K])
        b_desc = TensorDescriptor.from_tensor(b_use, [BLOCK_N, BLOCK_K])
        _fp8_gemm_tma_kernel[grid](
            a_desc,
            b_desc,
            c,
            scale,
            M,
            N,
            K_use,
            c.stride(0),
            c.stride(1),
            BLOCK_M=BLOCK_M,
            BLOCK_N=BLOCK_N,
            BLOCK_K=BLOCK_K,
            GROUP_M=GROUP_M,
            num_warps=num_warps,
            num_stages=num_stages,
        )
        return c


M = 4096
N = 4096
K = 4096


def get_inputs():
    x = (torch.rand(M, K) * 8 - 4).to(torch.float8_e4m3fn)
    return [x]


def get_init_inputs():
    return [M, N, K]

20260708_134136_grok_grok-4.5_01_fp8_gemm