"""Idealized DRAM-traffic matrix multiplication model (no measured points)."""
from __future__ import annotations
from math import log10
from pathlib import Path
def model(output: Path) -> dict:
size, tile, bytes_per_element = 256, 32, 4
flops = 2 * size**3
cases = []
for name, a_b_bytes in (("naive", 8 * size**3), ("tiled", 8 * size**3 // tile)):
bytes_dram = a_b_bytes + 8 * size**2
intensity = flops / bytes_dram
cases.append({"name": name, "dram_bytes_model": bytes_dram, "flops": flops, "operational_intensity_flop_per_byte": intensity, "model_bound_gflops": min(128, 32 * intensity), "measured": False})
def xcoord(value: float) -> float:
return 85 + 490 * (log10(value) + 1) / 3
def ycoord(value: float) -> float:
return 345 - 285 * (log10(value) + 1) / 3.5
roof = [(xcoord(10**(step / 20 - 1)), ycoord(min(128, 32 * 10**(step / 20 - 1)))) for step in range(61)]
path = " ".join(("M" if index == 0 else "L") + f"{x:.1f},{y:.1f}" for index, (x, y) in enumerate(roof))
dots = "\n".join(f'{case["name"]} (model)' for case in cases)
svg = f'''\n'''
output.write_text(svg, encoding="utf-8")
return {"evidence_level": "解析模型,非实测", "matrix": "C=A×B; square row-major float32, no FMA exception", "size": size, "tile_size": tile, "storage_level": "ideal DRAM traffic (no conflict/capacity misses, no write allocate)", "flop_accounting": "one multiply and one add per inner iteration = 2*N^3", "c_bytes": 8 * size**2, "naive_a_b_bytes": 8 * size**3, "tiled_a_b_bytes": 8 * size**3 // tile, "peak_gflops_assumed": 128, "bandwidth_gb_s_assumed": 32, "points": cases, "measured_points": [], "plot": output.name}