From 8d22fddf67bb84362169d5547d29a767088f2232 Mon Sep 17 00:00:00 2001 From: Stephan Seitz <stephan.seitz@fau.de> Date: Sun, 22 Sep 2019 22:31:33 +0200 Subject: [PATCH] llvm: Add llc to pystencils' config --- pystencils/cpu/cpujit.py | 13 +++++++++++++ pystencils/llvm/llvmjit.py | 9 +++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py index 00fe25c78..99ce2d6fb 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 f8b0205f5..0baec5452 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): -- GitLab