tvm
Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
tvm::runtime::vm::Instruction Struct Reference

A single virtual machine instruction. More...

#include <bytecode.h>

Collaboration diagram for tvm::runtime::vm::Instruction:

Public Member Functions

 Instruction ()
 
 Instruction (const Instruction &instr)
 
Instructionoperator= (const Instruction &instr)
 
 ~Instruction ()
 

Static Public Member Functions

static Instruction Ret (RegName return_reg)
 Construct a return instruction. More...
 
static Instruction Fatal ()
 Construct a fatal instruction. More...
 
static Instruction InvokePacked (Index packed_index, Index arity, Index output_size, const std::vector< RegName > &args)
 Construct a invoke packed instruction. More...
 
static Instruction AllocTensor (RegName storage, Index offset, const std::vector< int64_t > &shape, DLDataType dtype, RegName dst)
 Construct an allocate tensor instruction with constant shape. More...
 
static Instruction AllocTensorReg (RegName storage, Index offset, RegName shape_register, DLDataType dtype, RegName dst)
 Construct an allocate tensor instruction with register. More...
 
static Instruction AllocADT (Index tag, Index num_fields, const std::vector< RegName > &fields, RegName dst)
 Construct an allocate datatype instruction. More...
 
static Instruction AllocClosure (Index func_index, Index num_freevar, const std::vector< RegName > &free_vars, RegName dst)
 Construct an allocate closure instruction. More...
 
static Instruction GetField (RegName object_reg, Index field_index, RegName dst)
 Construct a get field instruction. More...
 
static Instruction GetTag (RegName object_reg, RegName dst)
 Construct a get_tag instruction. More...
 
static Instruction If (RegName test, RegName target, Index true_branch, Index false_branch)
 Construct an if instruction. More...
 
static Instruction Goto (Index pc_offset)
 Construct a goto instruction. More...
 
static Instruction Invoke (Index func_index, const std::vector< RegName > &args, RegName dst)
 Construct an invoke instruction. More...
 
static Instruction InvokeClosure (RegName closure, const std::vector< RegName > &args, RegName dst)
 Construct an invoke closure instruction. More...
 
static Instruction LoadConst (Index const_index, Index device_index, RegName dst)
 Construct a load constant instruction. More...
 
static Instruction LoadConsti (Index val, RegName dst)
 Construct a load_constanti instruction. More...
 
static Instruction Move (RegName src, RegName dst)
 Construct a move instruction. More...
 
static Instruction AllocStorage (RegName size, Index alignment, DLDataType dtype_hint, Index device_index, const std::vector< int64_t > &shape, RegName dst)
 Allocate a storage block. More...
 
static Instruction ShapeOf (RegName tensor, RegName dst)
 Get the shape of an input tensor. More...
 
static Instruction ReshapeTensor (RegName tensor, RegName newshape, RegName dst)
 Reshape the tensor given the new shape. More...
 
static Instruction DeviceCopy (RegName src, Index src_device_index, Index dst_device_index, RegName dst)
 Copy tensor cross different devices. More...
 
static Instruction KillRegister (RegName dst)
 

Public Attributes

Opcode op
 The instruction opcode. More...
 
RegName dst
 The destination register. More...
 
union {
   struct {
      RegName   storage
 The storage to allocate from. More...
 
      Index   offset
 The offset into the storage to allocate from. More...
 
      uint32_t   ndim
 The number of dimensions. More...
 
      int64_t *   shape
 The shape of tensor. More...
 
      DLDataType   dtype
 The datatype of tensor to be allocated. More...
 
   }   alloc_tensor
 
   struct {
      RegName   storage
 The storage to allocate from. More...
 
      Index   offset
 The offset into the storage to allocate from. More...
 
      RegName   shape_register
 The register to read the shape out of. More...
 
      DLDataType   dtype
 The datatype of tensor to be allocated. More...
 
   }   alloc_tensor_reg
 
   struct {
      RegName   closure
 The register containing the closure. More...
 
      Index   num_closure_args
 The number of arguments to the closure. More...
 
