Skip to content

Commit fa0a565

Browse files
authored
Merge pull request rust-lang#450 from tgross35/benchmark-soft-float
Set `force-soft-floats` for benchmarks
2 parents a7c6178 + 32dcbd9 commit fa0a565

File tree

4 files changed

+117
-35
lines changed

4 files changed

+117
-35
lines changed

.github/workflows/main.yaml

+3-24
Original file line numberDiff line numberDiff line change
@@ -170,29 +170,8 @@ jobs:
170170
- name: Run icount benchmarks
171171
env:
172172
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
173-
run: |
174-
set -eux
175-
iai_home="iai-home"
176-
# Download the baseline from master
177-
./ci/ci-util.py locate-baseline --download --extract
178-
179-
# Run iai-callgrind benchmarks
180-
cargo bench --no-default-features \
181-
--features unstable,unstable-float,icount \
182-
--bench icount \
183-
-- \
184-
--save-baseline=default \
185-
--home "$(pwd)/$iai_home" \
186-
--regression='ir=5.0' \
187-
--save-summary
188-
# NB: iai-callgrind should exit on error but does not, so we inspect the sumary
189-
# for errors. See https://github.com/iai-callgrind/iai-callgrind/issues/337
190-
./ci/ci-util.py check-regressions "$iai_home"
191-
192-
# Name and tar the new baseline
193-
name="baseline-icount-$(date -u +'%Y%m%d%H%M')-${GITHUB_SHA:0:12}"
194-
echo "BASELINE_NAME=$name" >> "$GITHUB_ENV"
195-
tar cJf "$name.tar.xz" "$iai_home"
173+
PR_NUMBER: ${{ github.event.pull_request.number }}
174+
run: ./ci/bench-icount.sh
196175

197176
- name: Upload the benchmark baseline
198177
uses: actions/upload-artifact@v4
@@ -205,7 +184,7 @@ jobs:
205184
# Always use the same seed for benchmarks. Ideally we should switch to a
206185
# non-random generator.
207186
export LIBM_SEED=benchesbenchesbenchesbencheswoo!
208-
cargo bench --all --features libm-test/short-benchmarks,libm-test/build-musl
187+
cargo bench --all --features short-benchmarks,build-musl,force-soft-floats
209188
210189
- name: Print test logs if available
211190
if: always()

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ target
66
Cargo.lock
77
musl/
88
**.tar.gz
9+
10+
# Benchmark cache
11+
iai-home
12+
baseline-*

ci/bench-icount.sh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
iai_home="iai-home"
6+
7+
# Download the baseline from master
8+
./ci/ci-util.py locate-baseline --download --extract
9+
10+
# Run benchmarks once
11+
function run_icount_benchmarks() {
12+
cargo_args=(
13+
"--bench" "icount"
14+
"--no-default-features"
15+
"--features" "unstable,unstable-float,icount"
16+
)
17+
18+
iai_args=(
19+
"--home" "$(pwd)/$iai_home"
20+
"--regression=ir=5.0"
21+
"--save-summary"
22+
)
23+
24+
# Parse `cargo_arg0 cargo_arg1 -- iai_arg0 iai_arg1` syntax
25+
parsing_iai_args=0
26+
while [ "$#" -gt 0 ]; do
27+
if [ "$parsing_iai_args" == "1" ]; then
28+
iai_args+=("$1")
29+
elif [ "$1" == "--" ]; then
30+
parsing_iai_args=1
31+
else
32+
cargo_args+=("$1")
33+
fi
34+
35+
shift
36+
done
37+
38+
# Run iai-callgrind benchmarks
39+
cargo bench "${cargo_args[@]}" -- "${iai_args[@]}"
40+
41+
# NB: iai-callgrind should exit on error but does not, so we inspect the sumary
42+
# for errors. See https://github.com/iai-callgrind/iai-callgrind/issues/337
43+
if [ -n "${PR_NUMBER:-}" ]; then
44+
# If this is for a pull request, ignore regressions if specified.
45+
./ci/ci-util.py check-regressions --home "$iai_home" --allow-pr-override "$PR_NUMBER"
46+
else
47+
./ci/ci-util.py check-regressions --home "$iai_home" || true
48+
fi
49+
}
50+
51+
# Run once with softfloats, once with arch instructions enabled
52+
run_icount_benchmarks --features force-soft-floats -- --save-baseline=softfloat
53+
run_icount_benchmarks -- --save-baseline=hardfloat
54+
55+
# Name and tar the new baseline
56+
name="baseline-icount-$(date -u +'%Y%m%d%H%M')-${GITHUB_SHA:0:12}"
57+
echo "BASELINE_NAME=$name" >>"$GITHUB_ENV"
58+
tar cJf "$name.tar.xz" "$iai_home"

