Skip to content

Commit

Permalink
feat(benchmark data): accelerate the benchmark data generation. 2^20 …
Browse files Browse the repository at this point in the history
…x 10 benchmark data can be gen in 5 min
  • Loading branch information
moven0831 committed Apr 16, 2024
1 parent 2a25cdf commit 66b0ae2
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
msm_size,num_msm,avg_processing_time(ms)
8,5,1.9163841111111113
8,10,1.7483373
12,5,10.582532222222222
12,10,10.095271
16,5,125.626062375
16,10,127.2508999
18,5,464.1663834
18,10,460.5166749
8,5,2.4868250000000005
8,10,1.4471125
12,5,11.718741600000001
12,10,13.3709541
22 changes: 0 additions & 22 deletions mopro-core/benchmarks/gpu_explorations/msm_bench_rust_laptop.csv

This file was deleted.

22 changes: 0 additions & 22 deletions mopro-core/benchmarks/gpu_explorations/msm_bench_swift_laptop.csv

This file was deleted.

10 changes: 2 additions & 8 deletions mopro-core/benchmarks/gpu_explorations/trapdoor_benchmark.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
msm_size,num_msm,avg_processing_time(ms)
8,5,5.533328777777778
8,10,5.5564666
12,5,47.73581022222222
12,10,47.852099800000005
16,5,512.365895875
16,10,514.2835289000001
18,5,1808.0984747999998
18,10,1813.8454333999998
8,5,5.826849999999999
8,10,5.126025200000001
19 changes: 10 additions & 9 deletions mopro-core/src/middleware/gpu_explorations/arkworks_pippenger.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use ark_bls12_377::{Fr as ScalarField, G1Affine, G1Projective};
// use ark_bn254::{Fr as ScalarField, FrConfig, G1Affine as GAffine, G1Projective as G};
use ark_ec::{AffineRepr, VariableBaseMSM};
use ark_ff::{BigInt, Field, FpConfig};
use ark_serialize::Write;
use ark_ec::VariableBaseMSM;
use ark_ff::BigInt;
use std::time::{Duration, Instant};

use crate::middleware::gpu_explorations::utils::{benchmark::BenchmarkResult, preprocess};

use std::fs::File;
use std::time::{Duration, Instant};

pub fn benchmark_msm<I>(
instances: I,
iterations: u32,
Expand Down Expand Up @@ -37,9 +34,9 @@ where
}

let mut instance_total_duration = Duration::ZERO;
for i in 0..iterations {
for _i in 0..iterations {
let start = Instant::now();
let result =
let _result =
<G1Projective as VariableBaseMSM>::msm(&parsed_points[..], &parsed_scalars[..])
.unwrap();

Expand Down Expand Up @@ -94,6 +91,9 @@ pub fn run_benchmark(
mod tests {
use super::*;

use ark_serialize::Write;
use std::fs::File;

const INSTANCE_SIZE: u32 = 16;
const NUM_INSTANCE: u32 = 10;
const UTILSPATH: &str = "../mopro-core/src/middleware/gpu_explorations/utils/vectors";
Expand Down Expand Up @@ -130,7 +130,8 @@ mod tests {
let output_path = format!("{}/{}_benchmark.txt", &BENCHMARKSPATH, "arkworks_pippenger");
let mut output_file = File::create(output_path).expect("output file creation failed");
writeln!(output_file, "msm_size,num_msm,avg_processing_time(ms)");
let instance_size = vec![8, 12, 16, 18];

let instance_size = vec![8, 12, 16, 18, 20];
let num_instance = vec![5, 10];
for size in &instance_size {
for num in &num_instance {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ mod local_msm;

use ark_bls12_377_3::G1Affine;
use ark_ec_3::AffineCurve;
use ark_ff::BigInt;
use ark_serialize_3::Write;
use ark_std::{One, Zero};
use local_msm::{
edwards_from_neg_one_a, edwards_proj_to_affine, edwards_to_neg_one_a, edwards_to_sw,
multi_scalar_mul, sw_to_edwards, EdwardsAffine, ExEdwardsAffine,
};
use std::fs::File;
use std::time::{Duration, Instant};
use thiserror::Error;

use crate::middleware::gpu_explorations::utils::{benchmark::BenchmarkResult, preprocess};

Expand Down Expand Up @@ -45,13 +41,13 @@ where
let scalars = &instance.1;

let mut total_duration = Duration::ZERO;
for i in 0..iterations {
for _i in 0..iterations {
let start = Instant::now();
let result = multi_scalar_mul(&points[..], &scalars[..]);
let result = edwards_from_neg_one_a(edwards_proj_to_affine(result));
let result = edwards_to_sw(result);

let result = if result.x == <G1Affine as AffineCurve>::BaseField::zero()
let _result = if result.x == <G1Affine as AffineCurve>::BaseField::zero()
&& result.y == <G1Affine as AffineCurve>::BaseField::one()
{
G1Affine::new(result.x, result.y, true)
Expand Down Expand Up @@ -110,6 +106,9 @@ pub fn run_benchmark(
mod tests {
use super::*;

use ark_serialize_3::Write;
use std::fs::File;

const INSTANCE_SIZE: u32 = 16;
const NUM_INSTANCE: u32 = 10;
const UTILSPATH: &str = "../mopro-core/src/middleware/gpu_explorations/utils/vectors";
Expand Down Expand Up @@ -146,7 +145,8 @@ mod tests {
let output_path = format!("{}/{}_benchmark.txt", &BENCHMARKSPATH, "trapdoor");
let mut output_file = File::create(output_path).expect("output file creation failed");
writeln!(output_file, "msm_size,num_msm,avg_processing_time(ms)");
let instance_size = vec![8, 12, 16, 18];

let instance_size = vec![8, 12, 16, 18, 20];
let num_instance = vec![5, 10];
for size in &instance_size {
for num in &num_instance {
Expand Down
10 changes: 3 additions & 7 deletions mopro-core/src/middleware/gpu_explorations/utils/preprocess.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use ark_bls12_377_3;
use ark_ff_3::{fields::Field, BigInteger, PrimeField};
use ark_ff_3::{fields::Field, PrimeField};
use ark_serialize_3::{CanonicalDeserialize, CanonicalSerialize, SerializationError};
use ark_std::{
rand::{Rng, RngCore},
Zero,
};
use ark_std::rand::{Rng, RngCore};
use std::collections::VecDeque;
use std::fs::File;
use thiserror::Error;
Expand Down Expand Up @@ -138,10 +135,9 @@ impl From<(Vec<Vec<Point>>, Vec<Vec<Scalar>>)> for VectorInputIterator {
}

fn gen_random_vectors<R: RngCore>(instance_size: u32, rng: &mut R) -> Instance {
let num_bytes = ark_bls12_377_3::Fr::zero();
let mut points = Vec::<Point>::new();
let mut scalars = Vec::<Scalar>::new();
let mut bytes = vec![0; instance_size as usize];
let mut bytes = vec![0; 32]; // the size of scalar is at most 32 Bytes
let mut scalar;

// Generate instances with each having instance_size points and scalars
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 66b0ae2

Please sign in to comment.