      RegName *   closure_args
 The closure arguments as an array. More...
 
   } 
 
   struct {
      RegName   result
 The register to return. More...
 
   } 
 
   struct {
      RegName   from
 The source register for a move operation. More...
 
   } 
 
   struct {
      Index   packed_index
 The index into the packed function table. More...
 
      Index   arity
 The arity of the packed function. More...
 
      Index   output_size
 The number of outputs produced by the packed function. More...
 
      RegName *   packed_args
 The arguments to pass to the packed function. More...
 
   } 
 
   struct {
      RegName   test
 The register containing the test value. More...
 
      RegName   target
 The register containing the target value. More...
 
      Index   true_offset
 The program counter offset for the true branch. More...
 
      Index   false_offset
 The program counter offset for the false branch. More...
 
   }   if_op
 
   struct {
      Index   func_index
 The function to call. More...
 
      Index   num_args
 The number of arguments to the function. More...
 
      RegName *   invoke_args_registers
 The registers containing the arguments. More...
 
   } 
 
   struct {
      Index   const_index
 
      Index   device_index
 The index of the device on which the load will be made. More...
 
   } 
 
   struct {
      Index   val
 
   }   load_consti
 
   struct {
      Index   pc_offset
 The jump offset. More...
 
   } 
 
   struct {
      RegName   object
 The register to project from. More...
 
      Index   field_index
 The field to read out. More...
 
   } 
 
   struct {
      RegName   object
 The register to project from. More...
 
   }   get_tag
 
   struct {
      Index   constructor_tag
 The datatype's constructor tag. More...
 
      Index   num_fields
 The number of fields to store in the datatype. More...
 
      RegName *   datatype_fields
 The fields as an array. More...
 
   } 
 
   struct {
      Index   clo_index
 The index into the function table. More...
 
      Index   num_freevar
 The number of free variables to capture. More...
 
      RegName *   free_vars
 The free variables as an array. More...
 
   } 
 
   struct {
      Index   alignment
 The alignment of the allocation. More...
 
      DLDataType   dtype_hint
 The hint of the dtype. More...
 
      uint32_t   ndim
 The number of dimensions. More...
 
      union {
         int64_t *   shape
 The shape of tensor. More...
 
         RegName   allocation_size
 The size of the allocation. More...
 
      } 
 
      Index   device_index
 The index of the device on which the allocation will be made. More...
 
   }   alloc_storage
 
   struct {
      RegName   tensor
 
   }   shape_of
 
   struct {
      RegName   tensor
 
      RegName   newshape
 
   }   reshape_tensor
 
   struct {
      RegName   src
 
      Index   src_device_index
 The index of the source device to copy from. More...
 
      Index   dst_device_index
 The index of the destination deviceto copy to. More...
 
   }   device_copy
 
}; 
 

Friends

std::ostream & operator<< (std::ostream &os, const Instruction &)
 

Detailed Description

A single virtual machine instruction.

The representation of the instruction is as a tagged union.

The first field represents which instruction, and by extension which field of the union is active.

Constructor & Destructor Documentation

◆ Instruction() [1/2]

tvm::runtime::vm::Instruction::Instruction ( )

◆ Instruction() [2/2]

tvm::runtime::vm::Instruction::Instruction ( const Instruction instr)

◆ ~Instruction()

tvm::runtime::vm::Instruction::~Instruction ( )

Member Function Documentation

◆ AllocADT()

static Instruction tvm::runtime::vm::Instruction::AllocADT ( Index  tag,
Index  num_fields,
const std::vector< RegName > &  fields,
RegName  dst 
)
static

Construct an allocate datatype instruction.

Parameters
tagThe datatype tag.
num_fieldsThe number of fields for the datatype.
fieldsThe registers containing the fields.
dstThe register name of the destination.
Returns
The allocate instruction tensor.

◆ AllocClosure()

static Instruction tvm::runtime::vm::Instruction::AllocClosure ( Index  func_index,
Index  num_freevar,
const std::vector< RegName > &  free_vars,
RegName  dst 
)
static

