tvm
Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
tvm::runtime::ModuleNode Class Referenceabstract

Base container of module. More...

#include <module.h>

Inheritance diagram for tvm::runtime::ModuleNode:
Collaboration diagram for tvm::runtime::ModuleNode:

Public Member Functions

virtual ~ModuleNode ()=default
 virtual destructor More...
 
virtual const char * type_key () const =0
 
virtual PackedFunc GetFunction (const String &name, const ObjectPtr< Object > &sptr_to_self)=0
 Get a PackedFunc from module. More...
 
virtual void SaveToFile (const String &file_name, const String &format)
 Save the module to file. More...
 
virtual void SaveToBinary (dmlc::Stream *stream)
 Save the module to binary stream. More...
 
virtual String GetSource (const String &format="")
 Get the source code of module, when available. More...
 
virtual String GetFormat ()
 Get the format of the module, when available. More...
 
PackedFunc GetFunction (const String &name, bool query_imports=false)
 Get packed function from current module by name. More...
 
void Import (Module other)
 Import another module into this module. More...
 
const PackedFuncGetFuncFromEnv (const String &name)
 Get a function from current environment The environment includes all the imports as well as Global functions. More...
 
void ClearImports ()
 Clear all imports of the module. More...
 
const std::vector< Module > & imports () const
 
virtual int GetPropertyMask () const
 Returns bitmap of property. By default, none of the property is set. Derived class can override this function and set its own property. More...
 
bool IsDSOExportable () const
 Returns true if this module is 'DSO exportable'. More...
 
bool IsBinarySerializable () const
 Returns true if this module is 'Binary Serializable'. More...
 
virtual bool ImplementsFunction (const String &name, bool query_imports=false)
 Returns true if this module has a definition for a function of name. If query_imports is true, also search in any imported modules. More...
 
 TVM_DECLARE_FINAL_OBJECT_INFO (ModuleNode, Object)
 
- Public Member Functions inherited from tvm::runtime::Object
uint32_t type_index () const
 
std::string GetTypeKey () const
 
size_t GetTypeKeyHash () const
 
template<typename TargetType >
bool IsInstance () const
 
bool unique () const
 
 Object ()
 
 Object (const Object &other)
 
 Object (Object &&other)
 
Objectoperator= (const Object &other)
 
Objectoperator= (Object &&other)
 

Static Public Attributes

static constexpr const uint32_t _type_index = TypeIndex::kRuntimeModule
 
static constexpr const char * _type_key = "runtime.Module"
 
- Static Public Attributes inherited from tvm::runtime::Object
static constexpr const char * _type_key = "runtime.Object"
 
static constexpr bool _type_final = false
 
static constexpr uint32_t _type_child_slots = 0
 
static constexpr bool _type_child_slots_can_overflow = true
 
static constexpr bool _type_has_method_visit_attrs = true
 
static constexpr bool _type_has_method_sequal_reduce = false
 
static constexpr bool _type_has_method_shash_reduce = false
 
static constexpr uint32_t _type_index = TypeIndex::kDynamic
 

Protected Attributes

std::vector< Moduleimports_
 The modules this module depend on. More...
 
- Protected Attributes inherited from tvm::runtime::Object
uint32_t type_index_ {0}
 Type index(tag) that indicates the type of the object. More...
 
RefCounterType ref_counter_ {0}
 The internal reference counter. More...
 
FDeleter deleter_ = nullptr
 deleter of this object to enable customized allocation. If the deleter is nullptr, no deletion will be performed. The creator of the object must always set the deleter field properly. More...
 

Friends

class Module
 
class ModuleInternal
 

Additional Inherited Members

- Public Types inherited from tvm::runtime::Object
typedef void(* FDeleter) (Object *self)
 Object deleter. More...
 
using RefCounterType = std::atomic< int32_t >
 
- Static Public Member Functions inherited from tvm::runtime::Object
static std::string TypeIndex2Key (uint32_t tindex)
 Get the type key of the corresponding index from runtime. More...
 
static size_t TypeIndex2KeyHash (uint32_t tindex)
 Get the type key hash of the corresponding index from runtime. More...
 
static uint32_t TypeKey2Index (const std::string &key)
 Get the type index of the corresponding key from runtime. More...
 
static uint32_t _GetOrAllocRuntimeTypeIndex ()
 
static uint32_t RuntimeTypeIndex ()
 
- Protected Member Functions inherited from tvm::runtime::Object
void IncRef ()
 developer function, increases reference counter. More...
 
void DecRef ()
 developer function, decrease reference counter. More...
 
- Static Protected Member Functions inherited from tvm::runtime::Object
static uint32_t GetOrAllocRuntimeTypeIndex (const std::string &key, uint32_t static_tindex, uint32_t parent_tindex, uint32_t type_child_slots, bool type_child_slots_can_overflow)
 Get the type index using type key. More...
 

Detailed Description

Base container of module.

Please subclass ModuleNode to create a specific runtime module.

class MyModuleNode : public ModuleNode {
public:
// implement the interface
};
// use make_object to create a specific
// instace of MyModuleNode.
Module CreateMyModule() {
ObjectPtr<MyModuleNode> n =
tvm::runtime::make_object<MyModuleNode>();
return Module(n);
}
friend class Module
Definition: module.h:263

