Merge master

This commit is contained in:
wborgeaud 2021-04-21 22:36:06 +02:00
commit 6b3aa02b01
5 changed files with 50 additions and 17 deletions

View File

@ -1,3 +1,5 @@
//! Performs a single exponentiation.
use std::time::Instant;
use plonky2::field::crandall_field::CrandallField;
@ -5,20 +7,19 @@ use plonky2::field::field::Field;
type F = CrandallField;
const EXPONENT: usize = 1000000000;
fn main() {
let m = F::from_canonical_u64(12345678901234567890);
let mut x = F::ONE;
let base = F::rand();
let mut state = F::ONE;
let start = Instant::now();
let num_muls = 2000000000;
for _ in 0..num_muls {
x *= m;
for _ in 0..EXPONENT {
state *= base;
}
let duration = start.elapsed();
println!("result {:?}", x);
println!("took {:?}", duration);
println!(
"avg {:?}ns",
duration.as_secs_f64() * 1e9 / (num_muls as f64)
);
println!("Result: {:?}", state);
println!("Average field mul: {:?}ns",
duration.as_secs_f64() * 1e9 / EXPONENT as f64);
}

View File

@ -0,0 +1,33 @@
//! Performs several exponentiations in an interleaved loop, to enable parallelism on the core.
use std::time::Instant;
use plonky2::field::crandall_field::CrandallField;
use plonky2::field::field::Field;
type F = CrandallField;
/// The number of exponentiations to perform in parallel.
const WIDTH: usize = 6;
const EXPONENT: usize = 1000000000;
fn main() {
let mut bases = [F::ZERO; WIDTH];
for i in 0..WIDTH {
bases[i] = F::rand();
}
let mut state = [F::ONE; WIDTH];
let start = Instant::now();
for _ in 0..EXPONENT {
for i in 0..WIDTH {
state[i] *= bases[i];
}
}
let duration = start.elapsed();
println!("Result: {:?}", state);
println!("Average field mul: {:?}ns",
duration.as_secs_f64() * 1e9 / (WIDTH * EXPONENT) as f64);
}

View File

@ -14,12 +14,13 @@ impl<F: Field> CircuitBuilder<F> {
/// enforced elsewhere.
pub(crate) fn split_le_virtual(&mut self, integer: Target, num_bits: usize) -> Vec<Target> {
let bit_targets = self.add_virtual_advice_targets(num_bits);
split_le_generator::<F>(integer, bit_targets.clone());
self.add_generator(SplitGenerator { integer, bits: bit_targets.clone() });
bit_targets
}
}
/// Generator for a little-endian split.
#[must_use]
pub fn split_le_generator<F: Field>(
integer: Target,
bits: Vec<Target>,
@ -28,6 +29,7 @@ pub fn split_le_generator<F: Field>(
}
/// Generator for a little-endian split.
#[must_use]
pub fn split_le_generator_local_wires<F: Field>(
gate: usize,
integer_input_index: usize,

View File

@ -62,8 +62,7 @@ impl<F: Field, const R: usize> GMiMCGate<F, R> {
impl<F: Field, const R: usize> Gate<F> for GMiMCGate<F, R> {
fn id(&self) -> String {
// TODO: This won't include generic params?
format!("{:?}", self)
format!("<R={}> {:?}", R, self)
}
fn eval_unfiltered(&self, vars: EvaluationVars<F>) -> Vec<F> {
@ -273,7 +272,7 @@ mod tests {
let gate = Gate::with_constants(constants.clone());
let config = CircuitConfig {
num_wires: 200,
num_wires: 134,
num_routed_wires: 200,
..Default::default()
};

View File

@ -1,7 +1,5 @@
//! Concrete instantiation of a hash function.
use std::convert::TryInto;
use rayon::prelude::*;
use crate::circuit_builder::CircuitBuilder;