Skip to content

Commit a846222

Browse files
author
Kunming Jiang
committed
Add multicore for vec mult
1 parent 2cfaf7c commit a846222

File tree

10 files changed

+46
-16
lines changed

10 files changed

+46
-16
lines changed

circ_blocks/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ from-pest = { version = "0.3", optional = true }
5151
itertools = "0.10"
5252
petgraph = { version = "0.6", optional = true }
5353
spartan = { version = "0.8", default-features = false, optional = true }
54-
spartan_parallel = { path = "../spartan_parallel", default-features = false, features = [
55-
"multicore",
56-
"profile",
57-
] }
54+
spartan_parallel = { path = "../spartan_parallel", default-features = false, features = ["profile"] }
5855
merlin = { version = "3.0.0" }
5956
curve25519-dalek = { version = "4", features = ["serde"], optional = true }
6057
# TODO: kill

circ_blocks/examples/zxc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl CompileTimeKnowledge {
357357
}
358358

359359
#[derive(Serialize, Deserialize)]
360-
struct RunTimeKnowledge<S: SpartanExtensionField> {
360+
struct RunTimeKnowledge<S: SpartanExtensionField + Send + Sync> {
361361
block_max_num_proofs: usize,
362362
block_num_proofs: Vec<usize>,
363363
consis_num_proofs: usize,
@@ -382,7 +382,7 @@ struct RunTimeKnowledge<S: SpartanExtensionField> {
382382
output_exec_num: usize,
383383
}
384384

385-
impl<S: SpartanExtensionField> RunTimeKnowledge<S> {
385+
impl<S: SpartanExtensionField + Send + Sync> RunTimeKnowledge<S> {
386386
fn serialize_to_file(&self, benchmark_name: String, max_file_size: usize) -> std::io::Result<()> {
387387
let content = bincode::serialize(&self).unwrap();
388388
println!("RTK SIZE: {}", content.len());
@@ -842,7 +842,7 @@ fn get_compile_time_knowledge<const VERBOSE: bool>(
842842
// --
843843
// Generate witnesses and others
844844
// --
845-
fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField>(
845+
fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField + Send + Sync>(
846846
path: PathBuf,
847847
options: &Options,
848848
entry_regs: Vec<Integer>,
@@ -1277,7 +1277,7 @@ fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField>(
12771277
}
12781278
}
12791279

1280-
fn run_spartan_proof<S: SpartanExtensionField>(
1280+
fn run_spartan_proof<S: SpartanExtensionField + Send + Sync>(
12811281
ctk: CompileTimeKnowledge,
12821282
rtk: RunTimeKnowledge<S>,
12831283
) {

spartan_parallel/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ rand = { version = "0.8", features = ["getrandom"], default-features = false }
2020
digest = { version = "0.10", default-features = false }
2121
sha3 = { version = "0.10", default-features = false }
2222
byteorder = { version = "1", default-features = false }
23-
rayon = { version = "1", optional = true }
23+
rayon = { version = "1" }
2424
serde = { version = "1", features = ["derive"], default-features = false }
2525
bincode = { version = "1", default-features = false }
2626
subtle = { version = "2", features = ["i128"], default-features = false }
@@ -52,9 +52,8 @@ std = [
5252
"itertools/use_std",
5353
"flate2/rust_backend",
5454
]
55-
multicore = ["rayon"]
5655
profile = ["colored"]
5756

5857
[[example]]
5958
name = "interface"
60-
required-features = ["multicore", "profile"]
59+
required-features = ["profile"]

spartan_parallel/src/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Instance<S: SpartanExtensionField> {
2626
pub digest: Vec<u8>,
2727
}
2828

29-
impl<S: SpartanExtensionField> Instance<S> {
29+
impl<S: SpartanExtensionField + Send + Sync> Instance<S> {
3030
/// Constructs a new `Instance` and an associated satisfying assignment
3131
pub fn new(
3232
num_instances: usize,

spartan_parallel/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ impl PartialEq for InstanceSortHelper {
643643
}
644644
impl Eq for InstanceSortHelper {}
645645

646-
impl<S: SpartanExtensionField> SNARK<S> {
646+
impl<S: SpartanExtensionField + Send + Sync> SNARK<S> {
647647
fn protocol_name() -> &'static [u8] {
648648
b"Spartan SNARK proof"
649649
}

spartan_parallel/src/r1csinstance.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use rayon::prelude::*;
2+
13
use std::cmp::{max, min};
24
use std::collections::HashMap;
35

@@ -65,7 +67,7 @@ impl<S: SpartanExtensionField> R1CSCommitment<S> {
6567
}
6668
}
6769

68-
impl<S: SpartanExtensionField> R1CSInstance<S> {
70+
impl<S: SpartanExtensionField + Send + Sync> R1CSInstance<S> {
6971
pub fn new(
7072
num_instances: usize,
7173
max_num_cons: usize,
@@ -243,6 +245,31 @@ impl<S: SpartanExtensionField> R1CSInstance<S> {
243245
Az.push(Vec::new());
244246
Bz.push(Vec::new());
245247
Cz.push(Vec::new());
248+
Az[p] = (0..num_proofs[p]).into_par_iter().map(|q|
249+
vec![self.A_list[p_inst].multiply_vec_disjoint_rounds(
250+
num_cons[p_inst].clone(),
251+
max_num_inputs,
252+
num_inputs[p],
253+
&z_list[q],
254+
)]
255+
).collect();
256+
Bz[p] = (0..num_proofs[p]).into_par_iter().map(|q|
257+
vec![self.B_list[p_inst].multiply_vec_disjoint_rounds(
258+
num_cons[p_inst].clone(),
259+
max_num_inputs,
260+
num_inputs[p],
261+
&z_list[q],
262+
)]
263+
).collect();
264+
Cz[p] = (0..num_proofs[p]).into_par_iter().map(|q|
265+
vec![self.C_list[p_inst].multiply_vec_disjoint_rounds(
266+
num_cons[p_inst].clone(),
267+
max_num_inputs,
268+
num_inputs[p],
269+
&z_list[q],
270+
)]
271+
).collect();
272+
/*
246273
for q in 0..num_proofs[p] {
247274
let z = &z_list[q];
248275
@@ -265,6 +292,7 @@ impl<S: SpartanExtensionField> R1CSInstance<S> {
265292
z,
266293
)]);
267294
}
295+
*/
268296
}
269297

270298
(

spartan_parallel/src/r1csproof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct R1CSProof<S: SpartanExtensionField> {
2626
// proof_eval_vars_at_ry_list: Vec<PolyEvalProof<S>>,
2727
}
2828

29-
impl<S: SpartanExtensionField> R1CSProof<S> {
29+
impl<S: SpartanExtensionField + Send + Sync> R1CSProof<S> {
3030
fn prove_phase_one(
3131
num_rounds: usize,
3232
num_rounds_x_max: usize,

spartan_parallel/src/scalar/fp.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ use zeroize::Zeroize;
1515
#[derive(Clone, Copy, Eq, Serialize, Deserialize, Hash, Debug)]
1616
pub struct Scalar(Goldilocks);
1717

18+
unsafe impl Send for Scalar {}
19+
unsafe impl Sync for Scalar {}
20+
1821
impl SpartanExtensionField for Scalar {
1922
type InnerType = Goldilocks;
2023
type BaseField = Goldilocks;

spartan_parallel/src/scalar/fp2.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use zeroize::Zeroize;
1414
#[derive(Clone, Copy, Eq, Serialize, Deserialize, Hash, Debug)]
1515
pub struct ScalarExt2(GoldilocksExt2);
1616

17+
unsafe impl Send for ScalarExt2 {}
18+
unsafe impl Sync for ScalarExt2 {}
19+
1720
impl From<GoldilocksExt2> for ScalarExt2 {
1821
fn from(g: GoldilocksExt2) -> Self {
1922
Self(g)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const u32 REPETITION = 10000
1+
const u32 REPETITION = 1000

0 commit comments

Comments
 (0)