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

Some parallel iters #15

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions halo2_backend/src/plonk/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ use crate::{
use halo2_middleware::circuit::{
Any, ColumnMid, CompiledCircuit, ConstraintSystemMid, ExpressionMid, VarMid,
};
use halo2_middleware::multicore::ParallelIterator;
use halo2_middleware::{lookup, poly::Rotation, shuffle};
use rayon::iter::IntoParallelRefIterator;
use std::collections::HashMap;

/// Creates a domain, constraint system, and configuration for a circuit.
Expand Down Expand Up @@ -107,19 +109,17 @@ where
}

// Compute fixeds

let fixed_polys: Vec<_> = circuit
.preprocessing
.fixed
.iter()
.par_iter()
.map(|poly| {
vk.domain
.lagrange_to_coeff(Polynomial::new_lagrange_from_vec(poly.clone()))
})
.collect();

let fixed_cosets = fixed_polys
.iter()
.par_iter()
.map(|poly| vk.domain.coeff_to_extended(poly.clone()))
.collect();

Expand Down
30 changes: 19 additions & 11 deletions halo2_backend/src/plonk/permutation/keygen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use group::Curve;
use halo2_middleware::ff::{Field, PrimeField};
use halo2_middleware::multicore::IndexedParallelIterator;
use halo2_middleware::multicore::ParallelIterator;
use halo2_middleware::zal::impls::H2cEngine;
use rayon::iter::IntoParallelRefMutIterator;

use super::{Argument, ProvingKey, VerifyingKey};
use crate::{
Expand Down Expand Up @@ -173,35 +176,40 @@ pub(crate) fn build_pk<C: CurveAffine, P: Params<C>>(
let mut permutations = vec![domain.empty_lagrange(); p.columns.len()];
{
parallelize(&mut permutations, |o, start| {
for (x, permutation_poly) in o.iter_mut().enumerate() {
let i = start + x;
for (j, p) in permutation_poly.iter_mut().enumerate() {
let (permuted_i, permuted_j) = mapping(i, j);
*p = deltaomega[permuted_i][permuted_j];
}
}
o.par_iter_mut()
.enumerate()
.for_each(|(x, permutation_poly)| {
let i = start + x;
permutation_poly
.par_iter_mut()
.enumerate()
.for_each(|(j, p)| {
let (permuted_i, permuted_j) = mapping(i, j);
*p = deltaomega[permuted_i][permuted_j];
})
})
});
}

let mut polys = vec![domain.empty_coeff(); p.columns.len()];
{
parallelize(&mut polys, |o, start| {
for (x, poly) in o.iter_mut().enumerate() {
o.par_iter_mut().enumerate().for_each(|(x, poly)| {
let i = start + x;
let permutation_poly = permutations[i].clone();
*poly = domain.lagrange_to_coeff(permutation_poly);
}
})
});
}

let mut cosets = vec![domain.empty_extended(); p.columns.len()];
{
parallelize(&mut cosets, |o, start| {
for (x, coset) in o.iter_mut().enumerate() {
o.par_iter_mut().enumerate().for_each(|(x, coset)| {
let i = start + x;
let poly = polys[i].clone();
*coset = domain.coeff_to_extended(poly);
}
})
});
}

Expand Down
Loading