Skip to content

Commit

Permalink
auto detect, test and run with clang++ for SourceBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
squarefk committed Sep 14, 2021
1 parent 26d4d41 commit 1de1dff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/taichi/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from taichi.lang.type_factory_impl import type_factory
from taichi.lang.util import (has_pytorch, is_taichi_class, python_scope,
taichi_scope, to_numpy_type, to_pytorch_type,
to_taichi_type)
to_taichi_type, has_clangpp)
from taichi.misc.util import deprecated
from taichi.snode.fields_builder import FieldsBuilder

Expand Down
3 changes: 2 additions & 1 deletion python/taichi/lang/source_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from taichi.lang.exception import TaichiSyntaxError
from taichi.lang.ops import asm, bitcode_func_call, external_func_call
from taichi.lang.util import get_clangpp


class SourceBuilder():
Expand All @@ -16,7 +17,7 @@ def __init__(self, source, mode='bc'):
self.compiled_file = os.path.join(self.td, 'source.bc')
with open(self.source_file, 'w') as f:
f.write(source)
os.system('clang++-11 -flto -c ' + self.source_file + ' -o ' +
os.system(get_clangpp() + ' -flto -c ' + self.source_file + ' -o ' +
self.compiled_file)
self.bc = self.compiled_file
elif self.mode == 'so':
Expand Down
12 changes: 12 additions & 0 deletions python/taichi/lang/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def has_pytorch():
return _has_pytorch


from distutils.spawn import find_executable
_clangpp_candidates = ['clang++-8', 'clang++-10', 'clang++-11', 'clang++-12', 'clang++']
_clangpp_presence = None
for c in _clangpp_candidates:
if find_executable(c) is not None:
_clangpp_presence = find_executable(c)
def has_clangpp():
return _clangpp_presence is not None
def get_clangpp():
return _clangpp_presence


def is_taichi_class(rhs):
taichi_class = False
try:
Expand Down
1 change: 1 addition & 0 deletions tests/python/test_external_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def func_so() -> ti.i32:
assert func_so() == 11**8


@pytest.mark.skipif(not ti.has_clangpp(), reason='Clang not installed.')
@ti.test(arch=[ti.cpu, ti.cuda])
def test_source_builder_bc():
source_bc = '''
Expand Down

0 comments on commit 1de1dff

Please sign in to comment.