From 5b9307c04d7c0221319bb33ce1d79593c971611a Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Thu, 26 Nov 2026 15:29:29 -0600 Subject: [PATCH 1/7] docs: ask PR authors to show a change works and is not slower The PR template gains sections for evidence that the change solves its problem, what was tested, and benchmark results the author runs on a GPU, with a table of which kinds of change need which. --- .github/pull_request_template.md | 79 ++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 0bd4f7fd9d..6b71c632d8 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,3 +7,82 @@ All contributions are expected to demonstrate: - Evidence of real-world usage or hands-on experience with the problem If these expectations are not met, we would prefer to implement the changes ourselves rather than spend time reviewing low-effort submissions. + +## What to fill in + +| Your change touches | 1. Problem | 2. Tests to run | 3. Speed | +|---|---|---|---| +| Docs only | N/A | N/A | N/A | +| Anything else (toolchain, CI, tests, examples) | required | N/A | N/A | +| `src/` | required | `./mfc.sh test --select-enforce` | required | +| Build flags or compiler versions (`CMakeLists.txt`, `cmake/`, `toolchain/cmake/`, `toolchain/modules`) | required | `./mfc.sh test` | required | + +If more than one row applies, do everything each of them requires. Write N/A with a reason; don't leave blanks. + +## 1. Does it solve the problem? + +Command that shows it: + +| Quantity | master | this PR | expected | +|---|---|---|---| +| | | | | + +## 2. Does it create another one? + +| Check | Result | +|---|---| +| Tests: command, number passed, number failed | | +| Golden files changed: count, largest difference, why | | +| Not tested | | + +## 3. Is it slower? + +When required, run the benchmarks on a GPU yourself. A pull request without these results is incomplete. + +GPU and compiler: + +Base commit: + +PR commit: + + + +If a case is below 0.95, run the commands again from the `for` loop, paste both tables, and explain it only if it stays below. If no benchmark case uses your change, add master and PR grind times for a case that does. + +
+Commands (run from your PR checkout, inside a GPU allocation) + +```bash +# Commit your changes first, so the PR commit id matches what you measure. +git fetch https://github.com/MFlowCode/MFC.git master +base=$(git merge-base FETCH_HEAD HEAD) +# Creates ../mfc-base, or moves one left from an earlier run to this base. +if [ -d ../mfc-base ]; then + git -C ../mfc-base checkout --detach $base +else + git worktree add --detach ../mfc-base $base +fi + +# is from toolchain/modules; names a file in toolchain/templates. On Frontier they are f and frontier. +# Elsewhere, load your own modules and drop both -c options. +source ./mfc.sh load -c -m g + +# One rank on every GPU in the allocation, as CI does: sets $gpu_ids and $ngpus. +source .github/scripts/detect-gpus.sh + +# Use --gpu mp for OpenMP offload. +for tree in ../mfc-base .; do + (cd $tree && + rm -f build/bench.yaml && + ./mfc.sh build --gpu acc -j 8 && + ./mfc.sh bench --mem 4 -o build/bench.yaml -- -c --gpu acc -g $gpu_ids -n $ngpus) +done + +rm -f build/speed.md +GITHUB_STEP_SUMMARY=build/speed.md ./mfc.sh bench_diff ../mfc-base/build/bench.yaml build/bench.yaml + +echo "Base commit: $(git -C ../mfc-base rev-parse --short HEAD)" +echo "PR commit: $(git rev-parse --short HEAD)" +``` + +
From 734d43fd9dbb97e753b22cd83cb972c34471b6f5 Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Thu, 26 Nov 2026 15:47:51 -0600 Subject: [PATCH 2/7] docs: shorten the PR template's speed section and stop on bad checkouts The commands now stop on uncommitted changes, on a checkout with nothing to compare, without a common commit with master, or when a step fails. Authors without a GPU can benchmark on CPUs. --- .github/pull_request_template.md | 50 ++++++++++++++------------------ 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 6b71c632d8..1b33e08f2a 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -37,52 +37,46 @@ Command that shows it: ## 3. Is it slower? -When required, run the benchmarks on a GPU yourself. A pull request without these results is incomplete. +Required for `src/` and build changes: benchmark your base commit and your PR on the same hardware. +Any supported GPU will do. No GPU? Run on CPUs and say so. -GPU and compiler: +Hardware and compiler: Base commit: PR commit: - + -If a case is below 0.95, run the commands again from the `for` loop, paste both tables, and explain it only if it stays below. If no benchmark case uses your change, add master and PR grind times for a case that does. +Explain any grind speedup below 0.95 that shows up twice.
-Commands (run from your PR checkout, inside a GPU allocation) +Commands ```bash -# Commit your changes first, so the PR commit id matches what you measure. +# Run inside a GPU job with your compiler loaded (supported clusters: source ./mfc.sh load -c -m g). +( +set -e # stop at the first failure +rm -f build/speed.md +git diff --quiet HEAD || { echo "Commit your changes first."; exit 1; } git fetch https://github.com/MFlowCode/MFC.git master -base=$(git merge-base FETCH_HEAD HEAD) -# Creates ../mfc-base, or moves one left from an earlier run to this base. -if [ -d ../mfc-base ]; then - git -C ../mfc-base checkout --detach $base -else - git worktree add --detach ../mfc-base $base -fi - -# is from toolchain/modules; names a file in toolchain/templates. On Frontier they are f and frontier. -# Elsewhere, load your own modules and drop both -c options. -source ./mfc.sh load -c -m g - -# One rank on every GPU in the allocation, as CI does: sets $gpu_ids and $ngpus. +base=$(git merge-base FETCH_HEAD HEAD) || { echo "No commit shared with master. Shallow clone? Run: git fetch --unshallow"; exit 1; } +base=$(git rev-parse --short $base) +[ $base != $(git rev-parse --short HEAD) ] || { echo "Nothing to compare: your commit is already in master."; exit 1; } +[ -d ../mfc-$base ] || git worktree add --detach ../mfc-$base $base source .github/scripts/detect-gpus.sh -# Use --gpu mp for OpenMP offload. -for tree in ../mfc-base .; do +# NVIDIA or Cray: --gpu acc. AMD flang: --gpu mp. On a cluster, add -c after "--". +# CPU only: drop --gpu and -g, and use --mem 1 -n . +for tree in ../mfc-$base .; do (cd $tree && - rm -f build/bench.yaml && ./mfc.sh build --gpu acc -j 8 && - ./mfc.sh bench --mem 4 -o build/bench.yaml -- -c --gpu acc -g $gpu_ids -n $ngpus) + ./mfc.sh bench --mem 4 -o build/bench.yaml -- --gpu acc -g $gpu_ids -n $ngpus) done -rm -f build/speed.md -GITHUB_STEP_SUMMARY=build/speed.md ./mfc.sh bench_diff ../mfc-base/build/bench.yaml build/bench.yaml - -echo "Base commit: $(git -C ../mfc-base rev-parse --short HEAD)" -echo "PR commit: $(git rev-parse --short HEAD)" +GITHUB_STEP_SUMMARY=build/speed.md ./mfc.sh bench_diff ../mfc-$base/build/bench.yaml build/bench.yaml +echo "Base commit: $base"; echo "PR commit: $(git rev-parse --short HEAD)" +) ```
From e74a04370e1f1a0a03fbb27b0f70dd2ef47076a3 Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Thu, 26 Nov 2026 15:49:25 -0600 Subject: [PATCH 3/7] docs: ask for GPU benchmarks only in the PR template --- .github/pull_request_template.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 1b33e08f2a..a9bf6794d8 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -37,10 +37,10 @@ Command that shows it: ## 3. Is it slower? -Required for `src/` and build changes: benchmark your base commit and your PR on the same hardware. -Any supported GPU will do. No GPU? Run on CPUs and say so. +Required for `src/` and build changes: benchmark your base commit and your PR on the same GPU. +Any supported GPU will do. -Hardware and compiler: +GPU and compiler: Base commit: @@ -67,7 +67,6 @@ base=$(git rev-parse --short $base) source .github/scripts/detect-gpus.sh # NVIDIA or Cray: --gpu acc. AMD flang: --gpu mp. On a cluster, add -c after "--". -# CPU only: drop --gpu and -g, and use --mem 1 -n . for tree in ../mfc-$base .; do (cd $tree && ./mfc.sh build --gpu acc -j 8 && From 775bea9b2842679db334986e9da617fa97528d94 Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Thu, 26 Nov 2026 15:52:07 -0600 Subject: [PATCH 4/7] docs: say what to do without a GPU, and require a case that uses the change --- .github/pull_request_template.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a9bf6794d8..8f4db39513 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -37,8 +37,8 @@ Command that shows it: ## 3. Is it slower? -Required for `src/` and build changes: benchmark your base commit and your PR on the same GPU. -Any supported GPU will do. +Required for `src/` and build changes: you must benchmark your base commit and your PR on the same GPU, and report which GPU it is. +Any supported GPU will do. If you have no access to one, say so here. GPU and compiler: @@ -48,7 +48,7 @@ PR commit: -Explain any grind speedup below 0.95 that shows up twice. +Explain any grind speedup below 0.95 that shows up twice. If no benchmark case uses your change, add master and PR grind times for a case that does.
Commands From e5b45032f07fd5d60167e8233b3f3c7f9108a882 Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Thu, 26 Nov 2026 15:56:12 -0600 Subject: [PATCH 5/7] docs: allow before and after figures in the PR template --- .github/pull_request_template.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 8f4db39513..40a7164f8c 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -21,12 +21,20 @@ If more than one row applies, do everything each of them requires. Write N/A wit ## 1. Does it solve the problem? +Show before and after with numbers, figures, or both. Delete what you don't use. + Command that shows it: | Quantity | master | this PR | expected | |---|---|---|---| | | | | | +| Figure: master | Figure: this PR | +|---|---| +| | | + +Why the new result is right (analytic solution, reference data, convergence, ...): + ## 2. Does it create another one? | Check | Result | From a98d1b15f9266f840b425e6b1e8ab45ae299a7b5 Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Thu, 26 Nov 2026 16:06:28 -0600 Subject: [PATCH 6/7] docs: let the PR author choose how many GPUs to benchmark on --- .github/pull_request_template.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 40a7164f8c..f83180f47e 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -72,13 +72,13 @@ base=$(git merge-base FETCH_HEAD HEAD) || { echo "No commit shared with master. base=$(git rev-parse --short $base) [ $base != $(git rev-parse --short HEAD) ] || { echo "Nothing to compare: your commit is already in master."; exit 1; } [ -d ../mfc-$base ] || git worktree add --detach ../mfc-$base $base -source .github/scripts/detect-gpus.sh +ngpus=1 # GPUs to use, one MPI rank each. To pick which ones, add -g to the bench line. # NVIDIA or Cray: --gpu acc. AMD flang: --gpu mp. On a cluster, add -c after "--". for tree in ../mfc-$base .; do (cd $tree && ./mfc.sh build --gpu acc -j 8 && - ./mfc.sh bench --mem 4 -o build/bench.yaml -- --gpu acc -g $gpu_ids -n $ngpus) + ./mfc.sh bench --mem 4 -o build/bench.yaml -- --gpu acc -n $ngpus) done GITHUB_STEP_SUMMARY=build/speed.md ./mfc.sh bench_diff ../mfc-$base/build/bench.yaml build/bench.yaml From e67cb8ee536dbbc21fe87769af529dd4860e4fb6 Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Thu, 26 Nov 2026 17:34:10 -0600 Subject: [PATCH 7/7] bench_diff: report only simulation grind time Execution times and pre_process/post_process timings are no longer shown, warned about, or required. --- toolchain/mfc/bench.py | 69 ++++++++++++-------------------- toolchain/mfc/test_bench_diff.py | 68 +++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 44 deletions(-) create mode 100644 toolchain/mfc/test_bench_diff.py diff --git a/toolchain/mfc/bench.py b/toolchain/mfc/bench.py index 85a182742e..c5aedc42da 100644 --- a/toolchain/mfc/bench.py +++ b/toolchain/mfc/bench.py @@ -10,7 +10,7 @@ import rich.table -from .build import DEFAULT_TARGETS, SIMULATION, get_targets +from .build import SIMULATION, get_targets from .common import MFC_BENCH_FILEPATH, MFC_BUILD_DIR, MFCException, console_safe, create_directory, file_dump_yaml, file_load_yaml, format_list_to_string, log_tail, system from .gpu_diagnostics import fault_diagnostic_env, summarize_rocm_debug_agent from .printer import cons @@ -193,7 +193,7 @@ def bench(targets=None): cons.unindent() -def _write_step_summary(lhs_path: str, rhs_path: str, rows: typing.List[typing.Tuple[str, str, str, str]], warnings: typing.List[str]): +def _write_step_summary(lhs_path: str, rhs_path: str, rows: typing.List[typing.Tuple[str, str]], warnings: typing.List[str]): """Put the speedup table on the workflow run's summary page. The same numbers already go to stdout, but reading them there means expanding the @@ -212,12 +212,12 @@ def _write_step_summary(lhs_path: str, rhs_path: str, rows: typing.List[typing.T lines = [ heading, "", - f"Speedups from `{lhs_path}` to `{rhs_path}`; greater than 1 is faster.", + f"Grind time speedups from `{lhs_path}` to `{rhs_path}`; greater than 1 is faster.", "", - "| Case | Pre Process | Simulation | Post Process |", - "| --- | --- | --- | --- |", + "| Case | Grind speedup |", + "| --- | --- |", ] - lines += [f"| `{slug}` | {pre} | {sim} | {post} |" for slug, pre, sim, post in rows] + lines += [f"| `{slug}` | {speedup} |" for slug, speedup in rows] if warnings: lines += ["", "**Below threshold**", ""] + [f"- {w}" for w in warnings] lines.append("") @@ -236,9 +236,7 @@ def diff(): lhs, rhs = file_load_yaml(ARG("lhs")), file_load_yaml(ARG("rhs")) lhs_path = os.path.relpath(ARG("lhs")) rhs_path = os.path.relpath(ARG("rhs")) - cons.print( - f"[bold]Comparing Benchmarks: Speedups from [magenta]{lhs_path}[/magenta] to [magenta]{rhs_path}[/magenta] are displayed below. Thus, numbers > 1 represent increases in performance.[/bold]" - ) + cons.print(f"[bold]Comparing Benchmarks: Grind time speedups from [magenta]{lhs_path}[/magenta] to [magenta]{rhs_path}[/magenta] are displayed below; numbers > 1 are faster.[/bold]") if lhs["metadata"] != rhs["metadata"]: @@ -267,48 +265,31 @@ def _lock_to_str(lock): table = rich.table.Table(show_header=True, box=rich.table.box.SIMPLE) table.add_column("[bold]Case[/bold]", justify="left") - table.add_column("[bold]Pre Process[/bold]", justify="right") - table.add_column("[bold]Simulation[/bold]", justify="right") - table.add_column("[bold]Post Process[/bold]", justify="right") + table.add_column("[bold]Grind speedup[/bold]", justify="right") err = 0 summary_rows = [] warnings = [] for slug in slugs: - lhs_summary, rhs_summary = lhs["cases"][slug]["output_summary"], rhs["cases"][slug]["output_summary"] - speedups = ["N/A", "N/A", "N/A"] + speedup = "N/A" - for i, target in enumerate(sorted(DEFAULT_TARGETS, key=lambda t: t.runOrder)): - if (target.name not in lhs_summary) or (target.name not in rhs_summary): - cons.print(f"{target.name} not present in lhs_summary or rhs_summary - Case: {slug}") + try: + lhs_grind, rhs_grind = (side["cases"][slug]["output_summary"][SIMULATION.name]["grind"] for side in (lhs, rhs)) + if not math.isfinite(lhs_grind) or not math.isfinite(rhs_grind): err = 1 - continue - - if not math.isfinite(lhs_summary[target.name]["exec"]) or not math.isfinite(rhs_summary[target.name]["exec"]): - err = 1 - cons.print(f"lhs_summary or rhs_summary reports non-real exec time for {target.name} - Case: {slug}") - try: - exec_time_value = lhs_summary[target.name]["exec"] / rhs_summary[target.name]["exec"] - if exec_time_value < 0.9: - cons.print(f"[bold yellow]Warning[/bold yellow]: Exec time speedup for {target.name} is less than 0.9 - Case: {slug}") - warnings.append(f"exec speedup {exec_time_value:.2f} < 0.90 for {target.name} in `{slug}`") - speedups[i] = f"Exec: {exec_time_value:.2f}" - if target == SIMULATION: - if not math.isfinite(lhs_summary[target.name]["grind"]) or not math.isfinite(rhs_summary[target.name]["grind"]): - err = 1 - cons.print(f"lhs_summary or rhs_summary reports non-real grind time for {target.name} - Case: {slug}") - - grind_time_value = lhs_summary[target.name]["grind"] / rhs_summary[target.name]["grind"] - speedups[i] += f" & Grind: {grind_time_value:.2f}" - if grind_time_value < 0.95: - cons.print(f"[bold yellow]Warning[/bold yellow]: Grind time speedup for {target.name} below threshold (<0.95) - Case: {slug}") - warnings.append(f"grind speedup {grind_time_value:.2f} < 0.95 for {target.name} in `{slug}`") - except Exception as e: - cons.print(f"[bold red]ERROR[/bold red]: Failed to compute speedup for {target.name} in {slug}: {e}\n{traceback.format_exc()}") - err = 1 - - table.add_row(f"[magenta]{slug}[/magenta]", *speedups) - summary_rows.append((slug, *speedups)) + cons.print(f"lhs_summary or rhs_summary reports non-real grind time - Case: {slug}") + + ratio = lhs_grind / rhs_grind + speedup = f"{ratio:.2f}" + if ratio < 0.95: + cons.print(f"[bold yellow]Warning[/bold yellow]: Grind time speedup below threshold (<0.95) - Case: {slug}") + warnings.append(f"grind speedup {ratio:.2f} < 0.95 in `{slug}`") + except Exception as e: + cons.print(f"[bold red]ERROR[/bold red]: Failed to compute grind speedup in {slug}: {e!r}\n{traceback.format_exc()}") + err = 1 + + table.add_row(f"[magenta]{slug}[/magenta]", speedup) + summary_rows.append((slug, speedup)) cons.raw.print(table) _write_step_summary(lhs_path, rhs_path, summary_rows, warnings) diff --git a/toolchain/mfc/test_bench_diff.py b/toolchain/mfc/test_bench_diff.py new file mode 100644 index 0000000000..050917f8a7 --- /dev/null +++ b/toolchain/mfc/test_bench_diff.py @@ -0,0 +1,68 @@ +"""bench_diff compares simulation grind time and nothing else. + +Execution times and pre_process/post_process timings bury the one number a +reviewer needs, so they are neither shown, warned about, nor required. +""" + +import pytest +import yaml + +from mfc import state +from mfc.bench import diff +from mfc.common import MFCException + + +def _results(tmp_path, name, cases): + path = tmp_path / f"{name}.yaml" + path.write_text(yaml.safe_dump({"metadata": {"invocation": ["bench"], "lock": {}}, "cases": {slug: {"output_summary": s} for slug, s in cases.items()}})) + return str(path) + + +def _diff(tmp_path, monkeypatch, lhs, rhs): + summary = tmp_path / "summary.md" + monkeypatch.setenv("GITHUB_STEP_SUMMARY", str(summary)) + monkeypatch.setitem(state.gARG, "lhs", _results(tmp_path, "lhs", lhs)) + monkeypatch.setitem(state.gARG, "rhs", _results(tmp_path, "rhs", rhs)) + diff() + return summary.read_text() + + +def _all_targets(grind, exec_time): + return {"pre_process": {"exec": exec_time}, "simulation": {"exec": exec_time, "grind": grind}, "post_process": {"exec": exec_time}} + + +def test_reports_only_grind_speedup(tmp_path, monkeypatch, capsys): + text = _diff(tmp_path, monkeypatch, {"ibm": _all_targets(3.0, 1.0)}, {"ibm": _all_targets(2.0, 1.0)}) + + assert "| Case | Grind speedup |" in text + assert "| `ibm` | 1.50 |" in text + printed = capsys.readouterr().out + for unwanted in ("Exec", "Pre Process", "Post Process"): + assert unwanted not in text + assert unwanted not in printed + + +def test_slower_exec_time_alone_does_not_warn(tmp_path, monkeypatch): + text = _diff(tmp_path, monkeypatch, {"ibm": _all_targets(3.0, 1.0)}, {"ibm": _all_targets(3.0, 9.0)}) + + assert "Below threshold" not in text + + +def test_slower_grind_time_warns(tmp_path, monkeypatch): + text = _diff(tmp_path, monkeypatch, {"ibm": _all_targets(3.0, 1.0)}, {"ibm": _all_targets(4.0, 1.0)}) + + assert "grind speedup 0.75 < 0.95 in `ibm`" in text + + +def test_needs_only_the_simulation_summary(tmp_path, monkeypatch): + simulation_only = {"simulation": {"grind": 3.0}} + + text = _diff(tmp_path, monkeypatch, {"ibm": simulation_only}, {"ibm": simulation_only}) + + assert "| `ibm` | 1.00 |" in text + + +@pytest.mark.parametrize("broken", [{}, {"simulation": {}}, {"simulation": {"grind": float("nan")}}]) +def test_missing_or_non_finite_grind_time_fails(tmp_path, monkeypatch, broken): + with pytest.raises(MFCException): + _diff(tmp_path, monkeypatch, {"ibm": _all_targets(3.0, 1.0)}, {"ibm": broken})