tvm
|
The virtual machine. More...
#include <vm.h>
Public Member Functions | |
virtual PackedFunc | GetFunction (const String &name, const ObjectPtr< Object > &sptr_to_self) |
Get a PackedFunc from module. More... | |
virtual | ~VirtualMachine () |
const char * | type_key () const final |
VirtualMachine () | |
virtual void | LoadExecutable (const ObjectPtr< Executable > &exec) |
load the executable for the virtual machine. More... | |
int | GetPropertyMask () const final |
Get the property of the runtime module . More... | |
Public Member Functions inherited from tvm::runtime::ModuleNode | |
virtual | ~ModuleNode ()=default |
virtual destructor 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 |
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) |
Protected Member Functions | |
void | PushFrame (Index arg_count, Index ret_pc, const VMFunction &vm_func) |
Push a call frame on to the call stack. More... | |
Index | PopFrame () |
Pop a frame off the call stack. More... | |
void | WriteRegister (RegName reg, const ObjectRef &obj) |
Write to a VM register. More... | |
ObjectRef | ReadRegister (RegName reg) const |
Read a VM register. More... | |
int64_t | LoadScalarInt (RegName reg) const |
Read a VM register and cast it to int32_t. More... | |
ObjectRef | Invoke (const VMFunction &func, const std::vector< ObjectRef > &args) |
Invoke a VM function. More... | |
ObjectRef | Invoke (const std::string &name, const std::vector< ObjectRef > &args) |
Invoke a VM function by name. More... | |
ObjectRef | Invoke (const VMFunction &func, const std::vector< ObjectRef > &input_args, const std::vector< ObjectRef > &output_args) |
Invoke a VM function. More... | |
virtual void | InvokePacked (Index packed_index, const PackedFunc &func, Index arg_count, Index output_size, const std::vector< ObjectRef > &args) |
Invoke a PackedFunction. More... | |
void | Init (const std::vector< Device > &physical_devices, const std::vector< AllocatorType > &alloc_types) |
Initialize the virtual machine for a set of (physical) devices. More... | |
void | RunLoop (const std::vector< Index > &output_tensor_reg_indices={}) |
Run VM dispatch loop. More... | |
Device | GetDevice (Index device_index) const |
Get device from the device list based on a given device index. More... | |
Allocator * | GetAllocator (Index device_index) const |
void | InvokeGlobal (const VMFunction &func, const std::vector< ObjectRef > &args) |
Invoke a global setting up the VM state to execute. More... | |
void | SetInput (std::string name, TVMArgs args, int offset) |
Set inputs to a function. More... | |
void | SetOneInput (std::string name, const TVMArgValue &tag, const TVMArgValue &tensor) |
Set one input tensor with index or name to a function. More... | |
void | SetOutputs (std::string name, TVMArgs args) |
Set pre-allocated output tensors to a function. It is native implementation of 'set_outputs' python method. It is used in scenario when output tensors are allocated outside each invocation. Note: it sets set_outputs_enabled_[name] true and fill outputs_[name] but after invocation the first is switched off and the second is cleared. More... | |
void | PrintInfoAndSetInputArgs (const VMFunction &func, const std::vector< ObjectRef > &args) |
Preparation part of Invoke method before RunLoop. More... | |
void | SetOutputTensorsToRegister (const std::string &func_name, const std::vector< ObjectRef > &outputs) |
Set pre-allocated outputs to register for specified function. More... | |
virtual void | OpStartHook (Instruction instr) |
Internal hook for profiling the start of an op. More... | |
virtual void | OpStopHook () |
Internal hook for profiling the end of an op. More... | |
Protected Member Functions inherited from tvm::runtime::Object | |
void | IncRef () |
developer function, increases reference counter. More... | |
void | DecRef () |
developer function, decrease reference counter. More... | |
Protected Attributes | |
std::vector< PackedFunc > | packed_funcs_ |
The virtual machine's packed function table. More... | |
std::vector< VMFrame > | frames_ |
The current stack of call frames. More... | |
Index | func_index_ |
The fuction table index of the current function. More... | |
const Instruction * | code_ |
The current pointer to the code section. More... | |
Index | pc_ |
The virtual machine PC. More... | |
ObjectRef | return_register_ |
The special return register. More... | |
ObjectPtr< Executable > | exec_ |
The executable the VM will operate on. More... | |
std::unordered_map< std::string, std::vector< ObjectRef > > | inputs_ |
The function name to inputs mapping. More... | |
std::unordered_map< std::string, bool > | set_outputs_enabled_ |
The function name to flag enabling scenario with set outputs. More... | |
Index | preresult_op_index_ = -1 |
The index of operation which destination is result. More... | |
std::unordered_map< std::string, std::vector< Index > > | output_tensor_reg_indices_ |
The function name to indices of output tensors in register file. More... | |
std::unordered_map< std::string, std::vector< ObjectRef > > | outputs_ |
The function name to pre-allocated outputs mapping. More... | |
std::vector< Device > | devices_ |
The "physical" devices the VM can execute primitives on. All "device indexes" are w.r.t. this vector. Each entry in this vector must match the corresponding entry in the executable's "virtual" devices vector. More... | |
std::vector< Allocator * > | allocators_ |
The cached memory allocators, one per device. More... | |
std::vector< ObjectRef > | const_pool_ |
The constant pool for runtime. It caches the device dependent object to avoid rellocation of constants during inference. 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... | |
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 () |
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 |
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... | |
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.
|
inlinevirtual |
|
inline |
Get device from the device list based on a given device index.
|
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
name | the name of the function. |
sptr_to_self | The shared_ptr that points to this module node. |
Implements tvm::runtime::ModuleNode.
|
inlinefinalvirtual |
Get the property of the runtime module .
Reimplemented from tvm::runtime::ModuleNode.
|
protected |
Initialize the virtual machine for a set of (physical) devices.
physical_devices | The set of TVM devices. |
alloc_types | The allocator types for each device. |
|
protected |
Invoke a VM function by name.
name | The function's name. |
args | The arguments to the function. |
|
protected |
Invoke a VM function.
func | The function. |
args | The arguments to the function. |
|
protected |
Invoke a VM function.
func | The function. |
input_args | The input arguments to the function. |
output_args | The pre-allocated output arguments of the function. |
|
protected |
Invoke a global setting up the VM state to execute.
This does not begin execution of the VM.
|
protectedvirtual |
Invoke a PackedFunction.
packed_index | The offset of the PackedFunction in all functions. |
func | The PackedFunction to be invoked. |
arg_count | The number of arguments to the PackedFunction. |
output_size | The number of outputs of the PackedFunction. |
args | Arguments to the PackedFunction. |
|
virtual |
load the executable for the virtual machine.
exec | The executable. |
|
protected |
Read a VM register and cast it to int32_t.
reg | The register to read from. |
|
protectedvirtual |
Internal hook for profiling the start of an op.
This hook is only called on certain ops that are likely to take a significant amount of runtime (normally because they alloc or transfer to device).
instr | Instruction that will be executed after this hook fires |
|
protectedvirtual |
Internal hook for profiling the end of an op.
|
protected |
Pop a frame off the call stack.
|
protected |
Preparation part of Invoke method before RunLoop.
func | the function. |
args | input args |
|
protected |
Push a call frame on to the call stack.
Read a VM register.
reg | The register to read from. |
|
protected |
Run VM dispatch loop.
|
protected |
Set inputs to a function.
name | The function name |
args | args[offset:] are arguments to the function. If the arguments are not of the correct device for the function, they will be copied to the device. |
offset | Starting offset of the arguments in args . |
|
protected |
Set one input tensor with index or name to a function.
name | The function name. |
tag | index or name of the input tensor . |
tensor | the input tensor. If the tensor is not of the correct device for the function, they will be copied to the device. |
|
protected |
Set pre-allocated output tensors to a function. It is native implementation of 'set_outputs' python method. It is used in scenario when output tensors are allocated outside each invocation. Note: it sets set_outputs_enabled_[name] true and fill outputs_[name] but after invocation the first is switched off and the second is cleared.
name | The function name |
args | outputs to the function. |
|
protected |
Set pre-allocated outputs to register for specified function.
func_name | The function's name. |
outputs | set of output tensors. |
|
inlinefinalvirtual |
Implements tvm::runtime::ModuleNode.
|
inlineprotected |
Write to a VM register.
reg | The register to write to. |
obj | The object to write to. |
|
protected |
The cached memory allocators, one per device.
|
protected |
The current pointer to the code section.
|
protected |
The constant pool for runtime. It caches the device dependent object to avoid rellocation of constants during inference.
|
protected |
The "physical" devices the VM can execute primitives on. All "device indexes" are w.r.t. this vector. Each entry in this vector must match the corresponding entry in the executable's "virtual" devices vector.
|
protected |
The executable the VM will operate on.
|
protected |
The current stack of call frames.
|
protected |
The fuction table index of the current function.
|
protected |
The function name to inputs mapping.
|
protected |
The function name to indices of output tensors in register file.
|
protected |
The function name to pre-allocated outputs mapping.
|
protected |
The virtual machine's packed function table.
|
protected |
The virtual machine PC.
|
protected |
The index of operation which destination is result.
|
protected |
The special return register.
|
protected |
The function name to flag enabling scenario with set outputs.