mirror of https://github.com/zcash/mpc.git
Parallelize vector group multiplication.
This commit is contained in:
parent
653c92a668
commit
fb0d84bac2
|
@ -5,6 +5,7 @@ extern crate crossbeam;
|
|||
extern crate rustc_serialize;
|
||||
|
||||
mod taupowers;
|
||||
mod multicore;
|
||||
mod sequences;
|
||||
mod qap;
|
||||
mod spairs;
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
use bn::*;
|
||||
use crossbeam;
|
||||
|
||||
pub const THREADS: usize = 8;
|
||||
|
||||
pub fn mul_all_by<G: Group>(v: &mut [G], c: Fr) {
|
||||
crossbeam::scope(|scope| {
|
||||
let window_size = v.len() / THREADS;
|
||||
for i in v.chunks_mut(window_size) {
|
||||
scope.spawn(move || {
|
||||
for i in i {
|
||||
*i = *i * c;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
12
src/qap.rs
12
src/qap.rs
|
@ -1,6 +1,7 @@
|
|||
use bn::*;
|
||||
use snark::*;
|
||||
use crossbeam;
|
||||
use multicore::*;
|
||||
|
||||
/// Evaluates the QAP A, B and C polynomials at tau given the powers of tau.
|
||||
/// Converts the powers of tau in G1 and G2 into the lagrange basis with an FFT
|
||||
|
@ -43,21 +44,12 @@ fn lagrange_coeffs<G: Group>(v: &[G], omega: Fr) -> Vec<G>
|
|||
{
|
||||
assert!(v.len() >= 2);
|
||||
assert_eq!((v.len() / 2) * 2, v.len());
|
||||
const THREADS: usize = 8;
|
||||
|
||||
let overd = Fr::from_str(&format!("{}", v.len())).unwrap().inverse().unwrap();
|
||||
let mut tmp = fft(v, omega, THREADS);
|
||||
tmp.reverse(); // coefficients are in reverse
|
||||
|
||||
crossbeam::scope(|scope| {
|
||||
for i in tmp.chunks_mut(v.len() / THREADS) {
|
||||
scope.spawn(move || {
|
||||
for i in i {
|
||||
*i = *i * overd;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
mul_all_by(&mut tmp, overd);
|
||||
|
||||
tmp
|
||||
}
|
||||
|
|
|
@ -3,17 +3,11 @@ use rand::Rng;
|
|||
use snark::*;
|
||||
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
|
||||
use sequences::*;
|
||||
use multicore::*;
|
||||
use taupowers::*;
|
||||
|
||||
pub type BlakeHash = [u8; 32];
|
||||
|
||||
// TODO: make more efficient using windowing
|
||||
fn mul_all_by<G: Group>(v: &mut [G], c: Fr) {
|
||||
for g in v {
|
||||
*g = *g * c;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Stage1Values {
|
||||
pub vk_a: G2,
|
||||
|
|
Loading…
Reference in New Issue