Skip to content
Snippets Groups Projects
Commit 8d22fddf authored by Stephan Seitz's avatar Stephan Seitz
Browse files

llvm: Add llc to pystencils' config

parent a57a164a
No related branches found
No related tags found
1 merge request!53Compile CUDA using the LLVM backend
......@@ -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__')
])
......
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment