diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py index 00fe25c787035ca00ce4fb9a890046786ff4463e..99ce2d6fbfbb31f87fdc90aec22fa203386935fe 100644 --- a/pystencils/cpu/cpujit.py +++ b/pystencils/cpu/cpujit.py @@ -134,11 +134,22 @@ def create_folder(path, is_file): pass +def get_llc_command(): + """Try to get executable for llvm's IR compiler llc + + We try if one of the following is in PATH: llc, llc-10, llc-9, llc-8, llc-7, llc-6 + """ + candidates = ['llc', 'llc-10', 'llc-9', 'llc-8', 'llc-7', 'llc-6'] + found_executables = (e for e in candidates if shutil.which(e)) + return next(found_executables, None) + + def read_config(): if platform.system().lower() == 'linux': default_compiler_config = OrderedDict([ ('os', 'linux'), ('command', 'g++'), + ('llc_command', get_llc_command() or 'llc'), ('flags', '-Ofast -DNDEBUG -fPIC -march=native -fopenmp -std=c++11'), ('restrict_qualifier', '__restrict__') ]) @@ -146,6 +157,7 @@ def read_config(): default_compiler_config = OrderedDict([ ('os', 'windows'), ('msvc_version', 'latest'), + ('llc_command', get_llc_command() or 'llc'), ('arch', 'x64'), ('flags', '/Ox /fp:fast /openmp /arch:avx'), ('restrict_qualifier', '__restrict') @@ -154,6 +166,7 @@ def read_config(): default_compiler_config = OrderedDict([ ('os', 'darwin'), ('command', 'clang++'), + ('llc_command', get_llc_command() or 'llc'), ('flags', '-Ofast -DNDEBUG -fPIC -march=native -Xclang -fopenmp -std=c++11'), ('restrict_qualifier', '__restrict__') ]) diff --git a/pystencils/llvm/llvmjit.py b/pystencils/llvm/llvmjit.py index f8b0205f5e4f7c4356903ea1c4b04d7bc645763a..0baec5452f80e6d8ca3c1b1d760ef23e510dcb0e 100644 --- a/pystencils/llvm/llvmjit.py +++ b/pystencils/llvm/llvmjit.py @@ -284,7 +284,7 @@ class CudaJit(Jit): self._llvmmod = llvm.parse_assembly(str(llvmmod)) def compile(self): - from pystencils.cpu.cpujit import get_cache_config + from pystencils.cpu.cpujit import get_cache_config, get_compiler_config, get_llc_command import hashlib compiler_cache = get_cache_config()['object_cache'] ir_file = join(compiler_cache, hashlib.md5(str(self._llvmmod).encode()).hexdigest() + '.ll') @@ -297,7 +297,12 @@ class CudaJit(Jit): if not exists(ptx_file): self.write_ll(ir_file) - subprocess.check_call(['llc-10', '-mcpu=' + arch, ir_file, '-o', ptx_file]) + if 'llc' in get_compiler_config(): + llc_command = get_compiler_config()['llc'] + else: + llc_command = get_llc_command() or 'llc' + + subprocess.check_call([llc_command, '-mcpu=' + arch, ir_file, '-o', ptx_file]) # cubin_file = ir_file.replace('.ll', '.cubin') # if not exists(cubin_file):