Skip to content

Commit

Permalink
chore: Refactor benchmarks for feature handling (#365)
Browse files Browse the repository at this point in the history
Helps with argumentcomputer/ci-workflows#49

- Renamed several environmental variables in various benchmarking scripts and configuration files for consistency.
- Introduced a new section for performing comparative benchmarks based on respective features and architecture.
- Added a new variable to the default benchmark configuration, `BENCH_OUTPUT`, set to `commit-comment`.
  • Loading branch information
huitseeker authored Mar 18, 2024
1 parent 6ed7a4c commit b4bfe89
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bench-pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
with:
default-runner: "self-hosted,gpu-bench"
default-benches: "supernova-ci"
default-env: "ARECIBO_BENCH_OUTPUT=pr-comment ARECIBO_BENCH_NUM_CONS=16384,524288"
default-env: "BENCH_OUTPUT=pr-comment BENCH_NUM_CONS=16384,524288"
12 changes: 6 additions & 6 deletions .github/workflows/gpu-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
cargo install criterion-table
- name: Set bench output format and base SHA
run: |
echo "ARECIBO_BENCH_OUTPUT=commit-comment" | tee -a $GITHUB_ENV
echo "ARECIBO_BENCH_NUM_CONS=16384,1038732" | tee -a $GITHUB_ENV
echo "BENCH_OUTPUT=commit-comment" | tee -a $GITHUB_ENV
echo "BENCH_NUM_CONS=16384,1038732" | tee -a $GITHUB_ENV
echo "BASE_COMMIT=${{ github.event.merge_group.base_sha }}" | tee -a $GITHUB_ENV
GPU_NAME=$(nvidia-smi --query-gpu=gpu_name --format=csv,noheader,nounits | tail -n1)
echo "GPU_ID=$(echo $GPU_NAME | awk '{ print $NF }')" | tee -a $GITHUB_ENV
Expand Down Expand Up @@ -91,17 +91,17 @@ jobs:
uses: peter-evans/commit-comment@v3
with:
body-path: BENCHMARKS.md
# TODO: Set `$ARECIBO_BENCH_NOISE_THRESHOLD` via `cardinalby/export-env-action` or hardcode to 1.3
# Check for a slowdown >= `$ARECIBO_BENCH_NOISE_THRESHOLD` (fallback is 30%/1.3x). If so, open an issue but don't block merge
# TODO: Set `$BENCH_NOISE_THRESHOLD` via `cardinalby/export-env-action` or hardcode to 1.3
# Check for a slowdown >= `$BENCH_NOISE_THRESHOLD` (fallback is 30%/1.3x). If so, open an issue but don't block merge
# Since we are parsing for slowdowns, we simply add 1 to the noise threshold decimal to get the regression factor
- name: Check for perf regression
id: regression-check
run: |
REGRESSIONS=$(grep -o '[0-9.]*x slower' BENCHMARKS.md | cut -d 'x' -f1)
echo $REGRESSIONS
if [ ! -z "${{ env.ARECIBO_BENCH_NOISE_THRESHOLD}}" ]; then
REGRESSION_FACTOR=$(echo "${{ env.ARECIBO_BENCH_NOISE_THRESHOLD }}+1" | bc)
if [ ! -z "${{ env.BENCH_NOISE_THRESHOLD}}" ]; then
REGRESSION_FACTOR=$(echo "${{ env.BENCH_NOISE_THRESHOLD }}+1" | bc)
else
REGRESSION_FACTOR=1.3
fi
Expand Down
3 changes: 2 additions & 1 deletion benches/bench.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Arecibo config, used only in `justfile` by default
ARECIBO_BENCH_NUM_CONS=16384,1048576
BENCH_NUM_CONS=16384,1048576
BENCH_OUTPUT=commit-comment
7 changes: 3 additions & 4 deletions benches/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ impl BenchParams {
}

fn output_type_env() -> anyhow::Result<String> {
std::env::var("ARECIBO_BENCH_OUTPUT")
.map_err(|e| anyhow!("ARECIBO_BENCH_OUTPUT env var isn't set: {e}"))
std::env::var("BENCH_OUTPUT").map_err(|e| anyhow!("BENCH_OUTPUT env var isn't set: {e}"))
}

pub(crate) fn noise_threshold_env() -> anyhow::Result<f64> {
std::env::var("ARECIBO_BENCH_NOISE_THRESHOLD")
.map_err(|e| anyhow!("ARECIBO_BENCH_NOISE_THRESHOLD env var isn't set: {e}"))
std::env::var("BENCH_NOISE_THRESHOLD")
.map_err(|e| anyhow!("BENCH_NOISE_THRESHOLD env var isn't set: {e}"))
.and_then(|nt| {
nt.parse::<f64>()
.map_err(|e| anyhow!("Failed to parse noise threshold: {e}"))
Expand Down
4 changes: 2 additions & 2 deletions benches/common/supernova/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub fn num_cons() -> Vec<usize> {
}

fn num_cons_env() -> anyhow::Result<Vec<usize>> {
std::env::var("ARECIBO_BENCH_NUM_CONS")
.map_err(|e| anyhow!("ARECIBO_BENCH_NUM_CONS env var not set: {e}"))
std::env::var("BENCH_NUM_CONS")
.map_err(|e| anyhow!("BENCH_NUM_CONS env var not set: {e}"))
.and_then(|rc| {
let vec: anyhow::Result<Vec<usize>> = rc
.split(',')
Expand Down
26 changes: 20 additions & 6 deletions benches/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ commit := `git rev-parse HEAD`
# Run CPU benchmarks
bench +benches:
#!/bin/sh
[ $(uname -m) = "x86_64" ] && FEATURES="asm" || FEATURES="default"

for bench in {{benches}}; do
cargo criterion --bench $bench
cargo criterion --bench $bench --features $FEATURES
done

# Run CUDA benchmarks on GPU
Expand All @@ -22,6 +24,7 @@ gpu-bench +benches:
export CUDA_ARCH=$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader | sed 's/\.//g')
export EC_GPU_CUDA_NVCC_ARGS="--fatbin --gpu-architecture=sm_$CUDA_ARCH --generate-code=arch=compute_$CUDA_ARCH,code=sm_$CUDA_ARCH"
export EC_GPU_FRAMEWORK="cuda"
[ $(uname -m) = "x86_64" ] && FEATURES="cuda, asm" || FEATURES="cuda"

for bench in {{benches}}; do
cargo criterion --bench $bench --features "cuda"
Expand All @@ -31,12 +34,23 @@ gpu-bench +benches:
gpu-bench-ci +benches:
#!/bin/sh
printenv PATH
if [ $(uname -m) = "x86_64" ]; then
FEATURES="cuda,asm"
else
FEATURES="cuda"
[ $(uname -m) = "x86_64" ] && FEATURES="cuda, asm" || FEATURES="cuda"

for bench in {{benches}}; do
cargo criterion --bench $bench --features $FEATURES --message-format=json > "$bench-{{commit}}".json
done

comparative-bench +benches:
#!/bin/sh
# Initialize FEATURES based on architecture
[ $(uname -m) = "x86_64" ] && FEATURES="asm" || FEATURES=""
# Append cuda to FEATURES if nvcc is found
if which nvcc > /dev/null; then
FEATURES="${FEATURES:+$FEATURES,}cuda"
fi
# add default if FEATURES is empty
FEATURES="${FEATURES:-default}"

for bench in {{benches}}; do
cargo criterion --bench $bench --features $FEATURES --message-format=json > "$bench-{{commit}}".json
done
done

1 comment on commit b4bfe89

@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 Arecibo GPU benchmarks.
NVIDIA L4
Intel(R) Xeon(R) CPU @ 2.20GHz
32 vCPUs
125 GB RAM
Workflow run: https://github.com/lurk-lab/arecibo/actions/runs/8327798672

Benchmark Results

RecursiveSNARK-NIVC-2

ref=b4bfe89 Prove Verify
StepCircuitSize-0-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03-18 N/A 38.67 ms (✅ 1.00x) 28.90 ms (✅ 1.34x faster)
StepCircuitSize-6540-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03-18 N/A 47.42 ms (✅ 1.00x) N/A
StepCircuitSize-6540-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03-1... N/A N/A 35.97 ms (✅ 1.00x)
StepCircuitSize-22924-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03-1... N/A 68.27 ms (✅ 1.00x) N/A
StepCircuitSize-22924-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03-... N/A N/A 52.48 ms (✅ 1.00x)
StepCircuitSize-55692-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03-1... N/A 55.09 ms (✅ 1.00x) N/A
StepCircuitSize-55692-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03-... N/A N/A 33.92 ms (✅ 1.00x)
StepCircuitSize-121228-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03-... N/A 63.99 ms (✅ 1.00x) N/A
StepCircuitSize-121228-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03... N/A N/A 38.85 ms (✅ 1.00x)
StepCircuitSize-252300-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03-... N/A 131.46 ms (✅ 1.00x) N/A
StepCircuitSize-252300-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03... N/A N/A 97.37 ms (✅ 1.00x)
StepCircuitSize-514444-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03-... N/A 207.42 ms (✅ 1.00x) N/A
StepCircuitSize-514444-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03... N/A N/A 151.07 ms (✅ 1.00x)
StepCircuitSize-1038732-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-03... N/A 370.37 ms (✅ 1.00x) N/A
StepCircuitSize-1038732-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-2024-0... N/A N/A 288.48 ms (✅ 1.00x)
Prove-NumCons-6540 47.06 ms (✅ 1.00x) N/A N/A
Verify-NumCons-6540 35.36 ms (✅ 1.00x) N/A N/A
Prove-NumCons-1028888 343.92 ms (✅ 1.00x) N/A N/A
Verify-NumCons-1028888 255.67 ms (✅ 1.00x) N/A N/A

CompressedSNARK-NIVC-Commitments-2

ref=b4bfe89 Verify Prove
StepCircuitSize-0-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9-... N/A N/A 9.69 s (✅ 1.00x)
StepCircuitSize-0-6ed7a4cb0a5c35f723d6ea450a915d01d93d41c9... N/A 62.44 ms (✅ 1.00x) N/A
StepCircuitSize-6540-6ed7a4cb0a5c35f723d6ea450a915d01d93d41... N/A N/A 13.55 s (✅ 1.00x)
StepCircuitSize-6540-6ed7a4cb0a5c35f723d6ea450a915d01d93d4... N/A 63.17 ms (✅ 1.00x) N/A
StepCircuitSize-22924-6ed7a4cb0a5c35f723d6ea450a915d01d93d4... N/A N/A 12.06 s (✅ 1.00x)
StepCircuitSize-22924-6ed7a4cb0a5c35f723d6ea450a915d01d93d... N/A 64.17 ms (✅ 1.00x) N/A
StepCircuitSize-55692-6ed7a4cb0a5c35f723d6ea450a915d01d93d4... N/A N/A 18.76 s (✅ 1.00x)
StepCircuitSize-55692-6ed7a4cb0a5c35f723d6ea450a915d01d93d... N/A 62.39 ms (✅ 1.00x) N/A
StepCircuitSize-121228-6ed7a4cb0a5c35f723d6ea450a915d01d93d... N/A N/A 11.99 s (✅ 1.00x)
StepCircuitSize-121228-6ed7a4cb0a5c35f723d6ea450a915d01d93... N/A 62.36 ms (✅ 1.00x) N/A
StepCircuitSize-252300-6ed7a4cb0a5c35f723d6ea450a915d01d93d... N/A N/A 18.92 s (✅ 1.00x)
StepCircuitSize-252300-6ed7a4cb0a5c35f723d6ea450a915d01d93... N/A 62.19 ms (✅ 1.00x) N/A
StepCircuitSize-514444-6ed7a4cb0a5c35f723d6ea450a915d01d93d... N/A N/A 32.19 s (✅ 1.00x)
StepCircuitSize-514444-6ed7a4cb0a5c35f723d6ea450a915d01d93... N/A 62.79 ms (✅ 1.00x) N/A
StepCircuitSize-1038732-6ed7a4cb0a5c35f723d6ea450a915d01d93... N/A N/A 57.43 s (✅ 1.00x)
StepCircuitSize-1038732-6ed7a4cb0a5c35f723d6ea450a915d01d9... N/A 62.31 ms (✅ 1.00x) N/A
Prove-NumCons-6540 13.57 s (✅ 1.00x) N/A N/A
Verify-NumCons-6540 62.87 ms (✅ 1.00x) N/A N/A
Prove-NumCons-1028888 58.59 s (✅ 1.00x) N/A N/A
Verify-NumCons-1028888 62.34 ms (✅ 1.00x) N/A N/A

Made with criterion-table

Please sign in to comment.