tvm
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
tvm::runtime::relax_vm::VirtualMachine Class Referenceabstract

The virtual machine. More...

#include <vm.h>

Inheritance diagram for tvm::runtime::relax_vm::VirtualMachine:
Collaboration diagram for tvm::runtime::relax_vm::VirtualMachine:

Public Member Functions

virtual void Init (const std::vector< Device > &devices, const std::vector< AllocatorType > &alloc_types)=0
 Initialize the virtual machine for a set of devices. More...
 
virtual void LoadExecutable (ObjectPtr< Executable > exec)=0
 Load the executable for the virtual machine. More...
 
virtual VMClosure GetClosure (const String &func_name)=0
 Get global function in the VM. More...
 
virtual void InvokeClosurePacked (const ObjectRef &closure_or_packedfunc, TVMArgs args, TVMRetValue *rv)=0
 Invoke closure or packed function using PackedFunc convention. More...
 
virtual void SetInstrument (PackedFunc instrument)=0
 Set an instrumentation function. More...
 
template<typename T , typename = std::enable_if_t<std::is_base_of<VMExtension, T>::value>>
GetOrCreateExtension ()
 Get or create a VM extension. Once created, the extension will be stored in the VM and held until the VM is destructed. More...
 
 ~VirtualMachine ()
 
- Public Member Functions inherited from tvm::runtime::ModuleNode
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 Member Functions

static ObjectPtr< VirtualMachineCreate ()
 Create a specific instance of VM. More...
 
static ObjectPtr< VirtualMachineCreateProfiler ()
 Create an instance of VM with the profiling feature enabled. More...
 
static VirtualMachineGetContextPtr (TVMArgValue arg)
 Helper function for vm closure functions to get the context ptr. More...
 
- 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 ()
 

Public Attributes

std::vector< Allocator * > allocators
 The memory allocators. More...
 
std::vector< Devicedevices
 Runtime physical device list. More...
 
std::unordered_map< uint32_t, VMExtensionextensions
 The VM extensions. Mapping from the type index of the extension to the extension instance. More...
 

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 Attributes inherited from tvm::runtime::ModuleNode
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 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...
 
- Protected Attributes inherited from tvm::runtime::ModuleNode
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...
 

Detailed Description

The virtual machine.

The virtual machine contains all the current execution state, as well as the executable.

The goal is to have a single self-contained object, enabling one to easily pass around VMs, execute them on multiple threads, or serialize them to disk or over the wire.

Constructor & Destructor Documentation

◆ ~VirtualMachine()

tvm::runtime::relax_vm::VirtualMachine::~VirtualMachine ( )
inline

Member Function Documentation

◆ Create()

static ObjectPtr<VirtualMachine> tvm::runtime::relax_vm::VirtualMachine::Create ( )
static

Create a specific instance of VM.

Returns
Created VM

◆ CreateProfiler()

static ObjectPtr<VirtualMachine> tvm::runtime::relax_vm::VirtualMachine::CreateProfiler ( )
static

Create an instance of VM with the profiling feature enabled.

Returns
Created VM

◆ GetClosure()

virtual VMClosure tvm::runtime::relax_vm::VirtualMachine::GetClosure ( const String func_name)
pure virtual

Get global function in the VM.

Parameters
func_nameThe name of the function.
Returns
The closure

◆ GetContextPtr()

static VirtualMachine* tvm::runtime::relax_vm::VirtualMachine::GetContextPtr ( TVMArgValue  arg)
inlinestatic

Helper function for vm closure functions to get the context ptr.

Parameters
argThe argument value.

◆ GetOrCreateExtension()

template<typename T , typename = std::enable_if_t<std::is_base_of<VMExtension, T>::value>>
T tvm::runtime::relax_vm::VirtualMachine::GetOrCreateExtension ( )
inline

Get or create a VM extension. Once created, the extension will be stored in the VM and held until the VM is destructed.

Template Parameters
TThe type of the extension
Returns
The extension instance

◆ Init()

virtual void tvm::runtime::relax_vm::VirtualMachine::Init ( const std::vector< Device > &  devices,
const std::vector< AllocatorType > &  alloc_types 
)
pure virtual

Initialize the virtual machine for a set of devices.

Parameters
devicesThe set of TVM devices.
alloc_typesThe allocator types for each device.

◆ InvokeClosurePacked()

virtual void tvm::runtime::relax_vm::VirtualMachine::InvokeClosurePacked ( const ObjectRef closure_or_packedfunc,
TVMArgs  args,
TVMRetValue rv 
)
pure virtual

Invoke closure or packed function using PackedFunc convention.

Parameters
closure_or_packedfuncA VM closure or a packed_func.
argsThe input arguments.
rvThe return value.

◆ LoadExecutable()

virtual void tvm::runtime::relax_vm::VirtualMachine::LoadExecutable ( ObjectPtr< Executable exec)
pure virtual

Load the executable for the virtual machine.

Parameters
execThe executable.

◆ SetInstrument()

virtual void tvm::runtime::relax_vm::VirtualMachine::SetInstrument ( PackedFunc  instrument)
pure virtual

Set an instrumentation function.

If instrument is present, the function will be called before/after each Call instruction.

bool instrument(func, func_symbol, before_run, args...)

  • func: Union[VMClosure, PackedFunc], the function object.
  • func_symbol: string, the symbol of the function.
  • before_run: bool, whether it is before or after call.
  • ret_value: Only valid in after run, otherwise it is null.
  • args: the arguments being passed to call.

instrument can return an int which corresponds to the action value.

See also
VMInstrumentAction
Parameters
instrumentThe instrument function.

Member Data Documentation

◆ allocators

std::vector<Allocator*> tvm::runtime::relax_vm::VirtualMachine::allocators

The memory allocators.

◆ devices

std::vector<Device> tvm::runtime::relax_vm::VirtualMachine::devices

Runtime physical device list.

◆ extensions

std::unordered_map<uint32_t, VMExtension> tvm::runtime::relax_vm::VirtualMachine::extensions

The VM extensions. Mapping from the type index of the extension to the extension instance.


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