Print per-scope runtime breakdown as percentages of kernel time. Raises if any expected scope is missing, since filling 0 would produce a bogus matmul derivation.
(trace: dict)
| 72 | |
| 73 | |
| 74 | def print_breakdown(trace: dict) -> None: |
| 75 | """Print per-scope runtime breakdown as percentages of kernel time. |
| 76 | |
| 77 | Raises if any expected scope is missing, since filling 0 would produce |
| 78 | a bogus matmul derivation. |
| 79 | """ |
| 80 | scopes = trace["scopes"] |
| 81 | counts = trace["counts"] |
| 82 | missing = [s for s in EXPECTED_SCOPES if s not in scopes] |
| 83 | if missing: |
| 84 | raise ValueError( |
| 85 | f"Chrome trace is missing scopes: {missing}. " |
| 86 | "The TTGIR injection likely failed (compiler renamed variables?). " |
| 87 | "Fix insert_proton_records.py patterns and re-run." |
| 88 | ) |
| 89 | |
| 90 | kernel = scopes["kernel"] |
| 91 | setup = scopes["setup"] |
| 92 | mask = scopes["mask"] |
| 93 | tile_mgmt = scopes["tile-mgmt"] |
| 94 | sample = scopes["sample"] |
| 95 | store = scopes["store"] |
| 96 | matmul = kernel - setup - mask - tile_mgmt - sample - store |
| 97 | |
| 98 | rows = [ |
| 99 | ("kernel", kernel, counts["kernel"]), |
| 100 | ("setup", setup, counts["setup"]), |
| 101 | ("matmul*", matmul, None), |
| 102 | ("mask", mask, counts["mask"]), |
| 103 | ("tile-mgmt", tile_mgmt, counts["tile-mgmt"]), |
| 104 | ("sample", sample, counts["sample"]), |
| 105 | ("store", store, counts["store"]), |
| 106 | ] |
| 107 | df = pd.DataFrame(rows, columns=["phase", "cycles", "count"]) |
| 108 | df["runtime_%"] = (df["cycles"] / kernel * 100).round(1) |
| 109 | print(df.to_markdown(index=False)) |
| 110 | print() |
| 111 | print("* matmul = kernel - setup - mask - tile-mgmt - sample - store") |
| 112 | |
| 113 | |
| 114 | if __name__ == "__main__": |
no outgoing calls
no test coverage detected