Skip to content

Commit 2b2702e

Browse files
Archith IyerArchith Iyer
authored andcommitted
revert CI changes
1 parent e11da22 commit 2b2702e

File tree

4 files changed

+110
-136
lines changed

4 files changed

+110
-136
lines changed

.github/workflows/bench.yml

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
steps:
1212
- name: Clone
1313
uses: actions/checkout@v4
14+
1415
- name: Detect Changes
1516
uses: dorny/paths-filter@v3
1617
id: changes
@@ -25,7 +26,7 @@ jobs:
2526
matrix:
2627
device: ['cpu', 'gpu']
2728
runs-on:
28-
group: phoenix
29+
group: phoenix
2930
labels: gt
3031
timeout-minutes: 1400
3132
env:
@@ -36,43 +37,32 @@ jobs:
3637
uses: actions/checkout@v4
3738
with:
3839
path: pr
40+
3941
- name: Clone - Master
4042
uses: actions/checkout@v4
4143
with:
4244
repository: MFlowCode/MFC
4345
ref: master
4446
path: master
4547

46-
- name: Bench (Master vs PR)
48+
- name: Bench (Master v. PR)
4749
run: |
48-
(cd pr && bash .github/workflows/phoenix/submit.sh .github/workflows/phoenix/bench.sh ${{ matrix.device }} double) &
49-
(cd master && bash .github/workflows/phoenix/submit.sh .github/workflows/phoenix/bench.sh ${{ matrix.device }} double) &
50+
(cd pr && bash .github/workflows/phoenix/submit.sh .github/workflows/phoenix/bench.sh ${{ matrix.device }}) &
51+
(cd master && bash .github/workflows/phoenix/submit.sh .github/workflows/phoenix/bench.sh ${{ matrix.device }}) &
5052
wait %1 && wait %2
5153
52-
(cd pr && bash .github/workflows/phoenix/submit.sh .github/workflows/phoenix/bench.sh ${{ matrix.device }} single) &
53-
wait %3
54-
5554
- name: Generate & Post Comment
5655
run: |
5756
(cd pr && . ./mfc.sh load -c p -m g)
58-
(cd pr && ./mfc.sh bench_diff ../master/bench-${{ matrix.device }}-double.yaml ../pr/bench-${{ matrix.device }}-double.yaml)
59-
60-
- name: Check PR Single vs Double Precision
61-
run: |
62-
# Compare single and double precision within the PR
63-
cd pr
64-
. ./mfc.sh load -c p -m ${{ matrix.device }}
65-
./mfc.sh bench_diff bench-${{ matrix.device }}-double.yaml bench-${{ matrix.device }}-single.yaml
57+
(cd pr && ./mfc.sh bench_diff ../master/bench-${{ matrix.device }}.yaml ../pr/bench-${{ matrix.device }}.yaml)
6658
6759
- name: Archive Logs
6860
uses: actions/upload-artifact@v4
69-
if: always()
61+
if: always()
7062
with:
71-
name: logs-${{ matrix.device }}
72-
path: |
73-
pr/bench-${{ matrix.device }}-*.*
74-
pr/build/benchmarks/*
75-
master/bench-${{ matrix.device }}-*.*
76-
master/build/benchmarks/*
77-
78-
63+
name: logs-${{ matrix.device }}
64+
path: |
65+
pr/bench-${{ matrix.device }}.*
66+
pr/build/benchmarks/*
67+
master/bench-${{ matrix.device }}.*
68+
master/build/benchmarks/*

.github/workflows/phoenix/bench.sh

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
11
#!/bin/bash
22

3-
4-
if [ -z "$job_device" ] || [ -z "$job_precision" ]; then
5-
echo "Usage: $0 [cpu|gpu] [single|double]"
6-
exit 1
7-
fi
8-
93
n_ranks=12
10-
precision_flag=""
11-
12-
if [ "$job_precision" == "single" ]; then
13-
precision_flag="--single"
14-
fi
154

165
if [ "$job_device" == "gpu" ]; then
17-
n_ranks=$(nvidia-smi -L | wc -l)
18-
gpu_ids=$(seq -s ' ' 0 $(($n_ranks-1)))
6+
n_ranks=$(nvidia-smi -L | wc -l) # number of GPUs on node
7+
gpu_ids=$(seq -s ' ' 0 $(($n_ranks-1))) # 0,1,2,...,gpu_count-1
198
device_opts="--gpu -g $gpu_ids"
20-
else
21-
device_opts=""
229
fi
2310

24-
mem_value=1
25-
if [ "$job_device" == "gpu" ]; then
26-
mem_value=12
27-
fi
28-
29-
./mfc.sh clean
30-
./mfc.sh build -j 8 -- $precision_flag
31-
./mfc.sh bench --mem $mem_value -j $(nproc) -o "bench-${job_device}-${job_precision}.yaml" -- $precision_flag -c phoenix $device_opts -n $n_ranks
32-
11+
if ["$job_device" == "gpu"]; then
12+
./mfc.sh bench --mem 12 -j $(nproc) -o "$job_slug.yaml" -- -c phoenix $device_opts -n $n_ranks
13+
else
14+
./mfc.sh bench --mem 1 -j $(nproc) -o "$job_slug.yaml" -- -c phoenix $device_opts -n $n_ranks
15+
fi

.github/workflows/phoenix/submit.sh

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,7 @@ else
3333
exit 1
3434
fi
3535

36-
# Set default precision to 'double' if not provided
37-
38-
if [ -z "$3" ]; then
39-
precision="double"
40-
else
41-
if [ "$3" != "single" ] && [ "$3" != "double" ]; then
42-
usage
43-
exit 1
44-
fi
45-
precision="$3"
46-
fi
47-
48-
49-
job_slug="`basename "$1" | sed 's/\.sh$//' | sed 's/[^a-zA-Z0-9]/-/g'`-$2-$precision"
36+
job_slug="`basename "$1" | sed 's/\.sh$//' | sed 's/[^a-zA-Z0-9]/-/g'`-$2"
5037

5138
sbatch <<EOT
5239
#!/bin/bash
@@ -67,9 +54,9 @@ echo "Running in $(pwd):"
6754
6855
job_slug="$job_slug"
6956
job_device="$2"
70-
job_precision="$precision"
7157
7258
. ./mfc.sh load -c p -m $2
7359
7460
$sbatch_script_contents
61+
7562
EOT

toolchain/mfc/bench.py

Lines changed: 87 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,170 @@
1-
import os, sys, uuid, subprocess, dataclasses, typing
1+
import os, sys, uuid, subprocess, dataclasses, typing, math
2+
3+
import rich.table
4+
25
from .printer import cons
3-
from .state import ARG, CFG
4-
from .build import get_targets
5-
from .common import system, MFC_BENCH_FILEPATH, MFC_BUILD_DIR, format_list_to_string
6-
from .common import file_load_yaml, file_dump_yaml, create_directory
7-
from .common import MFCException
6+
from .state import ARG, CFG
7+
from .build import get_targets, DEFAULT_TARGETS, SIMULATION
8+
from .common import system, MFC_BENCH_FILEPATH, MFC_BUILD_DIR, format_list_to_string
9+
from .common import file_load_yaml, file_dump_yaml, create_directory
10+
from .common import MFCException
11+
812

913
@dataclasses.dataclass
1014
class BenchCase:
1115
slug: str
1216
path: str
1317
args: typing.List[str]
1418

15-
def bench(targets=None):
19+
20+
def bench(targets = None):
1621
if targets is None:
1722
targets = ARG("targets")
1823

19-
precision = "single" if ARG("single") else "double"
20-
21-
additional_args = ARG("--")
22-
2324
targets = get_targets(targets)
25+
2426
bench_dirpath = os.path.join(MFC_BUILD_DIR, "benchmarks", str(uuid.uuid4())[:4])
2527
create_directory(bench_dirpath)
2628

27-
cons.print(f"[bold]Benchmarking {format_list_to_string(ARG('targets'), 'magenta')} in '{precision}' precision "
28-
f"([magenta]{os.path.relpath(bench_dirpath)}[/magenta]):[/bold]")
29+
cons.print()
30+
cons.print(f"[bold]Benchmarking {format_list_to_string(ARG('targets'), 'magenta')} ([magenta]{os.path.relpath(bench_dirpath)}[/magenta]):[/bold]")
2931
cons.indent()
3032
cons.print()
3133

32-
CASES = [BenchCase(**case) for case in file_load_yaml(MFC_BENCH_FILEPATH)]
34+
CASES = [ BenchCase(**case) for case in file_load_yaml(MFC_BENCH_FILEPATH) ]
3335

3436
for case in CASES:
35-
case.args = case.args + additional_args
36-
if precision == "single":
37-
case.args.append("--single")
37+
case.args = case.args + ARG("--")
3838
case.path = os.path.abspath(case.path)
3939

4040
results = {
4141
"metadata": {
4242
"invocation": sys.argv[1:],
43-
"lock": dataclasses.asdict(CFG()),
44-
"precision": precision
43+
"lock": dataclasses.asdict(CFG())
4544
},
4645
"cases": {},
4746
}
4847

4948
for i, case in enumerate(CASES):
50-
summary_filepath = os.path.join(bench_dirpath, f"{case.slug}-{precision}.yaml")
51-
log_filepath = os.path.join(bench_dirpath, f"{case.slug}-{precision}.out")
49+
summary_filepath = os.path.join(bench_dirpath, f"{case.slug}.yaml")
50+
log_filepath = os.path.join(bench_dirpath, f"{case.slug}.out")
5251

53-
cons.print(f"{str(i + 1).zfill(len(str(len(CASES))))}/{len(CASES)}: {case.slug} @ [bold]{os.path.relpath(case.path)}[/bold]")
52+
cons.print(f"{str(i+1).zfill(len(CASES) // 10 + 1)}/{len(CASES)}: {case.slug} @ [bold]{os.path.relpath(case.path)}[/bold]")
5453
cons.indent()
54+
cons.print()
5555
cons.print(f"> Log: [bold]{os.path.relpath(log_filepath)}[/bold]")
5656
cons.print(f"> Summary: [bold]{os.path.relpath(summary_filepath)}[/bold]")
5757

5858
with open(log_filepath, "w") as log_file:
59-
command = [
60-
"./mfc.sh", "run", case.path, "--case-optimization",
61-
"--targets"
62-
] + [t.name for t in targets] + [
63-
"--output-summary", summary_filepath
64-
] + case.args
65-
66-
cons.print(f"Case precision: {precision}")
67-
cons.print(f"Case args: {case.args}")
68-
cons.print(f"Running command: {' '.join(command)}")
69-
7059
system(
71-
command,
60+
["./mfc.sh", "run", case.path, "--case-optimization"] +
61+
["--targets"] + [t.name for t in targets] +
62+
["--output-summary", summary_filepath] +
63+
case.args +
64+
["--", "--gbpp", ARG('mem')],
7265
stdout=log_file,
73-
stderr=subprocess.STDOUT
74-
)
66+
stderr=subprocess.STDOUT)
7567

7668
results["cases"][case.slug] = {
77-
"description": dataclasses.asdict(case),
69+
"description": dataclasses.asdict(case),
7870
"output_summary": file_load_yaml(summary_filepath),
7971
}
80-
cons.unindent()
8172

8273
file_dump_yaml(ARG("output"), results)
74+
8375
cons.print(f"Wrote results to [bold magenta]{os.path.relpath(ARG('output'))}[/bold magenta].")
76+
8477
cons.unindent()
8578

79+
80+
# TODO: This function is too long and not nicely written at all. Someone should
81+
# refactor it...
82+
# pylint: disable=too-many-branches
8683
def diff():
87-
"""
88-
Compares the results between two benchmark YAML files (lhs vs rhs).
89-
Checks both PR vs master and PR single vs PR double precision.
90-
"""
9184
lhs, rhs = file_load_yaml(ARG("lhs")), file_load_yaml(ARG("rhs"))
9285

93-
lhs_precision = lhs["metadata"].get("precision", "double")
94-
rhs_precision = rhs["metadata"].get("precision", "double")
95-
96-
is_pr_single_vs_double = lhs_precision == "double" and rhs_precision == "single"
97-
98-
cons.print(f"[bold]Comparing Benchmarks: Speedups from [magenta]{os.path.relpath(ARG('lhs'))}[/magenta] to "
99-
f"[magenta]{os.path.relpath(ARG('rhs'))}[/magenta][/bold]")
100-
101-
if lhs["metadata"] != rhs["metadata"] and not is_pr_single_vs_double:
86+
cons.print(f"[bold]Comparing Benchmarks: Speedups from [magenta]{os.path.relpath(ARG('lhs'))}[/magenta] to [magenta]{os.path.relpath(ARG('rhs'))}[/magenta] are displayed below. Thus, numbers > 1 represent increases in performance.[/bold]")
87+
if lhs["metadata"] != rhs["metadata"]:
10288
def _lock_to_str(lock):
10389
return ' '.join([f"{k}={v}" for k, v in lock.items()])
10490

10591
cons.print(f"""\
10692
[bold yellow]Warning[/bold yellow]: Metadata in lhs and rhs are not equal.
93+
This could mean that the benchmarks are not comparable (e.g. one was run on CPUs and the other on GPUs).
10794
lhs:
10895
* Invocation: [magenta]{' '.join(lhs['metadata']['invocation'])}[/magenta]
10996
* Modes: {_lock_to_str(lhs['metadata']['lock'])}
110-
* Precision: {lhs_precision}
11197
rhs:
11298
* Invocation: {' '.join(rhs['metadata']['invocation'])}
11399
* Modes: [magenta]{_lock_to_str(rhs['metadata']['lock'])}[/magenta]
114-
* Precision: {rhs_precision}
115100
""")
116101

117102
slugs = set(lhs["cases"].keys()) & set(rhs["cases"].keys())
118103
if len(slugs) not in [len(lhs["cases"]), len(rhs["cases"])]:
119104
cons.print(f"""\
120105
[bold yellow]Warning[/bold yellow]: Cases in lhs and rhs are not equal.
121-
Using intersection: {slugs} with {len(slugs)} elements.""")
106+
* rhs cases: {', '.join(set(rhs['cases'].keys()) - slugs)}.
107+
* lhs cases: {', '.join(set(lhs['cases'].keys()) - slugs)}.
108+
Using intersection: {slugs} with {len(slugs)} elements.
109+
""")
122110

123111
table = rich.table.Table(show_header=True, box=rich.table.box.SIMPLE)
124-
table.add_column("[bold]Case[/bold]", justify="left")
125-
table.add_column("[bold]Speedup (Exec)[/bold]", justify="right")
126-
table.add_column("[bold]Speedup (Grind)[/bold]", justify="right")
112+
table.add_column("[bold]Case[/bold]", justify="left")
113+
table.add_column("[bold]Pre Process[/bold]", justify="right")
114+
table.add_column("[bold]Simulation[/bold]", justify="right")
115+
table.add_column("[bold]Post Process[/bold]", justify="right")
127116

128117
err = 0
129118

130119
for slug in slugs:
131120
lhs_summary = lhs["cases"][slug]["output_summary"]
132121
rhs_summary = rhs["cases"][slug]["output_summary"]
133122

134-
try:
135-
exec_speedup = lhs_summary["exec"] / rhs_summary["exec"]
136-
grind_speedup = lhs_summary["grind"] / rhs_summary["grind"]
123+
speedups = ['N/A', 'N/A', 'N/A']
124+
125+
for i, target in enumerate(sorted(DEFAULT_TARGETS, key=lambda t: t.runOrder)):
126+
if (target.name not in lhs_summary) or (target.name not in rhs_summary):
137127

138-
if is_pr_single_vs_double and exec_speedup < SINGLE_PRECISION_SPEEDUP_THRESHOLD:
139-
cons.print(f"[bold red]Error[/bold red]: Case {slug} failed speedup requirement: "
140-
f"Exec speedup {exec_speedup:.2f} < {SINGLE_PRECISION_SPEEDUP_THRESHOLD}.")
141128
err = 1
142129

143-
table.add_row(slug, f"{exec_speedup:.2f}x", f"{grind_speedup:.2f}x")
130+
if target.name not in lhs_summary:
131+
cons.print(f"{target.name} not present in lhs_summary - Case: {slug}")
144132

145-
except KeyError as e:
146-
table.add_row(slug, "Error", "Error")
147-
cons.print(f"[bold yellow]Warning[/bold yellow]: Missing key {e} for case {slug}.")
148-
except ZeroDivisionError:
149-
table.add_row(slug, "Inf", "Inf")
150-
cons.print(f"[bold yellow]Warning[/bold yellow]: Zero execution time in case {slug}.")
133+
if target.name not in rhs_summary:
134+
cons.print(f"{target.name} not present in rhs_summary - Case: {slug}")
151135

152-
cons.raw.print(table)
136+
continue
137+
138+
if not math.isfinite(lhs_summary[target.name]["exec"]) or not math.isfinite(rhs_summary[target.name]["exec"]):
139+
err = 1
140+
cons.print(f"lhs_summary or rhs_summary reports non-real exec time for {target.name} - Case: {slug}")
141+
142+
exec_time_speedup = "N/A"
143+
try:
144+
exec_time_speedup = f'{lhs_summary[target.name]["exec"] / rhs_summary[target.name]["exec"]:.2f}'
145+
except Exception as _:
146+
err = 1
147+
cons.print(f"lhs_summary or rhs_summary reports non-real exec time for {target.name} - Case: {slug}")
148+
149+
speedups[i] = f"Exec: {exec_time_speedup}"
150+
151+
if target == SIMULATION:
152+
grind_time_speedup = "N/A"
153+
if not math.isfinite(lhs_summary[target.name]["grind"]) or not math.isfinite(rhs_summary[target.name]["grind"]):
154+
err = 1
155+
cons.print(f"lhs_summary or rhs_summary reports non-real grind time for {target.name} - Case: {slug}")
156+
157+
try:
158+
grind_time_speedup = f'{lhs_summary[target.name]["grind"] / rhs_summary[target.name]["grind"]:.2f}'
159+
except Exception as _:
160+
err = 1
161+
cons.print(f"lhs_summary or rhs_summary reports non-real grind time for {target.name} - Case: {slug}")
153162

154-
if err:
155-
raise MFCException("Benchmarking failed: Some cases did not meet the performance requirements.")
163+
speedups[i] += f" & Grind: {grind_time_speedup}"
164+
165+
table.add_row(f"[magenta]{slug}[/magenta]", *speedups)
166+
167+
cons.raw.print(table)
156168

169+
if err != 0:
170+
raise MFCException("Benchmarking failed")

0 commit comments

Comments
 (0)