hamer-p150 / code /scripts /prof_blocks.py
changh95's picture
Optimized build (2026-10-03): model call 3.49 ms, device 3.36 ms
58ba6df verified
Raw History Blame Contribute Delete
1.6 kB
# SPDX-License-Identifier: Apache-2.0
"""Round 9: per-op-slot summary of the LAST forward in a tracy ops_perf_results CSV of scripts/prof.py
(TT_FUSED_CMM_ADDLN layout: 3 ingest ops, 32 x 6 ViT block ops, then the MANO head).
usage: python scripts/prof_blocks.py <ops_perf_results.csv>"""
import csv
import statistics as st
import sys
from collections import defaultdict
rows = [r for r in csv.DictReader(open(sys.argv[1])) if r.get("DEVICE KERNEL DURATION [ns]")]
starts = [i for i in range(len(rows) - 1) if rows[i]["OP CODE"].startswith("GenericOp") and rows[i]["CORE COUNT"] == "120"
and rows[i + 1]["OP CODE"].startswith("Matmul") and rows[i + 1]["CORE COUNT"] == "60"]
last = rows[starts[-1]:]
d = lambda r: float(r["DEVICE KERNEL DURATION [ns]"]) / 1e3
g = lambda r: float(r["OP TO OP LATENCY [ns]"] or 0) / 1e3
print(f"forwards {len(starts)} ops {len(last)} kernel sum {sum(map(d, last)):.1f} us gaps {sum(map(g, last[1:])):.1f} us")
print("ingest", [(r["OP CODE"][:12], round(d(r), 1), r["CORE COUNT"]) for r in last[:3]])
blk = defaultdict(list)
for b in range(32):
for j in range(6):
blk[j].append(last[3 + b * 6 + j])
for j in range(6):
v = blk[j]
print(f"block op {j} {v[0]['OP CODE'][:16]:16s} cores {v[0]['CORE COUNT']:>3s} dur med {st.median(map(d, v)):6.2f} us "
f"gap med {st.median(map(g, v)):5.2f} us")
vit = last[3:3 + 32 * 6]
head = last[3 + 32 * 6:]
print(f"ViT blocks: kernel {sum(map(d, vit)):.1f} us gaps {sum(map(g, vit)):.1f} us")
print(f"head: {len(head)} ops kernel {sum(map(d, head)):.1f} us gaps {sum(map(g, head)):.1f} us")