Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
62 lines
2.7 KiB
Python
62 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Timeline of a decode round from a CUPTI window: for each verify window graph followed by one commit graph, one MTP round graph and 0..n step graphs, the mean gaps
|
|
(verify end -> commit launch call / first kernel, -> round graph first kernel, launch call lengths, step gaps, draft end vs commit end, last draft kernel -> next verify).
|
|
|
|
python3 -I draftround-timeline.py <win.lct>
|
|
|
|
Classes by kernel count and names: V >= 1000 kernels (verify window), C has verify_gdn_conv_commit_kernel or draft_commit_* (the fused commit graph), S exactly 113 kernels (MTP step), R 140-200 kernels (MTP round graph).
|
|
"""
|
|
import sys, collections, statistics
|
|
sys.path.insert(0,"/data/leleka-e2e/decode/tools")
|
|
import lct as L
|
|
t = L.Trace(sys.argv[1])
|
|
gl = {x.corr: x for x in t.apis if "GraphLaunch" in t.names.get(x.name, "")}
|
|
byc = collections.defaultdict(list)
|
|
for k in t.kernels: byc[k.corr].append(k)
|
|
G=[]
|
|
for corr,x in gl.items():
|
|
ks=sorted(byc.get(corr,[]),key=lambda k:k.start)
|
|
if not ks: continue
|
|
names=[t.names.get(k.name,"?") for k in ks]
|
|
if len(ks)>=1000: cl="V"
|
|
elif any("conv_commit" in n or "draft_commit" in n for n in names): cl="C"
|
|
elif len(ks)==113: cl="S"
|
|
elif 140<=len(ks)<=200: cl="R"
|
|
else: cl="?"
|
|
G.append((ks[0].start, ks[-1].end, cl, x.start, x.end))
|
|
G.sort()
|
|
# rounds: V then C, R, S*
|
|
rows=[]
|
|
i=0
|
|
while i < len(G):
|
|
if G[i][2]=="V":
|
|
j=i+1; seq=[]
|
|
while j<len(G) and G[j][2]!="V": seq.append(G[j]); j+=1
|
|
if j<len(G) and seq:
|
|
rows.append((G[i],seq,G[j]))
|
|
i=j
|
|
else: i+=1
|
|
f=lambda a:statistics.mean(a)/1e3
|
|
acc=collections.defaultdict(list)
|
|
for v,seq,nv in rows:
|
|
C=[g for g in seq if g[2]=="C"]; R=[g for g in seq if g[2]=="R"]; S=[g for g in seq if g[2]=="S"]
|
|
if len(C)!=1 or len(R)!=1: continue
|
|
c=C[0]; r=R[0]
|
|
acc["V end -> C launch call start"].append(c[3]-v[1])
|
|
acc["V end -> C first kernel"].append(c[0]-v[1])
|
|
acc["C gpu span"].append(c[1]-c[0])
|
|
acc["V end -> R first kernel"].append(r[0]-v[1])
|
|
acc["R launch call (start->end)"].append(r[4]-r[3])
|
|
acc["R gpu span"].append(r[1]-r[0])
|
|
last=r
|
|
for k,s in enumerate(S):
|
|
acc["gap before step (prev end -> launch call start)"].append(s[3]-last[1])
|
|
acc["gap before step (prev end -> first kernel)"].append(s[0]-last[1])
|
|
acc["step gpu span"].append(s[1]-s[0])
|
|
last=s
|
|
acc["last draft kernel end -> next V first kernel"].append(nv[0]-last[1])
|
|
acc["C end vs draft end (draft end - C end)"].append(last[1]-c[1])
|
|
acc["V end -> next V start (round)"].append(nv[0]-v[1])
|
|
acc["nsteps"].append(len(S)*1e3)
|
|
for k,v in acc.items(): print("%-55s n=%4d mean %8.1f us p10 %8.1f p90 %8.1f"%(k,len(v),f(v),sorted(v)[len(v)//10]/1e3,sorted(v)[len(v)*9//10]/1e3))
|