Skip to content

Commit

Permalink
parallel sha256
Browse files Browse the repository at this point in the history
  • Loading branch information
weikengchen committed Aug 12, 2024
1 parent 38e79db commit 7292c41
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version.workspace = true
edition.workspace = true

[features]
default = ["parallel"]
parallel = ["rayon"]
small_blowup = []
tiny_blowup = []
Expand Down
23 changes: 15 additions & 8 deletions crates/prover/src/core/backend/simd/sha256.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use itertools::Itertools;
#[cfg(feature = "parallel")]
use rayon::prelude::*;

use crate::core::backend::simd::column::BaseColumn;
use crate::core::backend::simd::SimdBackend;
Expand All @@ -22,13 +24,18 @@ impl MerkleOps<BWSSha256MerkleHasher> for SimdBackend {
prev_layer: Option<&Vec<BWSSha256Hash>>,
columns: &[&BaseColumn],
) -> Vec<BWSSha256Hash> {
return (0..1 << log_size)
.map(|i| {
BWSSha256MerkleHasher::hash_node(
prev_layer.map(|prev_layer| (prev_layer[2 * i], prev_layer[2 * i + 1])),
&columns.iter().map(|column| column.at(i)).collect_vec(),
)
})
.collect();
#[cfg(not(feature = "parallel"))]
let iter = 0..1 << log_size;

#[cfg(feature = "parallel")]
let iter = (0..1 << log_size).into_par_iter();

iter.map(|i| {
BWSSha256MerkleHasher::hash_node(
prev_layer.map(|prev_layer| (prev_layer[2 * i], prev_layer[2 * i + 1])),
&columns.iter().map(|column| column.at(i)).collect_vec(),
)
})
.collect()
}
}
4 changes: 3 additions & 1 deletion crates/prover/src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ use crate::core::vcs::ops::MerkleOps;
use crate::core::vcs::verifier::MerkleVerificationError;

#[cfg(all(feature = "tiny_blowup", feature = "small_blowup"))]
compile_error!("feature \"tiny_blowup\" and feature \"small_blowup\" cannot be enabled at the same time");
compile_error!(
"feature \"tiny_blowup\" and feature \"small_blowup\" cannot be enabled at the same time"
);

#[cfg(not(any(feature = "small_blowup", feature = "tiny_blowup")))]
pub const LOG_BLOWUP_FACTOR: u32 = 10;
Expand Down

0 comments on commit 7292c41

Please sign in to comment.