Skip to content

Commit

Permalink
Clean up _ti_core.insert_external_func_call
Browse files Browse the repository at this point in the history
  • Loading branch information
squarefk committed Oct 27, 2021
1 parent aeddd68 commit e406372
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 58 deletions.
34 changes: 0 additions & 34 deletions misc/demo_call_cpp.py

This file was deleted.

20 changes: 0 additions & 20 deletions python/taichi/lang/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,26 +886,6 @@ def append(l, indices, val):
return a


def bitcode_func_call(filename, funcname, *args):
_ti_core.insert_external_func_call(0, '', filename, funcname,
make_expr_group(args),
make_expr_group([]))


def external_func_call(func, args=[], outputs=[]):
func_addr = ctypes.cast(func, ctypes.c_void_p).value
_ti_core.insert_external_func_call(func_addr, '', '', '',
make_expr_group(args),
make_expr_group(outputs))


@deprecated('asm()', 'ti.SourceBuilder(source, \'asm\')')
def asm(source, inputs=[], outputs=[]):
_ti_core.insert_external_func_call(0, source, '', '',
make_expr_group(inputs),
make_expr_group(outputs))


def is_active(l, indices):
return Expr(
_ti_core.insert_is_active(l.snode.ptr, make_expr_group(indices)))
Expand Down
17 changes: 13 additions & 4 deletions python/taichi/lang/source_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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, has_clangpp

from taichi.core.util import ti_core as _ti_core

class SourceBuilder:
def __init__(self, source, mode='bc'):
Expand Down Expand Up @@ -45,19 +45,28 @@ def cleanup():

def __call__(self, inputs=[], outputs=[]):
if self.mode == 'asm':
asm(self.asm, inputs, outputs)
_ti_core.insert_external_func_call(0, self.asm, '', '',
make_expr_group(inputs),
make_expr_group(outputs))
return
raise TaichiSyntaxError('Error occurs when calling external function.')

def __getattr__(self, item):
def bitcode_func_call_wrapper(*args):
bitcode_func_call(self.bc, item, *args)
_ti_core.insert_external_func_call(0, '', self.bc, item,
make_expr_group(args),
make_expr_group([]))


if self.mode == 'bc':
return bitcode_func_call_wrapper

def external_func_call_wrapper(args=[], outputs=[]):
external_func_call(self.so.__getattr__(item), args, outputs)
func_addr = ctypes.cast(self.so.__getattr__(item), ctypes.c_void_p).value
_ti_core.insert_external_func_call(func_addr, '', '', '',
make_expr_group(args),
make_expr_group(outputs))


if self.mode == 'so':
return external_func_call_wrapper
Expand Down

0 comments on commit e406372

Please sign in to comment.