mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-24 06:18:01 -05:00
clang needs -lm and is very slow
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user