Skip to main content

DevicePool

Struct DevicePool 

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

Per-device context pool for multi-GPU management.

Maintains a mapping from device ordinals to contexts, with thread-safe access for multi-threaded workloads. Each device gets exactly one context, created with default scheduling flags.

§Round-robin scheduling

The next_device method implements round-robin device selection using an atomic counter, making it safe to call from multiple threads without locking.

§Best-available scheduling

The best_available_device method selects the device with the most total memory. In a future release, this may query free memory at runtime when the driver supports it.

Implementations§

Source§

impl DevicePool

Source

pub fn new() -> CudaResult<Self>

Creates a new pool with contexts for all available devices.

Enumerates every CUDA-capable device and creates one context per device. The contexts are created with default scheduling flags (crate::context::flags::SCHED_AUTO).

§Errors
  • CudaError::NoDevice if no CUDA devices are available.
  • Other driver errors from device enumeration or context creation.
Source

pub fn with_devices(devices: &[Device]) -> CudaResult<Self>

Creates a pool with contexts for specific devices.

One context is created per device in the provided slice. The ordering in the slice determines the iteration and round-robin order.

§Errors
Source

pub fn context(&self, device_ordinal: i32) -> CudaResult<&Arc<Context>>

Returns the context for the given device ordinal.

Searches the pool for a device whose ordinal matches the given value.

§Errors

Returns CudaError::InvalidDevice if no device with the given ordinal is in the pool.

Source

pub fn device_count(&self) -> usize

Returns the number of devices in the pool.

Source

pub fn best_available_device(&self) -> CudaResult<Device>

Returns the device with the most total memory.

This is a heuristic for selecting the “best” device when you want to maximise available memory. For real-time free-memory queries, use cuMemGetInfo (once it is wired into the driver API).

§Errors

Returns an error if memory queries fail.

Source

pub fn next_device(&self) -> CudaResult<Device>

Selects a device using round-robin scheduling.

Each call advances an internal atomic counter and returns the next device in sequence. This is safe to call concurrently from multiple threads.

§Errors

This method is infallible for a properly constructed pool, but returns CudaResult for API consistency.

Source

pub fn iter(&self) -> impl Iterator<Item = (&Device, &Arc<Context>)>

Iterates over all (device, context) pairs in pool order.

Source

pub fn context_at(&self, index: usize) -> CudaResult<&Arc<Context>>

Returns the context for the device at the given pool index.

Pool indices are 0-based and correspond to the order in which devices were added to the pool.

§Errors

Returns CudaError::InvalidValue if the index is out of bounds.

Source

pub fn device_at(&self, index: usize) -> CudaResult<Device>

Returns the device at the given pool index.

§Errors

Returns CudaError::InvalidValue if the index is out of bounds.

Trait Implementations§

Source§

impl Debug for DevicePool

Source§

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

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

impl Send for DevicePool

Source§

impl Sync for DevicePool

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