-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Difficulty calculation * Benchmark various proving algos * Expose proof generation via C library * fix build * Refactor Prover::prove to accept raw bytes and index * Benchmark on many cores with rayon * Clean up deps and optimize staticlib size * Build for linux, macos and windows * Fix CI and reorg workflow file * Fix saving libpost.a artifact * Fix post library artifact name for windows * Test proving by checking if indicies in proof satisfy difficulty * Fix batch index and AES cipher creation * Review fixes * Build shared library in addition to static one (#5) * Build shared library instead of static one * Build on ubuntu-20.04 too * Build staticlib and dylib
- Loading branch information
Showing
16 changed files
with
863 additions
and
129 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
This file was deleted.
Oops, something went wrong.
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,140 @@ | ||
use std::hint::black_box; | ||
|
||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use post::Prover; | ||
use pprof::criterion::{Output, PProfProfiler}; | ||
use rand::{thread_rng, RngCore}; | ||
use rayon::prelude::{ParallelBridge, ParallelIterator}; | ||
|
||
const KIB: usize = 1024; | ||
const MIB: usize = 1024 * KIB; | ||
|
||
const CHALLENGE: &[u8; 32] = b"hello world, CHALLENGE me!!!!!!!"; | ||
|
||
fn threads_to_str(threads: usize) -> String { | ||
if threads == 0 { | ||
"auto".into() | ||
} else { | ||
threads.to_string() | ||
} | ||
} | ||
|
||
fn prover_bench(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("proving"); | ||
|
||
let mut data = vec![0; 32 * MIB]; | ||
thread_rng().fill_bytes(&mut data); | ||
group.throughput(criterion::Throughput::Bytes(data.len() as u64)); | ||
|
||
let chunk_size = 64 * KIB; | ||
|
||
for (nonces, threads) in itertools::iproduct!( | ||
[2, 20, 200], | ||
[0, 1] // 0 == automatic | ||
) { | ||
group.bench_with_input( | ||
BenchmarkId::new( | ||
format!("D=8/B=16/chunk={}KiB", chunk_size as f64 / KIB as f64), | ||
format!("nonces={nonces}/threads={}", threads_to_str(threads)), | ||
), | ||
&(nonces, threads), | ||
|b, &(nonces, threads)| { | ||
let prover = post::ConstDProver::new(CHALLENGE, 0, 0..nonces); | ||
b.iter(|| { | ||
let f = black_box(|_, _| false); | ||
match threads { | ||
1 => data.chunks_exact(chunk_size).for_each(|chunk| { | ||
prover.prove(chunk, 0, f); | ||
}), | ||
0 => data | ||
.chunks_exact(chunk_size) | ||
.par_bridge() | ||
.for_each(|chunk| { | ||
prover.prove(chunk, 0, f); | ||
}), | ||
n => { | ||
let pool = rayon::ThreadPoolBuilder::new() | ||
.num_threads(n) | ||
.build() | ||
.unwrap(); | ||
pool.install(|| { | ||
data.chunks_exact(chunk_size) | ||
.par_bridge() | ||
.for_each(|chunk| { | ||
prover.prove(chunk, 0, f); | ||
}) | ||
}); | ||
} | ||
} | ||
}); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
fn var_b_prover_bench(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("proving"); | ||
|
||
let mut data = vec![0; 32 * MIB]; | ||
thread_rng().fill_bytes(&mut data); | ||
group.throughput(criterion::Throughput::Bytes(data.len() as u64)); | ||
|
||
let chunk_size = 64 * KIB; | ||
|
||
for (nonces, threads, param_b) in itertools::iproduct!( | ||
[2, 20, 200], | ||
[0, 1], // 0 == automatic | ||
[8] | ||
) { | ||
group.bench_with_input( | ||
BenchmarkId::new( | ||
format!("D=8/chunk={}KiB", chunk_size as f64 / KIB as f64), | ||
format!( | ||
"B={param_b}/nonces={nonces}/threads={}", | ||
threads_to_str(threads) | ||
), | ||
), | ||
&(nonces, threads, param_b), | ||
|b, &(nonces, threads, param_b)| { | ||
let prover = post::ConstDVarBProver::new(CHALLENGE, 0, 0..nonces, param_b); | ||
b.iter(|| { | ||
let f = black_box(|_, _| false); | ||
match threads { | ||
1 => data.chunks_exact(chunk_size).for_each(|chunk| { | ||
prover.prove(chunk, 0, f); | ||
}), | ||
0 => data | ||
.chunks_exact(chunk_size) | ||
.par_bridge() | ||
.for_each(|chunk| { | ||
prover.prove(chunk, 0, f); | ||
}), | ||
n => { | ||
let pool = rayon::ThreadPoolBuilder::new() | ||
.num_threads(n) | ||
.build() | ||
.unwrap(); | ||
pool.install(|| { | ||
data.chunks_exact(chunk_size) | ||
.par_bridge() | ||
.for_each(|chunk| { | ||
prover.prove(chunk, 0, f); | ||
}) | ||
}); | ||
} | ||
} | ||
}); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
criterion_group!( | ||
name = benches; | ||
config = Criterion::default().with_profiler(PProfProfiler::new(1000, Output::Flamegraph(None))); | ||
targets= | ||
prover_bench, | ||
var_b_prover_bench, | ||
); | ||
|
||
criterion_main!(benches); |
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 @@ | ||
prover.h |
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,14 @@ | ||
[package] | ||
name = "post" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate_type = ["staticlib", "cdylib"] | ||
|
||
[dependencies] | ||
eyre = "0.6.8" | ||
post-rs = { path = "../" } | ||
|
||
[build-dependencies] | ||
cbindgen = "*" |
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,14 @@ | ||
extern crate cbindgen; | ||
|
||
use std::env; | ||
|
||
fn main() { | ||
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); | ||
|
||
cbindgen::Builder::new() | ||
.with_language(cbindgen::Language::C) | ||
.with_crate(crate_dir) | ||
.generate() | ||
.expect("Unable to generate bindings") | ||
.write_to_file("prover.h"); | ||
} |
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,2 @@ | ||
[toolchain] | ||
channel = "nightly-2023-02-28" |
Oops, something went wrong.