Files
kernbench2/tests/gemm/test_gemm_sweep.py
T
mukesh 0e346b939d gemm: test-generated GEMM plots under tests/gemm/ + docs/diagrams/gemm_plots/
Mirror the sccl pattern for GEMM figures: a tests/gemm/ package renders the
GEMM bar charts as PNGs from the committed docs/diagrams/gemm_sweep.json, so
the figures are fast test artifacts (run by default) while the heavy sim sweep
stays a manual script (scripts/gemm_sweep.py, kept) wrapped by a slow
regenerator test.

tests/gemm/:
- _gemm_plot_helpers.py: matplotlib renderers (series logic mirrors the
  GEMM _render_* functions in scripts/build_overview_slides.py).
- test_plot_gemm_stage_breakdown.py: gemm_stage_breakdown.png (load_ref).
- test_plot_gemm_mac_utilization.py: gemm_mac_utilization_measured.png +
  gemm_mac_utilization_theoretical_vs_measured.png (load_ref).
- test_gemm_sweep.py: @pytest.mark.slow regenerator (runs scripts/gemm_sweep.py).

Chart set trimmed to three (stage breakdown, MAC util, theoretical-vs-measured);
"formula" relabeled to "theoretical" throughout the comparison chart.

Known follow-ups (not blocking):
- gemm_mac_utilization_measured.png currently plots the theoretical ideal-
  pipeline model, not simulator-measured data; the name is a misnomer pending
  a decision to repoint its content or retitle.
- The theoretical-model constants (HBM 256 GB/s, T_stage 16 ns, 3 stages) are
  inherited verbatim from build_overview_slides.py and not yet verified against
  ADR-0033 / ADR-0014 / topology.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 09:58:08 -07:00

37 lines
1.1 KiB
Python

"""Regenerate docs/diagrams/gemm_sweep.json by running the GEMM sweep.
Heavy: drives matmul-composite across all shapes x variants through the
simulator (24 runs; the 512 shape alone is 2048 tiles). Marked ``slow`` so it
is excluded from the default ``pytest`` run (addopts: -m "not slow") and runs
on demand:
pytest -m slow tests/gemm/test_gemm_sweep.py
Delegates to scripts/gemm_sweep.py (the single source of the sweep logic) via
subprocess so there is no duplicated sim-driving code.
"""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
import pytest
from tests.gemm._gemm_plot_helpers import GEMM_SWEEP_JSON, ROOT
@pytest.mark.slow
def test_gemm_sweep_regenerates_json():
script = ROOT / "scripts" / "gemm_sweep.py"
assert script.exists(), f"missing {script}"
proc = subprocess.run(
[sys.executable, str(script)],
cwd=str(ROOT), capture_output=True, text=True,
)
assert proc.returncode == 0, (
f"gemm_sweep.py failed (rc={proc.returncode})\n"
f"stdout:\n{proc.stdout[-2000:]}\nstderr:\n{proc.stderr[-2000:]}"
)
assert Path(GEMM_SWEEP_JSON).exists()