Skip to content

Commit 13702eb

Browse files
committed
trace builder: packed KECCAK_RND chunks built four at a time
With the finish packing its tables (b2), each KECCAK_RND chunk's pack is serial on the task that built it, and one task building and packing every chunk in turn would make KECCAK_RND the finish's last table by more than it already is (BIG 561: gen_keccak_rnds ends 4.6 s after LT at 4.13x). Packed chunks are now built and packed in parallel waves of four, at most four of them (about 3 GiB) wide at once; the tables and their order are the same, and the unpacked path is unchanged.
1 parent 02a332a commit 13702eb

1 file changed

Lines changed: 28 additions & 12 deletions

File tree

‎prover/src/tables/trace_builder.rs‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3993,20 +3993,36 @@ pub(crate) fn keccak_rnd_chunks(
39933993
"{streamed} KECCAK_RND chunks were streamed but the run has {chunks}"
39943994
)));
39953995
}
3996-
Ok((0..chunks)
3997-
.map(|c| {
3998-
if c < streamed {
3999-
return streamed_placeholder();
4000-
}
4001-
let (first, end) = keccak_rnd_op_range(c, rows, ops.len());
4002-
packed_if(
4003-
pack,
4004-
keccak_rnd::generate_keccak_rnd_rows(&ops[first..end], c * rows - first * 24, rows),
4005-
)
4006-
})
4007-
.collect())
3996+
let chunk = |c: usize| {
3997+
if c < streamed {
3998+
return streamed_placeholder();
3999+
}
4000+
let (first, end) = keccak_rnd_op_range(c, rows, ops.len());
4001+
packed_if(
4002+
pack,
4003+
keccak_rnd::generate_keccak_rnd_rows(&ops[first..end], c * rows - first * 24, rows),
4004+
)
4005+
};
4006+
// Packed, a few chunks at a time in parallel: each chunk's pack is serial,
4007+
// and one task building them all one after another would be the finish's
4008+
// last; at most `KECCAK_RND_PACK_WAVE` chunks are wide at once.
4009+
#[cfg(feature = "parallel")]
4010+
if pack {
4011+
let mut tables = Vec::with_capacity(chunks);
4012+
let all: Vec<usize> = (0..chunks).collect();
4013+
for wave in all.chunks(KECCAK_RND_PACK_WAVE) {
4014+
tables.par_extend(wave.par_iter().map(|&c| chunk(c)));
4015+
}
4016+
return Ok(tables);
4017+
}
4018+
Ok((0..chunks).map(chunk).collect())
40084019
}
40094020

4021+
/// KECCAK_RND chunks built and packed at once ([`keccak_rnd_chunks`]): each is
4022+
/// ≈ 0.8 GiB at eight bytes a cell (1,480 columns of 2^16 rows) before its pack.
4023+
#[cfg(feature = "parallel")]
4024+
const KECCAK_RND_PACK_WAVE: usize = 4;
4025+
40104026
/// The ops whose rows reach KECCAK_RND chunk `chunk` of `rows` rows (24 rows an
40114027
/// op), clamped to the `len` ops there are.
40124028
pub(crate) fn keccak_rnd_op_range(chunk: usize, rows: usize, len: usize) -> (usize, usize) {

0 commit comments

Comments
 (0)