Skip to content

Commit

Permalink
Auto Format
Browse files Browse the repository at this point in the history
  • Loading branch information
taichi-gardener committed Sep 10, 2021
1 parent 941aaf3 commit 26d4d41
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions python/taichi/lang/source_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ 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()
self.source_file = os.path.join(self.td, 'source.cpp')
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
Expand Down
4 changes: 2 additions & 2 deletions taichi/codegen/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<llvm::Module> cpp_module = module_from_bitcode_file(
stmt->bc_filename, llvm_context);
std::unique_ptr<llvm::Module> 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);
Expand Down
8 changes: 7 additions & 1 deletion tests/python/test_external_func.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
import ctypes
import os

import pytest

import taichi as ti


Expand All @@ -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
Expand All @@ -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


Expand All @@ -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
Expand All @@ -67,13 +71,15 @@ 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


@pytest.mark.parametrize('x,y', [(2, 3), (-1, 4)])
@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
Expand Down

0 comments on commit 26d4d41

Please sign in to comment.