Skip to content

Commit

Permalink
Gpu workflow dispatch (#9)
Browse files Browse the repository at this point in the history
* Fix `commit-comment` benchmark comparison

* Test workflow_dispatch
  • Loading branch information
samuelburnham authored Nov 7, 2023
1 parent fc49598 commit 3868f29
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/gpu-branch-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Run GPU benchmark on a local branch when manually triggered
name: Manual GPU benchmarks

on:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

gpu-benchmark:
name: Run fibonacci bench on GPU
runs-on: [self-hosted, gpu-bench-local]
steps:
# Set up GPU
# Check we have access to the machine's Nvidia drivers
- run: nvidia-smi
# Check that CUDA is installed with a driver-compatible version
# This must also be compatible with the GPU architecture, see above link
- run: nvcc --version
- uses: actions/checkout@v4
# Install dependencies
- uses: actions-rs/toolchain@v1
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: just@1.15
- name: Install criterion
run: |
cargo install cargo-criterion
cargo install criterion-table
- name: Set bench output format type
run: echo "LURK_BENCH_OUTPUT=commit-comment" | tee -a $GITHUB_ENV
- name: Run GPU bench on branch
run: just --dotenv-filename bench.env gpu-bench fibonacci_lem
working-directory: ${{ github.workspace }}/benches
- name: copy the benchmark template and prepare it with data
run: |
cp .github/tables.toml .
# Get GPU name
GPU_NAME=$(nvidia-smi --query-gpu=gpu_name --format=csv,noheader,nounits | tail -n1)
# Get CPU model
CPU_MODEL=$(grep '^model name' /proc/cpuinfo | head -1 | awk -F ': ' '{ print $2 }')
# Get total RAM in GB
TOTAL_RAM=$(grep MemTotal /proc/meminfo | awk '{$2=$2/(1024^2); print $2, "GB RAM";}')
# Use conditionals to ensure that only non-empty variables are inserted
[[ ! -z "$GPU_NAME" ]] && sed -i "/^\"\"\"$/i $GPU_NAME" tables.toml
[[ ! -z "$CPU_MODEL" ]] && sed -i "/^\"\"\"$/i $CPU_MODEL" tables.toml
[[ ! -z "$TOTAL_RAM" ]] && sed -i "/^\"\"\"$/i $TOTAL_RAM" tables.toml
working-directory: ${{ github.workspace }}
# Create a `criterion-table` and write in commit comment
- name: Run `criterion-table`
run: cat ${{ github.sha }}.json | criterion-table > BENCHMARKS.md
- name: Write bench on commit comment
uses: peter-evans/commit-comment@v3
with:
body-path: BENCHMARKS.md
2 changes: 1 addition & 1 deletion .github/workflows/merge-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
working-directory: ${{ github.workspace }}
# Create a `criterion-table` and write in commit comment
- name: Run `criterion-table`
run: cat ${{ github.sha }}.json | criterion-table > BENCHMARKS.md
run: cat ${{ env.BASE_REF }}.json ${{ github.sha }}.json | criterion-table > BENCHMARKS.md
- name: Write bench on commit comment
uses: peter-evans/commit-comment@v3
with:
Expand Down
29 changes: 25 additions & 4 deletions benches/fibonacci_lem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ impl ProveParams {
let output_type = bench_parameters_env().unwrap_or("stdout".into());
match output_type.as_ref() {
"pr-comment" => ("fib".into(), format!("num-{}", self.fib_n)),
"commit-comment" => (
format!("fib-branch={}", env!("VERGEN_GIT_BRANCH")),
format!("num-{}", self.fib_n),
),
"commit-comment" => {
let branch = env!("VERGEN_GIT_BRANCH");
let branch_name = parse_merge_branch(branch).unwrap();
(
format!("fib-branch={}", branch_name),
format!("num-{}", self.fib_n),
)
}
// TODO: refine "gh-pages",
_ => (
"fib".into(),
Expand All @@ -73,6 +77,23 @@ impl ProveParams {
}
}

// Gets the last bit of a merge queue branch name for `commit-comment` comparison
// E.g. `gh-readonly-queue/master/pr-857-25c170bf85cd0676fd01237acd` => `pr-857-25c170bf85cd0676fd01237acd`
// Returns the input if the branch doesn't start with `gh-readonly-queue`
fn parse_merge_branch(branch: &str) -> anyhow::Result<String> {
let mut branch_split = branch.split('/');
let ret = branch_split.next().map_or_else(
|| anyhow::bail!("Expected a non-empty string"),
|x| match x {
"gh-readonly-queue" => branch_split
.last()
.ok_or_else(|| anyhow::anyhow!("Expected a merge queue branch")),
_ => Ok(branch),
},
)?;
Ok(ret.into())
}

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}"))
Expand Down

0 comments on commit 3868f29

Please sign in to comment.