Skip to main content

themis/law/
memory.rs

1//! Memory locality tiers.
2
3/// Memory tier classification.
4///
5/// Host-allocatable tiers (`Dram`, `Hbm`, `Gddr`, `HostPinned`, `Device`,
6/// `Persistent`) are valid allocation targets for allocators such as
7/// mnemosyne. The device-side tiers `Registers` and `SharedMem` are
8/// **budgeted, non-host-allocatable** (atlas ADR 0002): GPU compilers assign
9/// registers and kernels declare shared memory at launch, so these variants
10/// exist purely as the typed vocabulary for capacity queries and kernel
11/// resource budgets (occupancy planning) — never as allocation requests.
12/// [`MemoryTier::is_host_allocatable`] encodes the distinction.
13#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
14pub enum MemoryTier {
15    /// Standard host DRAM.
16    #[default]
17    Dram,
18    /// High-bandwidth memory (host- or device-attached HBM stacks).
19    Hbm,
20    /// Device-attached GDDR memory (discrete-GPU global memory that is not
21    /// HBM; distinct bandwidth/latency law from `Hbm`).
22    Gddr,
23    /// Page-locked (pinned) host memory for DMA staging transfers.
24    HostPinned,
25    /// Device-local memory of an unspecified technology.
26    Device,
27    /// Persistent memory.
28    Persistent,
29    /// GPU register file capacity (budgeted; compiler-assigned, never
30    /// host-allocated).
31    Registers,
32    /// GPU shared/local memory per compute unit (budgeted; declared at
33    /// kernel launch, never host-allocated).
34    SharedMem,
35}
36
37impl MemoryTier {
38    /// Returns true when the tier is a valid host-side allocation target.
39    ///
40    /// `Registers` and `SharedMem` return false: they are budget/capacity
41    /// vocabulary for occupancy planning, not allocatable address space.
42    #[must_use]
43    #[inline]
44    pub const fn is_host_allocatable(self) -> bool {
45        !matches!(self, Self::Registers | Self::SharedMem)
46    }
47}