Class ModuleObj#

Inheritance Relationships#

Base Type#

Class Documentation#

class ModuleObj : public tvm::ffi::Object#

A module that can dynamically load ffi::Functions or exportable source code.

See also

Module

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.

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 GetFunction result may be nullptr if the function is not yet callable without further compilation.

The default implementation just checks if GetFunction is 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 docstring of the function.

inline virtual Optional<String> GetFunctionMetadata(const String &name)#

Get the metadata of the function, if available.

Parameters:

name – The name of the function.

Returns:

The metadata stored in json string format.

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.

Parameters:
  • name – The name of the function.

  • query_imports – Whether to query imported modules.

Returns:

The function docstring of the function.

Optional<String> GetFunctionMetadata(const String &name, bool query_imports)#

Get the function metadata of the function if available.

Parameters:
  • name – The name of the function.

  • query_imports – Whether to query imported modules.

Returns:

The function metadata of the function in json format.

inline const Array<Any> &imports() const#

Get the imports of the module.

Note

Note the signature is not part of the public API.

Returns:

The imports of the module.

Protected Attributes

Array<Any> imports_#

The modules that this module depends on.

Note

Use ObjectRef to avoid circular dep on Module.

Friends

friend struct InternalUnsafe