Construct an allocate closure instruction.

Parameters
func_indexThe index of the function table.
num_freevarThe number of free variables.
free_varsThe registers of the free variables.
dstThe destination register.
Returns
The allocate closure instruction.

◆ AllocStorage()

static Instruction tvm::runtime::vm::Instruction::AllocStorage ( RegName  size,
Index  alignment,
DLDataType  dtype_hint,
Index  device_index,
const std::vector< int64_t > &  shape,
RegName  dst 
)
static

Allocate a storage block.

Parameters
sizeThe size of the allocation.
alignmentThe allocation's alignment.
dtype_hintThe data type hint for the allocator.
device_indexThe index of the device to allocate on.
shapeThe shape of the allocation.
dstThe destination to place the storage.
Returns
The alloc storage instruction.

◆ AllocTensor()

static Instruction tvm::runtime::vm::Instruction::AllocTensor ( RegName  storage,
Index  offset,
const std::vector< int64_t > &  shape,
DLDataType  dtype,
RegName  dst 
)
static

Construct an allocate tensor instruction with constant shape.

Parameters
storageThe storage to allocate out of.
offsetThe offset to allocate at.
shapeThe shape of the tensor.
dtypeThe dtype of the tensor.
dstThe destination register.
Returns
The allocate tensor instruction.

◆ AllocTensorReg()

static Instruction tvm::runtime::vm::Instruction::AllocTensorReg ( RegName  storage,
Index  offset,
RegName  shape_register,
DLDataType  dtype,
RegName  dst 
)
static

Construct an allocate tensor instruction with register.

Parameters
storageThe storage to allocate out of.
offsetThe offset into the storage to allocate from.
shape_registerThe register containing the shape.
dtypeThe dtype of the tensor.
dstThe destination register.
Returns
The allocate tensor instruction.

◆ DeviceCopy()

static Instruction tvm::runtime::vm::Instruction::DeviceCopy ( RegName  src,
Index  src_device_index,
Index  dst_device_index,
RegName  dst 
)
static

Copy tensor cross different devices.

Parameters
srcThe source register.
src_device_indexThe index of the device holding the tensor in the source register.
dst_device_indexThe index of the device to hold the tensor in the destination register.
dstThe destination register to store the copied tensor.
Returns
The device copy instruction.

◆ Fatal()

static Instruction tvm::runtime::vm::Instruction::Fatal ( )
static

Construct a fatal instruction.

Returns
The fatal instruction.

◆ GetField()

static Instruction tvm::runtime::vm::Instruction::GetField ( RegName  object_reg,
Index  field_index,
RegName  dst 
)
static

Construct a get field instruction.

Parameters
object_regThe register containing the object to project from.
field_indexThe field to read out of the object.
dstThe destination register.
Returns
The get field instruction.

◆ GetTag()

static Instruction tvm::runtime::vm::Instruction::GetTag ( RegName  object_reg,
RegName  dst 
)
static

Construct a get_tag instruction.

Parameters
object_regThe register containing the object to project from.
dstThe destination register.
Returns
The get_tag instruction.

◆ Goto()

static Instruction tvm::runtime::vm::Instruction::Goto ( Index  pc_offset)
static

Construct a goto instruction.

Parameters
pc_offsetThe offset from the current pc.
Returns
The goto instruction.

◆ If()

static Instruction tvm::runtime::vm::Instruction::If ( RegName  test,
RegName  target,
Index  true_branch,
Index  false_branch 
)
static

Construct an if instruction.

Parameters
testThe register containing the test value.
targetThe register containing the target value.
true_branchThe offset to the true branch.
false_branchThe offset to the false branch.
Returns
The if instruction.

◆ Invoke()

static Instruction tvm::runtime::vm::Instruction::Invoke ( Index  func_index,
const std::vector< RegName > &  args,
RegName  dst 
)
static

Construct an invoke instruction.

Parameters
func_indexThe index of the function to invoke.
argsThe registers containing the arguments.
dstThe destination register.
Returns
The invoke instruction.

