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_forchunk floor for a flat range oftotalelements: 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_forchunk floor for an outer loop ofunitsindependent items (e.g. (n,c) planes): one chunk per worker, at least one unit.- par_for
- par_
range - Parallel for: split
totalitems across threads.f(off, cnt)is called once per chunk with disjoint regions. - should_
parallelize - Should an op over
workelements 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.