From 72e0d1d0dc1fa8ef26bbf6dd37c25caed7bdcd85 Mon Sep 17 00:00:00 2001 From: qazal <77887910+Qazalin@users.noreply.github.com> Date: Sun, 3 Aug 2025 07:03:20 +0800 Subject: [PATCH] viz: profile the compiler in TINY device (#11457) * viz: profile the compiler in TINY device * leanup --- tinygrad/engine/realize.py | 7 +++++-- tinygrad/viz/js/index.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tinygrad/engine/realize.py b/tinygrad/engine/realize.py index 3c233092fa..111676d2d0 100644 --- a/tinygrad/engine/realize.py +++ b/tinygrad/engine/realize.py @@ -2,7 +2,7 @@ from typing import cast, Generator import time, pprint from dataclasses import dataclass, replace, field from tinygrad.helpers import all_same, colored, DEBUG, GlobalCounters, ansilen, BEAM, NOOPT, all_int, CAPTURING, Metadata, TRACEMETA, TracingKey -from tinygrad.helpers import DEVECTORIZE, time_to_str, VALIDATE_WITH_CPU, getenv +from tinygrad.helpers import DEVECTORIZE, time_to_str, VALIDATE_WITH_CPU, getenv, cpu_profile from tinygrad.uop.ops import Ops, PatternMatcher, UOp, UPat, Variable, sym_infer, graph_rewrite, print_uops, track_rewrites from tinygrad.device import Device, Buffer from tinygrad.renderer import Renderer, ProgramSpec, Estimates @@ -63,7 +63,10 @@ class CompiledRunner(Runner): def __init__(self, p:ProgramSpec, precompiled:bytes|None=None, prg=None): if DEBUG >= 4: print(p.src) self.p:ProgramSpec = p - self.lib:bytes = precompiled if precompiled is not None else Device[p.device].compiler.compile_cached(p.src) + if precompiled is not None: self.lib = precompiled + else: + with cpu_profile(TracingKey(f"compile {p.name}", (p.function_name,), cat="compiler"), "TINY"): + self.lib = Device[p.device].compiler.compile_cached(p.src) if DEBUG >= 7: Device[p.device].compiler.disassemble(self.lib) self._prg = Device[p.device].runtime(p.function_name, self.lib) if prg is None else prg super().__init__(p.name, p.device, p.estimates) diff --git a/tinygrad/viz/js/index.js b/tinygrad/viz/js/index.js index 5ed3bfc7f8..08c363d39d 100644 --- a/tinygrad/viz/js/index.js +++ b/tinygrad/viz/js/index.js @@ -109,7 +109,7 @@ function formatTime(ts, dur=ts) { } const formatUnit = (d, unit="") => d3.format(".3~s")(d)+unit; -const colorScheme = {TINY:["#1b5745", "#354f52", "#354f52", "#46acc2", "#1d2e62"], +const colorScheme = {TINY:["#1b5745", "#354f52", "#354f52", "#46acc2", "#1d2e62", "#63b0cd"], DEFAULT:["#2b2e39", "#2c2f3a", "#31343f", "#323544", "#2d303a", "#2e313c", "#343746", "#353847", "#3c4050", "#404459", "#444862", "#4a4e65"], BUFFER:["#3A57B7","#5066C1","#6277CD","#7488D8","#8A9BE3","#A3B4F2"], CATEGORICAL:["#ff8080", "#F4A261", "#C8F9D4", "#8D99AE", "#F4A261", "#ffffa2", "#ffffc0", "#87CEEB"],}