From 5abc262e227aeb604427d4ec8c019081bf300f7e Mon Sep 17 00:00:00 2001 From: Christopher Milan Date: Thu, 15 Jan 2026 17:25:42 -0800 Subject: [PATCH] fix dll.bind caching (#14168) --- tinygrad/runtime/support/c.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tinygrad/runtime/support/c.py b/tinygrad/runtime/support/c.py index 20913b787f..eaeeedea77 100644 --- a/tinygrad/runtime/support/c.py +++ b/tinygrad/runtime/support/c.py @@ -165,14 +165,14 @@ class DLL(ctypes.CDLL): if DEBUG >= 3: print(f"loading {nm} failed: {e}") elif DEBUG >= 3: print(f"loading {nm} failed: not found on system") - @functools.cache - def _get_func(self, name:str, args:tuple, res): - (fn:=getattr(self, name)).argtypes, fn.restype = args, res - return fn - def bind(self, fn): restype, argtypes = del_an((hints:=get_type_hints(fn, include_extras=True)).pop('return', None)), tuple(del_an(h) for h in hints.values()) - return lambda *args: self._get_func(fn.__name__, argtypes, restype)(*args) + cfunc = None + def wrapper(*args): + nonlocal cfunc + if cfunc is None: (cfunc:=getattr(self, fn.__name__)).argtypes, cfunc.restype = argtypes, restype + return cfunc(*args) + return wrapper def __getattr__(self, nm): if not self.loaded: raise AttributeError(f"failed to load library {self.nm}: " + (self.emsg or f"try setting {self.nm.upper()+'_PATH'}?"))