From 2e4c7d4cfb439686f8eca450b2e5509e1eb1bb99 Mon Sep 17 00:00:00 2001 From: chenyu Date: Thu, 12 Dec 2024 12:09:44 -0500 Subject: [PATCH] add "tinygrad" to be part of cache_dir [pr] (#8188) instead of having sqlite / http download / metal compile to add "tinygrad" separately. also make it non-private since it's used in metal --- tinygrad/helpers.py | 6 +++--- tinygrad/runtime/ops_metal.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tinygrad/helpers.py b/tinygrad/helpers.py index b5b3302534..4e9a273979 100644 --- a/tinygrad/helpers.py +++ b/tinygrad/helpers.py @@ -157,8 +157,8 @@ class Profiling(contextlib.ContextDecorator): # *** universal database cache *** -_cache_dir: str = getenv("XDG_CACHE_HOME", os.path.expanduser("~/Library/Caches" if OSX else "~/.cache")) -CACHEDB: str = getenv("CACHEDB", os.path.abspath(os.path.join(_cache_dir, "tinygrad", "cache.db"))) +cache_dir: str = os.path.join(getenv("XDG_CACHE_HOME", os.path.expanduser("~/Library/Caches" if OSX else "~/.cache")), "tinygrad") +CACHEDB: str = getenv("CACHEDB", os.path.abspath(os.path.join(cache_dir, "cache.db"))) CACHELEVEL = getenv("CACHELEVEL", 2) VERSION = 17 @@ -225,7 +225,7 @@ def _ensure_downloads_dir() -> pathlib.Path: subprocess.run(["sudo", "chown", "tiny:root", downloads_dir], check=True) subprocess.run(["sudo", "chmod", "775", downloads_dir], check=True) return downloads_dir - return pathlib.Path(_cache_dir) / "tinygrad" / "downloads" + return pathlib.Path(cache_dir) / "downloads" def fetch(url:str, name:Optional[Union[pathlib.Path, str]]=None, subdir:Optional[str]=None, gunzip:bool=False, allow_caching=not getenv("DISABLE_HTTP_CACHE")) -> pathlib.Path: diff --git a/tinygrad/runtime/ops_metal.py b/tinygrad/runtime/ops_metal.py index be3f77c407..82b50c929d 100644 --- a/tinygrad/runtime/ops_metal.py +++ b/tinygrad/runtime/ops_metal.py @@ -1,7 +1,7 @@ from __future__ import annotations import os, pathlib, struct, ctypes, tempfile, functools from typing import List, Any, Union, Tuple, cast -from tinygrad.helpers import prod, to_mv, getenv, round_up, _cache_dir, T, init_c_struct_t +from tinygrad.helpers import prod, to_mv, getenv, round_up, cache_dir, T, init_c_struct_t from tinygrad.device import Compiled, Compiler, CompileError, LRUAllocator from tinygrad.renderer.cstyle import MetalRenderer @@ -84,7 +84,7 @@ class MetalCompiler(Compiler): ret = CompileError(errorMessage.decode()) # llvm will create modules.timestamp in cache path and cache compilation of metal stdlib (250ms => 8ms compilation time) # note that llvm won't necessarily create anything else here as apple has prebuilt versions of many standard libraries - params = f'-fno-fast-math -std=metal3.1 --driver-mode=metal -x metal -fmodules-cache-path="{os.path.join(_cache_dir, "tinygrad")}"' + params = f'-fno-fast-math -std=metal3.1 --driver-mode=metal -x metal -fmodules-cache-path="{cache_dir}"' # source blob has to be padded to multiple of 4 but at least one 'b\x00' should be added, params blob just has to be null terminated src_padded, params_padded = src.encode() + b'\x00'*(round_up(len(src) + 1, 4) - len(src)), params.encode() + b'\x00' request = struct.pack('