tvm
|
The executable emitted by the VM compiler. More...
#include <executable.h>
Public Member Functions | |
PackedFunc | GetFunction (const std::string &name, const ObjectPtr< Object > &sptr_to_self) final |
Get a PackedFunc from an executable module. More... | |
void | SaveToBinary (dmlc::Stream *stream) final |
Write the Executable to the binary stream in serialized form. More... | |
void | SaveToFile (const std::string &path, const std::string &format) final |
Write the Executable to the provided path as a file contianing its serialized content. More... | |
TVMByteArray | Save () |
Serialize the executable into global section, constant section, and code section. More... | |
std::string | GetBytecode () const |
Get the serialized form of the functions . This is essentially bytecode serialization. More... | |
std::string | GetConstants () const |
Returns a description of all the contants in the executable in human-readable format. Not intended to be machine readable, but rather to help with debugging and diffing generated code. More... | |
std::string | Stats () const |
Print the detailed statistics of the given code, i.e. number of globls and constants, etc. More... | |
runtime::Module | GetLib () const |
Get the lib module in an executable. Users have the flexibility to call export_library from the frontend to save the library to disk. More... | |
void | SetLib (const runtime::Module &lib) |
Set the lib module in an executable. More... | |
int | GetFunctionArity (std::string func) const |
Get the arity of the VMFunction. More... | |
std::string | GetFunctionParameterName (std::string func, uint32_t index) const |
Get the parameter name given the function name and parameter index. More... | |
virtual | ~Executable () |
const char * | type_key () const final |
![]() | |
virtual | ~ModuleNode () |
virtual destructor More... | |
virtual std::string | GetSource (const std::string &format="") |
Get the source code of module, when available. More... | |
PackedFunc | GetFunction (const std::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 std::string &name) |
Get a function from current environment The environment includes all the imports as well as Global functions. More... | |
const std::vector< Module > & | imports () const |
TVM_DECLARE_FINAL_OBJECT_INFO (ModuleNode, 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 runtime::Module | Load (const std::string &code, const runtime::Module lib) |
Load the saved VM executable. More... | |
![]() | |
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< ObjectRef > | constants |
The global constant pool. More... | |
std::unordered_map< std::string, Index > | global_map |
A map from globals (as strings) to their index in the function map. More... | |
std::unordered_map< std::string, Index > | primitive_map |
A mapping from the packed function (as string) to the index that corresponds to the position of the packed_funcs list in a VirtualMachine object. More... | |
std::map< Index, Map< String, ObjectRef > > | op_attrs |
The structural hashes of the operators in this function. More... | |
std::vector< VMFunction > | functions |
The virtual machine's function table. More... | |
std::vector< Index > | const_device_type |
The device type for each constant. More... | |
Additional Inherited Members | |
![]() | |
typedef void(* | FDeleter) (Object *self) |
Object deleter. More... | |
using | RefCounterType = std::atomic< int32_t > |
![]() | |
static constexpr const uint32_t | _type_index = TypeIndex::kRuntimeModule |
static constexpr const char * | _type_key = "runtime.Module" |
![]() | |
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 |
![]() | |
void | IncRef () |
developer function, increases reference counter. More... | |
void | DecRef () |
developer function, decrease reference counter. More... | |
![]() | |
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... | |
![]() | |
std::vector< Module > | imports_ |
The modules this module depend on. More... | |
![]() | |
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 executable emitted by the VM compiler.
The executable contains information (e.g. data in different memory regions) to run in a virtual machine.
|
inlinevirtual |
std::string tvm::runtime::vm::Executable::GetBytecode | ( | ) | const |
Get the serialized form of the functions
. This is essentially bytecode serialization.
Each instruction is printed in the following format: opcode num_fields field1 ... fieldX # The text format.
Serializing an Instruction
requires us to deal with the bytecode. Each line of the instructions could be serialized as the following format: hash, opcode, f1, f2, ..., fX, field with variable length
from
and dst
fields of a Move
instruction. For example, DLDataType
will be unpacked into three fields (code, bits, lanes).InvokPacked
instruction, etc.The field starting from # is only used for debugging. The serialized code doesn't contain it, therefore the deserializer doens't need to handle it.
std::string tvm::runtime::vm::Executable::GetConstants | ( | ) | const |
Returns a description of all the contants in the executable in human-readable format. Not intended to be machine readable, but rather to help with debugging and diffing generated code.
|
finalvirtual |
Get a PackedFunc from an executable module.
name | the name of the function. |
sptr_to_self | The shared_ptr that points to this module node. |
Implements tvm::runtime::ModuleNode.
int tvm::runtime::vm::Executable::GetFunctionArity | ( | std::string | func | ) | const |
std::string tvm::runtime::vm::Executable::GetFunctionParameterName | ( | std::string | func, |
uint32_t | index | ||
) | const |
Get the parameter name given the function name and parameter index.
func | Function name. |
index | Parameter index. |
runtime::Module tvm::runtime::vm::Executable::GetLib | ( | ) | const |
Get the lib
module in an executable. Users have the flexibility to call export_library
from the frontend to save the library to disk.
|
static |
Load the saved VM executable.
code | The bytecode in string. |
lib | The compiled runtime library. |
TVMByteArray tvm::runtime::vm::Executable::Save | ( | ) |
Serialize the executable into global section, constant section, and code section.
|
finalvirtual |
Write the Executable to the binary stream in serialized form.
stream | The binary stream to save the executable to. |
Reimplemented from tvm::runtime::ModuleNode.
|
finalvirtual |
Write the Executable to the provided path as a file contianing its serialized content.
path | The path to write the serialized data to. |
format | The format of the serialized blob. |
Reimplemented from tvm::runtime::ModuleNode.
void tvm::runtime::vm::Executable::SetLib | ( | const runtime::Module & | lib | ) |
Set the lib
module in an executable.
This allows us to do partial initialization in the case of (de|ser)ialization cases. This method also ensures correct initialization of library ensuring we only Import a single library.
NB: This also provides some abstraction over how libraries are stored as there are plans to iterate on the way runtime::Module works in the backend of the compiler.
std::string tvm::runtime::vm::Executable::Stats | ( | ) | const |
Print the detailed statistics of the given code, i.e. number of globls and constants, etc.
|
inlinefinalvirtual |
Implements tvm::runtime::ModuleNode.
std::vector<Index> tvm::runtime::vm::Executable::const_device_type |
The device type for each constant.
std::vector<ObjectRef> tvm::runtime::vm::Executable::constants |
The global constant pool.
std::vector<VMFunction> tvm::runtime::vm::Executable::functions |
The virtual machine's function table.
std::unordered_map<std::string, Index> tvm::runtime::vm::Executable::global_map |
A map from globals (as strings) to their index in the function map.
The structural hashes of the operators in this function.
std::unordered_map<std::string, Index> tvm::runtime::vm::Executable::primitive_map |
A mapping from the packed function (as string) to the index that corresponds to the position of the packed_funcs
list in a VirtualMachine
object.