viz: readable pmc print, share unpacker with tests (#13655)

* viz: readable pmc print, share unpacker with tests

* sections

* static analyzer

* rm that
This commit is contained in:
qazal
2025-12-12 06:29:59 -05:00
committed by GitHub
parent 760e508c3a
commit 93ad1f7732
3 changed files with 29 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
import ctypes, pathlib, argparse, pickle, re, functools, dataclasses, itertools, threading
from tabulate import tabulate
from typing import Generator
from tinygrad.helpers import temp, unwrap, DEBUG
from tinygrad.device import ProfileEvent, ProfileDeviceEvent, ProfileProgramEvent
@@ -158,14 +159,12 @@ def decode(profile:list[ProfileEvent]) -> _ROCParseCtx:
t.join()
return ROCParseCtx
def print_pmc(ev:ProfilePMCEvent) -> None:
ptr = 0
view = memoryview(ev.blob).cast('Q')
for s in ev.sched:
print(f"\t{s.name}")
for xcc, inst, se_idx, sa_idx, wgp_idx in itertools.product(range(s.xcc), range(s.inst), range(s.se), range(s.sa), range(s.wgp)):
print(f"\t\tXCC {xcc} Inst {inst:<2} SE {se_idx} SA {sa_idx} WGP {wgp_idx}: {view[ptr]:#x}")
ptr += 1
def print_pmc(events:list[ProfilePMCEvent]) -> None:
from tinygrad.viz.serve import unpack_pmc
for e in events:
print("**", e.kern)
data = unpack_pmc(e)
print(tabulate([r[:-1] for r in data["rows"]], headers=data["cols"], tablefmt="github"))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
@@ -176,7 +175,4 @@ if __name__ == "__main__":
rctx = decode(profile)
print('SQTT:', rctx.inst_execs.keys())
for ev in profile:
if not isinstance(ev, ProfilePMCEvent): continue
print(f"PMC Event: dev={ev.device} kern={ev.kern}")
print_pmc(ev)
print_pmc([ev for ev in profile if isinstance(ev, ProfilePMCEvent)])

View File

@@ -40,7 +40,7 @@ class TestPMC(unittest.TestCase):
b = Tensor.custom_kernel(b, a, fxn=functools.partial(copy_kernel, stride=stride))[0]
with save_pmc() as pmc:
b.realize()
print_pmc(pmc[0])
print_pmc(pmc)
np.testing.assert_equal(a.numpy(), b.numpy())
def test_copy_uncoalesced(self): return self.test_copy(stride=17)