Browse Source

Multithread support for Shine.Gen()

Use numactl, not the RAYON_NUM_THREADS env var, to set the number of
threads to use.
Ian Goldberg 6 months ago
parent
commit
4a2174c5cf
4 changed files with 52 additions and 1 deletions
  1. 46 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 3 0
      src/bin/arctic.rs
  4. 2 1
      src/shine.rs

+ 46 - 0
Cargo.lock

@@ -9,6 +9,7 @@ dependencies = [
  "curve25519-dalek",
  "itertools",
  "rand",
+ "rayon",
  "sha2",
 ]
 
@@ -42,6 +43,31 @@ dependencies = [
  "libc",
 ]
 
+[[package]]
+name = "crossbeam-deque"
+version = "0.8.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d"
+dependencies = [
+ "crossbeam-epoch",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-epoch"
+version = "0.9.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
+dependencies = [
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-utils"
+version = "0.8.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
+
 [[package]]
 name = "curve25519-dalek"
 version = "2.1.3"
@@ -177,6 +203,26 @@ dependencies = [
  "rand_core",
 ]
 
+[[package]]
+name = "rayon"
+version = "1.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051"
+dependencies = [
+ "either",
+ "rayon-core",
+]
+
+[[package]]
+name = "rayon-core"
+version = "1.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
+dependencies = [
+ "crossbeam-deque",
+ "crossbeam-utils",
+]
+
 [[package]]
 name = "sha2"
 version = "0.9.9"

+ 1 - 0
Cargo.toml

@@ -11,3 +11,4 @@ curve25519-dalek = "2"
 rand = "0.7"
 sha2 = "0.9"
 itertools = "0.12"
+rayon = "1"

+ 3 - 0
src/bin/arctic.rs

@@ -61,6 +61,9 @@ fn main() {
     seckeys.truncate(coalitionsize as usize);
     let polys = arctic::lagrange_polys(&coalition);
 
+    rayon::ThreadPoolBuilder::new().build_global().unwrap();
+    println!("# num_threads = {}", rayon::current_num_threads());
+
     for _ in 0..reps {
         rng.fill_bytes(&mut msg);
         let (r1_outputs, sign1_iter_timings): (Vec<R1Output>, Vec<f64>) = seckeys

+ 2 - 1
src/shine.rs

@@ -7,6 +7,7 @@ use curve25519_dalek::traits::Identity;
 use curve25519_dalek::traits::VartimePrecomputedMultiscalarMul;
 use itertools::Itertools;
 use rand::RngCore;
+use rayon::prelude::*;
 use sha2::digest::FixedOutput;
 use sha2::Digest;
 use sha2::Sha256;
@@ -134,7 +135,7 @@ impl PreprocKey {
     pub fn gen(&self, w: &[u8]) -> (Scalar, RistrettoPoint) {
         let d = self
             .secrets
-            .iter()
+            .par_iter()
             .map(|(phi, lagrange)| hash1(phi, w) * lagrange)
             .sum();
         (d, &d * &dalek_constants::RISTRETTO_BASEPOINT_TABLE)