24#ifndef TVM_RUNTIME_DEVICE_API_H_
25#define TVM_RUNTIME_DEVICE_API_H_
27#include <tvm/ffi/any.h>
28#include <tvm/ffi/container/tensor.h>
29#include <tvm/ffi/device.h>
30#include <tvm/ffi/error.h>
31#include <tvm/ffi/optional.h>
32#include <tvm/ffi/string.h>
73typedef enum : int32_t {
83#ifdef TVM_KALLOC_ALIGNMENT
136 virtual ffi::Any
GetAttr(DLDevice dev,
const ffi::String& name) = 0;
146 virtual ffi::Tensor
Empty(ffi::ShapeView shape, DLDataType dtype, DLDevice device,
147 ffi::Optional<ffi::String> mem_scope = std::nullopt) = 0;
244 static bool NeedSetDevice(
int device_type) {
return device_type != kDLCPU; }
265 virtual void CopyDataFromTo(
const void* from,
size_t from_offset,
void* to,
size_t to_offset,
284 return "cuda_managed";
308 TVM_FFI_THROW(InternalError) <<
"unknown type = " << type;
313inline std::ostream&
operator<<(std::ostream& os, DLDevice dev) {
314 os << DLDeviceType2Str(static_cast<int>(dev.device_type)) <<
":" << dev.device_id;
TVM Runtime Device API, abstracts the device specific interface for memory management.
Definition device_api.h:108
static bool NeedSetDevice(int device_type)
Whether a certian device type requires set device device before launching the kernel function.
Definition device_api.h:244
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:249
virtual void * AllocWorkspace(Device dev, size_t nbytes, DLDataType type_hint={})
Allocate temporal workspace for backend execution.
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 ffi::Tensor Empty(ffi::ShapeView shape, DLDataType dtype, DLDevice device, ffi::Optional< ffi::String > mem_scope=std::nullopt)=0
Create an owning, compact tensor with uninitialized contents.
virtual void StreamSync(Device dev, TVMStreamHandle stream)=0
Synchronize the stream.
virtual ffi::Any GetAttr(DLDevice dev, const ffi::String &name)=0
Query an attribute of a 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.
virtual int GetDeviceIndex()
Get the currently selected runtime device index on the calling host thread.
virtual ~DeviceAPI()
virtual destructor
Definition device_api.h:111
void * TVMStreamHandle
The stream that is specific to device can be NULL, which indicates the default one.
Definition device_api.h:40
TVMDeviceExtType
Extension device types in TVM.
Definition device_api.h:75
@ TVMDeviceExtType_End
Definition device_api.h:80
constexpr int kMaxStackAlloca
Maximum size that can be allocated on stack.
Definition device_api.h:98
constexpr int kDefaultWorkspaceAlignment
Number of bytes each allocation must align to by default in the workspace buffer to service intermedi...
Definition device_api.h:102
const char * DLDeviceType2Str(int type)
The name of DLDeviceType.
Definition device_api.h:275
TVM_RUNTIME_DLL bool RuntimeEnabled(const ffi::String &target)
Check if runtime module is enabled for target.
constexpr int kTempAllocaAlignment
Number of bytes each allocation must align to in temporary allocation.
Definition device_api.h:94
constexpr int kAllocAlignment
Number of bytes each allocation must align to.
Definition device_api.h:91
std::ostream & operator<<(std::ostream &os, DLDevice dev)
Definition device_api.h:313
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
DLDevice Device
Definition device_api.h:45
#define TVM_RUNTIME_DLL
Definition base.h:100