Download code/scripts/micro/addln_prof.py from changh95/hamer-p150: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/changh95/hamer-p150/resolve/main/code/scripts/micro/addln_prof.py
- Command line
-
hf download hf://changh95/hamer-p150/code/scripts/micro/addln_prof.py
-
curl -L -o addln_prof.py https://huggingface.co/changh95/hamer-p150/resolve/main/code/scripts/micro/addln_prof.py
1.77 kB
| """Device-profiler zones of the addln kernel (ADDLN_EXP=prof, TT_METAL_DEVICE_PROFILER=1).""" | |
| import sys, os, glob, csv | |
| from pathlib import Path | |
| from collections import defaultdict | |
| from common import * | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[2])) | |
| from hamer import tt_kernels as tk | |
| dev = open_dev() | |
| res = ttnn.create_sharded_memory_config((192, 1280), core_grid=ttnn.CoreGrid(y=6, x=10), strategy=ttnn.ShardStrategy.BLOCK, | |
| orientation=ttnn.ShardOrientation.ROW_MAJOR) | |
| x = ttnn.from_torch(torch.randn(1, 1, 192, 1280), dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=dev, memory_config=res) | |
| y = ttnn.from_torch(torch.randn(1, 1, 192, 1280), dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=dev, memory_config=res) | |
| C = tk.addln_constants(torch.ones(1280), torch.zeros(1280), dev) | |
| for _ in range(5): | |
| s, h = tk.add_layernorm(x, y, C, 1e-6); ttnn.synchronize_device(dev); ttnn.deallocate(s); ttnn.deallocate(h) | |
| ttnn.ReadDeviceProfiler(dev) | |
| ttnn.close_device(dev) | |
| f = os.environ["TT_METAL_PROFILER_DIR"] + "/.logs/profile_log_device.csv" | |
| rows = list(csv.reader(open(f)))[2:] | |
| # columns: PCIe slot, core_x, core_y, RISC processor type, timer_id, time[cycles], data, run host ID, zone name, type, ... | |
| st = {}; dur = defaultdict(list) | |
| for r in rows: | |
| try: | |
| cx, cy, risc, cyc, name, typ = int(r[1]), int(r[2]), r[3].strip(), int(r[5]), r[10].strip(), r[11].strip() | |
| except Exception: | |
| continue | |
| key = (cx, cy, risc, name) | |
| if "START" in typ: st[key] = cyc | |
| elif "END" in typ and key in st: dur[(risc, name)].append((cyc - st.pop(key)) / 1.35) | |
| for k in sorted(dur): | |
| v = sorted(dur[k]); print(f"{k[0]:8s} {k[1]:28s} n={len(v):4d} med={v[len(v)//2]:8.0f} ns max={v[-1]:8.0f}") | |