Class ModuleObj#
Defined in File module.h
Inheritance Relationships#
Base Type#
public tvm::ffi::Object(Class Object)
Class Documentation#
-
class ModuleObj : public tvm::ffi::Object#
A module that can dynamically load ffi::Functions or exportable source code.
See also
Public Functions
-
virtual const char *kind() const = 0#
Note
This key is used to for serializing custom modules.
- Returns:
The per module type key.
-
inline virtual int GetPropertyMask() const#
Get the property mask of the module.
See also
- Returns:
The property mask of the module.
-
virtual Optional<Function> GetFunction(const String &name) = 0#
Get a ffi::Function from the module.
- Parameters:
name – The name of the function.
- Returns:
The function.
-
inline virtual bool ImplementsFunction(const String &name)#
Returns true if this module has a definition for a function of
name.Note that even if this function returns true the corresponding
GetFunctionresult may be nullptr if the function is not yet callable without further compilation.The default implementation just checks if
GetFunctionis non-null.- Parameters:
name – The name of the function.
- Returns:
True if the module implements the function, false otherwise.
-
inline virtual Optional<String> GetFunctionDoc(const String &name)#
Get the docstring of the function, if available.
- Parameters:
name – The name of the function.
- Returns:
The documentation string if available, nullopt otherwise.
-
inline virtual Optional<String> GetFunctionMetadata(const String &name)#
Get the metadata of the function, if available.
Module mod = Module::LoadFromFile("lib.so"); Optional<String> metadata = mod->GetFunctionMetadata("my_func"); if (metadata.has_value()) { // Parse JSON: {"type_schema": "..."} validate_signature(*metadata); }
See also
- Parameters:
name – The name of the function.
- Returns:
The metadata as JSON string if available, nullopt otherwise.
-
inline virtual void WriteToFile(const String &file_name, const String &format) const#
Write the current module to file with given format (for further compilation).
Note
This function is mainly used by modules that
- Parameters:
file_name – The file to be saved to.
format – The format of the file.
-
inline virtual Array<String> GetWriteFormats() const#
Get the possible write formats of the module, when available.
- Returns:
Possible write formats when available.
-
inline virtual Bytes SaveToBytes() const#
Serialize the the module to bytes.
- Returns:
The serialized module.
-
inline virtual String InspectSource(const String &format) const#
Get the source code of module, when available.
- Parameters:
format – Format of the source code, can be empty by default.
- Returns:
Possible source code when available, or empty string if not available.
-
virtual void ImportModule(const Module &other)#
Import another module.
- Parameters:
other – The module to import.
-
virtual void ClearImports()#
Clear all imported modules.
-
Optional<Function> GetFunction(const String &name, bool query_imports)#
Overloaded function to optionally query from imports.
- Parameters:
name – The name of the function.
query_imports – Whether to query imported modules.
- Returns:
The function.
-
bool ImplementsFunction(const String &name, bool query_imports)#
Overloaded function to optionally query from imports.
- Parameters:
name – The name of the function.
query_imports – Whether to query imported modules.
- Returns:
True if the module implements the function, false otherwise.
-
Optional<String> GetFunctionDoc(const String &name, bool query_imports)#
Get the function docstring of the function if available.
See also
- Parameters:
name – The name of the function.
query_imports – Whether to also query modules imported by this module.
- Returns:
The documentation string if available, nullopt otherwise.
-
Optional<String> GetFunctionMetadata(const String &name, bool query_imports)#
Get the function metadata of the function if available.
See also
- Parameters:
name – The name of the function.
query_imports – Whether to also query modules imported by this module.
- Returns:
The metadata as JSON string if available, nullopt otherwise.
Protected Attributes
Friends
- friend struct InternalUnsafe
-
virtual const char *kind() const = 0#