Return {"matmul": pct, "sampling": pct} from a chrome trace. Matmul is derived as kernel - setup - mask - tile-mgmt - sample - store. Sampling aggregates mask + sample + store (tile-mgmt excluded). Raises if any expected scope is missing, since filling 0 would produce a bogus matmu
(trace: dict)
| 39 | |
| 40 | |
| 41 | def trace_phase_pcts(trace: dict) -> dict[str, float]: |
| 42 | """Return {"matmul": pct, "sampling": pct} from a chrome trace. |
| 43 | |
| 44 | Matmul is derived as kernel - setup - mask - tile-mgmt - sample - store. |
| 45 | Sampling aggregates mask + sample + store (tile-mgmt excluded). |
| 46 | |
| 47 | Raises if any expected scope is missing, since filling 0 would produce |
| 48 | a bogus matmul derivation. |
| 49 | """ |
| 50 | scopes = trace["scopes"] |
| 51 | missing = [s for s in EXPECTED_SCOPES if s not in scopes] |
| 52 | if missing: |
| 53 | raise ValueError( |
| 54 | f"Chrome trace is missing scopes: {missing}. " |
| 55 | "The TTGIR injection likely failed (compiler renamed variables?). " |
| 56 | "Fix insert_proton_records.py patterns and re-run." |
| 57 | ) |
| 58 | kernel = scopes["kernel"] |
| 59 | setup = scopes["setup"] |
| 60 | mask = scopes["mask"] |
| 61 | tile_mgmt = scopes["tile-mgmt"] |
| 62 | sample = scopes["sample"] |
| 63 | store = scopes["store"] |
| 64 | matmul = kernel - setup - mask - tile_mgmt - sample - store |
| 65 | return { |
| 66 | "matmul": matmul / kernel * 100, |
| 67 | "sampling": (mask + sample + store) / kernel * 100, |
| 68 | } |
| 69 | |
| 70 | |
| 71 | EXPECTED_SCOPES = ["kernel", "setup", "mask", "tile-mgmt", "sample", "store"] |