tvm
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
tvm::runtime Namespace Reference

Namespaces

 contrib
 
 cuda_ipc
 
 memory
 
 
 micro_rpc
 
 profiling
 
 relax_vm
 
 symbol
 namespace for constant symbols
 
 threading
 
 vm
 

Classes

struct  PackedFuncValueConverter< PrimExpr >
 
struct  PackedFuncValueConverter< tvm::Integer >
 
struct  PackedFuncValueConverter< tvm::Bool >
 
class  ADTObj
 An object representing a structure or enumeration. More...
 
class  ADT
 reference to algebraic data type objects. More...
 
class  ArrayNode
 array node content in array More...
 
struct  is_valid_iterator
 Helper struct for type-checking. More...
 
struct  is_valid_iterator< Optional< T >, IterType >
 
class  Array
 Array, container representing a contiguous sequence of ObjectRefs. More...
 
struct  ObjectHash
 String-aware ObjectRef equal functor. More...
 
struct  ObjectEqual
 String-aware ObjectRef hash functor. More...
 
class  InplaceArrayBase
 Base template for classes with array like memory layout. More...
 
class  IterAdapter
 iterator adapter that adapts TIter to return another type. More...
 
class  ReverseIterAdapter
 iterator adapter that adapts TIter to return another type. More...
 
class  ClosureObj
 An object representing a closure. This object is used by both the Relay VM and interpreter. More...
 
class  Closure
 reference to closure. More...
 
class  MapNode
 Shared content of all specializations of hash map. More...
 
class  SmallMapNode
 A specialization of small-sized hash map. More...
 
class  DenseMapNode
 A specialization of hash map that implements the idea of array-based hash map. Another reference implementation can be found [1]. More...
 
class  Map
 Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places. More...
 
struct  NullOptType
 Helper to represent nullptr for optional. More...
 
class  Optional
 Optional container that to represent to a Nullable variant of T. More...
 
class  ShapeTupleObj
 An object representing a shape tuple. More...
 
class  ShapeTuple
 Reference to shape tuple objects. More...
 
class  StringObj
 An object representing string. It's POD type. More...
 
class  String
 Reference to string objects. More...
 
class  Variant
 
class  DataType
 Runtime primitive data type. More...
 
class  DeviceAPI
 TVM Runtime Device API, abstracts the device specific interface for memory management. More...
 
class  DiscoWorker
 A worker in Disco. It takes a channel to communication with the controler. The worker can be run in a separate thread or process as long as the channel supports bi-directional communication in-between. More...
 
class  DRefObj
 An object that exists on all workers. More...
 
class  DRef
 Managed reference to DRefObj. More...
 
class  SessionObj
 A Disco interactive session. It allows users to interact with the Disco command queue with various PackedFunc calling convention. More...
 
class  Session
 Managed reference to SessionObj. More...
 
class  DiscoChannel
 A bi-directional channel for controler-worker communication. This channel is primarily used to transfer control messages but not data. More...
 
class  WorkerZeroData
 A special communication channel between controler and worker-0, assuming they are always collocated in the same process. More...
 
class  ObjAllocatorBase
 Base class of object allocators that implements make. Use curiously recurring template pattern. More...
 
class  SimpleObjAllocator
 
class  Module
 Module container of TVM. More...
 
class  ModuleNode
 Base container of module. More...
 
class  NDArray
 Managed NDArray. The array is backed by reference counted blocks. More...
 
class  NVTXScopedRange
 A class to create a NVTX range. No-op if TVM is not built against NVTX. More...
 
struct  TypeIndex
 Namespace for the list of type index. More...
 
class  Object
 base class of all object containers. More...
 
class  ObjectPtr
 A custom smart pointer for Object. More...
 
class  ObjectRef
 Base class of all object reference. More...
 
struct  ObjectPtrHash
 ObjectRef hash functor. More...
 
struct  ObjectPtrEqual
 ObjectRef equal functor. More...
 
class  TypedPackedFunc
 Please refer to TypedPackedFunc<R(Args..)>. More...
 
struct  SignaturePrinter
 
class  PackedFuncObj
 Object container class that backs PackedFunc. More...
 
class  PackedFuncSubObj
 Derived object class for constructing PackedFuncObj. More...
 
class  PackedFunc
 Packed function is a type-erased function. The arguments are passed by packed format. More...
 
class  TypedPackedFunc< R(Args...)>
 A PackedFunc wrapper to provide typed function signature. It is backed by a PackedFunc internally. More...
 
class  TVMArgs
 Arguments into TVM functions. More...
 
struct  ObjectTypeChecker
 Type traits for runtime type check during FFI conversion. More...
 
struct  ObjectTypeChecker< Array< T > >
 
struct  ObjectTypeChecker< Map< K, V > >
 
class  TVMPODValue_
 Internal base class to handle conversion to POD values. More...
 
class  TVMArgValue
 A single argument value to PackedFunc. Containing both type_code and TVMValue. More...
 
class  TVMMovableArgValue_
 Internal auxiliary struct for TypedPackedFunc to indicate a movable argument. More...
 
class  TVMMovableArgValueWithContext_
 Internal auxiliary struct for TypedPackedFunc to indicate a movable argument with additional context information (function name and argument index) for better error reporting. More...
 
class  TVMRetValue
 Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlying container during destruction. More...
 
