Skip to content
Closed
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
16 changes: 10 additions & 6 deletions halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ rand_chacha = "0.3"
maybe-rayon = { version = "0.1.1"}
lazy_static = { version = "1", optional = true }
env_logger = "0.10.0"
rustc-hash = "2.0.0"

# GPU Icicle integration
icicle = { git = "https://github.com/ingonyama-zk/icicle.git", branch = "rust/large-bucket-factor-msm", optional = true }
icicle-core = { git = "https://github.com/ingonyama-zk/icicle", branch="ezkl-icicle2", package="icicle-core", optional = true }
icicle-bn254 = { git = "https://github.com/ingonyama-zk/icicle", branch="ezkl-icicle2", package="icicle-bn254", optional = true }
icicle-cuda-runtime = { git = "https://github.com/ingonyama-zk/icicle", branch="ezkl-icicle2", package="icicle-cuda-runtime", optional = true }
rustacuda = { version = "0.1", optional = true }
serde = { version = "1", optional = true, features = ["derive"] }
serde_derive = { version = "1", optional = true}
Expand All @@ -90,10 +93,10 @@ getrandom = { version = "0.2", features = ["js"] }
default = ["batch", "bits"]
dev-graph = ["plotters", "tabbycat"]
test-dev-graph = [
"dev-graph",
"plotters/bitmap_backend",
"plotters/bitmap_encoder",
"plotters/ttf",
"dev-graph",
"plotters/bitmap_backend",
"plotters/bitmap_encoder",
"plotters/ttf"
]
bits = ["halo2curves/bits"]
gadget-traces = ["backtrace"]
Expand All @@ -102,10 +105,11 @@ sanity-checks = []
batch = ["rand_core/getrandom"]
circuit-params = []
counter = ["lazy_static"]
icicle_gpu = ["icicle", "rustacuda"]
icicle_gpu = ["icicle-cuda-runtime", "icicle-bn254", "icicle-core"]
mv-lookup = []
cost-estimator = ["serde", "serde_derive"]
derive_serde = ["halo2curves/derive_serde"]
parallel-poly-read = []

[lib]
bench = false
Expand Down
3 changes: 2 additions & 1 deletion halo2_proofs/benches/commit_zk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use maybe_rayon::current_num_threads;
use rand_chacha::rand_core::RngCore;
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;
use std::{collections::HashMap, iter};
use rustc_hash::FxHashMap as HashMap;
use std::iter;

fn rand_poly_serial(mut rng: ChaCha20Rng, domain: usize) -> Vec<Scalar> {
// Sample a random polynomial of degree n - 1
Expand Down
93 changes: 83 additions & 10 deletions halo2_proofs/src/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! This module provides common utilities, traits and structures for group,
//! field and polynomial arithmetic.

#[cfg(feature = "icicle_gpu")]
use super::icicle;
use super::multicore;
pub use ff::Field;
use group::{
Expand All @@ -9,11 +11,6 @@ use group::{
};
pub use halo2curves::{CurveAffine, CurveExt};

#[cfg(feature = "icicle_gpu")]
use super::icicle;
#[cfg(feature = "icicle_gpu")]
use rustacuda::prelude::DeviceBuffer;

/// This represents an element of a group with basic operations that can be
/// performed. This allows an FFT implementation (for example) to operate
/// generically over either a field or elliptic curve group.
Expand Down Expand Up @@ -145,11 +142,75 @@ pub fn small_multiexp<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C]) -> C::C

