diff --git a/tinygrad/helpers.py b/tinygrad/helpers.py index b570338519..3e3a9a8ee5 100644 --- a/tinygrad/helpers.py +++ b/tinygrad/helpers.py @@ -1,5 +1,5 @@ from collections import namedtuple -import os, math, functools +import os, math, functools, time def dedup(x): return list(dict.fromkeys(x)) # retains list order def prod(x): return math.prod(x) @@ -11,6 +11,10 @@ def partition(lst, fxn): return [x for x in lst if fxn(x)], [x for x in lst if n def modn(x, a): return -((-x)%a) if x < 0 else x%a def make_pair(x): return (x,x) if isinstance(x, int) else x +class Timing(object): + def __enter__(self): self.st = time.monotonic_ns() + def __exit__(self, exc_type, exc_val, exc_tb): print(f"{(time.monotonic_ns()-self.st)*1e-6:.2f} ms") + @functools.lru_cache(maxsize=None) def getenv(key, default=0): return type(default)(os.getenv(key, default)) diff --git a/tinygrad/runtime/clang.py b/tinygrad/runtime/clang.py index f89fcb7fad..9d15c5928f 100644 --- a/tinygrad/runtime/clang.py +++ b/tinygrad/runtime/clang.py @@ -31,7 +31,7 @@ class CLProgram: # TODO: is there a way to not write this to disk? fn = f"/tmp/clang_{hashlib.md5(prg.encode('utf-8')).hexdigest()}.{'dylib' if OSX else 'so'}" if not os.path.exists(fn): - subprocess.check_output(['clang', '-shared', '-O2', '-x', 'c', '-', '-o', fn+".tmp"], input=prg.encode('utf-8')) + subprocess.check_output(['clang', '-shared', '-O2', '-lm', '-x', 'c', '-', '-o', fn+".tmp"], input=prg.encode('utf-8')) os.rename(fn+".tmp", fn) self.lib = ctypes.CDLL(fn) self.fxn = self.lib[name]