clang needs -lm and is very slow

This commit is contained in:
George Hotz
2023-02-20 21:02:04 -08:00
parent 4126bf2982
commit 4f4b7d05a7
2 changed files with 6 additions and 2 deletions

View File

@@ -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))

View File

@@ -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]