tvm_ffi.Module#

class tvm_ffi.Module[source]#

Bases: Object

Module container for dynamically loaded Module.

Examples

import tvm_ffi

# load the module from a tvm-ffi shared library
mod : tvm_ffi.Module = tvm_ffi.load_module("path/to/library.so")
# you can use mod.func_name to call the exported function
mod.func_name(*args)
__init__()#

Methods

__init__()

clear_imports()

Remove all imports of the module.

get_function(name[, query_imports])

Get function from the module.

get_property_mask()

Get the runtime module property mask.

get_write_formats()

Get the format of the module.

implements_function(name[, query_imports])

Return True if the module defines a global function.

import_module(module)

Add module to the import list of current one.

inspect_source([fmt])

Get source code from module, if available.

is_binary_serializable()

Return whether the module is binary serializable (supports save_to_bytes).

is_compilation_exportable()

Return whether the module is compilation exportable.

is_runnable()

Return whether the module is runnable (supports get_function).

same_as(other)

Check object identity.

write_to_file(file_name[, fmt])

Write the current module to file.

Attributes

entry_name

imports

Get imported modules.

imports_

kind

Get type key of the module.

entry_name = 'main'#
property kind: str#

Get type key of the module.

property imports: list[Module]#

Get imported modules.

Returns:

modules – The module

Return type:

list of Module

implements_function(name, query_imports=False)[source]#

Return True if the module defines a global function.

Note

that has_function(name) does not imply get_function(name) is non-null since the module that has_function(name) does not imply get_function(name) is non-null since the module may be, eg, a CSourceModule which cannot supply a packed-func implementation of the function without further compilation. However, get_function(name) non null should always imply has_function(name).

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

  • query_imports (bool) – Whether to also query modules imported by this module.

Returns:

b – True if module (or one of its imports) has a definition for name.

Return type:

Bool

get_function(name, query_imports=False)[source]#

Get function from the module.

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

  • query_imports (bool) – Whether also query modules imported by this module.

Returns:

f – The result function.

Return type:

tvm_ffi.Function

import_module(module)[source]#

Add module to the import list of current one.

Parameters:

module (tvm.runtime.Module) – The other module.

Return type:

None

inspect_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

get_write_formats()[source]#

Get the format of the module.

Return type:

list[str]

get_property_mask()[source]#

Get the runtime module property mask. The mapping is stated in ModulePropertyMask.

Returns:

mask – Bitmask of runtime module property

Return type:

int

is_binary_serializable()[source]#

Return whether the module is binary serializable (supports save_to_bytes).

Returns:

b – True if the module is binary serializable.

Return type:

Bool

is_runnable()[source]#

Return whether the module is runnable (supports get_function).

Returns:

b – True if the module is runnable.

Return type:

Bool

is_compilation_exportable()[source]#

Return whether the module is compilation exportable.

write_to_file is supported for object or source.

Returns:

b – True if the module is compilation exportable.

Return type:

Bool

clear_imports()[source]#

Remove all imports of the module.

Return type:

None

write_to_file(file_name, fmt='')[source]#

Write the current module to file.

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

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

Return type:

None

See also

runtime.Module.export_library

export the module to shared library.

property imports_#