Skip to main content

MemoryManagement

Struct MemoryManagement 

Source
pub struct MemoryManagement<Storage> { /* private fields */ }
Expand description

Reserves and keeps track of chunks of memory in the storage, and slices upon these chunks.

Implementations§

Source§

impl<Storage: ComputeStorage> MemoryManagement<Storage>

Source

pub fn from_configuration( storage: Storage, properties: &MemoryDeviceProperties, config: MemoryConfiguration, logger: Arc<ServerLogger>, options: MemoryManagementOptions, ) -> Self

Creates the options from device limits.

Source

pub fn configure( &mut self, config: MemoryConfiguration, properties: &MemoryDeviceProperties, ) -> bool

Rebuild the dynamic pools with a new layout, in place.

The old pools are cleaned up first (every currently-free page returned to the driver). Rebuilding only happens when no live allocation remains in them — a live slice carries its pool position, so swapping the pool list under it would corrupt routing. When something is still alive, the old layout is kept and false is returned; the caller reconfigures at a quiescent point (e.g. right after unloading a model) so this is the exceptional path, not the normal one.

The persistent pool is untouched: its slices route through a fixed sentinel position and its layout is model-agnostic.

Source

pub fn capture_begin(&mut self)

Begin a graph capture: force every allocation into the persistent pool — exact-fit slices with no bucket padding, which is what a graph’s static shapes want — and start recording which slices the window hands out (see reserve). Every slice the window touches belongs to the graph at capture_end; anything it never touches (pre-existing live buffers, idle free slices) does not. Slices stay reusable within the window — warmup populates the pool, then the capture run reuses those slices without a fresh device allocation (illegal mid-capture). Sets the mode directly, overriding the config gate that mode honors. If a capture is already active, only the mode is re-forced — the original capture keeps its touched set and restore state.

Source

pub fn capture_end(&mut self) -> Vec<ManagedMemoryHandle>

End a graph capture: restore the previous allocation mode and return a retained handle to every persistent slice the window touched — exactly the memory the graph’s recorded kernels replay against. The caller pins these on the graph so the pool never reuses graph memory (which a replay would corrupt); dropping the graph drops the handles and releases the slices. Slices the window never touched are left alone, so a pre-existing live buffer keeps its reuse and in-place (can_mut) semantics. Empty if no capture was active.

Source

pub fn mode(&mut self, mode: MemoryAllocationMode)

Change the mode of allocation.

Source

pub fn cleanup(&mut self, explicit: bool)

Cleanup allocations in pools that are deemed unnecessary.

Source

pub fn get_cursor(&self, binding: ManagedMemoryBinding) -> Result<u64, IoError>

Returns the storage from the specified binding

Source

pub fn get_storage( &mut self, binding: ManagedMemoryBinding, ) -> Result<StorageHandle, IoError>

Returns the storage from the specified binding

Source

pub fn get_resource( &mut self, binding: ManagedMemoryBinding, offset_start: Option<u64>, offset_end: Option<u64>, ) -> Result<Storage::Resource, IoError>

Returns the resource from the storage at the specified handle

Source

pub fn reserve(&mut self, size: u64) -> Result<ManagedMemoryHandle, IoError>

Finds a spot in memory for a resource with the given size in bytes, and returns a handle to it

Source

pub fn storage(&mut self) -> &mut Storage

Fetch the storage used by the memory manager.

§Notes

The storage should probably not be used for allocations since the handles won’t be compatible with the ones provided by the current trait. Prefer using the alloc and dealloc functions.

This is useful if you need to time the deallocations based on async computation, or to change the mode of storage for different reasons.

Source

pub fn memory_usage(&self) -> MemoryUsage

Get the current memory usage.

Source

pub fn print_memory_usage(&self)

Print out a report of the current memory usage.

Source

pub fn bind( &mut self, reserved: ManagedMemoryHandle, assigned: ManagedMemoryHandle, cursor: u64, ) -> Result<(), IoError>

Binds the given handle to a [MemorySlot].

Trait Implementations§

Source§

impl<Storage> Debug for MemoryManagement<Storage>

Source§

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

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

impl<Storage: ComputeStorage> Display for MemoryManagement<Storage>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Storage> !RefUnwindSafe for MemoryManagement<Storage>

§

impl<Storage> !UnwindSafe for MemoryManagement<Storage>

§

impl<Storage> Freeze for MemoryManagement<Storage>
where Storage: Freeze,

§

impl<Storage> Send for MemoryManagement<Storage>
where Storage: Send,

§

impl<Storage> Sync for MemoryManagement<Storage>
where Storage: Sync,

§

impl<Storage> Unpin for MemoryManagement<Storage>
where Storage: Unpin,

§

impl<Storage> UnsafeUnpin for MemoryManagement<Storage>
where Storage: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.