Skip to content

Commit b4bfe89

Browse files
authored
chore: Refactor benchmarks for feature handling (#365)
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`.
1 parent 6ed7a4c commit b4bfe89

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
lines changed

.github/workflows/bench-pr-comment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
with:
2121
default-runner: "self-hosted,gpu-bench"
2222
default-benches: "supernova-ci"
23-
default-env: "ARECIBO_BENCH_OUTPUT=pr-comment ARECIBO_BENCH_NUM_CONS=16384,524288"
23+
default-env: "BENCH_OUTPUT=pr-comment BENCH_NUM_CONS=16384,524288"

.github/workflows/gpu-bench.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
cargo install criterion-table
3939
- name: Set bench output format and base SHA
4040
run: |
41-
echo "ARECIBO_BENCH_OUTPUT=commit-comment" | tee -a $GITHUB_ENV
42-
echo "ARECIBO_BENCH_NUM_CONS=16384,1038732" | tee -a $GITHUB_ENV
41+
echo "BENCH_OUTPUT=commit-comment" | tee -a $GITHUB_ENV
42+
echo "BENCH_NUM_CONS=16384,1038732" | tee -a $GITHUB_ENV
4343
echo "BASE_COMMIT=${{ github.event.merge_group.base_sha }}" | tee -a $GITHUB_ENV
4444
GPU_NAME=$(nvidia-smi --query-gpu=gpu_name --format=csv,noheader,nounits | tail -n1)
4545
echo "GPU_ID=$(echo $GPU_NAME | awk '{ print $NF }')" | tee -a $GITHUB_ENV
@@ -91,17 +91,17 @@ jobs:
9191
uses: peter-evans/commit-comment@v3
9292
with:
9393
body-path: BENCHMARKS.md
94-
# TODO: Set `$ARECIBO_BENCH_NOISE_THRESHOLD` via `cardinalby/export-env-action` or hardcode to 1.3
95-
# Check for a slowdown >= `$ARECIBO_BENCH_NOISE_THRESHOLD` (fallback is 30%/1.3x). If so, open an issue but don't block merge
94+
# TODO: Set `$BENCH_NOISE_THRESHOLD` via `cardinalby/export-env-action` or hardcode to 1.3
95+
# Check for a slowdown >= `$BENCH_NOISE_THRESHOLD` (fallback is 30%/1.3x). If so, open an issue but don't block merge
9696
# Since we are parsing for slowdowns, we simply add 1 to the noise threshold decimal to get the regression factor
9797
- name: Check for perf regression
9898
id: regression-check
9999
run: |
100100
REGRESSIONS=$(grep -o '[0-9.]*x slower' BENCHMARKS.md | cut -d 'x' -f1)
101101
echo $REGRESSIONS
102102
103-
if [ ! -z "${{ env.ARECIBO_BENCH_NOISE_THRESHOLD}}" ]; then
104-
REGRESSION_FACTOR=$(echo "${{ env.ARECIBO_BENCH_NOISE_THRESHOLD }}+1" | bc)
103+
if [ ! -z "${{ env.BENCH_NOISE_THRESHOLD}}" ]; then
104+
REGRESSION_FACTOR=$(echo "${{ env.BENCH_NOISE_THRESHOLD }}+1" | bc)
105105
else
106106
REGRESSION_FACTOR=1.3
107107
fi

benches/bench.env

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Arecibo config, used only in `justfile` by default
2-
ARECIBO_BENCH_NUM_CONS=16384,1048576
2+
BENCH_NUM_CONS=16384,1048576
3+
BENCH_OUTPUT=commit-comment

benches/common/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ impl BenchParams {
3636
}
3737

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

4342
pub(crate) fn noise_threshold_env() -> anyhow::Result<f64> {
44-
std::env::var("ARECIBO_BENCH_NOISE_THRESHOLD")
45-
.map_err(|e| anyhow!("ARECIBO_BENCH_NOISE_THRESHOLD env var isn't set: {e}"))
43+
std::env::var("BENCH_NOISE_THRESHOLD")
44+
.map_err(|e| anyhow!("BENCH_NOISE_THRESHOLD env var isn't set: {e}"))
4645
.and_then(|nt| {
4746
nt.parse::<f64>()
4847
.map_err(|e| anyhow!("Failed to parse noise threshold: {e}"))

benches/common/supernova/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub fn num_cons() -> Vec<usize> {
5454
}
5555

5656
fn num_cons_env() -> anyhow::Result<Vec<usize>> {
57-
std::env::var("ARECIBO_BENCH_NUM_CONS")
58-
.map_err(|e| anyhow!("ARECIBO_BENCH_NUM_CONS env var not set: {e}"))
57+
std::env::var("BENCH_NUM_CONS")
58+
.map_err(|e| anyhow!("BENCH_NUM_CONS env var not set: {e}"))
5959
.and_then(|rc| {
6060
let vec: anyhow::Result<Vec<usize>> = rc
6161
.split(',')

benches/justfile

+20-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ commit := `git rev-parse HEAD`
99
# Run CPU benchmarks
1010
bench +benches:
1111
#!/bin/sh
12+
[ $(uname -m) = "x86_64" ] && FEATURES="asm" || FEATURES="default"
13+
1214
for bench in {{benches}}; do
13-
cargo criterion --bench $bench
15+
cargo criterion --bench $bench --features $FEATURES
1416
done
1517

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

2629
for bench in {{benches}}; do
2730
cargo criterion --bench $bench --features "cuda"
@@ -31,12 +34,23 @@ gpu-bench +benches:
3134
gpu-bench-ci +benches:
3235
#!/bin/sh
3336
printenv PATH
34-
if [ $(uname -m) = "x86_64" ]; then
35-
FEATURES="cuda,asm"
36-
else
37-
FEATURES="cuda"
37+
[ $(uname -m) = "x86_64" ] && FEATURES="cuda, asm" || FEATURES="cuda"
38+
39+
for bench in {{benches}}; do
40+
cargo criterion --bench $bench --features $FEATURES --message-format=json > "$bench-{{commit}}".json
41+
done
42+
43+
comparative-bench +benches:
44+
#!/bin/sh
45+
# Initialize FEATURES based on architecture
46+
[ $(uname -m) = "x86_64" ] && FEATURES="asm" || FEATURES=""
47+
# Append cuda to FEATURES if nvcc is found
48+
if which nvcc > /dev/null; then
49+
FEATURES="${FEATURES:+$FEATURES,}cuda"
3850
fi
51+
# add default if FEATURES is empty
52+
FEATURES="${FEATURES:-default}"
3953

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

0 commit comments

Comments
 (0)