#[cfg(feature = "icicle_gpu")]
/// Performs a multi-exponentiation operation on GPU using Icicle library
pub fn best_multiexp_gpu<C: CurveAffine>(coeffs: &[C::Scalar], is_lagrange: bool) -> C::Curve {
let scalars_ptr: DeviceBuffer<::icicle::curves::bn254::ScalarField_BN254> =
icicle::copy_scalars_to_device::<C>(coeffs);
pub fn best_multiexp_gpu<C: CurveAffine>(coeffs: &[C::Scalar], g: &[C]) -> C::Curve {
icicle::multiexp_on_device::<C>(coeffs, g)
}

/// Performs a multi-exponentiation operation
pub fn best_multiexp<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C]) -> C::Curve {
#[cfg(not(feature = "icicle_gpu"))]
{
best_multiexp_cpu(coeffs, bases)
}

return icicle::multiexp_on_device::<C>(scalars_ptr, is_lagrange);
#[cfg(feature = "icicle_gpu")]
if !icicle::should_use_cpu_msm(bases.len()) && icicle::is_gpu_supported_field(&coeffs[0]) {
best_multiexp_gpu(coeffs, bases)
} else {
best_multiexp_cpu(coeffs, bases)
}
}

/// Performs a FTT operation
pub fn best_ftt<Scalar: Field + ff::PrimeField, G: FftGroup<Scalar> + ff::PrimeField>(
scalars: &mut [G],
omega: Scalar,
log_n: u32,
) {
#[cfg(not(feature = "icicle_gpu"))]
{
best_fft(scalars, omega, log_n);
}

#[cfg(feature = "icicle_gpu")]
{
if !icicle::should_use_cpu_fft(scalars.len()) && icicle::is_gpu_supported_field(&scalars[0]) {
best_fft_gpu(scalars, omega, log_n, false);
} else {
best_fft(scalars, omega, log_n);
}
}
}

/// Performs a iNTT operation
pub fn best_iftt<Scalar: Field + ff::PrimeField, G: FftGroup<Scalar> + ff::PrimeField>(
scalars: &mut [G],
omega: Scalar,
log_n: u32,
divisor: Scalar,
) {
#[cfg(feature = "icicle_gpu")]
{
if !icicle::should_use_cpu_fft(scalars.len()) && icicle::is_gpu_supported_field(&scalars[0]) {
best_fft_gpu(scalars, omega, log_n, true);
} else {
best_fft(scalars, omega, log_n);
parallelize(scalars, |a, _| {
for a in a {
*a *= &divisor;
}
});
}
}
#[cfg(not(feature = "icicle_gpu"))]
{
best_fft(scalars, omega, log_n);
parallelize(scalars, |a, _| {
for a in a {
*a *= &divisor;
}
});
}
}

/// Performs a multi-exponentiation operation.
Expand Down Expand Up @@ -182,10 +243,22 @@ pub fn best_multiexp_cpu<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C]) -> C
} else {
let mut acc = C::Curve::identity();
multiexp_serial(coeffs, bases, &mut acc);

acc
}
}

/// Performs a NTT operation on GPU using Icicle library
#[cfg(feature = "icicle_gpu")]
pub fn best_fft_gpu<Scalar: Field + ff::PrimeField, G: FftGroup<Scalar> + ff::PrimeField>(
a: &mut [G],
omega: Scalar,
log_n: u32,
inverse: bool,
) {
icicle::fft_on_device::<Scalar, G>(a, omega, log_n, inverse);
}

/// Performs a radix-$2$ Fast-Fourier Transformation (FFT) on a vector of size
/// $n = 2^k$, when provided `log_n` = $k$ and an element of multiplicative
/// order $n$ called `omega` ($\omega$). The result is that the vector `a`, when
Expand Down Expand Up @@ -226,7 +299,7 @@ pub fn best_fft<Scalar: Field, G: FftGroup<Scalar>>(a: &mut [G], omega: Scalar,
Some(tw)
})
.collect();

