Skip to content

Commit

Permalink
use simd inner product?
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfloatersu committed Nov 13, 2024
1 parent 172a802 commit a324848
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 70 deletions.
77 changes: 52 additions & 25 deletions pcs/benches/orion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ use std::{hint::black_box, ops::Mul, time::Duration};
use arith::{Field, FieldSerde, SimdField};
use ark_std::test_rng;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use gf2::{GF2x128, GF2x64, GF2};
use gf2_128::GF2_128;
use mersenne31::{M31Ext3, M31x16, M31};
use gf2::{GF2x128, GF2x64, GF2x8, GF2};
use gf2_128::{GF2_128x8, GF2_128};
use mersenne31::{M31Ext3, M31Ext3x16, M31x16, M31};
use pcs::{OrionPCS, OrionPCSSetup, PolynomialCommitmentScheme, ORION_CODE_PARAMETER_INSTANCE};
use polynomials::MultiLinearPoly;
use transcript::{BytesHashTranscript, Keccak256hasher, Transcript};
use tynm::type_name;

fn committing_benchmark_helper<F, PackF, EvalF, T>(
fn committing_benchmark_helper<F, PackF, EvalF, IPPackF, IPPackEvalF, T>(
c: &mut Criterion,
lowest_num_vars: usize,
highest_num_vars: usize,
) where
F: Field + FieldSerde,
PackF: SimdField<Scalar = F>,
EvalF: Field + FieldSerde + From<F> + Mul<F, Output = EvalF>,
IPPackF: SimdField<Scalar = F>,
IPPackEvalF: SimdField<Scalar = EvalF> + Mul<IPPackF, Output = IPPackEvalF>,
T: Transcript<EvalF>,
{
let mut group = c.benchmark_group(format!(
Expand All @@ -32,7 +34,7 @@ fn committing_benchmark_helper<F, PackF, EvalF, T>(
for num_vars in lowest_num_vars..=highest_num_vars {
let random_poly = MultiLinearPoly::<F>::random(num_vars, &mut rng);

let orion_pp = OrionPCS::<F, PackF, EvalF, T>::gen_srs_for_testing(
let orion_pp = OrionPCS::<F, PackF, EvalF, IPPackF, IPPackEvalF, T>::gen_srs_for_testing(
&mut rng,
&OrionPCSSetup {
num_vars,
Expand All @@ -45,10 +47,12 @@ fn committing_benchmark_helper<F, PackF, EvalF, T>(
BenchmarkId::new(format!("{num_vars} variables"), num_vars),
|b| {
b.iter(|| {
_ = black_box(OrionPCS::<F, PackF, EvalF, T>::commit(
&orion_pp,
&random_poly,
))
_ = black_box(
OrionPCS::<F, PackF, EvalF, IPPackF, IPPackEvalF, T>::commit(
&orion_pp,
&random_poly,
),
)
})
},
)
Expand All @@ -58,22 +62,34 @@ fn committing_benchmark_helper<F, PackF, EvalF, T>(
}

fn orion_committing_benchmark(c: &mut Criterion) {
committing_benchmark_helper::<GF2, GF2x128, GF2_128, BytesHashTranscript<_, Keccak256hasher>>(
c, 19, 25,
);
committing_benchmark_helper::<M31, M31x16, M31Ext3, BytesHashTranscript<_, Keccak256hasher>>(
c, 15, 20,
);
committing_benchmark_helper::<
GF2,
GF2x128,
GF2_128,
GF2x8,
GF2_128x8,
BytesHashTranscript<_, Keccak256hasher>,
>(c, 19, 25);
committing_benchmark_helper::<
M31,
M31x16,
M31Ext3,
M31x16,
M31Ext3x16,
BytesHashTranscript<_, Keccak256hasher>,
>(c, 15, 20);
}

fn opening_benchmark_helper<F, PackF, EvalF, T>(
fn opening_benchmark_helper<F, PackF, EvalF, IPPackF, IPPackEvalF, T>(
c: &mut Criterion,
lowest_num_vars: usize,
highest_num_vars: usize,
) where
F: Field + FieldSerde,
PackF: SimdField<Scalar = F>,
EvalF: Field + FieldSerde + From<F> + Mul<F, Output = EvalF>,
IPPackF: SimdField<Scalar = F>,
IPPackEvalF: SimdField<Scalar = EvalF> + Mul<IPPackF, Output = IPPackEvalF>,
T: Transcript<EvalF>,
{
let mut group = c.benchmark_group(format!(
Expand All @@ -92,22 +108,23 @@ fn opening_benchmark_helper<F, PackF, EvalF, T>(
.map(|_| EvalF::random_unsafe(&mut rng))
.collect();

let orion_pp = OrionPCS::<F, PackF, EvalF, T>::gen_srs_for_testing(
let orion_pp = OrionPCS::<F, PackF, EvalF, IPPackF, IPPackEvalF, T>::gen_srs_for_testing(
&mut rng,
&OrionPCSSetup {
num_vars,
code_parameter: ORION_CODE_PARAMETER_INSTANCE,
},
);

let commitment_with_data = OrionPCS::<F, PackF, EvalF, T>::commit(&orion_pp, &random_poly);
let commitment_with_data =
OrionPCS::<F, PackF, EvalF, IPPackF, IPPackEvalF, T>::commit(&orion_pp, &random_poly);

group
.bench_function(
BenchmarkId::new(format!("{num_vars} variables"), num_vars),
|b| {
b.iter(|| {
_ = black_box(OrionPCS::<F, PackF, EvalF, T>::open(
_ = black_box(OrionPCS::<F, PackF, EvalF, IPPackF, IPPackEvalF, T>::open(
&orion_pp,
&random_poly,
&random_point,
Expand All @@ -123,12 +140,22 @@ fn opening_benchmark_helper<F, PackF, EvalF, T>(
}

fn orion_opening_benchmark(c: &mut Criterion) {
opening_benchmark_helper::<GF2, GF2x64, GF2_128, BytesHashTranscript<_, Keccak256hasher>>(
c, 19, 25,
);
opening_benchmark_helper::<M31, M31x16, M31Ext3, BytesHashTranscript<_, Keccak256hasher>>(
c, 15, 20,
);
opening_benchmark_helper::<
GF2,
GF2x64,
GF2_128,
GF2x8,
GF2_128x8,
BytesHashTranscript<_, Keccak256hasher>,
>(c, 19, 25);
opening_benchmark_helper::<
M31,
M31x16,
M31Ext3,
M31x16,
M31Ext3x16,
BytesHashTranscript<_, Keccak256hasher>,
>(c, 15, 20);
}

criterion_group!(bench, orion_committing_benchmark, orion_opening_benchmark);
Expand Down
Loading

0 comments on commit a324848

Please sign in to comment.