Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chunked batch inverse #983

Merged
merged 1 commit into from
Jan 14, 2025
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
25 changes: 23 additions & 2 deletions crates/prover/src/core/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,22 @@ pub fn batch_inverse_in_place<F: FieldExpOps>(column: &[F], dst: &mut [F]) {
dst[0..WIDTH].clone_from_slice(&tail_inverses);
}

// TODO(Ohad): chunks, parallelize.
pub fn batch_inverse<F: FieldExpOps>(column: &[F]) -> Vec<F> {
let mut dst = vec![unsafe { std::mem::zeroed() }; column.len()];
batch_inverse_in_place(column, &mut dst);
dst
}

// TODO(Ohad): parallelize.
pub fn batch_inverse_chunked<T: FieldExpOps>(column: &[T], chunk_size: usize) -> Vec<T> {
let mut dst = vec![unsafe { std::mem::zeroed() }; column.len()];
let iter = dst.chunks_mut(chunk_size).zip(column.chunks(chunk_size));
iter.for_each(|(dst, column)| {
batch_inverse_in_place(column, dst);
});
dst
}

pub trait Field:
NumAssign
+ Neg<Output = Self>
Expand Down Expand Up @@ -472,8 +481,8 @@ mod tests {
use rand::{Rng, SeedableRng};

use super::batch_inverse_in_place;
use crate::core::fields::batch_inverse;
use crate::core::fields::m31::M31;
use crate::core::fields::{batch_inverse, batch_inverse_chunked};

#[test]
fn test_batch_inverse() {
Expand All @@ -495,4 +504,16 @@ mod tests {

batch_inverse_in_place(&elements, &mut dst);
}

#[test]
fn test_batch_inverse_chunked() {
let mut rng = SmallRng::seed_from_u64(0);
let elements: [M31; 16] = rng.gen();
let chunk_size = 4;
let expected = batch_inverse(&elements);

let result = batch_inverse_chunked(&elements, chunk_size);

assert_eq!(expected, result);
}
}
Loading