tvm_ffi.Function#

class tvm_ffi.Function#

Bases: Object

Callable wrapper around a TVM FFI function.

Instances are obtained by converting Python callables with tvm_ffi.convert(), or by looking up globally-registered FFI functions using tvm_ffi.get_global_func().

Examples

@tvm_ffi.register_global_func("my.add")
def add(a, b):
    return a + b

f = tvm_ffi.get_global_func("my.add")
assert isinstance(f, tvm_ffi.Function)
assert f(1, 2) == 3

See also

tvm_ffi.register_global_func

How to register global function.

tvm_ffi.get_global_func

How to get global function.

__init__()#

Methods

__ffi_init__(*args)

Defined in Object as method __ffi_init__().

__from_extern_c__(c_symbol, *[, ...])

Convert a function from extern C address.

__from_mlir_packed_safe_call__(...[, ...])

Convert a function from MLIR packed safe call function pointer.

same_as(other)

Defined in Object as method same_as().

Attributes

release_gil

Whether calls release the Python GIL while executing.

static __from_extern_c__(c_symbol, *, keep_alive_object=None)#

Convert a function from extern C address.

Parameters:
  • c_symbol (int) – Function pointer to the safe call function. The function pointer must ignore the first argument, which is the function handle.

  • keep_alive_object (object) – Optional object to be captured and kept alive. Usually this can be the execution engine that JIT-compiled the function to ensure we keep the execution environment alive as long as the function is alive.

Return type:

Function

Returns:

Function – The function object.

static __from_mlir_packed_safe_call__(mlir_packed_symbol, *, keep_alive_object=None)#

Convert a function from MLIR packed safe call function pointer.

Parameters:
  • mlir_packed_symbol (int) – Function pointer to the MLIR packed call function that represents a safe call function.

  • keep_alive_object (object) – Optional object to be captured and kept alive. Usually this can be the execution engine that JIT-compiled the function to ensure we keep the execution environment alive as long as the function is alive.

Return type:

Function

Returns:

Function – The function object.

release_gil#

Whether calls release the Python GIL while executing.