struct  PackedFuncValueConverter
 Type trait to specify special value conversion rules from TVMArgValue and TVMRetValue. More...
 
class  TVMArgsSetter
 
struct  TVMArgsSetterApply
 
struct  PackedFuncValueConverter<::tvm::runtime::String >
 
struct  PackedFuncValueConverter< Optional< T > >
 
struct  PackedFuncValueConverter< Variant< VariantTypes... > >
 
class  TimerNode
 Base class for all implementations. More...
 
class  Timer
 Timer for a specific device. More...
 
class  WrappedPythonObject
 A class that wraps a Python object and preserves its ownership. More...
 
class  Registry
 Registry for global function. More...
 

Typedefs

using IntTuple = ShapeTuple
 
using IntTupleObj = ShapeTupleObj
 
using FSig = std::string()
 Using static function to output TypedPackedFunc signature. More...
 

Enumerations

enum  DeviceAttrKind : int {
  kExist = 0 , kMaxThreadsPerBlock = 1 , kWarpSize = 2 , kMaxSharedMemoryPerBlock = 3 ,
  kComputeVersion = 4 , kDeviceName = 5 , kMaxClockRate = 6 , kMultiProcessorCount = 7 ,
  kMaxThreadDimensions = 8 , kMaxRegistersPerBlock = 9 , kGcnArch = 10 , kApiVersion = 11 ,
  kDriverVersion = 12 , kL2CacheSizeBytes = 13 , kTotalGlobalMemory = 14
}
 the query type into GetAttr More...
 
enum class  ReduceKind : int32_t {
  kSum = 0 , kProd = 1 , kMin = 2 , kMax = 3 ,
  kAvg = 4
}
 Possible kinds of reduction operations. More...
 
enum class  DiscoAction : int32_t {
  kShutDown = 0 , kKillReg = 1 , kGetGlobalFunc = 2 , kCallPacked = 3 ,
  kSyncWorker = 4 , kCopyFromWorker0 = 5 , kCopyToWorker0 = 6 , kDebugGetFromRemote = 7 ,
  kDebugSetRegister = 8
}
 All possible kinds of Disco commands. More...
 
enum  ModulePropertyMask : int { kBinarySerializable = 0b001 , kRunnable = 0b010 , kDSOExportable = 0b100 }
 Property of runtime module We classify the property of runtime module into the following categories. More...
 

Functions

std::ostream & operator<< (std::ostream &os, const ObjectRef &n)
 
std::string AsLegacyRepr (const ObjectRef &n)
 
template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
Array< T > Concat (Array< T > lhs, const Array< T > &rhs)
 Concat two Arrays. More...
 
template<>
ObjectPtr< ArrayNodemake_object ()
 
template<typename K , typename V , typename = typename std::enable_if<std::is_base_of<ObjectRef, K>::value>::type, typename = typename std::enable_if<std::is_base_of<ObjectRef, V>::value>::type>
Map< K, V > Merge (Map< K, V > lhs, const Map< K, V > &rhs)
 Merge two Maps. More...
 
std::ostream & operator<< (std::ostream &os, const ShapeTuple &shape)
 
String operator+ (const String &lhs, const String &rhs)
 
String operator+ (const String &lhs, const std::string &rhs)
 
String operator+ (const std::string &lhs, const String &rhs)
 
String operator+ (const char *lhs, const String &rhs)
 
String operator+ (const String &lhs, const char *rhs)
 
bool operator< (const String &lhs, const std::string &rhs)
 
bool operator< (const std::string &lhs, const String &rhs)
 
bool operator< (const String &lhs, const String &rhs)
 
bool operator< (const String &lhs, const char *rhs)
 
bool operator< (const char *lhs, const String &rhs)
 
bool operator> (const String &lhs, const std::string &rhs)
 
bool operator> (const std::string &lhs, const String &rhs)
 
bool operator> (const String &lhs, const String &rhs)
 
bool operator> (const String &lhs, const char *rhs)
 
bool operator> (const char *lhs, const String &rhs)
 
bool operator<= (const String &lhs, const std::string &rhs)
 
bool operator<= (const std::string &lhs, const String &rhs)
 
bool operator<= (const String &lhs, const String &rhs)
 
bool operator<= (const String &lhs, const char *rhs)
 
bool operator<= (const char *lhs, const String &rhs)
 
bool operator>= (const String &lhs, const std::string &rhs)
 
bool operator>= (const std::string &lhs, const String &rhs)
 
bool operator>= (const String &lhs, const String &rhs)
 
bool operator>= (const String &lhs, const char *rhs)
 
bool operator>= (const char *lhs, const String &rhs)
 
bool operator== (const String &lhs, const std::string &rhs)
 
bool operator== (const std::string &lhs, const String &rhs)
 
bool operator== (const String &lhs, const String &rhs)
 
bool operator== (const String &lhs, const char *rhs)
 
bool operator== (const char *lhs, const String &rhs)
 
bool operator!= (const String &lhs, const std::string &rhs)
 
bool operator!= (const std::string &lhs, const String &rhs)
 
bool operator!= (const String &lhs, const String &rhs)
 
bool operator!= (const String &lhs, const char *rhs)
 
bool operator!= (const char *lhs, const String &rhs)
 
std::ostream & operator<< (std::ostream &out, const String &input)
 
int GetVectorBytes (DataType dtype)
 Get the number of bytes needed in a vector. More...
 
bool TypeMatch (DLDataType t, int code, int bits, int lanes=1)
 Check whether type matches the given spec. More...
 
bool TypeEqual (DLDataType lhs, DLDataType rhs)
 Check whether two types are equal . More...
 
std::string GetCustomTypeName (uint8_t type_code)
 Runtime utility for getting custom type name from code. More...
 
bool GetCustomTypeRegistered (uint8_t type_code)
 Runtime utility for checking whether custom type is registered. More...
 
uint8_t ParseCustomDatatype (const std::string &s, const char **scan)
 Runtime utility for parsing string of the form "custom[<typename>]". More...
 
const char * DLDataTypeCode2Str (DLDataTypeCode type_code)
 Convert type code to its name. More...
 
DLDataType String2DLDataType (std::string s)
 convert a string to TVM type. More...
 
std::string DLDataType2String (DLDataType t)
 convert a TVM type to string. More...
 
std::ostream & operator<< (std::ostream &os, DLDataType t)
 
std::ostream & operator<< (std::ostream &os, const DataType &dtype)
 
void AppendNDArray (std::ostream &os, const NDArray &nd_array, const DLDevice &host_device, bool show_content=true)
 Helpers to describe runtime objects in human-friendly form. For nd_arrays we show their shapes and dtypes, but also their contents if 'small' and on the host_device (mostly so that we can see dynamic shapes as they are computed). For adts we show the ADT fields. For objects we dispatch to one of the above as appropriate. More...
 
void AppendADT (std::ostream &os, const ADT &adt, const DLDevice &host_device, bool show_content=true)
 
void AppendRuntimeObject (std::ostream &os, const ObjectRef &object, const DLDevice &host_device, bool show_content=true)
 
std::string RuntimeObject2String (const ObjectRef &object, const DLDevice &host_device, bool show_content=true)
 
bool IsRPCSessionDevice (Device dev)
 Return true if a Device is owned by an RPC session. More...
 
int GetRPCSessionIndex (Device dev)
 Return the RPCSessTable index of the RPC Session that owns this device. More...
 
Device RemoveRPCSessionMask (Device dev)
 Remove the RPC session mask from a Device. RPC clients typically do this when encoding a Device for transmission to an RPC remote. On the wire, RPCdevice are expected to be valid on the server without interpretation. More...
 
std::ostream & operator<< (std::ostream &os, DLDevice dev)
 
Device AddRPCSessionMask (Device dev, int session_table_index)
 Add a RPC session mask to a Device. RPC clients typically do this when decoding a Device received from a RPC remote. More...
 
std::string ReduceKind2String (ReduceKind kind)
 Converts ReduceKind to string. More...
 
Module LoadVMModule (std::string path, Device device)
 Load a runtime Module, then create and initialize a RelaxVM. More...
 
NDArray DiscoEmptyNDArray (ShapeTuple shape, DataType dtype, Device device)
 Create an uninitialized empty NDArray. More...
 
void AllReduce (NDArray send, ReduceKind reduce_kind, NDArray recv)
 Perform an allreduce operation using the underlying communication library. More...
 
void AllGather (NDArray send, NDArray recv)
 Perform an allgather operation using the underlying communication library. More...
 
void BroadcastFromWorker0 (NDArray send, NDArray recv)
 Perform a broadcast operation from worker-0. More...
 
void ScatterFromWorker0 (Optional< NDArray > send, NDArray recv)
 Perform a scatter operation from worker-0, chunking the given buffer into equal parts. More...
 
void GatherToWorker0 (NDArray send, Optional< NDArray > recv)
 Perform a gather operation to worker-0. More...
 
void RecvFromWorker0 (NDArray buffer)
 Receive a buffer from worker-0. No-op if the current worker is worker-0. More...
 
int WorkerId ()
 Get the local worker id. More...
 
void SyncWorker ()
 Called by the worker thread. Waiting until the worker completes all its tasks. As a specific example, on a CUDA worker, it blocks until all kernels are launched and cudaStreamSynchronize is complete. More...
 
std::string DiscoAction2String (DiscoAction action)
 Converts the enum class DiscoAction to string. More...
 
template<typename T , typename... Args>
ObjectPtr< T > make_object (Args &&... args)
 Allocate an object using default allocator. More...
 
template<typename ArrayType , typename ElemType , typename... Args>
ObjectPtr< ArrayType > make_inplace_array_object (size_t num_elems, Args &&... args)
 
bool RuntimeEnabled (const String &target)
 Check if runtime module is enabled for target. More...
 
std::ostream & operator<< (std::ostream &out, const Module &module)
 
std::string SanitizeName (const std::string &name)
 Sanitize name for output into compiler artifacts. More...
 
bool SaveDLTensor (dmlc::Stream *strm, const DLTensor *tensor)
 Save a DLTensor to stream. More...
 
size_t GetDataSize (const DLTensor &arr)
 return the size of data the DLTensor hold, in term of number of bytes More...
 
ObjectTVMArrayHandleToObjectHandle (TVMArrayHandle handle)
 
template<typename RelayRefType , typename ObjectType >
RelayRefType GetRef (const ObjectType *ptr)
 Get a reference type from a raw object ptr type. More...
 