if log_n <= log_threads {
let mut chunk = 2_usize;
let mut twiddle_chunk = n / 2;
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/circuit/floor_planner/single_pass.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_hash::FxHashMap as HashMap;
use std::cmp;
use std::collections::HashMap;
use std::fmt;
use std::marker::PhantomData;

Expand Down
8 changes: 3 additions & 5 deletions halo2_proofs/src/circuit/floor_planner/v1/strategy.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::{
cmp,
collections::{BTreeSet, HashMap},
ops::Range,
};
use std::{cmp, collections::BTreeSet, ops::Range};

use rustc_hash::FxHashMap as HashMap;

use super::{RegionColumn, RegionShape};
use crate::{circuit::RegionStart, plonk::Any};
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/circuit/layouter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implementations of common circuit layouters.

use rustc_hash::FxHashSet as HashSet;
use std::cmp;
use std::collections::HashSet;
use std::fmt;

use ff::Field;
Expand Down
7 changes: 3 additions & 4 deletions halo2_proofs/src/circuit/table_layouter.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Implementations of common table layouters.

use std::{
collections::HashMap,
fmt::{self, Debug},
};
use std::fmt::{self, Debug};

use rustc_hash::FxHashMap as HashMap;

use ff::Field;

Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Tools for developing circuits.

use std::collections::HashMap;
use std::collections::HashSet;
use rustc_hash::FxHashMap as HashMap;
use rustc_hash::FxHashSet as HashSet;
use std::iter;
use std::ops::{Add, Mul, Neg, Range};

Expand Down
11 changes: 6 additions & 5 deletions halo2_proofs/src/dev/cost.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! Developer tools for investigating the cost of a circuit.

use std::{
cmp,
collections::{HashMap, HashSet},
iter,
cmp, iter,
marker::PhantomData,
ops::{Add, Mul},
};

use rustc_hash::FxHashMap as HashMap;
use rustc_hash::FxHashSet as HashSet;

use ff::{Field, PrimeField};
use group::prime::PrimeGroup;

Expand Down Expand Up @@ -288,7 +289,7 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
assert!((1 << k) >= cs.minimum_rows());

// Figure out how many point sets we have due to queried cells.
let mut column_queries: HashMap<Column<Any>, HashSet<i32>> = HashMap::new();
let mut column_queries: HashMap<Column<Any>, HashSet<i32>> = HashMap::default();
for (c, r) in iter::empty()
.chain(
cs.advice_queries
Expand All @@ -306,7 +307,7 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
{
column_queries.entry(c).or_default().insert(r.0);
}
let mut point_sets: HashSet<Vec<i32>> = HashSet::new();
let mut point_sets: HashSet<Vec<i32>> = HashSet::default();
for (_, r) in column_queries {
// Sort the query sets so we merge duplicates.
let mut query_set: Vec<_> = r.into_iter().collect();
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/dev/cost_model.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The cost estimator takes high-level parameters for a circuit design, and estimates the
//! verification cost, as well as resulting proof size.

use std::collections::HashSet;
use rustc_hash::FxHashSet as HashSet;
use std::{iter, num::ParseIntError, str::FromStr};

use crate::plonk::Circuit;
Expand Down
4 changes: 3 additions & 1 deletion halo2_proofs/src/dev/failure.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::collections::{BTreeMap, HashSet};
use std::collections::BTreeMap;
use std::fmt::{self, Debug};

use group::ff::Field;

use rustc_hash::FxHashSet as HashSet;

use super::metadata::{DebugColumn, DebugVirtualCell};
use super::MockProver;
use super::{
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/dev/graph/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use plotters::{
coord::Shift,
prelude::{DrawingArea, DrawingAreaErrorKind, DrawingBackend},
};
use std::collections::HashSet;
use rustc_hash::FxHashSet as HashSet;
use std::ops::Range;

use crate::{
Expand Down
7 changes: 3 additions & 4 deletions halo2_proofs/src/dev/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

use super::metadata::Column as ColumnMetadata;
use crate::plonk::{self, Any};
use std::{
collections::HashMap,
fmt::{self, Debug},
};
use std::fmt::{self, Debug};

use rustc_hash::FxHashMap as HashMap;
/// Metadata about a column within a circuit.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Column {
Expand Down
Loading