diff --git a/test/unit/test_viz.py b/test/unit/test_viz.py index 7dc673b6b9..7a3ee5becc 100644 --- a/test/unit/test_viz.py +++ b/test/unit/test_viz.py @@ -442,7 +442,7 @@ class TestVizMemoryLayout(BaseTestViz): profile_ret = load_profile(Buffer.profile_events) ret = profile_ret["layout"][f"{a.device} Memory"] self.assertEqual(ret["peak"], 2) - self.assertEqual(len(ret["events"]), 2) + self.assertEqual(len(ret["events"]), 4) def test_del_once(self): a = _alloc(1) @@ -451,7 +451,7 @@ class TestVizMemoryLayout(BaseTestViz): profile_ret = load_profile(Buffer.profile_events) ret = profile_ret["layout"][f"{b.device} Memory"] self.assertEqual(ret["peak"], 1) - self.assertEqual(len(ret["events"]), 3) + self.assertEqual(len(ret["events"]), 4) def test_alloc_free(self): a = _alloc(1) @@ -461,7 +461,7 @@ class TestVizMemoryLayout(BaseTestViz): profile_ret = load_profile(Buffer.profile_events) ret = profile_ret["layout"][f"{c.device} Memory"] self.assertEqual(ret["peak"], 2) - self.assertEqual(len(ret["events"]), 4) + self.assertEqual(len(ret["events"]), 6) def test_free_last(self): bufs = [] @@ -480,15 +480,24 @@ class TestVizMemoryLayout(BaseTestViz): self.assertEqual(len(profile["markers"]), 6) def test_producer_simple(self): - a = Tensor.empty(10, device="NULL") - Tensor.realize(a.add(1), a.add(2)) - b = Tensor.empty(10, device="NULL") - Tensor.realize(b.add(1)) + a = Tensor.ones(10, device="NULL") + Tensor.realize(a.add(1).contiguous()) + b = Tensor.ones(10, device="NULL") + Tensor.realize(b.add(1).contiguous()) profile = load_profile(cpu_events+Buffer.profile_events) buffers = profile["layout"]["NULL Memory"]["events"] programs = profile["layout"]["NULL"]["events"] user_cnt = [len(b["arg"]["users"]) for b in buffers if b["arg"].get("users")] self.assertEqual(len(user_cnt), len(programs)) + def test_inflight_buf(self): + a = Tensor.empty(1, device="NULL") + n = 4 + for i in range(n): (a+i).realize() + profile = load_profile(cpu_events+Buffer.profile_events) + buffers = profile["layout"]["NULL Memory"]["events"] + user_cnt = [len(b["arg"]["users"]) for b in buffers if b["arg"].get("users")] + self.assertEqual(max(user_cnt), n) + if __name__ == "__main__": unittest.main() diff --git a/tinygrad/viz/js/index.js b/tinygrad/viz/js/index.js index a96a5f762f..22405c51dc 100644 --- a/tinygrad/viz/js/index.js +++ b/tinygrad/viz/js/index.js @@ -272,10 +272,6 @@ async function renderProfiler() { } } } - for (const [_, v] of temp) { - v.x.push(x); - v.y.push(v.y.at(-1)); - } timestamps.push(dur); const height = heightScale(peak); const yscale = d3.scaleLinear().domain([0, peak]).range([height, 0]); diff --git a/tinygrad/viz/serve.py b/tinygrad/viz/serve.py index 392081d2c9..1055c76b23 100755 --- a/tinygrad/viz/serve.py +++ b/tinygrad/viz/serve.py @@ -152,12 +152,17 @@ def timeline_layout(dev_events:list[tuple[int, int, float, DevEvent]], start_ts: events.append(struct.pack(" bytes: + kernel_names = [enum_str(ei.key, scache) for ei in execs] + return struct.pack(f" bytes|None: peak, mem = 0, 0 temp:dict[int, int] = {} events:list[bytes] = [] buf_ei:dict[int, list[ProfilePointEvent]] = {} + for st,_,_,e in dev_events: if not isinstance(e, ProfilePointEvent): continue if e.name == "alloc": @@ -170,9 +175,9 @@ def mem_layout(dev_events:list[tuple[int, int, float, DevEvent]], start_ts:int, if e.name == "exec" and e.arg["bufs"]: for b in e.arg["bufs"]: buf_ei.setdefault(b, []).append(e) if e.name == "free": - kernel_names = [enum_str(ei.key, scache) for ei in buf_ei.pop(e.key, [])] - events.append(struct.pack(f"