tvm
|
The virtual machine. More...
#include <vm.h>
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>> | |
T | 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 PackedFunc * | GetFuncFromEnv (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) | |
Object & | operator= (const Object &other) |
Object & | operator= (Object &&other) |
Static Public Member Functions | |
static ObjectPtr< VirtualMachine > | Create () |
Create a specific instance of VM. More... | |
static ObjectPtr< VirtualMachine > | CreateProfiler () |
Create an instance of VM with the profiling feature enabled. More... | |
static VirtualMachine * | GetContextPtr (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< Device > | devices |
Runtime physical device list. More... | |
std::unordered_map< uint32_t, VMExtension > | extensions |
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< Module > | imports_ |
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... | |
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.
|
inline |
|
static |
Create a specific instance of VM.
|
static |
Create an instance of VM with the profiling feature enabled.
|
pure virtual |
Get global function in the VM.
func_name | The name of the function. |
|
inlinestatic |
Helper function for vm closure functions to get the context ptr.
arg | The argument value. |
|
inline |
Get or create a VM extension. Once created, the extension will be stored in the VM and held until the VM is destructed.
T | The type of the extension |
|
pure virtual |
Initialize the virtual machine for a set of devices.
devices | The set of TVM devices. |
alloc_types | The allocator types for each device. |
|
pure virtual |
Invoke closure or packed function using PackedFunc convention.
closure_or_packedfunc | A VM closure or a packed_func. |
args | The input arguments. |
rv | The return value. |
|
pure virtual |
Load the executable for the virtual machine.
exec | The executable. |
|
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...)
instrument can return an int which corresponds to the action value.
instrument | The instrument function. |
std::vector<Allocator*> tvm::runtime::relax_vm::VirtualMachine::allocators |
The memory allocators.
std::vector<Device> tvm::runtime::relax_vm::VirtualMachine::devices |
Runtime physical device list.
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.