-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SIMD backend for poseidon252 merkle ops - CPU IMPL
- Loading branch information
1 parent
387a072
commit b15bcbd
Showing
9 changed files
with
77 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use itertools::Itertools; | ||
use starknet_ff::FieldElement as FieldElement252; | ||
|
||
use super::CpuBackend; | ||
use crate::core::fields::m31::BaseField; | ||
use crate::core::vcs::ops::{MerkleHasher, MerkleOps}; | ||
use crate::core::vcs::poseidon252_merkle::Poseidon252MerkleHasher; | ||
|
||
impl MerkleOps<Poseidon252MerkleHasher> for CpuBackend { | ||
fn commit_on_layer( | ||
log_size: u32, | ||
prev_layer: Option<&Vec<FieldElement252>>, | ||
columns: &[&Vec<BaseField>], | ||
) -> Vec<FieldElement252> { | ||
(0..(1 << log_size)) | ||
.map(|i| { | ||
Poseidon252MerkleHasher::hash_node( | ||
prev_layer.map(|prev_layer| (prev_layer[2 * i], prev_layer[2 * i + 1])), | ||
&columns.iter().map(|column| column[i]).collect_vec(), | ||
) | ||
}) | ||
.collect() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use itertools::Itertools; | ||
use starknet_ff::FieldElement as FieldElement252; | ||
|
||
use super::SimdBackend; | ||
use crate::core::backend::{Col, Column, ColumnOps}; | ||
use crate::core::fields::m31::BaseField; | ||
#[cfg(not(target_arch = "wasm32"))] | ||
use crate::core::vcs::ops::MerkleHasher; | ||
use crate::core::vcs::ops::MerkleOps; | ||
use crate::core::vcs::poseidon252_merkle::Poseidon252MerkleHasher; | ||
|
||
impl ColumnOps<FieldElement252> for SimdBackend { | ||
type Column = Vec<FieldElement252>; | ||
|
||
fn bit_reverse_column(_column: &mut Self::Column) { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
impl MerkleOps<Poseidon252MerkleHasher> for SimdBackend { | ||
// TODO(ShaharS): replace with SIMD implementation. | ||
fn commit_on_layer( | ||
log_size: u32, | ||
prev_layer: Option<&Vec<FieldElement252>>, | ||
columns: &[&Col<Self, BaseField>], | ||
) -> Vec<FieldElement252> { | ||
(0..(1 << log_size)) | ||
.map(|i| { | ||
Poseidon252MerkleHasher::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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters