Skip to main content

GlobalDeviceBudget

Struct GlobalDeviceBudget 

Source
pub struct GlobalDeviceBudget { /* private fields */ }
Expand description

Per-runtime byte-limit decorator.

Implementations§

Source§

impl GlobalDeviceBudget

Source

pub fn new( inner: Box<dyn DeviceMemoryResource + Send + Sync>, limit: usize, ) -> Self

Wrap inner with a hard limit in bytes. The initial reserved tally and release baseline are sampled atomically from the inner resource’s canonical accounting ledger, so callers may compose around an inner that already has live allocations — though in practice the decorator is installed before any allocation flows through it.

Source

pub fn limit(&self) -> usize

Hard byte limit. Set at construction; not adjustable.

Source

pub fn reserved_bytes(&self) -> usize

Bytes currently reserved against the budget (live + pending async free). Matches inner.bytes_outstanding() at every quiescent moment.

Source

pub fn remaining(&self) -> usize

Headroom in bytes for the next allocation. Equal to limit - reserved_bytes, saturating at zero.

Trait Implementations§

Source§

impl DeviceMemoryResource for GlobalDeviceBudget

Source§

fn materialize(&self, request: AllocationRequest) -> ResourceResult<DeviceBlock>

Materialize one request. Decorators must forward the same request. Read more
Source§

fn allocation_accounting(&self) -> Arc<AllocationAccounting> ⓘ

Exact terminal-backend accounting domain. Decorators return the identical Arc. Later allocations must pass through the domain’s installed budgets.
Source§

fn deallocate(&self, block: DeviceBlock) -> ResourceResult<()>

Return block to the resource. After this call the block’s state is BlockState::Retired (or BlockState::Quarantined for debug-guard resources). Reuse of the underlying memory is resource-specific but must respect the stream-ordered contract. Read more
Source§

fn device_ordinal(&self) -> u32

CUDA device ordinal this resource serves. Resources are pinned to a single device.
Source§

fn bytes_outstanding(&self) -> usize

Bytes currently outstanding (live + retired-but-not-yet-freed). Used by tests and by the global budget adaptor.
Source§

fn budget_snapshot(&self) -> Option<ResourceBudgetSnapshot>

Return the outer resource stack’s reservable budget, if one exists. Base allocators have no declarative admission limit and return None; decorators must forward this query unless they enforce their own limit.
Source§

fn reap_pending(&self) -> ResourceResult<()>

Drain any retired-but-not-yet-freed bytes whose underlying CUDA work has completed. For synchronous backends this is a no-op. For stream-ordered async backends this synchronizes the streams that have queued cuMemFreeAsync calls and re-counts bytes_outstanding accordingly. Read more
Source§

fn record_block_use( &self, block: &DeviceBlock, use_stream: StreamId, ) -> ResourceResult<()>

Record that work has been (or is being) submitted on use_stream that touches block’s bytes. Resources that participate in cross-stream lifetime tracking (notably the stream-ordered async backend) MUST attach a CUDA event from use_stream to the block; on deallocate(block), the block’s alloc_stream will wait on every recorded event before queueing the underlying free. Read more
Source§

fn supports_block_use_tracking(&self) -> bool

Whether this resource (and any inner resources it composes) actually tracks cross-stream uses via record_block_use. Used by the launch recorder’s preflight to fail BEFORE queueing CUDA work, rather than after. The default returns false to match the trait’s default record_block_use behavior; resources that override record_block_use to track events MUST override this to return true. Decorators forward to inner.
Source§

fn prepare_block_use( &self, block: BlockId, use_stream: StreamId, access: Access, ) -> ResourceResult<()>

Pre-launch / pre-copy hook: queue any cross-stream waits required for use_stream to safely access block with access semantics. MUST be called BEFORE the GPU work is enqueued on use_stream. Read more
Source§

fn finish_block_use( &self, block: BlockId, use_stream: StreamId, access: Access, ) -> ResourceResult<()>

Post-launch / post-copy hook: record an event on use_stream capturing the work just enqueued and update block’s dependency state. Read more
Source§

fn allocate( &self, bytes: usize, stream: StreamId, tag: AllocTag, ) -> ResourceResult<DeviceBlock>

Allocate bytes bytes on the resource’s device, ordered on stream. The returned block is in BlockState::Live.
Source§

fn allocate_with_reservation_pressure( &self, bytes: usize, reservation_pressure_bytes: usize, stream: StreamId, tag: AllocTag, ) -> ResourceResult<DeviceBlock>

Allocate while accounting for bytes promised by the runtime but not yet materialized through this resource stack. Read more

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

Source§

type Output = T

Should always be Self
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.