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

The virtual machine. More...

#include <vm.h>

Inheritance diagram for tvm::runtime::vm::VirtualMachine:
Collaboration diagram for tvm::runtime::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< VMExecutable > 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, ffi::PackedArgs args, ffi::Any *rv)=0
 Invoke closure or packed function using ffi::Function convention. More...
 
virtual void SetInstrument (ffi::Function 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 ()
 

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 (ffi::AnyView arg)
 Helper function for vm closure functions to get the context ptr. More...
 

Public Attributes

std::vector< Allocator * > allocators
 The memory allocators. More...
 
std::vector< Devicedevices
 Runtime physical device list. More...
 
std::unordered_map< uint32_t, Any > extensions
 The VM extensions. Mapping from the type index of the extension to the extension instance. 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::vm::VirtualMachine::~VirtualMachine ( )
inline

Member Function Documentation

◆ Create()

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

Create a specific instance of VM.

Returns
Created VM

◆ CreateProfiler()

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

Create an instance of VM with the profiling feature enabled.

Returns
Created VM

◆ GetClosure()

virtual VMClosure tvm::runtime::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::vm::VirtualMachine::GetContextPtr ( ffi::AnyView  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::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::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::vm::VirtualMachine::InvokeClosurePacked ( const ObjectRef &  closure_or_packedfunc,
ffi::PackedArgs  args,
ffi::Any *  rv 
)
pure virtual

Invoke closure or packed function using ffi::Function convention.

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

◆ LoadExecutable()

virtual void tvm::runtime::vm::VirtualMachine::LoadExecutable ( ObjectPtr< VMExecutable exec)
pure virtual

Load the executable for the virtual machine.

Parameters
execThe executable.

◆ SetInstrument()

virtual void tvm::runtime::vm::VirtualMachine::SetInstrument ( ffi::Function  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, ffi::Function], 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::vm::VirtualMachine::allocators

The memory allocators.

◆ devices

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

Runtime physical device list.

◆ extensions

std::unordered_map<uint32_t, Any> tvm::runtime::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: