Skip to content

Commit

Permalink
feat(mopro-ffi): enable arkworks_pippenger to benchmark through uniffi
Browse files Browse the repository at this point in the history
  • Loading branch information
moven0831 committed Apr 12, 2024
1 parent e025f08 commit 3df7313
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 48 deletions.
130 changes: 105 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn run_benchmark(
/ instance_durations.len() as f64;

println!(
"Done running benchmark. Check the result at: mopro-core/{:?}",
"Done running benchmark. Check the result at: {:?}",
benchmark_dir
);
Ok(BenchmarkResult {
Expand All @@ -103,8 +103,8 @@ mod tests {

const INSTANCE_SIZE: u32 = 16;
const NUM_INSTANCE: u32 = 10;
const UTILSPATH: &str = "src/middleware/gpu_explorations/utils";
const BENCHMARKSPATH: &str = "benchmarks/gpu_explorations";
const UTILSPATH: &str = "mopro-core/src/middleware/gpu_explorations/utils";
const BENCHMARKSPATH: &str = "mopro-core/benchmarks/gpu_explorations";

#[test]
fn test_benchmark_msm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ mod tests {

const INSTANCE_SIZE: u32 = 16;
const NUM_INSTANCE: u32 = 10;
const UTILSPATH: &str = "src/middleware/gpu_explorations/utils";
const BENCHMARKSPATH: &str = "benchmarks/gpu_explorations";
const UTILSPATH: &str = "mopro-core/src/middleware/gpu_explorations/utils";
const BENCHMARKSPATH: &str = "mopro-core/benchmarks/gpu_explorations";

#[test]
fn test_benchmark_msm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub type Instance = (Vec<Point>, Vec<Scalar>);

const INSTANCE_SIZE: u32 = 16;
const NUM_INSTANCE: u32 = 10;
const PATH: &str = "src/middleware/gpu_explorations/utils";
const PATH: &str = "mopro-core/src/middleware/gpu_explorations/utils";

impl FileInputIterator {
pub fn open(dir: &str) -> Result<Self, HarnessError> {
Expand Down
50 changes: 36 additions & 14 deletions mopro-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use mopro_core::middleware::circom;
use mopro_core::MoproError;

#[cfg(feature = "gpu-benchmarks")]
use mopro_core::middleware::gpu_explorations::{self, arkworks_pippenger::BenchmarkResult};
// #[cfg(feature = "gpu-benchmarks")]
use mopro_core::middleware::gpu_explorations::{
self, arkworks_pippenger,
utils::benchmark::BenchmarkResult,
};

use num_bigint::BigInt;
use std::collections::HashMap;
Expand Down Expand Up @@ -48,9 +51,9 @@ pub struct ProofCalldata {
#[derive(Debug, Clone)]
#[cfg(not(feature = "gpu-benchmarks"))]
pub struct BenchmarkResult {
pub num_msm: u32,
pub instance_size: u32,
pub num_instance: u32,
pub avg_processing_time: f64,
pub total_processing_time: f64,
}

// pub inputs: Vec<u8>,
Expand Down Expand Up @@ -213,15 +216,31 @@ impl MoproCircom {
}

#[cfg(feature = "gpu-benchmarks")]
pub fn arkworks_pippenger(num_msm: Option<u32>) -> Result<BenchmarkResult, MoproError> {
let benchmarks = gpu_explorations::arkworks_pippenger::run_msm_benchmark(num_msm).unwrap();
pub fn arkworks_pippenger(
instance_size: u32,
num_instance: u32,
utils_dir: &str,
benchmark_dir: &str,
) -> Result<BenchmarkResult, MoproError> {
let benchmarks = gpu_explorations::arkworks_pippenger::run_benchmark(
instance_size,
num_instance,
&utils_dir,
&benchmark_dir,
)
.unwrap();
Ok(benchmarks)
}

#[cfg(not(feature = "gpu-benchmarks"))]
pub fn arkworks_pippenger(_num_msm: Option<u32>) -> Result<BenchmarkResult, MoproError> {
pub fn arkworks_pippenger(
instance_size: u32,
num_instance: u32,
utils_dir: &str,
benchmark_dir: &str,
) -> Result<BenchmarkResult, MoproError> {
println!("gpu-benchmarks feature not enabled!");
// panic!("gpu-benchmarks feature not enabled!");
Ok(())
}

fn add(a: u32, b: u32) -> u32 {
Expand All @@ -243,6 +262,8 @@ uniffi::include_scaffolding!("mopro");

#[cfg(test)]
mod tests {
use core::num;

use super::*;
use ark_bn254::Fr;
use num_bigint::BigUint;
Expand Down Expand Up @@ -378,12 +399,13 @@ mod tests {
#[test]
#[cfg(feature = "gpu-benchmarks")]
fn test_arkworks_pippenger() -> Result<(), MoproError> {
let benchmarks = arkworks_pippenger(None).unwrap();
println!("\nBenchmarking {:?} msm on BN254 curve", benchmarks.num_msm);
println!(
"└─ Average msm time: {:.5} ms\n└─ Overall processing time: {:.5} ms",
benchmarks.avg_processing_time, benchmarks.total_processing_time
);
let instance_size = 16;
let num_instance = 10;
let utils_dir = "../mopro-core/src/middleware/gpu_explorations/utils";
let benchmark_dir = "../mopro-core/benchmarks/gpu_explorations";
let result =
arkworks_pippenger(instance_size, num_instance, &utils_dir, &benchmark_dir).unwrap();
println!("Benchmark result: {:#?}", result);
Ok(())
}
}
Loading

0 comments on commit 3df7313

Please sign in to comment.