Skip to main content

MemoryClass

Enum MemoryClass 

Source
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.

ValueVariant
0x00Standard
0x01HostPinned
0x02Unified
0x03Peer
0x04–0xEFreserved → Error::ReservedMemoryClass
0xF0–0xFEPrivate(b)
0xFFpermanently 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

Source

pub fn from_byte(b: u8) -> Result<Self>

Parses a MemoryClass from its one-byte wire representation.

§Errors
§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))));
Source

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);
Source

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

Source§

fn clone(&self) -> MemoryClass

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MemoryClass

Source§

impl Debug for MemoryClass

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MemoryClass

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

§Examples
use hurray_core::MemoryClass;

assert_eq!(MemoryClass::Standard.to_string(), "standard");
assert_eq!(MemoryClass::Unified.to_string(), "unified");
Source§

impl Eq for MemoryClass

Source§

impl Hash for MemoryClass

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MemoryClass

Source§

fn eq(&self, other: &MemoryClass) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for MemoryClass

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.