template<typename SubRef , typename BaseRef >
SubRef Downcast (BaseRef ref)
 Downcast a base reference type to a more specific type. More...
 
template<typename BaseType , typename ObjectType >
ObjectPtr< BaseType > GetObjectPtr (ObjectType *ptr)
 Get an object ptr type from a raw object ptr. More...
 
template<typename RefType , typename ObjType >
RefType GetRef (const ObjType *ptr)
 
template<typename BaseType , typename ObjType >
ObjectPtr< BaseType > GetObjectPtr (ObjType *ptr)
 
const char * ArgTypeCode2Str (int type_code)
 Convert argument type code to string. More...
 
const char * DLDeviceType2Str (int type)
 The name of DLDeviceType. More...
 
template<typename... Args>
void TVM_ALWAYS_INLINE PackArgs (TVMValue *values, int *type_codes, Args &&... args)
 
Timer DefaultTimer (Device dev)
 Default timer if one does not exist for the device. More...
 
void EnvCheckSignals ()
 Check if signals have been sent to the process and if so invoke the registered signal handler in the frontend environment. More...
 
template<typename T >
void parallel_for_with_threading_backend (T flambda, int64_t begin, int64_t end)
 

Variables

template<typename T , typename IterType >
constexpr bool is_valid_iterator_v = is_valid_iterator<T, IterType>::value
 
template<typename T >
constexpr bool is_tvm_array = false
 
template<typename T >
constexpr bool is_tvm_array< Array< T > > = true
 
constexpr int kAllocAlignment = 64
 Number of bytes each allocation must align to. More...
 
constexpr int kTempAllocaAlignment = 64
 Number of bytes each allocation must align to in temporary allocation. More...
 
constexpr int kMaxStackAlloca = 1024
 Maximum size that can be allocated on stack. More...
 
constexpr int kDefaultWorkspaceAlignment = 1
 Number of bytes each allocation must align to by default in the workspace buffer to service intermediate tensors. More...
 
constexpr int kRPCSessMask = 128
 The device type bigger than this is RPC device. More...
 
constexpr uint64_t kTVMNDArrayMagic = 0xDD5E40F096B4A13F
 Magic number for NDArray file. More...
 

Typedef Documentation

◆ FSig

using tvm::runtime::FSig = typedef std::string()

Using static function to output TypedPackedFunc signature.

◆ IntTuple

◆ IntTupleObj

Enumeration Type Documentation

◆ DeviceAttrKind

the query type into GetAttr

Enumerator
kExist 
kMaxThreadsPerBlock 
kWarpSize 
kMaxSharedMemoryPerBlock 
kComputeVersion 
kDeviceName 
kMaxClockRate 
kMultiProcessorCount 
kMaxThreadDimensions 
kMaxRegistersPerBlock 
kGcnArch 
kApiVersion 
kDriverVersion 
kL2CacheSizeBytes 
kTotalGlobalMemory 

◆ DiscoAction

enum tvm::runtime::DiscoAction : int32_t
strong

All possible kinds of Disco commands.

Enumerator
kShutDown 
kKillReg 
kGetGlobalFunc 
kCallPacked 
kSyncWorker 
kCopyFromWorker0 
kCopyToWorker0 
kDebugGetFromRemote 
kDebugSetRegister 

◆ ModulePropertyMask

Property of runtime module We classify the property of runtime module into the following categories.

Enumerator
kBinarySerializable 

kBinarySerializable we can serialize the module to the stream of bytes. CUDA/OpenCL/JSON runtime are representative examples. A binary exportable module can be integrated into final runtime artifact by being serialized as data into the artifact, then deserialized at runtime. This class of modules must implement SaveToBinary, and have a matching deserializer registered as 'runtime.module.loadbinary_<type_key>'.

kRunnable 

kRunnable we can run the module directly. LLVM/CUDA/JSON runtime, executors (e.g, virtual machine) runtimes are runnable. Non-runnable modules, such as CSourceModule, requires a few extra steps (e.g,. compilation, link) to make it runnable.

kDSOExportable 

kDSOExportable we can export the module as DSO. A DSO exportable module (e.g., a CSourceModuleNode of type_key 'c') can be incorporated into the final runtime artifact (ie shared library) by compilation and/or linking using the external compiler (llvm, nvcc, etc). DSO exportable modules must implement SaveToFile. In general, DSO exportable modules are not runnable unless there is a special support like JIT for LLVMModule.

◆ ReduceKind

enum tvm::runtime::ReduceKind : int32_t
strong

Possible kinds of reduction operations.

Enumerator
kSum 
kProd 
kMin 
kMax 
kAvg 

Function Documentation

◆ AddRPCSessionMask()

Device tvm::runtime::AddRPCSessionMask ( Device  dev,
int  session_table_index 
)
inline

Add a RPC session mask to a Device. RPC clients typically do this when decoding a Device received from a RPC remote.

Parameters
devA Device without any RPC Session mask, valid on the RPC server.
session_table_indexNumeric index of the RPC session in the session table.
Returns
A Device with RPC session mask added, valid on the RPC client.

◆ AllGather()

void tvm::runtime::AllGather ( NDArray  send,
NDArray  recv 
)

Perform an allgather operation using the underlying communication library.

