UnifiedMemory¶
- class
UnifiedMemory
¶ Memory to manage both the host and device data.
Constructors¶
- inline
dragon::UnifiedMemory::
UnifiedMemory
()¶ Constructor.
- inline
dragon::UnifiedMemory::
UnifiedMemory
(
const TypeMeta &meta,
size_t size)¶ Constructor with the type meta and size.
Public Types¶
State¶
- enum
dragon::UnifiedMemory::
State
¶ The device-aware state for data consistency.
Values:
- enumerator
UNINITIALIZED
¶ Initial state.
- enumerator
STATE_AT_CPU
¶ Data is mutable to cpu.
- enumerator
STATE_AT_CUDA
¶ Data is mutable to cuda.
- enumerator
STATE_AT_MPS
¶ Data is mutable to mps.
- enumerator
SYNCED
¶ Data is synced between host and device.
- enumerator
Public Properties¶
cpu_data¶
- const void *
dragon::UnifiedMemory::
cpu_data
(
size_t size = 0,
size_t offset = 0)¶ Return the const cpu data.
cuda_data¶
- const void *
dragon::UnifiedMemory::
cuda_data
(
size_t size = 0,
size_t offset = 0)¶ Return the const cuda data.
device¶
- inline int
dragon::UnifiedMemory::
device
() const¶ Return the device index.
info¶
- Map<string, string>
dragon::UnifiedMemory::
info
() const¶ Return the data info.
mps_data¶
- const void *
dragon::UnifiedMemory::
mps_data
(size_t size = 0)¶ Return the const mps data.
order¶
- inline StorageOrder
dragon::UnifiedMemory::
order
() const¶ Return the storage order.
size¶
- inline size_t
dragon::UnifiedMemory::
size
() const¶ Return the data size.
size¶
- inline size_t
dragon::UnifiedMemory::
size
(
const string &device_type,
int device_id) const¶ Return the data size on given device.
state¶
- inline State
dragon::UnifiedMemory::
state
() const¶ Return the state.
mutable_cpu_data¶
- void *
dragon::UnifiedMemory::
mutable_cpu_data
(size_t size = 0)¶ Return the mutable cpu data.
mutable_cuda_data¶
- void *
dragon::UnifiedMemory::
mutable_cuda_data
(size_t size = 0)¶ Return the mutable cuda data.
set_cpu_data¶
- bool
dragon::UnifiedMemory::
set_cpu_data
(
void *cpu_ptr,
size_t size)¶ Set to use an external block of cpu data.
set_cuda_data¶
- void
dragon::UnifiedMemory::
set_cuda_data
(
void *cuda_ptr,
size_t size,
int device)¶ Set to use an external block of cuda data.
set_order¶
- inline void
dragon::UnifiedMemory::
set_order
(StorageOrder order)¶ Set the storage order.
Public Functions¶
SwitchToCUDADevice¶
- void
dragon::UnifiedMemory::
SwitchToCUDADevice
(int device)¶ Switch to the given cuda device.
SwitchToMPSDevice¶
- void
dragon::UnifiedMemory::
SwitchToMPSDevice
(int device)¶ Switch to the given mps device.
ToCPU¶
- void
dragon::UnifiedMemory::
ToCPU
(size_t size = 0)¶ Set to the cpu state.
ToCUDA¶
- void
dragon::UnifiedMemory::
ToCUDA
(size_t size = 0)¶ Set to the cuda state.
ToMPS¶
- void
dragon::UnifiedMemory::
ToMPS
(size_t size = 0)¶ Set to the cuda state.