heterocl.tvm.module module

Container of compiled functions of TVM.

class Module(handle)[source]

Bases: heterocl.tvm._ffi.function.ModuleBase

Module container of all TVM generated functions

export_library(file_name, fcompile=None, **kwargs)[source]

Export the module and its imported device code one library.

This function only works on host llvm modules. It will pack all the imported modules

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

  • fcompile (function(target, file_list, kwargs), optional) – Compilation function to use create dynamic library. If fcompile has attribute object_format, will compile host library to that format. Otherwise, will use default format “o”.

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

get_source(fmt='')[source]

Get source code from module, if available.

Parameters

fmt (str, optional) – The specified format.

Returns

source – The result source code.

Return type

str

imported_modules

Get imported modules

Returns

modules – The module

Return type

list of Module

report(target)[source]
save(file_name, fmt='')[source]

Save the module to file.

This do not save the dependent device modules. See also export_shared

Parameters
  • file_name (str) – The name of the file.

  • fmt (str) – The format of the file.

See also

Module.export_library()

export the module to shared library.

time_evaluator(func_name, ctx, number, repeat=1)[source]

Get an evaluator that measures time cost of running function.

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

  • ctx (TVMContext) – The context we should run this function on.

  • number (int) – The number of steps used in measuring each time interval

  • repeat (int, optional) – Number of times to run the timer measurement If repeat equals 3, then we will get 3 numbers in the ProfileResult.

Note

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

Returns

ftimer – The function that takes same argument as func and return a float representing seconds per function call.

Return type

Function

type_key

Get type key of the module.

class ProfileResult(mean, results)

Bases: tuple

mean

Alias for field number 0

results

Alias for field number 1

enabled(target)[source]

Whether module runtime is enabled for target

Parameters

target (str) – The target device type.

Returns

enabled – Whether runtime is enabled.

Return type

bool

Examples

The following code checks if gpu is enabled.

>>> tvm.module.enabled("gpu")
load(path, fmt='')[source]

Load module from file

Parameters
  • path (str) – The path to the module file.

  • fmt (str, optional) – The format of the file, if not specified it will be inferred from suffix of the file.

Returns

module – The loaded module

Return type

Module

system_lib()[source]

Get system-wide library module singleton.

System lib is a global module that contains self register functions in startup. Unlike normal dso modules which need to be loaded explicitly. It is useful in environments where dynamic loading api like dlopen is banned.

To build system lib function, simply specify target option `llvm --system-lib` The system lib will be available as long as the result code is linked by the program.

The system lib is intended to be linked and loaded during the entire life-cyle of the program. If you want dynamic loading features, use dso modules instead.

Returns

module – The system-wide library module.

Return type

Module