pub enum MemoryClass {
Standard,
HostPinned,
Unified,
Peer,
Private(PrivateMemoryClass),
}Expand description
The memory access class of a buffer handle.
Identifies how a buffer is accessible — whether it is device-exclusive or can be accessed by the CPU and/or peer accelerators without copying.
The memory_class field in the binary buffer handle is a single uint8 at
offset 14. Use MemoryClass::from_byte to parse and MemoryClass::to_byte
to serialize. See docs/spec/buffer-protocol.md § Memory Class for the
normative definition.
| Value | Variant |
|---|---|
0x00 | Standard |
0x01 | HostPinned |
0x02 | Unified |
0x03 | Peer |
0x04–0xEF | reserved → Error::ReservedMemoryClass |
0xF0–0xFE | Private(b) |
0xFF | permanently invalid → Error::InvalidMemoryClass |
§Examples
use hurray_core::{MemoryClass, Error};
assert_eq!(MemoryClass::from_byte(0x00).unwrap(), MemoryClass::Standard);
assert_eq!(MemoryClass::from_byte(0x02).unwrap(), MemoryClass::Unified);
assert!(matches!(MemoryClass::from_byte(0x04), Err(Error::ReservedMemoryClass(0x04))));
assert!(matches!(MemoryClass::from_byte(0xFF), Err(Error::InvalidMemoryClass(0xFF))));Variants§
Standard
Device-exclusive memory. Only the primary compute unit of the tagged device
can access this buffer without a copy. Default for all device types; backward-
compatible with pre-ADR-020 descriptors whose _reserved[0] byte was 0x00.
HostPinned
CPU-accessible, device-mapped. No hardware-managed coherency. Examples:
cudaMallocHost, hipHostMalloc, CL_MEM_ALLOC_HOST_PTR.
Unified
Hardware-managed unified or coherent memory. CPU and device can access this
buffer simultaneously; the hardware ensures coherency. Examples:
cudaMallocManaged, ROCm HMM, Metal MTLStorageModeShared.
Peer
Peer-to-peer device memory. Accessible by a set of peer accelerators agreed out of band (NVLink, xGMI, PCIe BAR). Not CPU-accessible without a copy.
Private(PrivateMemoryClass)
Implementation-private memory class (0xF0–0xFE). Semantics agreed out of band.
Implementations§
Source§impl MemoryClass
impl MemoryClass
Sourcepub fn from_byte(b: u8) -> Result<Self>
pub fn from_byte(b: u8) -> Result<Self>
Parses a MemoryClass from its one-byte wire representation.
§Errors
Error::ReservedMemoryClass— byte is0x04–0xEF.Error::InvalidMemoryClass— byte is0xFF.
§Examples
use hurray_core::{MemoryClass, Error};
assert_eq!(MemoryClass::from_byte(0x00).unwrap(), MemoryClass::Standard);
assert_eq!(MemoryClass::from_byte(0x01).unwrap(), MemoryClass::HostPinned);
assert_eq!(MemoryClass::from_byte(0x02).unwrap(), MemoryClass::Unified);
assert_eq!(MemoryClass::from_byte(0x03).unwrap(), MemoryClass::Peer);
assert!(matches!(MemoryClass::from_byte(0x04), Err(Error::ReservedMemoryClass(0x04))));
assert!(matches!(MemoryClass::from_byte(0xEF), Err(Error::ReservedMemoryClass(0xEF))));
assert!(matches!(MemoryClass::from_byte(0xFF), Err(Error::InvalidMemoryClass(0xFF))));Sourcepub fn to_byte(self) -> u8
pub fn to_byte(self) -> u8
Returns the one-byte wire representation of this memory class.
§Examples
use hurray_core::MemoryClass;
assert_eq!(MemoryClass::Standard.to_byte(), 0x00);
assert_eq!(MemoryClass::HostPinned.to_byte(), 0x01);
assert_eq!(MemoryClass::Unified.to_byte(), 0x02);
assert_eq!(MemoryClass::Peer.to_byte(), 0x03);Sourcepub fn is_private(self) -> bool
pub fn is_private(self) -> bool
Returns true if this is an implementation-private memory class (0xF0–0xFE).
§Examples
use hurray_core::MemoryClass;
assert!(!MemoryClass::Standard.is_private());
assert!(MemoryClass::from_byte(0xF0).unwrap().is_private());Trait Implementations§
Source§impl Clone for MemoryClass
impl Clone for MemoryClass
Source§fn clone(&self) -> MemoryClass
fn clone(&self) -> MemoryClass
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more