◆ InvokeClosure()

static Instruction tvm::runtime::vm::Instruction::InvokeClosure ( RegName  closure,
const std::vector< RegName > &  args,
RegName  dst 
)
static

Construct an invoke closure instruction.

Parameters
closureThe register of the closure to invoke.
argsThe registers containing the arguments.
dstThe destination register.
Returns
The invoke closure instruction.

◆ InvokePacked()

static Instruction tvm::runtime::vm::Instruction::InvokePacked ( Index  packed_index,
Index  arity,
Index  output_size,
const std::vector< RegName > &  args 
)
static

Construct a invoke packed instruction.

Parameters
packed_indexThe index of the packed function.
arityThe arity of the function.
output_sizeThe number of outputs of the packed function.
argsThe argument registers.
Returns
The invoke packed instruction.

◆ KillRegister()

static Instruction tvm::runtime::vm::Instruction::KillRegister ( RegName  dst)
static

◆ LoadConst()

static Instruction tvm::runtime::vm::Instruction::LoadConst ( Index  const_index,
Index  device_index,
RegName  dst 
)
static

Construct a load constant instruction.

Parameters
const_indexThe index of the constant.
device_indexThe index of the device to load on.
dstThe destination register.
Returns
The load constant instruction.

◆ LoadConsti()

static Instruction tvm::runtime::vm::Instruction::LoadConsti ( Index  val,
RegName  dst 
)
static

Construct a load_constanti instruction.

Parameters
valThe interger constant value.
dstThe destination register.
Returns
The load_constanti instruction.

◆ Move()

static Instruction tvm::runtime::vm::Instruction::Move ( RegName  src,
RegName  dst 
)
static

Construct a move instruction.

Parameters
srcThe source register.
dstThe destination register.
Returns
The move instruction.

◆ operator=()

Instruction& tvm::runtime::vm::Instruction::operator= ( const Instruction instr)

◆ ReshapeTensor()

static Instruction tvm::runtime::vm::Instruction::ReshapeTensor ( RegName  tensor,
RegName  newshape,
RegName  dst 
)
static

Reshape the tensor given the new shape.

Parameters
tensorThe input tensor.
newshapeThe shape tensor.
dstThe destination to store the output tensor with new shape.
Returns
The reshape tensor instruction.

◆ Ret()

static Instruction tvm::runtime::vm::Instruction::Ret ( RegName  return_reg)
static

Construct a return instruction.

Parameters
return_regThe register containing the return value.
Returns
The return instruction.

◆ ShapeOf()

static Instruction tvm::runtime::vm::Instruction::ShapeOf ( RegName  tensor,
RegName  dst 
)
static

Get the shape of an input tensor.

Parameters
tensorThe input tensor.
dstThe destination to store the shape of the given tensor.
Returns
The shape of instruction.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Instruction  
)
friend

Member Data Documentation

◆ 

union { ... }

◆ alignment

Index tvm::runtime::vm::Instruction::alignment

The alignment of the allocation.

◆ 

struct { ... } tvm::runtime::vm::Instruction::alloc_storage

◆ 

struct { ... } tvm::runtime::vm::Instruction::alloc_tensor

◆ 

struct { ... } tvm::runtime::vm::Instruction::alloc_tensor_reg

◆ allocation_size

RegName tvm::runtime::vm::Instruction::allocation_size

The size of the allocation.

◆ arity

Index tvm::runtime::vm::Instruction::arity

The arity of the packed function.

◆ clo_index

Index tvm::runtime::vm::Instruction::clo_index

The index into the function table.

◆ closure

RegName tvm::runtime::vm::Instruction::closure

The register containing the closure.

◆ closure_args

RegName* tvm::runtime::vm::Instruction::closure_args

The closure arguments as an array.

◆ const_index

Index tvm::runtime::vm::Instruction::const_index

◆ constructor_tag

Index tvm::runtime::vm::Instruction::constructor_tag

The datatype's constructor tag.

◆ datatype_fields

RegName* tvm::runtime::vm::Instruction::datatype_fields

The fields as an array.

