Skip to content

Commit

Permalink
integrated batch inverse to cpu twiddles (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohad-starkware authored Mar 18, 2024
1 parent e9aa5fc commit 20a76bf
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/core/backend/cpu/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ impl PolyOps for CPUBackend {
}

fn precompute_twiddles(mut coset: Coset) -> TwiddleTree<Self> {
const CHUNK_LOG_SIZE: usize = 12;
const CHUNK_SIZE: usize = 1 << CHUNK_LOG_SIZE;

let root_coset = coset;
let mut twiddles = Vec::with_capacity(coset.size());
for _ in 0..coset.log_size() {
Expand All @@ -146,8 +149,24 @@ impl PolyOps for CPUBackend {
}
twiddles.push(1.into());

// TODO(spapini): Batch inverse.
let itwiddles = twiddles.iter().map(|&t| t.inverse()).collect();
// Inverse twiddles.
// Fallback to the non-chunked version if the domain is not big enough.
if CHUNK_SIZE > coset.size() {
let itwiddles = twiddles.iter().map(|&t| t.inverse()).collect();
return TwiddleTree {
root_coset,
twiddles,
itwiddles,
};
}

let mut itwiddles = vec![BaseField::zero(); twiddles.len()];
twiddles
.array_chunks::<CHUNK_SIZE>()
.zip(itwiddles.array_chunks_mut::<CHUNK_SIZE>())
.for_each(|(src, dst)| {
BaseField::batch_inverse(src, dst);
});

TwiddleTree {
root_coset,
Expand Down

0 comments on commit 20a76bf

Please sign in to comment.