pub mod allocator;
pub mod binding;
pub mod capability;
pub mod context_pin;
pub mod deferred;
pub use allocator::{
AllocationCommitRange, DeviceAllocator, DeviceKey, HostAllocator, MappedAllocation,
SharedDevicePrefix, SharedPrefixCommitInfo,
};
pub use binding::{
AllocationGeneration, AllocationIdentity, AuthorityIdentity, BindingError, BindingGeneration,
BindingId, BindingIdentity, BindingRegistry, BindingResource, BoundAllocation, BoundMemoryView,
BoundSharedMapping, BoundSharedPrefix, BoundVirtualBacking, ExplicitReleaseError,
MechanismCoherence, MechanismIdentity, MechanismLifecycle, MechanismSnapshot, MemoryBinding,
OwnedView, OwningAllocation, OwningReleaseError, ProviderContextIdentity, RegisteredAuthority,
RegisteredMechanism, RegisteredProviderContext, ValidatedMemoryView,
};
pub use capability::{SharedMapping, VirtualBacking};
pub use context_pin::{ProviderContextPin, ProviderContextPinError, ProviderContextPinSource};
pub use deferred::{
AllocationReleaseOutcome, AllocationReleaseState, DeferredEnqueueError,
DeferredEnqueueRejection, DeferredReleaseDisposition, DeferredReleaseQueue,
PreparedAllocationRelease, QuarantineReason, QuarantinedAllocation, ReleaseAccounting,
ReleaseFailure, ResidualOwnership,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Tier {
Device,
Host,
Disk,
}
impl Tier {
pub const ALL: [Tier; 3] = [Tier::Device, Tier::Host, Tier::Disk];
pub const fn index(self) -> usize {
match self {
Tier::Device => 0,
Tier::Host => 1,
Tier::Disk => 2,
}
}
pub const fn name(self) -> &'static str {
match self {
Tier::Device => "device",
Tier::Host => "host",
Tier::Disk => "disk",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MemoryRole {
KvCache,
Workspace { step_scoped: bool },
Weights,
Activation,
}
#[derive(Debug, thiserror::Error)]
pub enum MemoryError {
#[error(
"cannot reserve {requested} bytes of {tier} memory for {role:?}: {used} of {limit} bytes \
are already leased, leaving {available}; free memory by closing sessions, lower the \
demand, or raise the {tier} limit"
)]
TierExhausted {
tier: &'static str,
requested: u64,
used: u64,
limit: u64,
available: u64,
role: MemoryRole,
},
#[error("cannot reserve {requested} bytes of {tier} memory: {reason}")]
InvalidRequest {
tier: &'static str,
requested: u64,
reason: &'static str,
},
#[error("cannot allocate {requested} bytes of {tier} memory: {reason}")]
AllocationFailed {
tier: &'static str,
requested: u64,
reason: String,
},
#[error(
"cannot make {requested} bytes of {tier} capacity available for {role:?}: only \
{available} bytes became available; {detail}"
)]
CapacityUnavailable {
tier: &'static str,
requested: u64,
available: u64,
role: MemoryRole,
detail: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tier_order_and_names_are_stable() {
assert_eq!(Tier::ALL, [Tier::Device, Tier::Host, Tier::Disk]);
assert_eq!(Tier::Device.name(), "device");
assert_eq!(Tier::Host.name(), "host");
assert_eq!(Tier::Disk.name(), "disk");
}
}