tvm.Function

tvm.Function

alias of tvm.runtime.packed_func.PackedFunc

tvm.register_func(func_name, f=None, override=False)

Register global function

Parameters
  • func_name (str or function) – The function name

  • f (function, optional) – The function to be registered.

  • override (boolean optional) – Whether override existing entry.

Returns

fregister – Register function if f is not specified.

Return type

function

Examples

The following code registers my_packed_func as global function. Note that we simply get it back from global function table to invoke it from python side. However, we can also invoke the same function from C++ backend, or in the compiled TVM code.

targs = (10, 10.0, "hello")
@tvm.register_func
def my_packed_func(*args):
    assert(tuple(args) == targs)
    return 10
# Get it out from global function table
f = tvm.get_global_func("my_packed_func")
assert isinstance(f, tvm.PackedFunc)
y = f(*targs)
assert y == 10
tvm.get_global_func(name, allow_missing=False)

Get a global function by name

Parameters
  • name (str) – The name of the global function

  • allow_missing (bool) – Whether allow missing function or raise an error.

Returns

func – The function to be returned, None if function is missing.

Return type

PackedFunc