tvm_ffi.Module#
- class tvm_ffi.Module(*args, **kwargs)[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) - See also - Notes - If you load a module within a local scope, be careful when any called function creates and returns an object. The memory deallocation routines are part of the library’s code. If the module is unloaded before the object is destroyed, the deleter may call an invalid address. Keep the module loaded until all returned objects are deleted. You can safely use returned objects inside a nested function that finishes before the module goes out of scope. When possible, consider keeping the module alive in a long-lived/global scope (for example, in a global state) to avoid premature unloading. - def bad_pattern(x): # Bad: unload order of `tensor` and `mod` is not guaranteed mod = tvm_ffi.load_module("path/to/library.so") # ... do something with the tensor tensor = mod.func_create_and_return_tensor(x) def good_pattern(x): # Good: `tensor` is freed before `mod` goes out of scope mod = tvm_ffi.load_module("path/to/library.so") def run_some_tests(): tensor = mod.func_create_and_return_tensor(x) # ... do something with the tensor run_some_tests() - Methods - __ffi_init__(*args)- Defined in - Objectas method- __ffi_init__().- __init__(*args, **kwargs)- Remove all imports of the module. - get_function(name[, query_imports])- Get function from the module. - Get the runtime module property mask. - 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. - Return whether the module is binary serializable (supports save_to_bytes). - Return whether the module is compilation exportable. - Return whether the module is runnable (supports get_function). - same_as(other)- write_to_file(file_name[, fmt])- Write the current module to file. - Attributes - Get imported modules. - Get type key of the module. - property imports_#
 - 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). 
 - get_property_mask()[source]#
- Get the runtime module property mask. The mapping is stated in ModulePropertyMask. - Return type:
- Returns:
- mask – Bitmask of runtime module property 
 
 - is_binary_serializable()[source]#
- Return whether the module is binary serializable (supports save_to_bytes). - Return type:
- Returns:
- b – True if the module is binary serializable. 
 
 - is_runnable()[source]#
- Return whether the module is runnable (supports get_function). - Return type:
- Returns:
- b – True if the module is runnable.