diff --git a/python/taichi/lang/source_builder.py b/python/taichi/lang/source_builder.py index ad465150cf2baa..744d070558f86b 100644 --- a/python/taichi/lang/source_builder.py +++ b/python/taichi/lang/source_builder.py @@ -16,8 +16,8 @@ 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 ' + self.compiled_file) + os.system('clang++-11 -flto -c ' + self.source_file + ' -o ' + + self.compiled_file) self.bc = self.compiled_file elif self.mode == 'so': self.td = tempfile.mkdtemp() @@ -25,8 +25,8 @@ def __init__(self, source, mode='bc'): self.compiled_file = os.path.join(self.td, 'source.so') with open(self.source_file, 'w') as f: f.write(source) - os.system('g++ ' + self.source_file + ' -o ' + - self.compiled_file + ' -fPIC -shared') + os.system('g++ ' + self.source_file + ' -o ' + self.compiled_file + + ' -fPIC -shared') self.so = ctypes.CDLL(self.compiled_file) elif self.mode == 'asm': self.asm = source diff --git a/taichi/codegen/codegen_llvm.cpp b/taichi/codegen/codegen_llvm.cpp index b81bb3b29ebe7f..b506fec48b6568 100644 --- a/taichi/codegen/codegen_llvm.cpp +++ b/taichi/codegen/codegen_llvm.cpp @@ -2002,8 +2002,8 @@ void CodeGenLLVM::visit_call_bitcode(ExternalFuncCallStmt *stmt) { // Link external module to the core module if (linked_modules.find(stmt->bc_filename) == linked_modules.end()) { linked_modules.insert(stmt->bc_filename); - std::unique_ptr cpp_module = module_from_bitcode_file( - stmt->bc_filename, llvm_context); + std::unique_ptr cpp_module = + module_from_bitcode_file(stmt->bc_filename, llvm_context); auto *func_ptr = cpp_module->getFunction(stmt->bc_funcname); TI_ASSERT_INFO(func_ptr != nullptr, "{} is not founded in {}.", stmt->bc_funcname, stmt->bc_filename); diff --git a/tests/python/test_external_func.py b/tests/python/test_external_func.py index c8f6e04b20093b..fe78f1625d134b 100644 --- a/tests/python/test_external_func.py +++ b/tests/python/test_external_func.py @@ -1,7 +1,8 @@ -import pytest import ctypes import os +import pytest + import taichi as ti @@ -23,6 +24,7 @@ def test_source_builder_so(): } ''' sb_so = ti.SourceBuilder(source_so, 'so') + @ti.kernel def func_so() -> ti.i32: a = 2.0 @@ -34,6 +36,7 @@ def func_so() -> ti.i32: p = 0 sb_so.pow_int(args=(int(c + d), e), outputs=(p, )) return p + assert func_so() == 11**8 @@ -55,6 +58,7 @@ def test_source_builder_bc(): } ''' sb_bc = ti.SourceBuilder(source_bc, 'bc') + @ti.kernel def func_bc() -> ti.i32: a = 2.0 @@ -67,6 +71,7 @@ def func_bc() -> ti.i32: c_plus_d = int(c + d) sb_bc.pow_int(c_plus_d, e, p) return p + assert func_bc() == 11**8 @@ -74,6 +79,7 @@ def func_bc() -> ti.i32: @ti.test(exclude=ti.cpu, require=ti.extension.extfunc) def test_source_builder_asm(x, y): sb = ti.SourceBuilder('$0 = %0 * %1', mode='asm') + @ti.kernel def another_func(x: ti.f32, y: ti.f32) -> ti.f32: z = 0.0