| """Audit graded-shape sizing: can a ROOFLINE kernel actually reach peak at these sizes? |
| |
| A kernel only approaches peak if its runtime is long enough that launch overhead (~5-10us), the wave |
| quantisation tail, and cache warm-up are amortised. Rule of thumb used here: the implied roofline runtime |
| at the LARGEST graded shape should be >= ~200us. Anything under ~50us is capped by overhead no matter how |
| good the kernel is, which silently compresses the top of the leaderboard. |
| """ |
| import ast |
| import pathlib |
| import sys |
|
|
| |
| |
| ONLY = set(sys.argv[1:]) |
|
|
| H200_TFLOPS = 700.0 |
| H200_GBPS = 4800.0 |
| |
| |
| |
| LINK_GBPS = 50.0 |
|
|
| for d in sorted(p for p in pathlib.Path(".").iterdir() if p.is_dir() and not p.name.startswith("_")): |
| v = d / "tests" / "verify_env.py" |
| if not v.exists() or (ONLY and d.name not in ONLY): |
| continue |
| if "canonical_work" not in v.read_text(): |
| |
| print(f"{d.name:34s} n/a (megakernel family - use MegaSpec.floor_us(), see _mega_factory)") |
| continue |
| src = v.read_text() |
| ns = {} |
| try: |
| tree = ast.parse(src) |
| for node in tree.body: |
| |
| |
| if isinstance(node, ast.FunctionDef): |
| exec(compile(ast.Module([node], []), "<w>", "exec"), ns) |
| |
| elif isinstance(node, ast.Assign): |
| try: |
| exec(compile(ast.Module([node], []), "<w>", "exec"), ns) |
| except Exception: |
| pass |
| if isinstance(node, ast.Assign) and getattr(node.targets[0], "id", "") == "GRADER_SHAPES": |
| shapes = ast.literal_eval(node.value) |
| if isinstance(node, ast.Assign) and getattr(node.targets[0], "id", "") == "REWARD_DIR": |
| pass |
| metric = "GB/s" if 'GB/s' in src else "TFLOP/s" |
| cw = ns["canonical_work"] |
| works = [cw(*s) for s in shapes] |
| big = max(works) |
| if metric == "TFLOP/s": |
| us = big / (H200_TFLOPS * 1e12) * 1e6 |
| unit = f"{big/1e9:8.1f} GFLOP" |
| else: |
| bw = LINK_GBPS if d.name.startswith("dist-") else H200_GBPS |
| us = big / (bw * 2**30) * 1e6 |
| unit = f"{big/2**30:8.2f} GiB" + (" [link]" if d.name.startswith("dist-") else "") |
| flag = " <-- TOO SMALL" if us < 50 else (" <- marginal" if us < 200 else "") |
| print(f"{d.name:34s} {metric:8s} max {unit} roofline {us:8.1f} us{flag}") |
| except Exception as e: |
| print(f"{d.name:34s} audit failed: {type(e).__name__}: {str(e)[:60]}") |
|
|