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>
impl<Storage: ComputeStorage> MemoryManagement<Storage>
Sourcepub fn from_configuration(
storage: Storage,
properties: &MemoryDeviceProperties,
config: MemoryConfiguration,
logger: Arc<ServerLogger>,
options: MemoryManagementOptions,
) -> Self
pub fn from_configuration( storage: Storage, properties: &MemoryDeviceProperties, config: MemoryConfiguration, logger: Arc<ServerLogger>, options: MemoryManagementOptions, ) -> Self
Creates the options from device limits.
Sourcepub fn configure(
&mut self,
config: MemoryConfiguration,
properties: &MemoryDeviceProperties,
) -> bool
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.
Sourcepub fn capture_begin(&mut self)
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.
Sourcepub fn capture_end(&mut self) -> Vec<ManagedMemoryHandle>
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.
Sourcepub fn mode(&mut self, mode: MemoryAllocationMode)
pub fn mode(&mut self, mode: MemoryAllocationMode)
Change the mode of allocation.
Sourcepub fn cleanup(&mut self, explicit: bool)
pub fn cleanup(&mut self, explicit: bool)
Cleanup allocations in pools that are deemed unnecessary.
Sourcepub fn get_cursor(&self, binding: ManagedMemoryBinding) -> Result<u64, IoError>
pub fn get_cursor(&self, binding: ManagedMemoryBinding) -> Result<u64, IoError>
Returns the storage from the specified binding
Sourcepub fn get_storage(
&mut self,
binding: ManagedMemoryBinding,
) -> Result<StorageHandle, IoError>
pub fn get_storage( &mut self, binding: ManagedMemoryBinding, ) -> Result<StorageHandle, IoError>
Returns the storage from the specified binding
Sourcepub fn get_resource(
&mut self,
binding: ManagedMemoryBinding,
offset_start: Option<u64>,
offset_end: Option<u64>,
) -> Result<Storage::Resource, IoError>
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
Sourcepub fn reserve(&mut self, size: u64) -> Result<ManagedMemoryHandle, IoError>
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
Sourcepub fn storage(&mut self) -> &mut Storage
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.
Sourcepub fn memory_usage(&self) -> MemoryUsage
pub fn memory_usage(&self) -> MemoryUsage
Get the current memory usage.
Sourcepub fn print_memory_usage(&self)
pub fn print_memory_usage(&self)
Print out a report of the current memory usage.
Sourcepub fn bind(
&mut self,
reserved: ManagedMemoryHandle,
assigned: ManagedMemoryHandle,
cursor: u64,
) -> Result<(), IoError>
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>
impl<Storage> Debug for MemoryManagement<Storage>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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