matx.runtime.module module

Runtime Module namespace.

class matx.runtime.module.Module(handle)[source]

Bases: object

Runtime Module.

__init__(handle)[source]
export_library(file_name, fcompile=None, addons=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, optional) – Additional arguments passed to fcompile

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:

matx.runtime.PackedFunc

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

handle
import_module(module)[source]

Add module to the import list of current one.

Parameters:

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

property imported_modules

Get imported modules

Returns:

modules – The module

Return type:

list of Module

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

runtime.Module.export_library

export the module to shared library.

property type_key

Get type key of the module.

matx.runtime.module.load_module(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:

runtime.Module

matx.runtime.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:

runtime.Module