Skip to content

Commit

Permalink
fix: roll back "compute_inner_product" to simple loop
Browse files Browse the repository at this point in the history
  • Loading branch information
guorong009 committed Oct 23, 2024
1 parent 381eb3e commit ef6f740
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions halo2_backend/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,12 @@ pub(crate) fn eval_polynomial<F: Field>(poly: &[F], point: F) -> F {
pub(crate) fn compute_inner_product<F: Field>(a: &[F], b: &[F]) -> F {
assert_eq!(a.len(), b.len());

let n = a.len();
let num_threads = multicore::current_num_threads();
if n * 2 < num_threads {
let mut acc = F::ZERO;
for (a, b) in a.iter().zip(b.iter()) {
acc += (*a) * (*b);
}
acc
} else {
let chunk_size = (n + num_threads - 1) / num_threads;
let mut parts = vec![F::ZERO; num_threads];
multicore::scope(|scope| {
for (chunk_idx, (out, a)) in parts.chunks_mut(1).zip(a.chunks(chunk_size)).enumerate() {
scope.spawn(move |_| {
let mut acc = F::ZERO;
for (a, b) in a.iter().zip(&b[chunk_idx * chunk_size..]) {
acc += (*a) * (*b);
}
out[0] = acc;
});
}
});
parts.iter().fold(F::ZERO, |acc, coeff| acc + coeff)
let mut acc = F::ZERO;
for (a, b) in a.iter().zip(b.iter()) {
acc += (*a) * (*b);
}

acc
}

/// Divides polynomial `a` in `X` by `X - b` with
Expand Down

0 comments on commit ef6f740

Please sign in to comment.