Parameters
sendThe array send to perform allgather on
recvThe array receives the outcome of allgather

◆ AllReduce()

void tvm::runtime::AllReduce ( NDArray  send,
ReduceKind  reduce_kind,
NDArray  recv 
)

Perform an allreduce operation using the underlying communication library.

Parameters
sendThe array send to perform allreduce on
reduce_kindThe kind of reduction operation (e.g. sum, avg, min, max)
recvThe array receives the outcome of allreduce

◆ AppendADT()

void tvm::runtime::AppendADT ( std::ostream &  os,
const ADT adt,
const DLDevice &  host_device,
bool  show_content = true 
)

◆ AppendNDArray()

void tvm::runtime::AppendNDArray ( std::ostream &  os,
const NDArray nd_array,
const DLDevice &  host_device,
bool  show_content = true 
)

Helpers to describe runtime objects in human-friendly form. For nd_arrays we show their shapes and dtypes, but also their contents if 'small' and on the host_device (mostly so that we can see dynamic shapes as they are computed). For adts we show the ADT fields. For objects we dispatch to one of the above as appropriate.

◆ AppendRuntimeObject()

void tvm::runtime::AppendRuntimeObject ( std::ostream &  os,
const ObjectRef object,
const DLDevice &  host_device,
bool  show_content = true 
)

◆ ArgTypeCode2Str()

const char * tvm::runtime::ArgTypeCode2Str ( int  type_code)
inline

Convert argument type code to string.

Parameters
type_codeThe input type code.
Returns
The corresponding string repr.

◆ AsLegacyRepr()

std::string tvm::runtime::AsLegacyRepr ( const ObjectRef n)
inline

◆ BroadcastFromWorker0()

void tvm::runtime::BroadcastFromWorker0 ( NDArray  send,
NDArray  recv 
)

Perform a broadcast operation from worker-0.

Parameters
sendThe buffer to be broadcasted
recvThe buffer receives the broadcasted array

◆ Concat()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
Array<T> tvm::runtime::Concat ( Array< T >  lhs,
const Array< T > &  rhs 
)
inline

Concat two Arrays.

Parameters
lhsfirst Array to be concatenated.
rhssecond Array to be concatenated.
Returns
The concatenated Array. Original Arrays are kept unchanged.

◆ DefaultTimer()

Timer tvm::runtime::DefaultTimer ( Device  dev)

Default timer if one does not exist for the device.

Parameters
devThe device to time on.

Note that this timer performs synchronization between the device and CPU, which can lead to overhead in the reported results.

◆ DiscoAction2String()

std::string tvm::runtime::DiscoAction2String ( DiscoAction  action)
inline

Converts the enum class DiscoAction to string.

◆ DiscoEmptyNDArray()

NDArray tvm::runtime::DiscoEmptyNDArray ( ShapeTuple  shape,
DataType  dtype,
Device  device 
)

Create an uninitialized empty NDArray.

Parameters
shapeThe shape of the NDArray
dtypeThe dtype of the NDArray
deviceThe device the NDArray is created on. If None, use the thread local default device
Returns
The NDArray created

◆ DLDataType2String()

std::string tvm::runtime::DLDataType2String ( DLDataType  t)
inline

convert a TVM type to string.

Parameters
tThe type to be converted.
Returns
The corresponding tvm type in string.

◆ DLDataTypeCode2Str()

const char * tvm::runtime::DLDataTypeCode2Str ( DLDataTypeCode  type_code)
inline

Convert type code to its name.

Parameters
type_codeThe type code .
Returns
The name of type code.

◆ DLDeviceType2Str()

const char* tvm::runtime::DLDeviceType2Str ( int  type)
inline

The name of DLDeviceType.

Parameters
typeThe device type.
Returns
the device name.

◆ Downcast()

template<typename SubRef , typename BaseRef >
SubRef tvm::runtime::Downcast ( BaseRef  ref)
inline

Downcast a base reference type to a more specific type.

Parameters
refThe input reference
Returns
The corresponding SubRef.
Template Parameters
SubRefThe target specific reference type.
BaseRefthe current reference type.

◆ EnvCheckSignals()

void tvm::runtime::EnvCheckSignals ( )

Check if signals have been sent to the process and if so invoke the registered signal handler in the frontend environment.

When running TVM in another language (Python), the signal handler may not be immediately executed, but instead the signal is marked in the interpreter state (to ensure non-blocking of the signal handler).

This function can be explicitly invoked to check the cached signal and run the related processing if a signal is marked.

On Linux, when siginterrupt() is set, invoke this function whenever a syscall returns EINTR. When it is not set, invoke it between long-running syscalls when you will not immediately return to the frontend. On Windows, the same rules apply, but due to differences in signal processing, these are likely to only make a difference when used with Ctrl+C and socket calls.

Not inserting this function will not cause any correctness issue, but will delay invoking the Python-side signal handler until the function returns to the Python side. This means that the effect of e.g. pressing Ctrl+C or sending signals the process will be delayed until function return. When a C function is blocked on a syscall such as accept(), it needs to be called when EINTR is received. So this function is not needed in most API functions, which can finish quickly in a reasonable, deterministic amount of time.

int check_signal_every_k_iter = 10;
for (int iter = 0; iter < very_large_number; ++iter) {
if (iter % check_signal_every_k_iter == 0) {
}
// do work here
}
void EnvCheckSignals()
Check if signals have been sent to the process and if so invoke the registered signal handler in the ...
Note
This function is a nop when no PyErr_CheckSignals is registered.
Exceptions
Thisfunction throws an exception when the frontend signal handler indicate an error happens, otherwise it returns normally.

◆ GatherToWorker0()

void tvm::runtime::GatherToWorker0 ( NDArray  send,
Optional< NDArray recv 
)

Perform a gather operation to worker-0.

Parameters
sendThe sending buffer, which must not be None.
recvFor worker-0, it must be provided, and otherwise, the buffer must be None. The receiving buffer will be divided into equal parts and receive from each worker accordingly.

◆ GetCustomTypeName()

std::string tvm::runtime::GetCustomTypeName ( uint8_t  type_code)

Runtime utility for getting custom type name from code.

Parameters
type_codeCustom type code
Returns
Custom type name

◆ GetCustomTypeRegistered()

bool tvm::runtime::GetCustomTypeRegistered ( uint8_t  type_code)

Runtime utility for checking whether custom type is registered.

Parameters
type_codeCustom type code
Returns
Bool representing whether type is registered

◆ GetDataSize()

size_t tvm::runtime::GetDataSize ( const DLTensor &  arr)
inline

return the size of data the DLTensor hold, in term of number of bytes

Parameters
arrthe input DLTensor
Returns
number of bytes of data in the DLTensor.

◆ GetObjectPtr() [1/2]

template<typename BaseType , typename ObjectType >
ObjectPtr<BaseType> tvm::runtime::GetObjectPtr ( ObjectType *  ptr)
inline

Get an object ptr type from a raw object ptr.

Parameters
ptrThe object pointer
Template Parameters
BaseTypeThe reference type
ObjectTypeThe object type
Returns
The corresponding RefType

◆ GetObjectPtr() [2/2]

template<typename BaseType , typename ObjType >
ObjectPtr<BaseType> tvm::runtime::GetObjectPtr ( ObjType *  ptr)
inline

◆ GetRef() [1/2]

template<typename RelayRefType , typename ObjectType >
RelayRefType tvm::runtime::GetRef ( const ObjectType *  ptr)
inline

Get a reference type from a raw object ptr type.

It is always important to get a reference type if we want to return a value as reference or keep the object alive beyond the scope of the function.

Parameters
ptrThe object pointer
Template Parameters
RefTypeThe reference type
ObjectTypeThe object type
Returns
The corresponding RefType

◆ GetRef() [2/2]

template<typename RefType , typename ObjType >
RefType tvm::runtime::GetRef ( const ObjType *  ptr)
inline

◆ GetRPCSessionIndex()

int tvm::runtime::GetRPCSessionIndex ( Device  dev)
inline

Return the RPCSessTable index of the RPC Session that owns this device.

Returns
the table index.

◆ GetVectorBytes()

int tvm::runtime::GetVectorBytes ( DataType  dtype)
inline

Get the number of bytes needed in a vector.

Parameters
dtypeThe data type.
Returns
Number of bytes needed.

◆ IsRPCSessionDevice()

bool tvm::runtime::IsRPCSessionDevice ( Device  dev)
inline

Return true if a Device is owned by an RPC session.

◆ LoadVMModule()

Module tvm::runtime::LoadVMModule ( std::string  path,
Device  device 
)

Load a runtime Module, then create and initialize a RelaxVM.

Parameters
pathThe path to the runtime Module (a DSO file) to be loaded
deviceThe default device used to initialize the RelaxVM
Returns
The RelaxVM as a runtime Module

◆ make_inplace_array_object()

template<typename ArrayType , typename ElemType , typename... Args>
ObjectPtr<ArrayType> tvm::runtime::make_inplace_array_object ( size_t  num_elems,
Args &&...  args 
)
inline

◆ make_object() [1/2]

template<>
ObjectPtr< MapNode > tvm::runtime::make_object ( )
inlinedelete

◆ make_object() [2/2]

template<typename T , typename... Args>
ObjectPtr< T > tvm::runtime::make_object ( Args &&...  args)
inline

Allocate an object using default allocator.

Parameters
argsarguments to the constructor.
Template Parameters
Tthe node type.
Returns
The ObjectPtr to the allocated object.

◆ Merge()

template<typename K , typename V , typename = typename std::enable_if<std::is_base_of<ObjectRef, K>::value>::type, typename = typename std::enable_if<std::is_base_of<ObjectRef, V>::value>::type>
Map<K, V> tvm::runtime::Merge ( Map< K, V >  lhs,
const Map< K, V > &  rhs 
)
inline

Merge two Maps.

Parameters
lhsthe first Map to merge.
rhsthe second Map to merge.
Returns
The merged Array. Original Maps are kept unchanged.

◆ operator!=() [1/5]

bool tvm::runtime::operator!= ( const char *  lhs,
const String rhs 
)
inline

◆ operator!=() [2/5]

bool tvm::runtime::operator!= ( const std::string &  lhs,
const String rhs 
)
inline

◆ operator!=() [3/5]

bool tvm::runtime::operator!= ( const String lhs,
const char *  rhs 
)
inline

◆ operator!=() [4/5]

bool tvm::runtime::operator!= ( const String lhs,
const std::string &  rhs 
)
inline

◆ operator!=() [5/5]

bool tvm::runtime::operator!= ( const String lhs,
const String rhs 
)
inline

◆ operator+() [1/5]

String tvm::runtime::operator+ ( const char *  lhs,
const String rhs 
)
inline

◆ operator+() [2/5]

String tvm::runtime::operator+ ( const std::string &  lhs,
const String rhs 
)
inline

◆ operator+() [3/5]

String tvm::runtime::operator+ ( const String lhs,
const char *  rhs 
)
inline

◆ operator+() [4/5]

String tvm::runtime::operator+ ( const String lhs,
const std::string &  rhs 
)
inline

◆ operator+() [5/5]

String tvm::runtime::operator+ ( const String lhs,
const String rhs 
)
inline

◆ operator<() [1/5]

bool tvm::runtime::operator< ( const char *  lhs,
const String rhs 
)
inline

◆ operator<() [2/5]

bool tvm::runtime::operator< ( const std::string &  lhs,
const String rhs 
)
inline

◆ operator<() [3/5]

bool tvm::runtime::operator< ( const String lhs,
const char *  rhs 
)
inline

◆ operator<() [4/5]

bool tvm::runtime::operator< ( const String lhs,
const std::string &  rhs 
)
inline

◆ operator<() [5/5]

bool tvm::runtime::operator< ( const String lhs,
const String rhs 
)
inline

◆ operator<<() [1/7]

std::ostream& tvm::runtime::operator<< ( std::ostream &  os,
const DataType dtype 
)
inline

◆ operator<<() [2/7]

std::ostream& tvm::runtime::operator<< ( std::ostream &  os,
const ObjectRef n 
)
inline

◆ operator<<() [3/7]

std::ostream& tvm::runtime::operator<< ( std::ostream &  os,
const ShapeTuple shape 
)
inline

◆ operator<<() [4/7]

std::ostream& tvm::runtime::operator<< ( std::ostream &  os,
DLDataType  t 
)
inline

◆ operator<<() [5/7]

std::ostream & tvm::runtime::operator<< ( std::ostream &  os,
DLDevice  dev 
)
inline

◆ operator<<() [6/7]

std::ostream& tvm::runtime::operator<< ( std::ostream &  out,
const Module module 
)
inline

◆ operator<<() [7/7]

std::ostream& tvm::runtime::operator<< ( std::ostream &  out,
const String input 
)
inline

◆ operator<=() [1/5]

bool tvm::runtime::operator<= ( const char *  lhs,
const String rhs 
)
inline

◆ operator<=() [2/5]

bool tvm::runtime::operator<= ( const std::string &  lhs,
const String rhs 
)
inline

◆ operator<=() [3/5]

bool tvm::runtime::operator<= ( const String lhs,
const char *  rhs 
)
inline

◆ operator<=() [4/5]

bool tvm::runtime::operator<= ( const String lhs,
const std::string &  rhs 
)
inline

◆ operator<=() [5/5]

bool tvm::runtime::operator<= ( const String lhs,
const String rhs 
)
inline

◆ operator==() [1/5]

bool tvm::runtime::operator== ( const char *  lhs,
const String rhs 
)
inline

◆ operator==() [2/5]

bool tvm::runtime::operator== ( const std::string &  lhs,
const String rhs 
)
inline

◆ operator==() [3/5]

bool tvm::runtime::operator== ( const String lhs,
const char *  rhs 
)
inline

◆ operator==() [4/5]

bool tvm::runtime::operator== ( const String lhs,
const std::string &  rhs 
)
inline

◆ operator==() [5/5]

bool tvm::runtime::operator== ( const String lhs,
const String rhs 
)
inline

◆ operator>() [1/5]

bool tvm::runtime::operator> ( const char *  lhs,
const String rhs 
)
inline

◆ operator>() [2/5]

bool tvm::runtime::operator> ( const std::string &  lhs,
const String rhs 
)
inline

◆ operator>() [3/5]

bool tvm::runtime::operator> ( const String lhs,
const char *  rhs 
)
inline

◆ operator>() [4/5]

bool tvm::runtime::operator> ( const String lhs,
const std::string &  rhs 
)
inline

◆ operator>() [5/5]

bool tvm::runtime::operator> ( const String lhs,
const String rhs 
)
inline

◆ operator>=() [1/5]

bool tvm::runtime::operator>= ( const char *  lhs,
const String rhs 
)
inline

◆ operator>=() [2/5]

bool tvm::runtime::operator>= ( const std::string &  lhs,
const String rhs 
)
inline

◆ operator>=() [3/5]

bool tvm::runtime::operator>= ( const String lhs,
const char *  rhs 
)
inline

◆ operator>=() [4/5]

bool tvm::runtime::operator>= ( const String lhs,
const std::string &  rhs 
)
inline

◆ operator>=() [5/5]

bool tvm::runtime::operator>= ( const String lhs,
const String rhs 
)
inline

◆ PackArgs()

template<typename... Args>
void TVM_ALWAYS_INLINE tvm::runtime::PackArgs ( TVMValue values,
int *  type_codes,
Args &&...  args 
)

◆ parallel_for_with_threading_backend()

template<typename T >
void tvm::runtime::parallel_for_with_threading_backend ( flambda,
int64_t  begin,
int64_t  end 
)
inline

◆ ParseCustomDatatype()

uint8_t tvm::runtime::ParseCustomDatatype ( const std::string &  s,
const char **  scan 
)

Runtime utility for parsing string of the form "custom[<typename>]".

Parameters
sString to parse
scanpointer to parsing pointer, which is scanning across s
Returns
type code of custom type parsed

◆ RecvFromWorker0()

void tvm::runtime::RecvFromWorker0 ( NDArray  buffer)

Receive a buffer from worker-0. No-op if the current worker is worker-0.

Parameters
bufferThe buffer to be received

◆ ReduceKind2String()

std::string tvm::runtime::ReduceKind2String ( ReduceKind  kind)
inline

Converts ReduceKind to string.

◆ RemoveRPCSessionMask()

Device tvm::runtime::RemoveRPCSessionMask ( Device  dev)
inline

Remove the RPC session mask from a Device. RPC clients typically do this when encoding a Device for transmission to an RPC remote. On the wire, RPCdevice are expected to be valid on the server without interpretation.

Parameters
devA Device with non-zero RPC Session mask, valid on the RPC client.
Returns
A Device without any RPC Session mask, valid on the RPC server.

◆ RuntimeEnabled()

bool tvm::runtime::RuntimeEnabled ( const String target)

Check if runtime module is enabled for target.

Parameters
targetThe target module name.
Returns
Whether runtime is enabled.

◆ RuntimeObject2String()

std::string tvm::runtime::RuntimeObject2String ( const ObjectRef object,
const DLDevice &  host_device,
bool  show_content = true 
)

◆ SanitizeName()

std::string tvm::runtime::SanitizeName ( const std::string &  name)

Sanitize name for output into compiler artifacts.

Parameters
nameOriginal name
Returns
Sanitized name

◆ SaveDLTensor()

bool tvm::runtime::SaveDLTensor ( dmlc::Stream *  strm,
const DLTensor *  tensor 
)
inline

Save a DLTensor to stream.

Parameters
strmThe output stream
tensorThe tensor to be saved.

◆ ScatterFromWorker0()

void tvm::runtime::ScatterFromWorker0 ( Optional< NDArray send,
NDArray  recv 
)

Perform a scatter operation from worker-0, chunking the given buffer into equal parts.

Parameters
sendFor worker-0, it must be provided, and otherwise, the buffer must be None. The buffer will be divided into equal parts and sent to each worker accordingly.
recvThe receiving buffer, which must not be None.

◆ String2DLDataType()

DLDataType tvm::runtime::String2DLDataType ( std::string  s)
inline

convert a string to TVM type.

Parameters
sThe string to be converted.
Returns
The corresponding tvm type.

◆ SyncWorker()

void tvm::runtime::SyncWorker ( )

Called by the worker thread. Waiting until the worker completes all its tasks. As a specific example, on a CUDA worker, it blocks until all kernels are launched and cudaStreamSynchronize is complete.

◆ TVMArrayHandleToObjectHandle()

Object* tvm::runtime::TVMArrayHandleToObjectHandle ( TVMArrayHandle  handle)
inline

◆ TypeEqual()

bool tvm::runtime::TypeEqual ( DLDataType  lhs,
DLDataType  rhs 
)
inline

Check whether two types are equal .

Parameters
lhsThe left operand.
rhsThe right operand.

◆ TypeMatch()

bool tvm::runtime::TypeMatch ( DLDataType  t,
int  code,
int  bits,
int  lanes = 1 
)
inline

Check whether type matches the given spec.

Parameters
tThe type
codeThe type code.
bitsThe number of bits to be matched.
lanesThe number of lanes in the type.

◆ WorkerId()

int tvm::runtime::WorkerId ( )

Get the local worker id.

Variable Documentation

◆ is_tvm_array

template<typename T >
constexpr bool tvm::runtime::is_tvm_array = false
inlineconstexpr

◆ is_tvm_array< Array< T > >

template<typename T >
constexpr bool tvm::runtime::is_tvm_array< Array< T > > = true
inlineconstexpr

◆ is_valid_iterator_v

template<typename T , typename IterType >
constexpr bool tvm::runtime::is_valid_iterator_v = is_valid_iterator<T, IterType>::value
inlineconstexpr

◆ kAllocAlignment

constexpr int tvm::runtime::kAllocAlignment = 64
constexpr

Number of bytes each allocation must align to.

◆ kDefaultWorkspaceAlignment

constexpr int tvm::runtime::kDefaultWorkspaceAlignment = 1
constexpr

Number of bytes each allocation must align to by default in the workspace buffer to service intermediate tensors.

◆ kMaxStackAlloca

constexpr int tvm::runtime::kMaxStackAlloca = 1024
constexpr

Maximum size that can be allocated on stack.

◆ kRPCSessMask

constexpr int tvm::runtime::kRPCSessMask = 128
constexpr

The device type bigger than this is RPC device.

◆ kTempAllocaAlignment

constexpr int tvm::runtime::kTempAllocaAlignment = 64
constexpr

Number of bytes each allocation must align to in temporary allocation.

◆ kTVMNDArrayMagic

constexpr uint64_t tvm::runtime::kTVMNDArrayMagic = 0xDD5E40F096B4A13F
constexpr

Magic number for NDArray file.