24 #ifndef TVM_RUNTIME_DEVICE_API_H_ 25 #define TVM_RUNTIME_DEVICE_API_H_ 54 #ifdef TVM_KALLOC_ALIGNMENT 62 constexpr
int kAllocAlignment = 64;
65 constexpr
int kTempAllocaAlignment = 64;
66 #endif // TVM_KALLOC_ALIGNMENT 87 virtual void SetDevice(
Device dev) = 0;
114 virtual void* AllocDataSpace(
Device dev,
size_t nbytes,
size_t alignment,
115 DLDataType type_hint) = 0;
125 virtual void* AllocDataSpace(
Device dev,
int ndim,
const int64_t*
shape, DLDataType dtype,
132 virtual void FreeDataSpace(
Device dev,
void* ptr) = 0;
141 virtual void CopyDataFromTo(DLTensor* from, DLTensor* to,
TVMStreamHandle stream);
198 virtual void* AllocWorkspace(
Device dev,
size_t nbytes, DLDataType type_hint = {});
205 virtual void FreeWorkspace(
Device dev,
void* ptr);
221 return device_type != kDLCPU && device_type !=
kDLMicroDev;
238 virtual void CopyDataFromTo(
const void* from,
size_t from_offset,
void* to,
size_t to_offset,
261 return "cuda_managed";
291 LOG(FATAL) <<
"unknown type =" << type;
306 return dev.device_type / kRPCSessMask - 1;
317 dev.device_type =
static_cast<DLDeviceType
>(dev.device_type %
kRPCSessMask);
321 inline std::ostream&
operator<<(std::ostream& os, DLDevice dev) {
326 os << tvm::runtime::DeviceName(static_cast<int>(dev.device_type)) <<
"(" << dev.device_id <<
")";
338 CHECK(!
IsRPCSessionDevice(dev)) <<
"AddRPCSessionMask: dev already non-zero RPCSessionIndex: " 341 static_cast<DLDeviceType
>(dev.device_type | (kRPCSessMask * (session_table_index + 1)));
348 #endif // TVM_RUNTIME_DEVICE_API_H_ std::ostream & operator<<(std::ostream &os, const ObjectRef &n)
Definition: repr_printer.h:97
Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlyi...
Definition: packed_func.h:799
constexpr const char * device_type
The device type.
Definition: stmt.h:1355
Definition: c_runtime_api.h:125
Definition: device_api.h:50
constexpr int kDefaultWorkspaceAlignment
Number of bytes each allocation must align to by default in the workspace buffer to service intermedi...
Definition: device_api.h:73
Definition: c_runtime_api.h:122
constexpr int kMaxStackAlloca
Maximum size that can be allocated on stack.
Definition: device_api.h:69
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
TVM Runtime Device API, abstracts the device specific interface for memory management.
Definition: device_api.h:79
Definition: c_runtime_api.h:121
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:337
int GetRPCSessionIndex(Device dev)
Return the RPCSessTable index of the RPC Session that owns this device.
Definition: device_api.h:304
virtual void GetTargetProperty(Device dev, const std::string &property, TVMRetValue *rv)
Query the device for specified properties.
Definition: device_api.h:103
void * TVMStreamHandle
The stream that is specific to device can be NULL, which indicates the default one.
Definition: c_runtime_api.h:236
constexpr int kRPCSessMask
The device type bigger than this is RPC device.
Definition: device_api.h:244
virtual ~DeviceAPI()
virtual destructor
Definition: device_api.h:82
bool IsRPCSessionDevice(Device dev)
Return true if a Device is owned by an RPC session.
Definition: device_api.h:298
constexpr int kTempAllocaAlignment
Number of bytes each allocation must align to in temporary allocation.
Definition: device_api.h:65
static bool NeedSetDevice(int device_type)
Whether a certian device type requires set device device before launching the kernel function...
Definition: device_api.h:220
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:316
A device-independent managed NDArray abstraction.
Definition: device_api.h:39
Definition: c_runtime_api.h:124
Definition: c_runtime_api.h:123
Definition: device_api.h:42
Definition: device_api.h:45
Definition: device_api.h:51
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:1768
DLDevice Device
Definition: ndarray.h:43
Definition: device_api.h:41
Definition: device_api.h:49
const char * DeviceName(int type)
The name of Device API factory.
Definition: device_api.h:252
Definition: device_api.h:47
Definition: device_api.h:40
constexpr int kAllocAlignment
Number of bytes each allocation must align to.
Definition: device_api.h:62
DeviceAttrKind
the query type into GetAttr
Definition: device_api.h:38
Definition: device_api.h:44
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
constexpr runtime::NullOptType NullOpt
Definition: optional.h:160
Definition: device_api.h:46
Definition: device_api.h:48
virtual void SetStream(Device dev, TVMStreamHandle stream)
Set the stream.
Definition: device_api.h:168
Type-erased function used across TVM API.
Definition: device_api.h:43