Skip to main content

GpuPool

Struct GpuPool 

Source
pub struct GpuPool { /* private fields */ }

Implementations§

Source§

impl GpuPool

Source

pub fn new(devices: &[GpuDevice]) -> Self

Build a pool from the host’s detected GPU inventory. An empty inventory is permitted — the resulting pool always returns None from claim() so CPU-only hosts work without special-casing at the call site.

Source

pub fn pending_claimers(&self) -> usize

How many variant tasks are currently parked inside claim() waiting for a permit. The LeaseArbiter consults this to decide whether to dispatch a helper: when pending_claimers() > 0, at least one variant task wants a GPU and the arbiter must step back so the variant claims first (FIFO fairness).

Reads with Ordering::Acquire. The result is momentary — by the time the caller observes it, a claim may have resolved or a new one parked. That’s expected; the arbiter re-checks before each dispatch decision.

Source

pub fn capacity(&self) -> usize

How many GPUs this pool manages. Useful for pre-spawning variants when fewer variants exist than GPUs (no point over-claiming).

Source

pub fn snapshot_leases(&self) -> Vec<GpuLeaseEntry>

Snapshot per-GPU lease state. Result preserves slot order (matches the order GpuPool::new saw devices), so callers stitching the result against the hello frame’s gpu_pool see consistent indices across both reports.

Reads free slots with Ordering::Acquire. The result is a momentary snapshot — by the time the caller observes it, a claim or drop may have flipped any slot. That’s expected; load reporting is best-effort observability, not a transactional view.

Used by the worker’s Phase 2 (2026-05-07) load-tick task to build the worker_load frame’s gpu_pool field.

Source

pub async fn claim(self: &Arc<Self>) -> Option<GpuLease>

Claim an available GPU. Awaits if every GPU is currently leased. Returns None immediately on CPU-only hosts — the caller should fall back to CPU encode.

Source

pub fn try_claim(self: &Arc<Self>) -> Option<GpuLease>

Try to claim a GPU without blocking. Returns None if every GPU is currently leased OR if the host has no GPUs.

Used by the LeaseArbiter (planned 2026-05-10) to grab a helper lease without contending with blocked variant tasks. Tokio’s Semaphore preserves FIFO ordering for queued waiters — a permit released while a variant task is parked in acquire_owned().await is reserved for that waiter and is NOT visible to try_acquire_owned(), so this method cannot steal a permit out from under a queued variant.

Does NOT increment pending_claimers; helpers are not blocked claimers in the spare-capacity sense.

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more