Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion crates/xcl/src/shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,13 @@ fn prepare_workers() -> usize {
}
let cores = std::thread::available_parallelism().map_or(4, |n| n.get());
let (used, limit) = crate::host::system_commit();
workers_for(cores, limit.saturating_sub(used))
workers_for_commit(cores, used, limit)
}

/// The workers for `cores` logical processors and the system's commit charge `used` and its
/// `limit`, both in bytes as `host::system_commit` gives them.
fn workers_for_commit(cores: usize, used: u64, limit: u64) -> usize {
workers_for(cores, limit.saturating_sub(used) >> 20)
}

/// The workers for `cores` logical processors (threads, not cores) and `free_mb` of commit left.
Expand Down Expand Up @@ -3248,6 +3254,17 @@ mod tests {
assert_eq!(workers_for(32, 0), 1);
}

/// The commit figures come in bytes: 6 GiB left on 16 logical processors is room for two
/// workers, not twelve; a commit that is not known (0, 0) gives one.
#[test]
fn preparation_workers_take_the_commit_left_in_bytes() {
const GIB: u64 = 1 << 30;
assert_eq!(workers_for_commit(16, 10 * GIB, 16 * GIB), 2);
assert_eq!(workers_for_commit(16, 0, 64 * GIB), 12);
assert_eq!(workers_for_commit(16, 0, 0), 1);
assert_eq!(workers_for_commit(16, 20 * GIB, 16 * GIB), 1);
}

/// A builder's progress line gives its record count; its other lines give none.
#[test]
fn a_builders_progress_line_gives_its_count() {
Expand Down
Loading