Files
leleka/scripts/e2e/codex/speed/kernel_roles.py
T

41 lines
2.2 KiB
Python

import re,sys,collections
RULES=[
("wait on CPU leg / flag waits", r"wait_flag_ge|chain_wait_copy"),
("doorbell, mapped copies, fetch_blobs, hit tally", r"doorbell|copy_rows_from_mapped|copy_i32_from_mapped|copy_from_mapped|add_hits|rebase_ptrs|fetch_blobs|verify_copy|copy_indexed|^copy$|chain_copy"),
("draft chain GR up/down/split/norm (MTP routed experts)", r"chain_gr|gr_down|gr_up|gr_norm_split|chain_scale_rows|chain_row_top|chain_sampler|mtp_scalar_gr|mtp_full|mtp_original|mtp_scalar|mtp_prefill|sampler|row_top_prob|mtp_select"),
("verify routed experts (gate/up/swiglu, down, combine)", r"window_moe|moe_gu|native_gu_swiglu|native_down_multi|native_swiglu|native_q8_1_interleave|sigmoid_scale|combine|gu_grouped|down_grouped|verify_gu|swiglu"),
("GDN (step/conv/ab/commit)", r"gdn|conv_residual|conv_l2"),
("attention (decode/QSA/chunk/topk/merge/append)", r"qsa|attn|block_|^resolve$|^append|kv_append|norm_rope|rope|^copy$"),
("dense MMVQ / MMVF / lm head (head_n*, mmvq, mmvf)", r"head_n|head_quant|head_embed|mmvq|mmvf|bf16_f32|native_small|quantize_q8_1|native_quantize|embed_rows|head_"),
("norms, small, ple, misc", r".*"),
]
def load(p):
d=collections.OrderedDict()
for l in open(p).read().splitlines()[1:]:
f=l.split("\t")
if len(f)<4 or f[0]=="ALL kernels": continue
d[f[0]]=(float(f[1]),float(f[2]))
return d
def role(n):
for r,rx in RULES:
if re.search(rx,n): return r
def agg(d):
a=collections.defaultdict(lambda:[0,0.0]);
for n,(c,m) in d.items():
r=role(n); a[r][0]+=c; a[r][1]+=m
return a
L=load(sys.argv[1]); V=load(sys.argv[2])
aL,aV=agg(L),agg(V)
rows=[]
for r,_ in RULES:
rows.append((aL[r][1]-aV[r][1],r,aL[r],aV[r]))
rows.sort(reverse=True)
print("%-58s %8s %8s %8s %7s %7s"%("role","LEL ms","VANL ms","diff ms","LELcnt","VANcnt"))
for d,r,l,v in rows: print("%-58s %8.3f %8.3f %+8.3f %7.0f %7.0f"%(r,l[1],v[1],d,l[0],v[0]))
print("TOTAL", sum(x[1] for x in aL.values()), sum(x[1] for x in aV.values()), sum(x[0] for x in aL.values()), sum(x[0] for x in aV.values()))
if len(sys.argv)>3:
for n,(c,m) in L.items():
if role(n)==sys.argv[3]: print("L",n,c,m)
for n,(c,m) in V.items():
if role(n)==sys.argv[3]: print("V",n,c,m)