Skip to main content

AmbientRayonScope

Struct AmbientRayonScope 

Source
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§

Source§

impl AmbientRayonScope

Source

pub fn new(num_threads: usize) -> Self

Trait Implementations§

Source§

impl ParallelScope for AmbientRayonScope

Source§

fn install_session(&self, f: &mut dyn FnMut())

enter a session-scoped parallel region. On backends that support persistent sections (currently 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 more
Source§

fn par_for_each_index(&self, count: usize, f: &(dyn Fn(usize) + Send + Sync))

Runs 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), )

Runs 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))

Runs a and b in parallel, returns both results. Equivalent to rayon::join(a, b).
Source§

fn current_worker_index(&self) -> Option<usize>

The caller’s worker index, 0..num_threads, if running on one of this pool’s workers. 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

Number of worker threads.

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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.