pub struct GpuLoadBalancer { /* private fields */ }Expand description
Distributes GPU work across multiple devices using a least-loaded strategy.
All mutating operations are thread-safe via an internal Mutex.
§Example
use oxirs_vec::gpu::{GpuLoadBalancer, SimpleGpuDevice};
let balancer = GpuLoadBalancer::new();
balancer.register_device(SimpleGpuDevice::new(0, "GPU-0", 8192, 128));
balancer.register_device(SimpleGpuDevice::new(1, "GPU-1", 16384, 256));
if let Some(id) = balancer.select_device(512) {
balancer.record_workload(id, 512);
// ... do GPU work ...
balancer.release_workload(id, 512);
}Implementations§
Source§impl GpuLoadBalancer
impl GpuLoadBalancer
Sourcepub fn register_device(&self, device: SimpleGpuDevice)
pub fn register_device(&self, device: SimpleGpuDevice)
Register a GPU device. If a device with the same id already exists it is
replaced (workload is reset to zero).
Sourcepub fn unregister_device(&self, device_id: u32)
pub fn unregister_device(&self, device_id: u32)
Remove a device from the balancer.
Sourcepub fn select_device(&self, workload_mb: u64) -> Option<u32>
pub fn select_device(&self, workload_mb: u64) -> Option<u32>
Select the device best suited to handle workload_mb megabytes of new work.
Returns the id of the device with the lowest current utilisation that has
enough free memory to accept the workload, or None if no suitable device
exists or no devices are registered.
Sourcepub fn record_workload(&self, device_id: u32, mb: u64) -> Result<()>
pub fn record_workload(&self, device_id: u32, mb: u64) -> Result<()>
Record mb megabytes of additional workload on device_id.
Returns an error if device_id is not registered.
Sourcepub fn release_workload(&self, device_id: u32, mb: u64) -> Result<()>
pub fn release_workload(&self, device_id: u32, mb: u64) -> Result<()>
Release mb megabytes of workload from device_id.
Clamps to zero to prevent underflow. Returns an error if the device is not registered.
Sourcepub fn utilization(&self, device_id: u32) -> Option<f64>
pub fn utilization(&self, device_id: u32) -> Option<f64>
Utilisation of device_id as a fraction in [0.0, 1.0].
Returns None if the device is not registered.
Sourcepub fn total_capacity_mb(&self) -> u64
pub fn total_capacity_mb(&self) -> u64
Sum of memory across all registered devices in MB.
Sourcepub fn device_count(&self) -> usize
pub fn device_count(&self) -> usize
Number of registered devices.
Sourcepub fn utilization_snapshot(&self) -> Vec<(u32, f64)>
pub fn utilization_snapshot(&self) -> Vec<(u32, f64)>
Returns a snapshot of device IDs and their current utilisation.
Trait Implementations§
Source§impl Clone for GpuLoadBalancer
impl Clone for GpuLoadBalancer
Source§fn clone(&self) -> GpuLoadBalancer
fn clone(&self) -> GpuLoadBalancer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GpuLoadBalancer
impl Debug for GpuLoadBalancer
Auto Trait Implementations§
impl Freeze for GpuLoadBalancer
impl !RefUnwindSafe for GpuLoadBalancer
impl Send for GpuLoadBalancer
impl Sync for GpuLoadBalancer
impl Unpin for GpuLoadBalancer
impl UnsafeUnpin for GpuLoadBalancer
impl !UnwindSafe for GpuLoadBalancer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.