tvm.support

Support infra of TVM.

Functions:

get_global_func()

Get a global function by name.

libinfo()

Returns a dictionary containing compile-time info, including cmake flags and git commit hash

describe()

Print out information about TVM and the current Python environment

Classes:

Module

Runtime Module.

FrontendTestModule([entry_name])

A tvm.runtime.Module whose member functions are PackedFunc.

tvm.support.get_global_func(name: str, allow_missing: bool = False) Function | None

Get a global function by name.

Parameters:
  • name – The name of the global function

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

Returns:

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

Return type:

func

Examples

import tvm_ffi

@tvm_ffi.register_global_func("demo.echo")
def echo(x):
    return x


f = tvm_ffi.get_global_func("demo.echo")
assert f(123) == 123

See also

tvm_ffi.register_global_func()

class tvm.support.Module

Runtime Module.

Methods:

export_library(file_name, *[, fcompile, ...])

Export the module and all imported modules into a single device library.

time_evaluator(func_name, dev[, number, ...])

Get an evaluator that measures time cost of running function.

export_library(file_name, *, fcompile=None, fpack_imports=None, addons=None, workspace_dir=None, **kwargs)

Export the module and all imported modules into a single device library.

This function only works on host LLVM modules, other runtime::Module subclasses will work with this API but they must support implement the save and load mechanisms of modules completely including saving from streams and files. This will pack your non-shared library module into a single shared library which can later be loaded by TVM.

Parameters:
  • file_name (str) – The name of the shared library.

  • fcompile (function(target, file_list, kwargs), optional) –

    The compilation function to use create the final library object during export.

    For example, when fcompile=_cc.create_shared, or when it is not supplied but module is “llvm,” this is used to link all produced artifacts into a final dynamic library.

    This behavior is controlled by the type of object exported. If fcompile has attribute object_format, will compile host library to that format. Otherwise, will use default format “o”.

  • fpack_imports (function(mod: runtime.Module, is_system_lib: bool, symbol_prefix: str,) –

    workspace_dir: str) -> str Function used to pack imported modules from mod into a file suitable for passing to fcompile as an input file. The result can be a C source, or an .o object file, or any other file that the fcompile function can handle. The function returns the name of the created file.

    If not provided, the imported modules will be serialized either via packing to an LLVM module, or to a C source file.

  • workspace_dir (str, optional) – The path of the directory used to create the intermediate artifacts when exporting the module. If this is not provided a temporary dir will be created.

  • kwargs (dict, optional) – Additional arguments passed to fcompile

Returns:

result of fcompile() – If the compilation function returns an artifact it would be returned via export_library, if any.

Return type:

unknown, optional

time_evaluator(func_name, dev, number=10, repeat=1, min_repeat_ms=0, limit_zero_time_iterations=100, cooldown_interval_ms=0, repeats_to_cooldown=1, cache_flush_bytes=0, f_preproc='')

Get an evaluator that measures time cost of running function.

Parameters:
  • func_name (str) – The name of the function in the module.

  • dev (Device) – The device we should run this function on.

  • number (int) – The number of times to run this function for taking average. We call these runs as one repeat of measurement.

  • repeat (int, optional) – The number of times to repeat the measurement. In total, the function will be invoked (1 + number x repeat) times, where the first one is warm up and will be discarded. The returned result contains repeat costs, each of which is an average of number costs.

  • min_repeat_ms (int, optional) – The minimum duration of one repeat in milliseconds. By default, one repeat contains number runs. If this parameter is set, the parameters number will be dynamically adjusted to meet the minimum duration requirement of one repeat. i.e., When the run time of one repeat falls below this time, the number parameter will be automatically increased.

  • limit_zero_time_iterations (int, optional) – The maximum number of repeats when measured time is equal to 0. It helps to avoid hanging during measurements.

  • cooldown_interval_ms (int, optional) – The cooldown interval in milliseconds between the number of repeats defined by repeats_to_cooldown.

  • repeats_to_cooldown (int, optional) – The number of repeats before the cooldown is activated.

  • cache_flush_bytes (int, optional) – The number of bytes to flush from the cache before each repeat.

  • f_preproc (str, optional) – The preprocess function name we want to execute before executing the time evaluator.

Note

The function will be invoked (1 + number x repeat) times, with the first call discarded in case there is lazy initialization.

Returns:

ftimer – The function that takes same argument as func and returns a BenchmarkResult. The ProfileResult reports repeat time costs in seconds.

Return type:

function

tvm.support.libinfo()

Returns a dictionary containing compile-time info, including cmake flags and git commit hash

Returns:

info – The dictionary of compile-time info.

Return type:

Dict[str, str]

tvm.support.describe()

Print out information about TVM and the current Python environment

class tvm.support.FrontendTestModule(entry_name=None)

A tvm.runtime.Module whose member functions are PackedFunc.