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;
|
extern crate rustc_serialize;
|
||||||
|
|
||||||
mod taupowers;
|
mod taupowers;
|
||||||
|
mod multicore;
|
||||||
mod sequences;
|
mod sequences;
|
||||||
mod qap;
|
mod qap;
|
||||||
mod spairs;
|
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 bn::*;
|
||||||
use snark::*;
|
use snark::*;
|
||||||
use crossbeam;
|
use crossbeam;
|
||||||
|
use multicore::*;
|
||||||
|
|
||||||
/// Evaluates the QAP A, B and C polynomials at tau given the powers of tau.
|
/// 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
|
/// 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!(v.len() >= 2);
|
||||||
assert_eq!((v.len() / 2) * 2, v.len());
|
assert_eq!((v.len() / 2) * 2, v.len());
|
||||||
const THREADS: usize = 8;
|
|
||||||
|
|
||||||
let overd = Fr::from_str(&format!("{}", v.len())).unwrap().inverse().unwrap();
|
let overd = Fr::from_str(&format!("{}", v.len())).unwrap().inverse().unwrap();
|
||||||
let mut tmp = fft(v, omega, THREADS);
|
let mut tmp = fft(v, omega, THREADS);
|
||||||
tmp.reverse(); // coefficients are in reverse
|
tmp.reverse(); // coefficients are in reverse
|
||||||
|
|
||||||
crossbeam::scope(|scope| {
|
mul_all_by(&mut tmp, overd);
|
||||||
for i in tmp.chunks_mut(v.len() / THREADS) {
|
|
||||||
scope.spawn(move || {
|
|
||||||
for i in i {
|
|
||||||
*i = *i * overd;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
tmp
|
tmp
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,17 +3,11 @@ use rand::Rng;
|
||||||
use snark::*;
|
use snark::*;
|
||||||
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
|
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
|
||||||
use sequences::*;
|
use sequences::*;
|
||||||
|
use multicore::*;
|
||||||
use taupowers::*;
|
use taupowers::*;
|
||||||
|
|
||||||
pub type BlakeHash = [u8; 32];
|
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)]
|
#[derive(Clone)]
|
||||||
pub struct Stage1Values {
|
pub struct Stage1Values {
|
||||||
pub vk_a: G2,
|
pub vk_a: G2,
|
||||||
|
|
Loading…
Reference in New Issue