Constructor & Destructor Documentation

◆ ~ModuleNode()

virtual tvm::runtime::ModuleNode::~ModuleNode ( )
virtualdefault

virtual destructor

Member Function Documentation

◆ ClearImports()

void tvm::runtime::ModuleNode::ClearImports ( )
inline

Clear all imports of the module.

◆ GetFormat()

virtual String tvm::runtime::ModuleNode::GetFormat ( )
virtual

Get the format of the module, when available.

Returns
Possible format when available.

◆ GetFuncFromEnv()

const PackedFunc* tvm::runtime::ModuleNode::GetFuncFromEnv ( const String name)

Get a function from current environment The environment includes all the imports as well as Global functions.

Parameters
namename of the function.
Returns
The corresponding function.

◆ GetFunction() [1/2]

PackedFunc tvm::runtime::ModuleNode::GetFunction ( const String name,
bool  query_imports = false 
)

Get packed function from current module by name.

Parameters
nameThe name of the function.
query_importsWhether also query dependency modules.
Returns
The result function. This function will return PackedFunc(nullptr) if function do not exist.
Note
Implemented in packed_func.cc

◆ GetFunction() [2/2]

virtual PackedFunc tvm::runtime::ModuleNode::GetFunction ( const String name,
const ObjectPtr< Object > &  sptr_to_self 
)
pure virtual

Get a PackedFunc from module.

The PackedFunc may not be fully initialized, there might still be first time running overhead when executing the function on certain devices. For benchmarking, use prepare to eliminate

Parameters
namethe name of the function.
sptr_to_selfThe ObjectPtr that points to this module node.
Returns
PackedFunc(nullptr) when it is not available.
Note
The function will always remain valid. If the function need resource from the module(e.g. late linking), it should capture sptr_to_self.

Implemented in tvm::runtime::vm::VirtualMachine.

◆ GetPropertyMask()

virtual int tvm::runtime::ModuleNode::GetPropertyMask ( ) const
inlinevirtual

Returns bitmap of property. By default, none of the property is set. Derived class can override this function and set its own property.

Reimplemented in tvm::runtime::vm::VirtualMachine, tvm::runtime::vm::Executable, and tvm::runtime::relax_vm::Executable.

◆ GetSource()

virtual String tvm::runtime::ModuleNode::GetSource ( const String format = "")
virtual

Get the source code of module, when available.

Parameters
formatFormat of the source code, can be empty by default.
Returns
Possible source code when available.

◆ ImplementsFunction()

virtual bool tvm::runtime::ModuleNode::ImplementsFunction ( const String name,
bool  query_imports = false 
)
virtual

Returns true if this module has a definition for a function of name. If query_imports is true, also search in any imported modules.

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 checkis if GetFunction is non-null.

◆ Import()

void tvm::runtime::ModuleNode::Import ( Module  other)

Import another module into this module.

Parameters
otherThe module to be imported.
Note
Cyclic dependency is not allowed among modules, An error will be thrown when cyclic dependency is detected.

◆ imports()

const std::vector<Module>& tvm::runtime::ModuleNode::imports ( ) const
inline
Returns
The module it imports from

◆ IsBinarySerializable()

bool tvm::runtime::ModuleNode::IsBinarySerializable ( ) const
inline

Returns true if this module is 'Binary Serializable'.

◆ IsDSOExportable()

bool tvm::runtime::ModuleNode::IsDSOExportable ( ) const
inline

Returns true if this module is 'DSO exportable'.

◆ SaveToBinary()

virtual void tvm::runtime::ModuleNode::SaveToBinary ( dmlc::Stream *  stream)
virtual

Save the module to binary stream.

Parameters
streamThe binary stream to save to.
Note
It is recommended to implement this for device modules, but not necessarily host modules. We can use this to do AOT loading of bundled device functions.

Reimplemented in tvm::runtime::vm::Executable, and tvm::runtime::relax_vm::Executable.

◆ SaveToFile()

virtual void tvm::runtime::ModuleNode::SaveToFile ( const String file_name,
const String format 
)
virtual

Save the module to file.

Parameters
file_nameThe file to be saved to.
formatThe format of the file.

Reimplemented in tvm::runtime::vm::Executable, and tvm::runtime::relax_vm::Executable.

◆ TVM_DECLARE_FINAL_OBJECT_INFO()

tvm::runtime::ModuleNode::TVM_DECLARE_FINAL_OBJECT_INFO ( ModuleNode  ,
Object   
)

◆ type_key()

virtual const char* tvm::runtime::ModuleNode::type_key ( ) const
pure virtual
Returns
The per module type key.
Note
This key is used to for serializing custom modules.

Implemented in tvm::runtime::vm::VirtualMachine.

Friends And Related Function Documentation

◆ Module

friend class Module
friend

◆ ModuleInternal

friend class ModuleInternal
friend

Member Data Documentation

◆ _type_index

constexpr const uint32_t tvm::runtime::ModuleNode::_type_index = TypeIndex::kRuntimeModule
staticconstexpr

◆ _type_key

constexpr const char* tvm::runtime::ModuleNode::_type_key = "runtime.Module"
staticconstexpr

◆ imports_

std::vector<Module> tvm::runtime::ModuleNode::imports_
protected

The modules this module depend on.


The documentation for this class was generated from the following file: