24 #ifndef TVM_RUNTIME_DEVICE_API_H_
25 #define TVM_RUNTIME_DEVICE_API_H_
57 #ifdef TVM_KALLOC_ALIGNMENT
126 DLDataType type_hint) = 0;
262 virtual void CopyDataFromTo(
const void* from,
size_t from_offset,
void* to,
size_t to_offset,
293 dev.device_type =
static_cast<DLDeviceType
>(dev.device_type %
kRPCSessMask);
297 inline std::ostream&
operator<<(std::ostream& os, DLDevice dev) {
302 os << tvm::runtime::DLDeviceType2Str(static_cast<int>(dev.device_type)) <<
":" << dev.device_id;
314 CHECK(!
IsRPCSessionDevice(dev)) <<
"AddRPCSessionMask: dev already non-zero RPCSessionIndex: "
317 static_cast<DLDeviceType
>(dev.device_type | (
kRPCSessMask * (session_table_index + 1)));
@ kDLMicroDev
Definition: c_runtime_api.h:125
@ TVMDeviceExtType_End
Definition: c_runtime_api.h:126
void * TVMStreamHandle
The stream that is specific to device can be NULL, which indicates the default one.
Definition: c_runtime_api.h:238
TVM Runtime Device API, abstracts the device specific interface for memory management.
Definition: device_api.h:82
static bool NeedSetDevice(int device_type)
Whether a certian device type requires set device device before launching the kernel function.
Definition: device_api.h:239
static DeviceAPI * Get(Device dev, bool allow_missing=false)
Get device API based on device.
virtual void CopyDataFromTo(DLTensor *from, DLTensor *to, TVMStreamHandle stream)
copy data from one place to another
virtual TVMStreamHandle CreateStream(Device dev)
Create a new stream of execution.
virtual void SyncStreamFromTo(Device dev, TVMStreamHandle event_src, TVMStreamHandle event_dst)
Synchronize 2 streams of execution.
virtual void FreeWorkspace(Device dev, void *ptr)
Free temporal workspace in backend execution.
virtual bool SupportsDevicePointerArithmeticsOnHost()
Whether pointer arithmetics on a device owned pointer may be performed on the host.
Definition: device_api.h:246
virtual void * AllocDataSpace(Device dev, int ndim, const int64_t *shape, DLDataType dtype, Optional< String > mem_scope=NullOpt)
Allocate a data space on device with memory scope support.
virtual void SetDevice(Device dev)=0
Set the environment device id to device.
virtual void FreeStream(Device dev, TVMStreamHandle stream)
Free a stream of execution.
virtual TVMStreamHandle GetCurrentStream(Device dev)
Get the current stream.
virtual void GetTargetProperty(Device dev, const std::string &property, TVMRetValue *rv)
Query the device for specified properties.
Definition: device_api.h:114
virtual size_t GetDataSize(const DLTensor &arr, Optional< String > mem_scope=NullOpt)
Get the physical memory size required.
virtual void * AllocWorkspace(Device dev, size_t nbytes, DLDataType type_hint={})
Allocate temporal workspace for backend execution.
virtual void GetAttr(Device dev, DeviceAttrKind kind, TVMRetValue *rv)=0
Get attribute of specified device.
virtual void StreamSync(Device dev, TVMStreamHandle stream)=0
Synchronize the stream.
virtual void FreeDataSpace(Device dev, void *ptr)=0
Free a data space on device.
virtual void CopyDataFromTo(const void *from, size_t from_offset, void *to, size_t to_offset, size_t num_bytes, Device dev_from, Device dev_to, DLDataType type_hint, TVMStreamHandle stream)
copy data from one place to another
virtual void SetStream(Device dev, TVMStreamHandle stream)
Set the stream.
Definition: device_api.h:181
virtual void * AllocDataSpace(Device dev, size_t nbytes, size_t alignment, DLDataType type_hint)=0
Allocate a data space on device.
virtual ~DeviceAPI()
virtual destructor
Definition: device_api.h:85
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlyi...
Definition: packed_func.h:946
constexpr int kMaxStackAlloca
Maximum size that can be allocated on stack.
Definition: device_api.h:72
DeviceAttrKind
the query type into GetAttr
Definition: device_api.h:38
@ kDeviceName
Definition: device_api.h:44
@ kDriverVersion
Definition: device_api.h:51
@ kMaxThreadsPerBlock
Definition: device_api.h:40
@ kMultiProcessorCount
Definition: device_api.h:46
@ kMaxThreadDimensions
Definition: device_api.h:47
@ kApiVersion
Definition: device_api.h:50
@ kMaxClockRate
Definition: device_api.h:45
@ kWarpSize
Definition: device_api.h:41
@ kTotalGlobalMemory
Definition: device_api.h:53
@ kAvailableGlobalMemory
Definition: device_api.h:54
@ kMaxRegistersPerBlock
Definition: device_api.h:48
@ kComputeVersion
Definition: device_api.h:43
@ kGcnArch
Definition: device_api.h:49
@ kMaxSharedMemoryPerBlock
Definition: device_api.h:42
@ kExist
Definition: device_api.h:39
@ kL2CacheSizeBytes
Definition: device_api.h:52
constexpr int kRPCSessMask
The device type bigger than this is RPC device.
Definition: device_api.h:268
constexpr int kDefaultWorkspaceAlignment
Number of bytes each allocation must align to by default in the workspace buffer to service intermedi...
Definition: device_api.h:76
int GetRPCSessionIndex(Device dev)
Return the RPCSessTable index of the RPC Session that owns this device.
Definition: device_api.h:280
constexpr int kTempAllocaAlignment
Number of bytes each allocation must align to in temporary allocation.
Definition: device_api.h:68
bool IsRPCSessionDevice(Device dev)
Return true if a Device is owned by an RPC session.
Definition: device_api.h:274
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 fro...
Definition: device_api.h:313
constexpr int kAllocAlignment
Number of bytes each allocation must align to.
Definition: device_api.h:65
std::ostream & operator<<(std::ostream &os, const ObjectRef &n)
Definition: repr_printer.h:97
Device RemoveRPCSessionMask(Device dev)
Remove the RPC session mask from a Device. RPC clients typically do this when encoding a Device for t...
Definition: device_api.h:292
constexpr const char * device_type
The device type.
Definition: stmt.h:1422
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1913
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
DLDevice Device
Definition: ndarray.h:43
constexpr runtime::NullOptType NullOpt
Definition: optional.h:169
A device-independent managed NDArray abstraction.
Type-erased function used across TVM API.