◆ 

struct { ... } tvm::runtime::vm::Instruction::device_copy

◆ device_index

Index tvm::runtime::vm::Instruction::device_index

The index of the device on which the load will be made.

The index of the device on which the allocation will be made.

◆ dst

RegName tvm::runtime::vm::Instruction::dst

The destination register.

◆ dst_device_index

Index tvm::runtime::vm::Instruction::dst_device_index

The index of the destination deviceto copy to.

◆ dtype

DLDataType tvm::runtime::vm::Instruction::dtype

The datatype of tensor to be allocated.

◆ dtype_hint

DLDataType tvm::runtime::vm::Instruction::dtype_hint

The hint of the dtype.

◆ false_offset

Index tvm::runtime::vm::Instruction::false_offset

The program counter offset for the false branch.

◆ field_index

Index tvm::runtime::vm::Instruction::field_index

The field to read out.

◆ free_vars

RegName* tvm::runtime::vm::Instruction::free_vars

The free variables as an array.

◆ from

RegName tvm::runtime::vm::Instruction::from

The source register for a move operation.

◆ func_index

Index tvm::runtime::vm::Instruction::func_index

The function to call.

◆ 

struct { ... } tvm::runtime::vm::Instruction::get_tag

◆ 

struct { ... } tvm::runtime::vm::Instruction::if_op

◆ invoke_args_registers

RegName* tvm::runtime::vm::Instruction::invoke_args_registers

The registers containing the arguments.

◆ 

struct { ... } tvm::runtime::vm::Instruction::load_consti

◆ ndim

uint32_t tvm::runtime::vm::Instruction::ndim

The number of dimensions.

◆ newshape

RegName tvm::runtime::vm::Instruction::newshape

◆ num_args

Index tvm::runtime::vm::Instruction::num_args

The number of arguments to the function.

◆ num_closure_args

Index tvm::runtime::vm::Instruction::num_closure_args

The number of arguments to the closure.

◆ num_fields

Index tvm::runtime::vm::Instruction::num_fields

The number of fields to store in the datatype.

◆ num_freevar

Index tvm::runtime::vm::Instruction::num_freevar

The number of free variables to capture.

◆ object

RegName tvm::runtime::vm::Instruction::object

The register to project from.

◆ offset

Index tvm::runtime::vm::Instruction::offset

The offset into the storage to allocate from.

◆ op

Opcode tvm::runtime::vm::Instruction::op

The instruction opcode.

◆ output_size

Index tvm::runtime::vm::Instruction::output_size

The number of outputs produced by the packed function.

◆ packed_args

RegName* tvm::runtime::vm::Instruction::packed_args

The arguments to pass to the packed function.

◆ packed_index

Index tvm::runtime::vm::Instruction::packed_index

The index into the packed function table.

◆ pc_offset

Index tvm::runtime::vm::Instruction::pc_offset

The jump offset.

◆ 

struct { ... } tvm::runtime::vm::Instruction::reshape_tensor

◆ result

RegName tvm::runtime::vm::Instruction::result

The register to return.

◆ shape

int64_t* tvm::runtime::vm::Instruction::shape

The shape of tensor.

◆ 

struct { ... } tvm::runtime::vm::Instruction::shape_of

◆ shape_register

RegName tvm::runtime::vm::Instruction::shape_register

The register to read the shape out of.

◆ src

RegName tvm::runtime::vm::Instruction::src

◆ src_device_index

Index tvm::runtime::vm::Instruction::src_device_index

The index of the source device to copy from.

◆ storage

RegName tvm::runtime::vm::Instruction::storage

The storage to allocate from.

◆ target

RegName tvm::runtime::vm::Instruction::target

The register containing the target value.

◆ tensor

RegName tvm::runtime::vm::Instruction::tensor

◆ test

RegName tvm::runtime::vm::Instruction::test

The register containing the test value.

◆ true_offset

Index tvm::runtime::vm::Instruction::true_offset

The program counter offset for the true branch.

◆ val

Index tvm::runtime::vm::Instruction::val

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