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>
74typedef enum : int32_t {
84#ifdef TVM_KALLOC_ALIGNMENT
133 virtual ffi::Any
GetAttr(DLDevice dev,
const ffi::String& name) = 0;
143 virtual ffi::Tensor
Empty(ffi::ShapeView shape, DLDataType dtype, DLDevice device,
144 ffi::Optional<MemoryScope> mem_scope = std::nullopt) = 0;
241 static bool NeedSetDevice(
int device_type) {
return device_type != kDLCPU; }
274 virtual void CopyDataFromTo(
const void* from,
size_t from_offset,
void* to,
size_t to_offset,
293 return "cuda_managed";
317 TVM_FFI_THROW(InternalError) <<
"unknown type = " << type;
322inline std::ostream&
operator<<(std::ostream& os, DLDevice dev) {
323 os << DLDeviceType2Str(static_cast<int>(dev.device_type)) <<
":" << dev.device_id;
#define TVM_RUNTIME_DLL
Definition base.h:73
TVM Runtime Device API, abstracts the device specific interface for memory management.
Definition device_api.h:105
static bool NeedSetDevice(int device_type)
Whether a certain device type requires setting the device before launching the kernel function.
Definition device_api.h:241
virtual bool SupportsDevicePtrArithmeticOnHost()
Whether pointer arithmetics on a device owned pointer may be performed on the host.
Definition device_api.h:246
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 * GetMappedHostPtrIfAvailable(void *data)
Query an existing host mapping of a device allocation, if available.
Definition device_api.h:258
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 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< MemoryScope > 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:108
void * TVMStreamHandle
The stream that is specific to device can be NULL, which indicates the default one.
Definition device_api.h:41
Memory scopes and allocation properties for runtime storage.
TVMDeviceExtType
Extension device types in TVM.
Definition device_api.h:76
@ TVMDeviceExtType_End
Definition device_api.h:81
constexpr int kMaxStackAlloca
Maximum size that can be allocated on stack.
Definition device_api.h:99
const char * DLDeviceType2Str(int type)
The name of DLDeviceType.
Definition device_api.h:284
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:95
constexpr int kAllocAlignment
Number of bytes each allocation must align to.
Definition device_api.h:92
std::ostream & operator<<(std::ostream &os, DLDevice dev)
Definition device_api.h:322
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41
DLDevice Device
Definition device_api.h:46