diff --git a/tinygrad/device.py b/tinygrad/device.py index d4782120c1..e1777aa02f 100644 --- a/tinygrad/device.py +++ b/tinygrad/device.py @@ -310,7 +310,7 @@ if PROFILE: for dev in devs: dev.synchronize() for dev in devs: dev._at_profile_finalize() - with open(temp("profile.pkl"), "wb") as f: pickle.dump(Compiled.profile_events, f) + with open(fn:=temp("profile.pkl", append_user=True), "wb") as f: pickle.dump(Compiled.profile_events, f) from tinygrad.ops import launch_viz - launch_viz("PROFILE", temp("profile.pkl")) + launch_viz("PROFILE", fn) diff --git a/tinygrad/helpers.py b/tinygrad/helpers.py index d47f62d7d7..39d50fed8a 100644 --- a/tinygrad/helpers.py +++ b/tinygrad/helpers.py @@ -78,7 +78,8 @@ def polyN(x:T, p:list[float]) -> T: return functools.reduce(lambda acc,c: acc*x+ def to_function_name(s:str): return ''.join([c if c in (string.ascii_letters+string.digits+'_') else f'{ord(c):02X}' for c in ansistrip(s)]) @functools.lru_cache(maxsize=None) def getenv(key:str, default=0): return type(default)(os.getenv(key, default)) -def temp(x:str) -> str: return (pathlib.Path(tempfile.gettempdir()) / x).as_posix() +def temp(x:str, append_user:bool=False) -> str: + return (pathlib.Path(tempfile.gettempdir()) / (f"{x}.{os.getenv('USERNAME', os.getlogin())}" if append_user else x)).as_posix() class Context(contextlib.ContextDecorator): def __init__(self, **kwargs): self.kwargs = kwargs diff --git a/tinygrad/ops.py b/tinygrad/ops.py index 639d16819f..74892dbed8 100644 --- a/tinygrad/ops.py +++ b/tinygrad/ops.py @@ -815,10 +815,10 @@ if TRACK_MATCH_STATS: @atexit.register def print_match_stats(): if TRACK_MATCH_STATS >= 2: - with open(fn:=temp("rewrites.pkl"), "wb") as f: + with open(fn:=temp("rewrites.pkl", append_user=True), "wb") as f: print(f"rewrote {len(tracked_ctxs)} graphs and matched {sum(len(r.matches) for x in tracked_ctxs for r in x)} times, saved to {fn}") with Context(PICKLE_BUFFERS=0): pickle.dump((tracked_keys, tracked_ctxs), f) - if getenv("VIZ"): launch_viz("VIZ", temp("rewrites.pkl")) + if getenv("VIZ"): launch_viz("VIZ", temp("rewrites.pkl", append_user=True)) if getenv("PRINT_MATCH_STATS", 1): ret = [0,0,0.0,0.0] for k,v in sorted(list(match_stats.items()), key=lambda x: x[1][2]+x[1][3]):