Skip to main content

Module pool

Module pool 

Source
Expand description

Rayon-backed parallel for: par_for(total, grain, |off, cnt| …).

Replaces the old per-worker Condvar pool with Rayon’s work-stealing scheduler. Same (offset, count) chunk API so all existing call sites (BLAS tiling, SDPA, LayerNorm, …) pick up Rayon without changes.

Constants§

ELEMENTWISE_PAR_FLOOR
Minimum elements that make threading an element-wise kernel worthwhile. Below this the rayon hand-off costs more than the work it saves. Kept in one place so conv/transpose/pool/relu/region kernels share a single, tunable cutover instead of sprinkling magic constants at each call site.

Functions§

chunk_floor
par_for chunk floor for a flat range of total elements: aim for one chunk per worker, never below the amortization floor.
num_threads
Total Rayon worker count (configured from [RuntimeConfig::pool_workers]).
outer_chunk
par_for chunk floor for an outer loop of units independent items (e.g. (n,c) planes): one chunk per worker, at least one unit.
par_for
par_range
Parallel for: split total items across threads. f(off, cnt) is called once per chunk with disjoint regions.
should_parallelize
Should an op over work elements run in parallel? True only with >1 worker and enough work to keep them busy past the amortization floor. Use this at every data-parallel kernel call site instead of a hand-picked threshold.