pub struct WorkStealingScheduler { /* private fields */ }Expand description
Dynamic work-stealing scheduler.
Implementations§
Source§impl WorkStealingScheduler
impl WorkStealingScheduler
Sourcepub fn new(backend_ids: Vec<&'static str>) -> Self
pub fn new(backend_ids: Vec<&'static str>) -> Self
Create a scheduler over the live runtime backends available to the process.
Sourcepub fn partition(&self, total_len: usize) -> Vec<Shard>
pub fn partition(&self, total_len: usize) -> Vec<Shard>
Partition a large haystack across available GPUs.
Sourcepub fn try_partition(
&self,
total_len: usize,
) -> Result<Vec<Shard>, BackendError>
pub fn try_partition( &self, total_len: usize, ) -> Result<Vec<Shard>, BackendError>
Partition a large haystack across available GPUs with explicit staging allocation failure reporting.
Sourcepub fn claim_next_unit(&self) -> usize
pub fn claim_next_unit(&self) -> usize
Atomically claim the next fine-grained work unit. Worker threads
call this in a loop; the returned value is the unit index they
own. When the returned index is >= num_units, the worker is
done. This is the work-stealing primitive: fast backends call
claim_next_unit more times in the same wall-clock window.
§Examples
use vyre_runtime::scheduler::WorkStealingScheduler;
let scheduler = WorkStealingScheduler::new(Vec::new());
assert_eq!(scheduler.claim_next_unit(), 0);
assert_eq!(scheduler.claim_next_unit(), 1);
scheduler.reset_unit_cursor();
assert_eq!(scheduler.claim_next_unit(), 0);Sourcepub fn reset_unit_cursor(&self)
pub fn reset_unit_cursor(&self)
Reset the work-unit cursor to zero. Call between dispatches that reuse the same scheduler.
Sourcepub fn partition_into(&self, total_len: usize, out: &mut Vec<Shard>)
pub fn partition_into(&self, total_len: usize, out: &mut Vec<Shard>)
Partition a large haystack into many fine-grained work units
assigned round-robin to backends. A caller-side dispatch loop
uses Self::claim_next_unit to let worker threads atomically
claim units so fast backends steal more work.
§Panics
Panics when total_len cannot be partitioned into work units. Callers that must
recover use the try_ twin.
Sourcepub fn try_partition_into(
&self,
total_len: usize,
out: &mut Vec<Shard>,
) -> Result<(), BackendError>
pub fn try_partition_into( &self, total_len: usize, out: &mut Vec<Shard>, ) -> Result<(), BackendError>
Partition into caller-owned storage with explicit staging allocation failure reporting.