pub struct AmbientRayonScope { /* private fields */ }Expand description
Zero-thread parallel scope for the rayon inference path.
rayon::ThreadPool-backed runners already install their pool via
pool.install(|| run_onnx_model_inner(...)). Every par_iter call
inside that closure automatically uses pool’s workers — no separate
scope pool is needed. Maintaining a second static rayon pool (the old
build_parallel_scope RAYON_SCOPES approach) added N scope-pool threads
that would spin-idle alongside N pool threads = 2N threads on an N-core
machine: pure oversubscription that regresses multi-thread latency.
AmbientRayonScope fixes this by delegating all dispatch to the ambient
rayon pool with zero extra threads. num_threads is reported as the
logical count so downstream threshold checks (blocked_blocks >= nthreads)
remain accurate.
Implementations§
Trait Implementations§
Source§impl ParallelScope for AmbientRayonScope
impl ParallelScope for AmbientRayonScope
Source§fn install_session(&self, f: &mut dyn FnMut())
fn install_session(&self, f: &mut dyn FnMut())
YscvPool), all pool
workers enter a tight-poll loop, and parallel dispatch inside
f routes through the section’s single-atomic-pointer
mechanism instead of rayon’s fork-join. On rayon, this is a
pass-through that just invokes f. Read moreSource§fn par_for_each_index(&self, count: usize, f: &(dyn Fn(usize) + Send + Sync))
fn par_for_each_index(&self, count: usize, f: &(dyn Fn(usize) + Send + Sync))
f(i) for each i in 0..count, in parallel. Blocks until
every iteration completes. Equivalent to rayon’s
(0..count).into_par_iter().for_each(f).Source§fn par_chunks_mut_dyn(
&self,
data: &mut [f32],
chunk_size: usize,
f: &(dyn Fn(usize, &mut [f32]) + Send + Sync),
)
fn par_chunks_mut_dyn( &self, data: &mut [f32], chunk_size: usize, f: &(dyn Fn(usize, &mut [f32]) + Send + Sync), )
f(chunk_idx, chunk) for each chunk_size-wide slice of data,
in parallel. The last chunk may be short when data.len() is not a
multiple of chunk_size. Blocks until every chunk completes.
Equivalent to data.par_chunks_mut(chunk_size).enumerate().for_each(…).Source§fn join_dyn(&self, a: &mut (dyn FnMut() + Send), b: &mut (dyn FnMut() + Send))
fn join_dyn(&self, a: &mut (dyn FnMut() + Send), b: &mut (dyn FnMut() + Send))
a and b in parallel, returns both results. Equivalent
to rayon::join(a, b).Source§fn current_worker_index(&self) -> Option<usize>
fn current_worker_index(&self) -> Option<usize>
None when called from outside the pool (e.g. from
the main thread before install). Used by matmul.rs at 538/684 to
decide whether to further parallelise — we don’t want nested pool
dispatch on an already-parallel worker.Source§fn num_threads(&self) -> usize
fn num_threads(&self) -> usize
Auto Trait Implementations§
impl Forget for AmbientRayonScope
impl Freeze for AmbientRayonScope
impl Move for AmbientRayonScope
impl RefUnwindSafe for AmbientRayonScope
impl Send for AmbientRayonScope
impl Sync for AmbientRayonScope
impl Unpin for AmbientRayonScope
impl UnsafeUnpin for AmbientRayonScope
impl UnwindSafe for AmbientRayonScope
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> 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 more