ci/ci-util.py

+52-11
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333
3434
Note that `--extract` will overwrite files in `iai-home`.
3535
36-
check-regressions [iai-home]
36+
check-regressions [--home iai-home] [--allow-pr-override pr_number]
3737
Check `iai-home` (or `iai-home` if unspecified) for `summary.json`
3838
files and see if there are any regressions. This is used as a workaround
3939
for `iai-callgrind` not exiting with error status; see
4040
<https://github.com/iai-callgrind/iai-callgrind/issues/337>.
41+
42+
If `--allow-pr-override` is specified, the regression check will not exit
43+
with failure if any line in the PR starts with `allow-regressions`.
4144
"""
4245
)
4346

@@ -46,6 +49,8 @@
4649
DEFAULT_BRANCH = "master"
4750
WORKFLOW_NAME = "CI" # Workflow that generates the benchmark artifacts
4851
ARTIFACT_GLOB = "baseline-icount*"
52+
# Place this in a PR body to skip regression checks (must be at the start of a line).
53+
REGRESSION_DIRECTIVE = "ci: allow-regressions"
4954

5055
# Don't run exhaustive tests if these files change, even if they contaiin a function
5156
# definition.
@@ -256,12 +261,26 @@ def locate_baseline(flags: list[str]) -> None:
256261
eprint("baseline extracted successfully")
257262

258263

259-
def check_iai_regressions(iai_home: str | None | Path):
264+
def check_iai_regressions(args: list[str]):
260265
"""Find regressions in iai summary.json files, exit with failure if any are
261266
found.
262267
"""
263-
if iai_home is None:
264-
iai_home = "iai-home"
268+
269+
iai_home = "iai-home"
270+
pr_number = False
271+
272+
while len(args) > 0:
273+
match args:
274+
case ["--home", home, *rest]:
275+
iai_home = home
276+
args = rest
277+
case ["--allow-pr-override", pr_num, *rest]:
278+
pr_number = pr_num
279+
args = rest
280+
case _:
281+
eprint(USAGE)
282+
exit(1)
283+
265284
iai_home = Path(iai_home)
266285

267286
found_summaries = False
@@ -286,9 +305,33 @@ def check_iai_regressions(iai_home: str | None | Path):
286305
eprint(f"did not find any summary.json files within {iai_home}")
287306
exit(1)
288307

289-
if len(regressions) > 0:
290-
eprint("Found regressions:", json.dumps(regressions, indent=4))
291-
exit(1)
308+
if len(regressions) == 0:
309+
eprint("No regressions found")
310+
return
311+
312+
eprint("Found regressions:", json.dumps(regressions, indent=4))
313+
314+
if pr_number is not None:
315+
pr_info = sp.check_output(
316+
[
317+
"gh",
318+
"pr",
319+
"view",
320+
str(pr_number),
321+
"--json=number,commits,body,createdAt",
322+
"--jq=.commits |= map(.oid)",
323+
],
324+
text=True,
325+
)
326+
pr = json.loads(pr_info)
327+
eprint("PR info:", json.dumps(pr, indent=4))
328+
329+
lines = pr["body"].splitlines()
330+
if any(line.startswith(REGRESSION_DIRECTIVE) for line in lines):
331+
eprint("PR allows regressions, returning")
332+
return
333+
334+
exit(1)
292335

293336

294337
def main():
@@ -299,10 +342,8 @@ def main():
299342
print(f"matrix={output}")
300343
case ["locate-baseline", *flags]:
301344
locate_baseline(flags)
302-
case ["check-regressions"]:
303-
check_iai_regressions(None)
304-
case ["check-regressions", iai_home]:
305-
check_iai_regressions(iai_home)
345+
case ["check-regressions", *args]:
346+
check_iai_regressions(args)
306347
case ["--help" | "-h"]:
307348
print(USAGE)
308349
exit()

0 commit comments

Comments
 (0)