Skip to content

Commit

Permalink
Parameterize BenchmarkId on output type (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelburnham authored Nov 1, 2023
1 parent 8fe45e7 commit 0a94149
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 39 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/bench-pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ jobs:
run: sudo apt-get install -y pkg-config libssl-dev
- uses: actions-rs/toolchain@v1
- uses: Swatinem/rust-cache@v2
- name: Load env vars
run: |
set -a
source bench.env
set +a
echo "LURK_BENCH_OUTPUT=pr-comment" >> $GITHUB_ENV
env | grep -E 'LURK|EC_GPU|CUDA'
working-directory: ${{ github.workspace }}/benches
# Run the comparative benchmark and comment output on the PR
- uses: boa-dev/criterion-compare-action@v3
with:
Expand Down Expand Up @@ -77,6 +85,7 @@ jobs:
set -a
source bench.env
set +a
echo "LURK_BENCH_OUTPUT=pr-comment" >> $GITHUB_ENV
env | grep -E 'LURK|EC_GPU|CUDA'
working-directory: ${{ github.workspace }}/benches
# Run the comparative benchmark and comment output on the PR
Expand Down
83 changes: 44 additions & 39 deletions benches/fibonacci_lem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,44 +59,73 @@ impl ProveParams {
fn name(&self) -> String {
format!("Fibonacci-rc={}", self.reduction_count)
}

fn params(&self) -> String {
let output_type = bench_parameters_env().unwrap_or("stdout".into());
match output_type.as_ref() {
"pr-comment" => format!("num-{}", self.fib_n),
"commit-comment" => todo!(),
"gh-pages" => todo!(),
_ => format!("num-{}/{}-{}", self.fib_n, self.sha, self.date),
}
}
}

fn bench_parameters_env() -> anyhow::Result<String> {
std::env::var("LURK_BENCH_OUTPUT")
.map_err(|e| anyhow!("Noise threshold env var isn't set: {e}"))
}

fn rc_env() -> anyhow::Result<Vec<usize>> {
std::env::var("LURK_RC")
.map_err(|e| anyhow!("Reduction count env var isn't set: {e}"))
.and_then(|rc| {
let vec: anyhow::Result<Vec<usize>> = rc
.split(',')
.map(|rc| {
rc.parse::<usize>()
.map_err(|e| anyhow!("Failed to parse RC: {e}"))
})
.collect();
vec
})
}

fn noise_threshold_env() -> anyhow::Result<f64> {
std::env::var("LURK_BENCH_NOISE_THRESHOLD")
.map_err(|e| anyhow!("Noise threshold env var isn't set: {e}"))
.and_then(|nt| {
nt.parse::<f64>()
.map_err(|e| anyhow!("Failed to parse noise threshold: {e}"))
})
}

fn fibo_prove<M: measurement::Measurement>(
prove_params: ProveParams,
c: &mut BenchmarkGroup<'_, M>,
state: &Rc<RefCell<State>>,
) {
let ProveParams {
fib_n,
reduction_count,
date,
sha,
} = prove_params;

let limit = fib_limit(fib_n, reduction_count);
let limit = fib_limit(prove_params.fib_n, prove_params.reduction_count);
let lang_pallas = Lang::<pallas::Scalar, Coproc<pallas::Scalar>>::new();
let lang_rc = Arc::new(lang_pallas.clone());

// use cached public params
let instance = Instance::new(
reduction_count,
prove_params.reduction_count,
lang_rc.clone(),
true,
Kind::NovaPublicParams,
);
let pp = public_params::<_, _, MultiFrame<'_, _, _>>(&instance).unwrap();

// Track the number of `Lurk frames / sec`
let rc = reduction_count as u64;
let rc = prove_params.reduction_count as u64;
c.throughput(criterion::Throughput::Elements(
rc * u64::div_ceil((11 + 16 * fib_n) as u64, rc),
rc * u64::div_ceil((11 + 16 * prove_params.fib_n) as u64, rc),
));

c.bench_with_input(
BenchmarkId::new(
prove_params.name(),
format!("num-{}/{sha}-{date}", prove_params.fib_n),
),
BenchmarkId::new(prove_params.name(), prove_params.params()),
&prove_params,
|b, prove_params| {
let store = Store::default();
Expand Down Expand Up @@ -125,30 +154,6 @@ fn fibo_prove<M: measurement::Measurement>(
);
}

fn rc_env() -> anyhow::Result<Vec<usize>> {
std::env::var("LURK_RC")
.map_err(|e| anyhow!("Reduction count env var isn't set: {e}"))
.and_then(|rc| {
let vec: anyhow::Result<Vec<usize>> = rc
.split(',')
.map(|rc| {
rc.parse::<usize>()
.map_err(|e| anyhow!("Failed to parse RC: {e}"))
})
.collect();
vec
})
}

fn noise_threshold_env() -> anyhow::Result<f64> {
std::env::var("LURK_BENCH_NOISE_THRESHOLD")
.map_err(|e| anyhow!("Noise threshold env var isn't set: {e}"))
.and_then(|nt| {
nt.parse::<f64>()
.map_err(|e| anyhow!("Failed to parse noise threshold: {e}"))
})
}

fn fibonacci_prove(c: &mut Criterion) {
tracing_subscriber::fmt::init();
set_bench_config();
Expand Down

1 comment on commit 0a94149

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Table of Contents

Overview

This benchmark report shows the Fibonacci GPU benchmark.
Tesla T4

Benchmark Results

LEM Prove

Fibonacci-rc=100 Fibonacci-rc=600
num-100 6.88 s (✅ 1.00x) 7.52 s (✅ 1.09x slower)
num-200 14.47 s (✅ 1.00x) 16.77 s (❌ 1.16x slower)

Made with criterion-table

Please sign in to comment.