23 #ifndef TVM_RUNTIME_RELAX_VM_VM_H_
24 #define TVM_RUNTIME_RELAX_VM_VM_H_
26 #ifndef TVM_RELAX_VM_ENABLE_PROFILER
27 #define TVM_RELAX_VM_ENABLE_PROFILER 1
32 #include <unordered_map>
35 #include "../memory/memory_manager.h"
42 using memory::Allocator;
44 using memory::MemoryManager;
45 using memory::Storage;
46 using memory::StorageObj;
80 static constexpr
const char*
_type_key =
"relax.vm.Closure";
112 static constexpr
const char*
_type_key =
"runtime.VMExtension";
141 const std::vector<AllocatorType>& alloc_types) = 0;
189 template <typename T, typename = std::enable_if_t<std::is_base_of<VMExtension, T>::value>>
191 using ContainerType =
typename T::ContainerType;
192 uint32_t key = ContainerType::RuntimeTypeIndex();
194 return Downcast<T>((*it).second);
196 auto [it, _] =
extensions.emplace(key, T::Create());
197 return Downcast<T>((*it).second);
An object representing a closure. This object is used by both the Relay VM and interpreter.
Definition: closure.h:36
reference to closure.
Definition: closure.h:44
Base container of module.
Definition: module.h:142
A custom smart pointer for Object.
Definition: object.h:362
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:141
Reference to string objects.
Definition: string.h:98
A single argument value to PackedFunc. Containing both type_code and TVMValue.
Definition: packed_func.h:796
Arguments into TVM functions.
Definition: packed_func.h:394
Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlyi...
Definition: packed_func.h:946
An object representing a vm closure.
Definition: vm.h:63
PackedFunc impl
The implementation of the Closure.
Definition: vm.h:77
static constexpr const char * _type_key
Definition: vm.h:80
String func_name
The function name. The function could be any function object that is compatible to the VM runtime.
Definition: vm.h:69
TVM_DECLARE_FINAL_OBJECT_INFO(VMClosureObj, ClosureObj)
static constexpr const uint32_t _type_index
Definition: vm.h:79
reference to closure.
Definition: vm.h:85
TVM_DEFINE_OBJECT_REF_METHODS(VMClosure, Closure, VMClosureObj)
static PackedFunc BindLastArgs(PackedFunc func, std::vector< TVMRetValue > last_args)
Create another PackedFunc with last arguments already bound to last_args.
VMClosure(String func_name, PackedFunc impl)
Represent a VM extension. A VM extension allows the user to extend the VM with target specific functi...
Definition: vm.h:109
static constexpr const uint32_t _type_index
Definition: vm.h:111
TVM_DECLARE_BASE_OBJECT_INFO(VMExtensionNode, Object)
static constexpr const char * _type_key
Definition: vm.h:112
Managed reference to VM extension.
Definition: vm.h:117
TVM_DEFINE_OBJECT_REF_METHODS(VMExtension, ObjectRef, VMExtensionNode)
The virtual machine.
Definition: vm.h:133
std::vector< Device > devices
Runtime physical device list.
Definition: vm.h:226
std::unordered_map< uint32_t, VMExtension > extensions
The VM extensions. Mapping from the type index of the extension to the extension instance.
Definition: vm.h:229
static VirtualMachine * GetContextPtr(TVMArgValue arg)
Helper function for vm closure functions to get the context ptr.
Definition: vm.h:214
virtual void InvokeClosurePacked(const ObjectRef &closure_or_packedfunc, TVMArgs args, TVMRetValue *rv)=0
Invoke closure or packed function using PackedFunc convention.
std::vector< Allocator * > allocators
The memory allocators.
Definition: vm.h:224
T GetOrCreateExtension()
Get or create a VM extension. Once created, the extension will be stored in the VM and held until the...
Definition: vm.h:190
static ObjectPtr< VirtualMachine > Create()
Create a specific instance of VM.
~VirtualMachine()
Definition: vm.h:218
virtual void SetInstrument(PackedFunc instrument)=0
Set an instrumentation function.
static ObjectPtr< VirtualMachine > CreateProfiler()
Create an instance of VM with the profiling feature enabled.
virtual void LoadExecutable(ObjectPtr< Executable > exec)=0
Load the executable for the virtual machine.
virtual VMClosure GetClosure(const String &func_name)=0
Get global function in the VM.
virtual void Init(const std::vector< Device > &devices, const std::vector< AllocatorType > &alloc_types)=0
Initialize the virtual machine for a set of devices.
AllocatorType
Definition: memory_manager.h:42
VMInstrumentReturnKind
Possible instrument actions.
Definition: vm.h:53
@ kNoOp
Running as normal.
@ kSkipRun
Skip the following run, only valid in before.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
@ kDynamic
Type index is allocated during runtime.
Definition: object.h:84
The bytecode for Relay virtual machine.
The Relay virtual machine executable.