tvm
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
tvm::runtime::vm::Executable Class Reference

The executable emitted by the VM compiler. More...

#include <executable.h>

Inheritance diagram for tvm::runtime::vm::Executable:
Collaboration diagram for tvm::runtime::vm::Executable:

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
 
- Public Member Functions inherited from tvm::runtime::ModuleNode
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 PackedFuncGetFuncFromEnv (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)
 
- 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)
 
Objectoperator= (const Object &other)
 
Objectoperator= (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 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< ObjectRefconstants
 The global constant pool. More...
 
std::unordered_map< std::string, Indexglobal_map
 A map from globals (as strings) to their index in the function map. More...
 
std::unordered_map< std::string, Indexprimitive_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< VMFunctionfunctions
 The virtual machine's function table. More...
 
std::vector< Indexconst_device_type
 The device type for each constant. 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< Moduleimports_
 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...
 

Detailed Description

The executable emitted by the VM compiler.

The executable contains information (e.g. data in different memory regions) to run in a virtual machine.

Constructor & Destructor Documentation

◆ ~Executable()

virtual tvm::runtime::vm::Executable::~Executable ( )
inlinevirtual

Member Function Documentation

◆ GetBytecode()

std::string tvm::runtime::vm::Executable::GetBytecode ( ) const

Get the serialized form of the functions. This is essentially bytecode serialization.

Returns
The serialized vm bytecode.
Note
The bytecode is in the following format: func_name reg_file_size num_instructions param1 param2 ... paramM instruction1 instruction2 ... instructionN

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

  1. hash: the hash of the instruction. This number will be used to help us validate if an instruction is well-formed during deserialization.
  2. opcode: the opcode code of the instruction.
  3. f1, f2, ..., fX. These fields together represent the fixed fields in an instruction, e.g., from and dst fields of a Move instruction. For example, DLDataType will be unpacked into three fields (code, bits, lanes).
  4. The rest of the line indicates the field with variable length, e.g., the shape of a tensor, the args used by an 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.

◆ GetConstants()

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.

◆ GetFunction()

PackedFunc tvm::runtime::vm::Executable::GetFunction ( const std::string &  name,
const ObjectPtr< Object > &  sptr_to_self 
)
finalvirtual

Get a PackedFunc from an executable module.

Parameters
namethe name of the function.
sptr_to_selfThe shared_ptr that points to this module node.
Returns
PackedFunc or nullptr when it is not available.

Implements tvm::runtime::ModuleNode.

◆ GetFunctionArity()

int tvm::runtime::vm::Executable::GetFunctionArity ( std::string  func) const

Get the arity of the VMFunction.

Parameters
funcFunction name.
Returns
The number of parameters.

◆ GetFunctionParameterName()

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.

Parameters
funcFunction name.
indexParameter index.
Returns
The parameter name.

◆ GetLib()

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.

Returns
The runtime module that contains the hardware dependent code.

◆ Load()

static runtime::Module tvm::runtime::vm::Executable::Load ( const std::string &  code,
const runtime::Module  lib 
)
static

Load the saved VM executable.

Parameters
codeThe bytecode in string.
libThe compiled runtime library.
Returns
exe The constructed executable.

◆ Save()

TVMByteArray tvm::runtime::vm::Executable::Save ( )

Serialize the executable into global section, constant section, and code section.

Returns
The binary representation of the VM.

◆ SaveToBinary()

void tvm::runtime::vm::Executable::SaveToBinary ( dmlc::Stream *  stream)
finalvirtual

Write the Executable to the binary stream in serialized form.

Parameters
streamThe binary stream to save the executable to.

Reimplemented from tvm::runtime::ModuleNode.

◆ SaveToFile()

void tvm::runtime::vm::Executable::SaveToFile ( const std::string &  path,
const std::string &  format 
)
finalvirtual

Write the Executable to the provided path as a file contianing its serialized content.

Parameters
pathThe path to write the serialized data to.
formatThe format of the serialized blob.

Reimplemented from tvm::runtime::ModuleNode.

◆ SetLib()

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.

◆ Stats()

std::string tvm::runtime::vm::Executable::Stats ( ) const

Print the detailed statistics of the given code, i.e. number of globls and constants, etc.

◆ type_key()

const char* tvm::runtime::vm::Executable::type_key ( ) const
inlinefinalvirtual
Returns
The per module type key.
Note
This key is used to for serializing custom modules.

Implements tvm::runtime::ModuleNode.

Member Data Documentation

◆ const_device_type

std::vector<Index> tvm::runtime::vm::Executable::const_device_type

The device type for each constant.

◆ constants

std::vector<ObjectRef> tvm::runtime::vm::Executable::constants

The global constant pool.

◆ functions

std::vector<VMFunction> tvm::runtime::vm::Executable::functions

The virtual machine's function table.

◆ global_map

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.

◆ op_attrs

std::map<Index, Map<String, ObjectRef> > tvm::runtime::vm::Executable::op_attrs

The structural hashes of the operators in this function.

◆ primitive_map

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.


The documentation for this class was generated from the following file: