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

Feat/sphere/fft mem opt #28

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ name = "fft"
harness = false

[dependencies]
itertools = "0.10"
backtrace = { version = "0.3", optional = true }
rayon = "1.5.1"
ff = "0.12"
Expand Down
7 changes: 3 additions & 4 deletions halo2_proofs/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,11 @@ pub struct PinnedVerificationKey<'a, C: CurveAffine> {
#[derive(Clone, Debug)]
pub struct ProvingKey<C: CurveAffine> {
vk: VerifyingKey<C>,
l0: Polynomial<C::Scalar, ExtendedLagrangeCoeff>,
l_last: Polynomial<C::Scalar, ExtendedLagrangeCoeff>,
l_active_row: Polynomial<C::Scalar, ExtendedLagrangeCoeff>,
l0: Polynomial<C::Scalar, Coeff>,
l_last: Polynomial<C::Scalar, Coeff>,
l_active_row: Polynomial<C::Scalar, Coeff>,
fixed_values: Vec<Polynomial<C::Scalar, LagrangeCoeff>>,
fixed_polys: Vec<Polynomial<C::Scalar, Coeff>>,
fixed_cosets: Vec<Polynomial<C::Scalar, ExtendedLagrangeCoeff>>,
permutation: permutation::ProvingKey<C>,
ev: Evaluator<C>,
}
Expand Down
67 changes: 67 additions & 0 deletions halo2_proofs/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::cmp::max;
use core::ops::{Add, Mul};
use ff::Field;
use itertools::Itertools;
use std::{
convert::TryFrom,
ops::{Neg, Sub},
Expand Down Expand Up @@ -1051,6 +1052,72 @@ impl<F: Field> Expression<F> {
&|a, _| a,
)
}

/// Extracts all used instance columns in this expression
pub fn extract_instances(&self) -> Vec<usize> {
self.evaluate(
&|_| vec![],
&|_| vec![],
&|_| vec![],
&|_| vec![],
&|query| vec![query.column_index],
&|_| vec![],
&|a| a,
&|mut a, b| {
a.extend(b);
a.into_iter().unique().collect()
},
&|mut a, b| {
a.extend(b);
a.into_iter().unique().collect()
},
&|a, _| a,
)
}

/// Extracts all used advice columns in this expression
pub fn extract_advices(&self) -> Vec<usize> {
self.evaluate(
&|_| vec![],
&|_| vec![],
&|_| vec![],
&|query| vec![query.column_index],
&|_| vec![],
&|_| vec![],
&|a| a,
&|mut a, b| {
a.extend(b);
a.into_iter().unique().collect()
},
&|mut a, b| {
a.extend(b);
a.into_iter().unique().collect()
},
&|a, _| a,
)
}

/// Extracts all used fixed columns in this expression
pub fn extract_fixed(&self) -> Vec<usize> {
self.evaluate(
&|_| vec![],
&|_| vec![],
&|query| vec![query.column_index],
&|_| vec![],
&|_| vec![],
&|_| vec![],
&|a| a,
&|mut a, b| {
a.extend(b);
a.into_iter().unique().collect()
},
&|mut a, b| {
a.extend(b);
a.into_iter().unique().collect()
},
&|a, _| a,
)
}
}

impl<F: std::fmt::Debug> std::fmt::Debug for Expression<F> {
Expand Down
Loading