From fb8ce329d4d855489638676d2e7a27f5962dd3ad Mon Sep 17 00:00:00 2001 From: Henry LE BERRE Date: Thu, 14 Dec 2023 19:42:05 -0800 Subject: [PATCH] #49: GitHub CI Benchmarking --- .github/workflows/bench.yml | 65 ++++++++++++++++++ .github/workflows/docker.yml | 2 +- .github/workflows/phoenix/bench.sh | 3 + .github/workflows/phoenix/compare.py | 51 ++++++++++++++ .github/workflows/phoenix/submit.sh | 58 ++++++++++++++++ .github/workflows/phoenix/test.sh | 9 +++ .github/workflows/{ci.yml => test.yml} | 9 +-- misc/run-phoenix-release-cpu.sh | 16 ----- misc/run-phoenix-release-gpu.sh | 24 ------- toolchain/bench.yaml | 7 ++ toolchain/mfc/args.py | 4 +- toolchain/mfc/bench.py | 95 ++++++++++++-------------- toolchain/mfc/common.py | 11 ++- 13 files changed, 247 insertions(+), 107 deletions(-) create mode 100644 .github/workflows/bench.yml create mode 100644 .github/workflows/phoenix/bench.sh create mode 100644 .github/workflows/phoenix/compare.py create mode 100644 .github/workflows/phoenix/submit.sh create mode 100644 .github/workflows/phoenix/test.sh rename .github/workflows/{ci.yml => test.yml} (95%) delete mode 100644 misc/run-phoenix-release-cpu.sh delete mode 100644 misc/run-phoenix-release-gpu.sh create mode 100644 toolchain/bench.yaml diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml new file mode 100644 index 0000000000..886b75ae87 --- /dev/null +++ b/.github/workflows/bench.yml @@ -0,0 +1,65 @@ +name: 'Benchmark' + +on: + push: + paths: + - '**.f90' + - '**.fpp' + - '**.py' + - '**.yml' + - 'mfc.sh' + - 'CMakeLists.txt' + - 'requirements.txt' + + pull_request: + +jobs: + self: + name: Georgia Tech | Phoenix (NVHPC) + if: github.repository == 'MFlowCode/MFC' + strategy: + matrix: + device: ['cpu', 'gpu'] + runs-on: + group: phoenix + labels: self-hosted + steps: + - name: Clone - PR + uses: actions/checkout@v3 + + - name: Bench - PR + run: | + bash .github/workflows/phoenix/submit.sh .github/workflows/phoenix/bench.sh ${{ matrix.device }} + mv bench-${{ matrix.device }}.out ~/bench-${{ matrix.device }}-pr.out + + - name: Clone - Master + uses: actions/checkout@v3 + with: + ref: master + + - name: Bench - Master + run: | + bash .github/workflows/phoenix/submit.sh .github/workflows/phoenix/bench.sh ${{ matrix.device }} + mv bench-${{ matrix.device }}.out ~/bench-${{ matrix.device }}-master.out + + - name: Generate Comment + run: | + export "BENCH_COMMENT="$(python3 .github/workflows/phoenix/compare.py ~/bench-${{ matrix.device }}-master.out ~/bench-${{ matrix.device }}-pr.out)"" >> $GITHUB_ENV + + - name: Post Comment + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: process.env.BENCH_COMMENT + }) + + - name: Print + if: always() + run: | + cat bench-${{ matrix.device }}-master.out || true + cat bench-${{ matrix.device }}-pr.out || true diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4e3431ab2a..ac27cf6dc3 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -22,7 +22,7 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: Build & Publish thereto - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v3 with: file: toolchain/Dockerfile push: true diff --git a/.github/workflows/phoenix/bench.sh b/.github/workflows/phoenix/bench.sh new file mode 100644 index 0000000000..e4b9feb67b --- /dev/null +++ b/.github/workflows/phoenix/bench.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +./mfc.sh bench "$job_slug.yaml" -j $(nproc) -b mpirun diff --git a/.github/workflows/phoenix/compare.py b/.github/workflows/phoenix/compare.py new file mode 100644 index 0000000000..90be62996e --- /dev/null +++ b/.github/workflows/phoenix/compare.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +import argparse + +import yaml + +parser = argparse.ArgumentParser() +parser.add_argument('master', metavar="MASTER", type=str) +parser.add_argument('pr', metavar="PR", type=str) + +args = parser.parse_args() + +def load_cases(filepath): + return { case["name"]: case for case in yaml.safe_load(open(filepath))["cases"] } + +master, pr = load_cases(args.master), load_cases(args.pr) + +master_keys = set(master.keys()) +pr_keys = set(pr.keys()) + +missing_cases = master_keys.symmetric_difference(pr_keys) + +if len(missing_cases) > 0: + print("**Warning:** The following cases are **missing** from master or this PR:\n") + + for case in missing_cases: + print(f" - {case}.") + + print("") + +speedups = {} + +for case in master_keys.intersection(pr_keys): + speedups[case] = { + "pre_proess": pr[case]["pre_process"] / master[case]["pre_process"], + "simulation": pr[case]["simulation"] / master[case]["simulation"], + } + +avg_speedup = sum([ speedups[case]["simulation"] for case in speedups ]) / len(speedups) + +print(f"""\ +**[Benchmark Results]** Compared to Master, this PR's `simulation` is on average **~{avg_speedup:0.2f}x faster**. + +| **Case** | **Master** | **PR** | **Speedup** | +| -------- | ---------- | ------ | ----------- |\ +""") + +for case in sorted(speedups.keys()): + speedup = speedups[case] + + print(f"| {case} | {master[case]['simulation']:0.2f}s | {pr[case]['simulation']:0.2f}s | {speedups[case]['simulation']:0.2f}x |") diff --git a/.github/workflows/phoenix/submit.sh b/.github/workflows/phoenix/submit.sh new file mode 100644 index 0000000000..09f5b80dea --- /dev/null +++ b/.github/workflows/phoenix/submit.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +usage() { + echo "Usage: $0 [script.sh] [cpu|gpu]" +} + +if [ ! -z "$1" ]; then + sbatch_script_contents=`cat $1` +else + usage + exit 1 +fi + +sbatch_cpu_opts="\ +#SBATCH --ntasks-per-node=12 # Number of cores per node required +#SBATCH --mem-per-cpu=2G # Memory per core\ +" + +sbatch_gpu_opts="\ +#SBATCH -CV100-16GB +#SBATCH -G2\ +" + +if [ "$2" == "cpu" ]; then + sbatch_device_opts="$sbatch_cpu_opts" +elif [ "$2" == "gpu" ]; then + sbatch_device_opts="$sbatch_gpu_opts" +else + usage + exit 1 +fi + +job_slug="`basename "$1" | sed 's/\.sh$//' | sed 's/[^a-zA-Z0-9]/-/g'`-$2" + +sbatch <