gpu: incremental HeapRanges spans, chunked wide_each refreshes, and zero-alloc prelude/front_spans

This commit is contained in:
theme613 committed 2026-11-28 16:07:21 +08:00
1 parent 6f34121d31
commit 8503191734
3 files changed
+361 -159

No files matched your search

+34
View File
@@ -1843,6 +1843,40 @@ pub(crate) fn wide_each(n: usize, work: impl Fn(usize) + Send + Sync + 'static)
wide(jobs);
}
/// As [`wide_each`], but hands out contiguous slices of up to `chunk` indices
/// per atomic claim to eliminate cross-core cache-line bouncing on thousands
/// of lightweight items (e.g. unchanged copy checks).
pub(crate) fn wide_each_chunked(
n: usize,
chunk: usize,
work: impl Fn(std::ops::Range<usize>) + Send + Sync + 'static,
) {
let chunk = chunk.max(1);
let chunks = n.div_ceil(chunk);
if chunks == 0 {
return;
}
let next = Arc::new(std::sync::atomic::AtomicUsize::new(0));
let work = Arc::new(work);
let threads = (wide_threads() + 1).min(chunks);
let jobs = (0..threads)
.map(|_| {
let (next, work) = (next.clone(), work.clone());
Box::new(move || {
loop {
let c = next.fetch_add(1, Ordering::Relaxed);
let start = c.saturating_mul(chunk);
if start >= n {
break;
}
work(start..(start + chunk).min(n));
}
}) as Job
})
.collect();
wide(jobs);
}
/// About this many bytes to a piece of work for [`wide`].
const WIDE_JOB: usize = 1 << 20;