From f4e419d6c2e46adec5751eb6c82a4211a5de06a9 Mon Sep 17 00:00:00 2001 From: moven0831 Date: Tue, 16 Jan 2024 18:08:31 +0800 Subject: [PATCH 01/11] refactor(gpu-benchmarks): add feature flags for gpu-benchmarks --- mopro-core/Cargo.toml | 9 ++++++--- .../gpu_exploration/bin/generate_benchmark_report.rs | 9 +++++++-- mopro-core/src/middleware/mod.rs | 2 ++ mopro-ffi/Cargo.toml | 3 ++- mopro-ffi/src/lib.rs | 6 +++++- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/mopro-core/Cargo.toml b/mopro-core/Cargo.toml index c2b87f78..dd902ed5 100644 --- a/mopro-core/Cargo.toml +++ b/mopro-core/Cargo.toml @@ -13,6 +13,7 @@ wasmer = { git = "https://github.com/oskarth/wasmer.git", rev = "09c7070" } [features] default = [] dylib = ["wasmer/dylib"] +gpu-benchmarks = ["jemalloc-ctl", "jemallocator"] [dependencies] ark-circom = { git = "https://github.com/arkworks-rs/circom-compat.git" } @@ -44,8 +45,10 @@ ark-zkey = { path = "../ark-zkey" } thiserror = "=1.0.39" color-eyre = "=0.6.2" criterion = "=0.3.6" -jemalloc-ctl = "0.5.4" -jemallocator = "0.5.4" + +# GPU benchmarks +jemalloc-ctl = { version = "0.5.4", optional = true} +jemallocator = { version = "0.5.4", optional = true} [build-dependencies] color-eyre = "0.6" @@ -54,4 +57,4 @@ wasmer = { git = "https://github.com/oskarth/wasmer.git", rev = "09c7070" } [[bin]] name = "generate_benchmark_report" -path = "src/middleware/gpu_exploration/bin/generate_benchmark_report.rs" +path = "src/middleware/gpu_explorations/bin/generate_benchmark_report.rs" diff --git a/mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs b/mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs index 9ca522bc..140c54a1 100644 --- a/mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs +++ b/mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs @@ -1,9 +1,14 @@ // This file is used to generate the benchmark report for the GPU exploration middleware. -use std::{env, fs::File, io::Write}; -use mopro_core::middleware::gpu_exploration::run_msm_benchmark; +#[cfg(feature = "gpu-benchmarks")] +use { + std::{env, fs::File, io::Write}, + mopro_core::middleware::gpu_exploration::run_msm_benchmark +}; + +#[cfg(feature = "gpu-benchmarks")] fn main() { let path = env::current_dir() .unwrap() diff --git a/mopro-core/src/middleware/mod.rs b/mopro-core/src/middleware/mod.rs index 629650cb..93ff7dc7 100644 --- a/mopro-core/src/middleware/mod.rs +++ b/mopro-core/src/middleware/mod.rs @@ -1,2 +1,4 @@ pub mod circom; + +#[cfg(feature = "gpu-benchmarks")] pub mod gpu_exploration; diff --git a/mopro-ffi/Cargo.toml b/mopro-ffi/Cargo.toml index e8fbd111..141c5aaa 100644 --- a/mopro-ffi/Cargo.toml +++ b/mopro-ffi/Cargo.toml @@ -16,8 +16,9 @@ path = "uniffi-bindgen.rs" [features] default = [] -# If we enable dylib here it should be enabled in mopro-core as well +# If we enable them here, they should be enabled in mopro-core as well dylib = ["mopro-core/dylib"] +gpu-benchmarks = ["mopro-core/gpu-benchmarks"] [patch.crates-io] # NOTE: Forked wasmer to work around memory limits diff --git a/mopro-ffi/src/lib.rs b/mopro-ffi/src/lib.rs index 892293b0..70c1f1e9 100644 --- a/mopro-ffi/src/lib.rs +++ b/mopro-ffi/src/lib.rs @@ -1,7 +1,9 @@ use mopro_core::middleware::circom; -use mopro_core::middleware::gpu_exploration::{self, BenchmarkResult}; use mopro_core::MoproError; +#[cfg(feature = "gpu-benchmarks")] +use mopro_core::middleware::gpu_exploration::{self, BenchmarkResult}; + use num_bigint::BigInt; use std::collections::HashMap; use std::path::Path; @@ -159,6 +161,7 @@ impl MoproCircom { } } +#[cfg(feature = "gpu-benchmarks")] pub fn run_msm_benchmark(num_msm: Option) -> Result { let benchmarks = gpu_exploration::run_msm_benchmark(num_msm).unwrap(); Ok(benchmarks) @@ -300,6 +303,7 @@ mod tests { } #[test] + #[cfg(feature = "gpu-benchmarks")] fn test_run_msm_benchmark() -> Result<(), MoproError> { let benchmarks = run_msm_benchmark(None).unwrap(); println!("\nBenchmarking {:?} msm on BN254 curve", benchmarks.num_msm); From a3acb44958f5f88d8970906312e245417746b332 Mon Sep 17 00:00:00 2001 From: moven0831 Date: Tue, 16 Jan 2024 18:14:16 +0800 Subject: [PATCH 02/11] chore(generate benchmark report): move the report to non-code dir --- .../gpu_explorations}/msm_bench.csv | 0 .../middleware/gpu_exploration/bin/generate_benchmark_report.rs | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename mopro-core/{src/middleware/gpu_exploration => benchmarks/gpu_explorations}/msm_bench.csv (100%) diff --git a/mopro-core/src/middleware/gpu_exploration/msm_bench.csv b/mopro-core/benchmarks/gpu_explorations/msm_bench.csv similarity index 100% rename from mopro-core/src/middleware/gpu_exploration/msm_bench.csv rename to mopro-core/benchmarks/gpu_explorations/msm_bench.csv diff --git a/mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs b/mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs index 140c54a1..a0deb10f 100644 --- a/mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs +++ b/mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs @@ -12,7 +12,7 @@ use { fn main() { let path = env::current_dir() .unwrap() - .join("src/middleware/gpu_exploration/msm_bench.csv"); + .join("benchmarks/gpu_explorations/msm_bench.csv"); let mut file = File::create(path).unwrap(); writeln!( file, From 5f1c7d69969641f0b6c1bb809bbf500bfd9a1862 Mon Sep 17 00:00:00 2001 From: moven0831 Date: Tue, 16 Jan 2024 18:21:28 +0800 Subject: [PATCH 03/11] style(gpu_explorations): rename the directory and related import dep --- .../bin/generate_benchmark_report.rs | 2 +- .../middleware/{gpu_exploration => gpu_explorations}/mod.rs | 0 mopro-core/src/middleware/mod.rs | 2 +- mopro-ffi/src/lib.rs | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename mopro-core/src/middleware/{gpu_exploration => gpu_explorations}/bin/generate_benchmark_report.rs (93%) rename mopro-core/src/middleware/{gpu_exploration => gpu_explorations}/mod.rs (100%) diff --git a/mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs b/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs similarity index 93% rename from mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs rename to mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs index a0deb10f..87fb8f26 100644 --- a/mopro-core/src/middleware/gpu_exploration/bin/generate_benchmark_report.rs +++ b/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs @@ -4,7 +4,7 @@ #[cfg(feature = "gpu-benchmarks")] use { std::{env, fs::File, io::Write}, - mopro_core::middleware::gpu_exploration::run_msm_benchmark + mopro_core::middleware::gpu_explorations::run_msm_benchmark }; diff --git a/mopro-core/src/middleware/gpu_exploration/mod.rs b/mopro-core/src/middleware/gpu_explorations/mod.rs similarity index 100% rename from mopro-core/src/middleware/gpu_exploration/mod.rs rename to mopro-core/src/middleware/gpu_explorations/mod.rs diff --git a/mopro-core/src/middleware/mod.rs b/mopro-core/src/middleware/mod.rs index 93ff7dc7..1e1bf466 100644 --- a/mopro-core/src/middleware/mod.rs +++ b/mopro-core/src/middleware/mod.rs @@ -1,4 +1,4 @@ pub mod circom; #[cfg(feature = "gpu-benchmarks")] -pub mod gpu_exploration; +pub mod gpu_explorations; diff --git a/mopro-ffi/src/lib.rs b/mopro-ffi/src/lib.rs index 70c1f1e9..9995def4 100644 --- a/mopro-ffi/src/lib.rs +++ b/mopro-ffi/src/lib.rs @@ -2,7 +2,7 @@ use mopro_core::middleware::circom; use mopro_core::MoproError; #[cfg(feature = "gpu-benchmarks")] -use mopro_core::middleware::gpu_exploration::{self, BenchmarkResult}; +use mopro_core::middleware::gpu_explorations::{self, BenchmarkResult}; use num_bigint::BigInt; use std::collections::HashMap; @@ -163,7 +163,7 @@ impl MoproCircom { #[cfg(feature = "gpu-benchmarks")] pub fn run_msm_benchmark(num_msm: Option) -> Result { - let benchmarks = gpu_exploration::run_msm_benchmark(num_msm).unwrap(); + let benchmarks = gpu_explorations::run_msm_benchmark(num_msm).unwrap(); Ok(benchmarks) } From 7ca9e5916fbd62888afe58f1de5571f92cbc7566 Mon Sep 17 00:00:00 2001 From: moven0831 Date: Tue, 16 Jan 2024 18:29:22 +0800 Subject: [PATCH 04/11] fix(memory benchmark): now only benchmark allocated memory in the current process --- .../benchmarks/gpu_explorations/msm_bench.csv | 68 +++++++++---------- .../src/middleware/gpu_explorations/mod.rs | 3 - 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/mopro-core/benchmarks/gpu_explorations/msm_bench.csv b/mopro-core/benchmarks/gpu_explorations/msm_bench.csv index 88afe9a0..bd72afbf 100644 --- a/mopro-core/benchmarks/gpu_explorations/msm_bench.csv +++ b/mopro-core/benchmarks/gpu_explorations/msm_bench.csv @@ -1,35 +1,35 @@ num_msm,avg_processing_time(sec),total_processing_time(sec),memory_allocated(MiB) -1,0.008822708,0.008822708,2.312103271484375 -31,0.004979676,0.154369957,2.358978271484375 -61,0.004754233,0.290008248,2.358978271484375 -91,0.004735598,0.430939507,2.1419601440429688 -121,0.004737351,0.57321958,0.9750289916992188 -151,0.004769703,0.72022524,0.69183349609375 -181,0.004792001,0.867352249,0.5846481323242188 -211,0.004802445,1.01331618,0.5482406616210938 -241,0.004778901,1.151715413,0.5423812866210938 -271,0.004821324,1.306579126,0.5702133178710938 -301,0.004762685,1.433568411,0.5643539428710938 -331,0.005091614,1.685324322,0.5599594116210938 -361,0.005040754,1.8197122559999999,0.5672836303710938 -391,0.004781469,1.8695547380000002,0.5497055053710938 -421,0.004786061,2.0149323,0.5584945678710938 -451,0.004767077,2.149952535,0.5658187866210938 -481,0.004910287,2.361848501,0.5628890991210938 -511,0.004764801,2.434813838,0.5628890991210938 -541,0.004781617,2.586855505,0.5599594116210938 -571,0.004769476,2.723371822,0.5438461303710938 -601,0.004779723,2.872613956,0.5628890991210938 -631,0.004779016,3.015559335,0.5658187866210938 -661,0.004775623,3.1566879979999998,0.5423812866210938 -691,0.004799624,3.316540845,0.5497055053710938 -721,0.004821745,3.476478916,0.5599594116210938 -751,0.004786715,3.594824006,0.5423812866210938 -781,0.004852893,3.790110259,0.5687484741210938 -811,0.004822955,3.911417633,0.5614242553710938 -841,0.004861652,4.088650051,0.5467758178710938 -871,0.004823686,4.201431704,0.5628890991210938 -901,0.004804262,4.328640835,0.5658187866210938 -931,0.004812316,4.480266961,0.5467758178710938 -961,0.004810656,4.62304139,0.5453109741210938 -991,0.004872067,4.828219615,0.5643539428710938 +1,0.012875625,0.012875625,0.0498046875 +31,0.005799682,0.179790167,0.0498046875 +61,0.005228821,0.318958082,0.0498046875 +91,0.005265641,0.47917334,0.0498046875 +121,0.005257575,0.636166627,0.0498046875 +151,0.005289685,0.798742547,0.0498046875 +181,0.005295827,0.958544867,0.0498046875 +211,0.005356247,1.130168299,0.0498046875 +241,0.005232349,1.260996293,0.0498046875 +271,0.005230386,1.417434817,0.0498046875 +301,0.005238259,1.5767161650000001,0.0498046875 +331,0.005267676,1.7436007629999999,0.0498046875 +361,0.005276224,1.9047169579999998,0.0498046875 +391,0.005249628,2.052604921,0.0498046875 +421,0.005256333,2.212916535,0.0498046875 +451,0.00523339,2.360259162,0.0498046875 +481,0.005247296,2.523949487,0.0498046875 +511,0.005240642,2.677968135,0.0498046875 +541,0.005248035,2.8391869720000003,0.0498046875 +571,0.005339112,3.048633024,0.0498046875 +601,0.005241671,3.150244678,0.0498046875 +631,0.005250702,3.313193055,0.0498046875 +661,0.005264906,3.480103197,0.0498046875 +691,0.005282993,3.650548787,0.0498046875 +721,0.005282146,3.808427579,0.0498046875 +751,0.005244537,3.938647653,0.0498046875 +781,0.00524456,4.096001381,0.0498046875 +811,0.005246436,4.254860241,0.0498046875 +841,0.005322642,4.476341959,0.0498046875 +871,0.005358956,4.667651485,0.0498046875 +901,0.005256114,4.735759053,0.0498046875 +931,0.005252209,4.889806914,0.0498046875 +961,0.005254823,5.049885773,0.0498046875 +991,0.00526165,5.214295943,0.0498046875 diff --git a/mopro-core/src/middleware/gpu_explorations/mod.rs b/mopro-core/src/middleware/gpu_explorations/mod.rs index 1422c839..e6cb7ede 100644 --- a/mopro-core/src/middleware/gpu_explorations/mod.rs +++ b/mopro-core/src/middleware/gpu_explorations/mod.rs @@ -14,9 +14,6 @@ pub struct BenchmarkResult { pub allocated_memory: f64, } -#[global_allocator] -static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; - fn single_msm() -> Result<(), Box> { let mut rng = ark_std::test_rng(); From 3135f58a52780c5ee2ae29ff2b9da683c6936938 Mon Sep 17 00:00:00 2001 From: moven0831 Date: Tue, 16 Jan 2024 18:37:41 +0800 Subject: [PATCH 05/11] fix(udl): still finding a way to represent function with feature flags --- mopro-ffi/src/mopro.udl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mopro-ffi/src/mopro.udl b/mopro-ffi/src/mopro.udl index 185f3a1d..5420081e 100644 --- a/mopro-ffi/src/mopro.udl +++ b/mopro-ffi/src/mopro.udl @@ -14,8 +14,8 @@ namespace mopro { [Throws=MoproError] boolean verify_proof2(bytes proof, bytes public_input); - [Throws=MoproError] - BenchmarkResult run_msm_benchmark(u32? num_msm); + // [Throws=MoproError] + // BenchmarkResult run_msm_benchmark(u32? num_msm); }; dictionary SetupResult { @@ -27,12 +27,12 @@ dictionary GenerateProofResult { bytes inputs; }; -dictionary BenchmarkResult { - u32 num_msm; - double avg_processing_time; - double total_processing_time; - double allocated_memory; -}; +// dictionary BenchmarkResult { +// u32 num_msm; +// double avg_processing_time; +// double total_processing_time; +// double allocated_memory; +// }; [Error] enum MoproError { From 227602c12f59907bb65e5001ad938d5411a4155e Mon Sep 17 00:00:00 2001 From: moven0831 Date: Tue, 16 Jan 2024 18:41:37 +0800 Subject: [PATCH 06/11] style(benchmark report): match fmt --- .../gpu_explorations/bin/generate_benchmark_report.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs b/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs index 87fb8f26..83701fc9 100644 --- a/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs +++ b/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs @@ -1,13 +1,11 @@ // This file is used to generate the benchmark report for the GPU exploration middleware. - #[cfg(feature = "gpu-benchmarks")] use { + mopro_core::middleware::gpu_explorations::run_msm_benchmark, std::{env, fs::File, io::Write}, - mopro_core::middleware::gpu_explorations::run_msm_benchmark }; - #[cfg(feature = "gpu-benchmarks")] fn main() { let path = env::current_dir() From 8ffd6ab5a06a9f74deeef57ddc9ccd90d4352672 Mon Sep 17 00:00:00 2001 From: moven0831 Date: Tue, 16 Jan 2024 19:24:38 +0800 Subject: [PATCH 07/11] refactor(msm_benchmarks): adjust the scale of benchmarks --- .../bin/generate_benchmark_report.rs | 2 +- mopro-core/src/middleware/gpu_explorations/mod.rs | 14 ++++++-------- mopro-ffi/src/lib.rs | 4 ++-- mopro-ffi/src/mopro.udl | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs b/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs index 83701fc9..0269f2b2 100644 --- a/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs +++ b/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs @@ -14,7 +14,7 @@ fn main() { let mut file = File::create(path).unwrap(); writeln!( file, - "num_msm,avg_processing_time(sec),total_processing_time(sec),memory_allocated(MiB)" + "num_msm,avg_processing_time(ms),total_processing_time(ms),memory_allocated(Bytes)" ) .unwrap(); // generate 30 figures to run (range from 1 to 1000) diff --git a/mopro-core/src/middleware/gpu_explorations/mod.rs b/mopro-core/src/middleware/gpu_explorations/mod.rs index e6cb7ede..7e27ad76 100644 --- a/mopro-core/src/middleware/gpu_explorations/mod.rs +++ b/mopro-core/src/middleware/gpu_explorations/mod.rs @@ -11,7 +11,7 @@ pub struct BenchmarkResult { pub num_msm: u32, pub avg_processing_time: f64, pub total_processing_time: f64, - pub allocated_memory: f64, + pub allocated_memory: u32, } fn single_msm() -> Result<(), Box> { @@ -45,15 +45,13 @@ pub fn run_msm_benchmark(num_msm: Option) -> Result Date: Tue, 16 Jan 2024 19:25:58 +0800 Subject: [PATCH 08/11] chore(report): update the benchmarks with new scale and release mode --- .../benchmarks/gpu_explorations/msm_bench.csv | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/mopro-core/benchmarks/gpu_explorations/msm_bench.csv b/mopro-core/benchmarks/gpu_explorations/msm_bench.csv index bd72afbf..afe83153 100644 --- a/mopro-core/benchmarks/gpu_explorations/msm_bench.csv +++ b/mopro-core/benchmarks/gpu_explorations/msm_bench.csv @@ -1,35 +1,35 @@ -num_msm,avg_processing_time(sec),total_processing_time(sec),memory_allocated(MiB) -1,0.012875625,0.012875625,0.0498046875 -31,0.005799682,0.179790167,0.0498046875 -61,0.005228821,0.318958082,0.0498046875 -91,0.005265641,0.47917334,0.0498046875 -121,0.005257575,0.636166627,0.0498046875 -151,0.005289685,0.798742547,0.0498046875 -181,0.005295827,0.958544867,0.0498046875 -211,0.005356247,1.130168299,0.0498046875 -241,0.005232349,1.260996293,0.0498046875 -271,0.005230386,1.417434817,0.0498046875 -301,0.005238259,1.5767161650000001,0.0498046875 -331,0.005267676,1.7436007629999999,0.0498046875 -361,0.005276224,1.9047169579999998,0.0498046875 -391,0.005249628,2.052604921,0.0498046875 -421,0.005256333,2.212916535,0.0498046875 -451,0.00523339,2.360259162,0.0498046875 -481,0.005247296,2.523949487,0.0498046875 -511,0.005240642,2.677968135,0.0498046875 -541,0.005248035,2.8391869720000003,0.0498046875 -571,0.005339112,3.048633024,0.0498046875 -601,0.005241671,3.150244678,0.0498046875 -631,0.005250702,3.313193055,0.0498046875 -661,0.005264906,3.480103197,0.0498046875 -691,0.005282993,3.650548787,0.0498046875 -721,0.005282146,3.808427579,0.0498046875 -751,0.005244537,3.938647653,0.0498046875 -781,0.00524456,4.096001381,0.0498046875 -811,0.005246436,4.254860241,0.0498046875 -841,0.005322642,4.476341959,0.0498046875 -871,0.005358956,4.667651485,0.0498046875 -901,0.005256114,4.735759053,0.0498046875 -931,0.005252209,4.889806914,0.0498046875 -961,0.005254823,5.049885773,0.0498046875 -991,0.00526165,5.214295943,0.0498046875 +num_msm,avg_processing_time(ms),total_processing_time(ms),memory_allocated(Bytes) +1,0.6250840000000001,0.6250840000000001,52224 +31,0.40569758064516126,12.576625,52224 +61,0.32727327868852457,19.96367,52224 +91,0.3113585054945055,28.333624,52224 +121,0.32912845454545453,39.824543,52224 +151,0.33073816556291386,49.941463,52224 +181,0.3360711325966851,60.828875,52224 +211,0.3318633886255924,70.023175,52224 +241,0.3411267178423236,82.211539,52224 +271,0.32159117712177115,87.151209,52224 +301,0.3078752524916944,92.670451,52224 +331,0.30928764652567975,102.374211,52224 +361,0.32174583102493076,116.150245,52224 +391,0.3085680255754476,120.650098,52224 +421,0.3061851757719715,128.90395900000001,52224 +451,0.306365,138.170615,52224 +481,0.31938593970893975,153.624637,52224 +511,0.30569840900195694,156.211887,52224 +541,0.30587036783733823,165.475869,52224 +571,0.3043690210157618,173.79471099999998,52224 +601,0.31386711480865226,188.634136,52224 +631,0.3041413914421553,191.913218,52224 +661,0.30660368381240544,202.665035,52224 +691,0.3066131534008683,211.869689,52224 +721,0.30503057558945906,219.927045,52224 +751,0.30833299201065245,231.558077,52224 +781,0.3131149014084507,244.542738,52224 +811,0.3048875141800247,247.26377399999998,52224 +841,0.3059034256837099,257.26478099999997,52224 +871,0.3077411458094145,268.042538,52224 +901,0.32275668812430636,290.803776,52224 +931,0.32837154027926957,305.71390399999996,52224 +961,0.3213010801248699,308.770338,52224 +991,0.31405781735620586,311.23129700000004,52224 From 6a94aa5eaf7d1c0bbf0d639762ab0046800e590f Mon Sep 17 00:00:00 2001 From: moven0831 Date: Tue, 16 Jan 2024 19:54:17 +0800 Subject: [PATCH 09/11] chore(report): add more data points due to the enhanced speed in release mode --- .../benchmarks/gpu_explorations/msm_bench.csv | 55 +++++++------------ .../bin/generate_benchmark_report.rs | 7 +-- 2 files changed, 24 insertions(+), 38 deletions(-) diff --git a/mopro-core/benchmarks/gpu_explorations/msm_bench.csv b/mopro-core/benchmarks/gpu_explorations/msm_bench.csv index afe83153..f5dfaf98 100644 --- a/mopro-core/benchmarks/gpu_explorations/msm_bench.csv +++ b/mopro-core/benchmarks/gpu_explorations/msm_bench.csv @@ -1,35 +1,22 @@ num_msm,avg_processing_time(ms),total_processing_time(ms),memory_allocated(Bytes) -1,0.6250840000000001,0.6250840000000001,52224 -31,0.40569758064516126,12.576625,52224 -61,0.32727327868852457,19.96367,52224 -91,0.3113585054945055,28.333624,52224 -121,0.32912845454545453,39.824543,52224 -151,0.33073816556291386,49.941463,52224 -181,0.3360711325966851,60.828875,52224 -211,0.3318633886255924,70.023175,52224 -241,0.3411267178423236,82.211539,52224 -271,0.32159117712177115,87.151209,52224 -301,0.3078752524916944,92.670451,52224 -331,0.30928764652567975,102.374211,52224 -361,0.32174583102493076,116.150245,52224 -391,0.3085680255754476,120.650098,52224 -421,0.3061851757719715,128.90395900000001,52224 -451,0.306365,138.170615,52224 -481,0.31938593970893975,153.624637,52224 -511,0.30569840900195694,156.211887,52224 -541,0.30587036783733823,165.475869,52224 -571,0.3043690210157618,173.79471099999998,52224 -601,0.31386711480865226,188.634136,52224 -631,0.3041413914421553,191.913218,52224 -661,0.30660368381240544,202.665035,52224 -691,0.3066131534008683,211.869689,52224 -721,0.30503057558945906,219.927045,52224 -751,0.30833299201065245,231.558077,52224 -781,0.3131149014084507,244.542738,52224 -811,0.3048875141800247,247.26377399999998,52224 -841,0.3059034256837099,257.26478099999997,52224 -871,0.3077411458094145,268.042538,52224 -901,0.32275668812430636,290.803776,52224 -931,0.32837154027926957,305.71390399999996,52224 -961,0.3213010801248699,308.770338,52224 -991,0.31405781735620586,311.23129700000004,52224 +1,1.318041,1.318041,52224 +500,0.358647444,179.323722,52224 +1000,0.303445498,303.445498,52224 +1500,0.30560589400000004,458.408841,52224 +2000,0.307506974,615.013948,52224 +2500,0.30087727480000004,752.1931870000001,52224 +3000,0.2974580376666667,892.3741130000001,52224 +3500,0.29932860400000005,1047.650114,52224 +4000,0.29971050875,1198.842035,52224 +4500,0.29770848288888885,1339.6881729999998,52224 +5000,0.29796124,1489.8062,52224 +5500,0.29821722199999995,1640.1947209999998,52224 +6000,0.29704238,1782.25428,52224 +6500,0.2977782895384615,1935.558882,52224 +7000,0.2997174805714286,2098.0223640000004,52224 +7500,0.29769822346666663,2232.736676,52224 +8000,0.29741228725,2379.298298,52224 +8500,0.29773156623529407,2530.718313,52224 +9000,0.2976449374444445,2678.8044370000002,52224 +9500,0.29733350284210525,2824.6682769999998,52224 +10000,0.29742018890000005,2974.201889,52224 diff --git a/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs b/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs index 0269f2b2..7056bd00 100644 --- a/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs +++ b/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs @@ -3,7 +3,7 @@ #[cfg(feature = "gpu-benchmarks")] use { mopro_core::middleware::gpu_explorations::run_msm_benchmark, - std::{env, fs::File, io::Write}, + std::{env, cmp, fs::File, io::Write}, }; #[cfg(feature = "gpu-benchmarks")] @@ -17,9 +17,8 @@ fn main() { "num_msm,avg_processing_time(ms),total_processing_time(ms),memory_allocated(Bytes)" ) .unwrap(); - // generate 30 figures to run (range from 1 to 1000) - let trials = (1..1000).step_by(30); - + // generate trials = [1, 500, 1_000, 1_500, ..., 10_000] + let trials: Vec = (0..21).map(|i| cmp::max(i * 500, 1)).collect(); for each in trials { let bench_data = run_msm_benchmark(Some(each)).unwrap(); writeln!( From 6669736401c69c51b88865a744df26dc96768c73 Mon Sep 17 00:00:00 2001 From: moven0831 Date: Tue, 16 Jan 2024 22:38:25 +0800 Subject: [PATCH 10/11] chore(generate report): match fmt --- .../gpu_explorations/bin/generate_benchmark_report.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs b/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs index 7056bd00..533f9e39 100644 --- a/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs +++ b/mopro-core/src/middleware/gpu_explorations/bin/generate_benchmark_report.rs @@ -3,7 +3,7 @@ #[cfg(feature = "gpu-benchmarks")] use { mopro_core::middleware::gpu_explorations::run_msm_benchmark, - std::{env, cmp, fs::File, io::Write}, + std::{cmp, env, fs::File, io::Write}, }; #[cfg(feature = "gpu-benchmarks")] From dabe3899da7512798303dd451bd678b59eef5394 Mon Sep 17 00:00:00 2001 From: moven0831 Date: Tue, 16 Jan 2024 22:40:39 +0800 Subject: [PATCH 11/11] fix(uniffi-bindgen): the udl file can be satisfied no matter the gpu feature flag in on or off --- mopro-ffi/src/lib.rs | 16 ++++++++++++++++ mopro-ffi/src/mopro.udl | 16 ++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/mopro-ffi/src/lib.rs b/mopro-ffi/src/lib.rs index b9e10188..4ee8f8ea 100644 --- a/mopro-ffi/src/lib.rs +++ b/mopro-ffi/src/lib.rs @@ -29,6 +29,16 @@ pub struct SetupResult { pub provingKey: Vec, } +// NOTE: Need to hardcode the types here, otherwise UniFFI will complain if the gpu-benchmarks feature is not enabled +#[derive(Debug, Clone)] +#[cfg(not(feature = "gpu-benchmarks"))] +pub struct BenchmarkResult { + pub num_msm: u32, + pub avg_processing_time: f64, + pub total_processing_time: f64, + pub allocated_memory: u32, +} + // pub inputs: Vec, impl From for FFIError { @@ -167,6 +177,12 @@ pub fn run_msm_benchmark(num_msm: Option) -> Result) -> Result { + println!("gpu-benchmarks feature not enabled!"); + panic!("gpu-benchmarks feature not enabled!"); +} + fn add(a: u32, b: u32) -> u32 { a + b } diff --git a/mopro-ffi/src/mopro.udl b/mopro-ffi/src/mopro.udl index 22d9932c..457045b2 100644 --- a/mopro-ffi/src/mopro.udl +++ b/mopro-ffi/src/mopro.udl @@ -14,8 +14,8 @@ namespace mopro { [Throws=MoproError] boolean verify_proof2(bytes proof, bytes public_input); - // [Throws=MoproError] - // BenchmarkResult run_msm_benchmark(u32? num_msm); + [Throws=MoproError] + BenchmarkResult run_msm_benchmark(u32? num_msm); }; dictionary SetupResult { @@ -27,12 +27,12 @@ dictionary GenerateProofResult { bytes inputs; }; -// dictionary BenchmarkResult { -// u32 num_msm; -// double avg_processing_time; -// double total_processing_time; -// u32 allocated_memory; -// }; +dictionary BenchmarkResult { + u32 num_msm; + double avg_processing_time; + double total_processing_time; + u32 allocated_memory; +}; [Error] enum MoproError {