Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor benchmarks for feature handling #365

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
samuelburnham marked this conversation as resolved.
Show resolved Hide resolved
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