Skip to content

Commit acd567e

Browse files
committed
separate rf, pme benchmarks, apply ther comments
1 parent d740745 commit acd567e

File tree

3 files changed

+6005
-133
lines changed

3 files changed

+6005
-133
lines changed

devops/scripts/benchmarks/benches/gromacs.py

Lines changed: 94 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import os
77
import subprocess
8-
import tarfile
9-
import urllib.request
108
from pathlib import Path
119
from .base import Suite, Benchmark
1210
from options import options
@@ -40,7 +38,7 @@ def name(self):
4038
return "Gromacs Bench"
4139

4240
def benchmarks(self) -> list[Benchmark]:
43-
models = [
41+
models_rf = [
4442
"0001.5",
4543
"0003",
4644
"0006",
@@ -51,19 +49,30 @@ def benchmarks(self) -> list[Benchmark]:
5149
"0192",
5250
"0384",
5351
]
54-
return [GromacsSystemBenchmark(self, model) for model in models]
52+
benches_rf = [GromacsBenchmark(self, model, "rf") for model in models_rf]
53+
models_pme = [
54+
"0001.5",
55+
"0003",
56+
"0006",
57+
"0012",
58+
"0024",
59+
"0048",
60+
"0096",
61+
"0192",
62+
"0384",
63+
]
64+
benches_pme = [GromacsBenchmark(self, model, "pme") for model in models_pme]
65+
# Add more models as needed
66+
67+
return benches_rf + benches_pme
5568

5669
def setup(self):
57-
if not (self.gromacs_src).exists():
58-
self.gromacs_src = git_clone(
59-
self.directory,
60-
"gromacs-repo",
61-
self.git_url(),
62-
self.git_tag(),
63-
)
64-
else:
65-
if options.verbose:
66-
print(f"GROMACS repository already exists at {self.gromacs_src}")
70+
self.gromacs_src = git_clone(
71+
self.directory,
72+
"gromacs-repo",
73+
self.git_url(),
74+
self.git_tag(),
75+
)
6776

6877
# Build GROMACS
6978
run(
@@ -101,18 +110,21 @@ def download_and_extract_grappa(self):
101110
checksum="cc02be35ba85c8b044e47d097661dffa8bea57cdb3db8b5da5d01cdbc94fe6c8902652cfe05fb9da7f2af0698be283a2",
102111
untar=True,
103112
)
104-
print(f"Grappa tar file downloaded and extracted to {model}")
113+
if options.verbose:
114+
print(f"Grappa tar file downloaded and extracted to {model}")
105115
else:
106-
print(f"Grappa tar file already exists at {grappa_tar_file}")
116+
if options.verbose:
117+
print(f"Grappa tar file already exists at {grappa_tar_file}")
107118

108119
def teardown(self):
109120
pass
110121

111122

112-
class GromacsSystemBenchmark(Benchmark):
113-
def __init__(self, suite, model):
123+
class GromacsBenchmark(Benchmark):
124+
def __init__(self, suite, model, type):
114125
self.suite = suite
115126
self.model = model # The model name (e.g., "0001.5")
127+
self.type = type
116128
self.gromacs_src = suite.gromacs_src
117129
self.grappa_dir = suite.grappa_dir
118130
self.gmx_path = suite.gromacs_build_path / "bin" / "gmx"
@@ -121,51 +133,65 @@ def name(self):
121133
return f"gromacs-{self.model}"
122134

123135
def setup(self):
124-
pass
136+
model_dir = self.grappa_dir / self.model
137+
if self.type == "rf":
138+
cmd_list = [
139+
str(self.gmx_path),
140+
"grompp",
141+
"-f",
142+
str(self.grappa_dir / "rf.mdp"),
143+
"-c",
144+
str(model_dir / "conf.gro"),
145+
"-p",
146+
str(model_dir / "topol.top"),
147+
"-o",
148+
str(model_dir / "rf.tpr"),
149+
]
150+
elif self.type == "pme":
151+
cmd_list = [
152+
str(self.gmx_path),
153+
"grompp",
154+
"-f",
155+
str(self.grappa_dir / "pme.mdp"),
156+
"-c",
157+
str(model_dir / "conf.gro"),
158+
"-p",
159+
str(model_dir / "topol.top"),
160+
"-o",
161+
str(model_dir / "pme.tpr"),
162+
]
163+
else:
164+
raise ValueError(f"Unknown benchmark type: {self.type}")
165+
166+
# Generate configuration files
167+
self.conf_result = run(
168+
cmd_list,
169+
add_sycl=True,
170+
)
125171

126172
def run(self, env_vars):
127173
if not self.gmx_path.exists():
128174
raise FileNotFoundError(f"gmx executable not found at {self.gmx_path}")
129175

130-
system_dir = self.grappa_dir / self.model
176+
model_dir = self.grappa_dir / self.model
131177

132-
if not system_dir.exists():
133-
raise FileNotFoundError(f"System directory not found: {system_dir}")
178+
if not model_dir.exists():
179+
raise FileNotFoundError(f"Model directory not found: {model_dir}")
134180

135181
env_vars.update(
136182
{
137-
"LD_LIBRARY_PATH": str(self.grappa_dir)
138-
+ os.pathsep
139-
+ os.environ.get("LD_LIBRARY_PATH", ""),
140183
"SYCL_CACHE_PERSISTENT": "1",
141184
"GMX_CUDA_GRAPH": "1",
142185
}
143186
)
144187

145-
try:
146-
# Generate configurations for RF
147-
rf_grompp_result = run(
148-
[
149-
str(self.gmx_path),
150-
"grompp",
151-
"-f",
152-
str(self.grappa_dir / "rf.mdp"),
153-
"-c",
154-
str(system_dir / "conf.gro"),
155-
"-p",
156-
str(system_dir / "topol.top"),
157-
"-o",
158-
str(system_dir / "rf.tpr"),
159-
],
160-
add_sycl=True,
161-
)
162-
163-
# Run RF benchmark
164-
rf_command = [
188+
# Run benchmark
189+
if self.type == "rf":
190+
command = [
165191
str(self.gmx_path),
166192
"mdrun",
167193
"-s",
168-
str(system_dir / "rf.tpr"),
194+
str(model_dir / "rf.tpr"),
169195
"-nb",
170196
"gpu",
171197
"-update",
@@ -183,38 +209,12 @@ def run(self, env_vars):
183209
"-pin",
184210
"on",
185211
]
186-
rf_mdrun_result = run(
187-
rf_command,
188-
add_sycl=True,
189-
)
190-
rf_mdrun_result_output = rf_mdrun_result.stderr.decode()
191-
rf_time = self._extract_execution_time(rf_mdrun_result_output, "RF")
192-
193-
print(f"[{self.name()}-RF] Time: {rf_time:.3f} seconds")
194-
195-
# Generate configurations for PME
196-
pme_grompp_result = run(
197-
[
198-
str(self.gmx_path),
199-
"grompp",
200-
"-f",
201-
str(self.grappa_dir / "pme.mdp"),
202-
"-c",
203-
str(system_dir / "conf.gro"),
204-
"-p",
205-
str(system_dir / "topol.top"),
206-
"-o",
207-
str(system_dir / "pme.tpr"),
208-
],
209-
add_sycl=True,
210-
)
211-
212-
# Run PME benchmark
213-
pme_command = [
212+
else: # type == "pme"
213+
command = [
214214
str(self.gmx_path),
215215
"mdrun",
216216
"-s",
217-
str(system_dir / "pme.tpr"),
217+
str(model_dir / "pme.tpr"),
218218
"-pme",
219219
"gpu",
220220
"-pmefft",
@@ -237,53 +237,32 @@ def run(self, env_vars):
237237
"-pin",
238238
"on",
239239
]
240-
pme_mdrun_result = run(
241-
pme_command,
242-
add_sycl=True,
243-
)
244240

245-
pme_mdrun_result_output = pme_mdrun_result.stderr.decode()
246-
247-
pme_time = self._extract_execution_time(pme_mdrun_result_output, "PME")
248-
print(f"[{self.name()}-PME] Time: {pme_time:.3f} seconds")
241+
mdrun_result = run(
242+
command,
243+
add_sycl=True,
244+
)
245+
mdrun_result_output = mdrun_result.stderr.decode()
246+
time = self._extract_execution_time(mdrun_result_output, type)
249247

250-
except subprocess.CalledProcessError as e:
251-
print(f"Error during execution of {self.name()}: {e}")
252-
raise
248+
if options.verbose:
249+
print(f"[{self.name()}-RF] Time: {time:.3f} seconds")
253250

254251
# Return results as a list of Result objects
255252
return [
256-
self._result(
257-
"RF",
258-
rf_time,
259-
rf_grompp_result,
260-
rf_mdrun_result,
261-
rf_command,
262-
env_vars,
263-
),
264-
self._result(
265-
"PME",
266-
pme_time,
267-
pme_grompp_result,
268-
pme_mdrun_result,
269-
pme_command,
270-
env_vars,
271-
),
253+
Result(
254+
label=f"{self.name()}-{self.type}",
255+
value=time,
256+
unit="s",
257+
passed=(mdrun_result.returncode == 0),
258+
command=" ".join(map(str, command)),
259+
env=env_vars,
260+
stdout=self.conf_result.stderr.decode() + mdrun_result.stderr.decode(),
261+
git_url=self.suite.git_url(),
262+
git_hash=self.suite.git_tag(),
263+
)
272264
]
273265

274-
def _result(self, label, time, gr_result, md_result, command, env_vars):
275-
return Result(
276-
label=f"{self.name()}-{label}",
277-
value=time,
278-
unit="s",
279-
passed=(gr_result.returncode == 0 and md_result.returncode == 0),
280-
command=" ".join(map(str, command)),
281-
env=env_vars,
282-
stdout=gr_result.stderr.decode() + md_result.stderr.decode(),
283-
git_url=self.suite.git_url(),
284-
git_hash=self.suite.git_tag(),
285-
)
286-
287266
def _extract_execution_time(self, log_content, benchmark_type):
288267
# Look for the line containing "Time:"
289268
# and extract the first numeric value after it
@@ -303,22 +282,5 @@ def _extract_execution_time(self, log_content, benchmark_type):
303282
f"No numeric value found in the 'Time:' line for {benchmark_type}."
304283
)
305284

306-
# def _extract_first_number(self, line):
307-
# parts = line.split()
308-
# for part in parts:
309-
# if part.replace(".", "", 1).isdigit():
310-
# return float(part)
311-
# return None
312-
313-
# def _parse_result(self, result, benchmark_type, execution_time):
314-
# passed = result.returncode == 0
315-
# return {
316-
# "type": f"{self.name()}-{benchmark_type}",
317-
# "passed": passed,
318-
# "execution_time": execution_time,
319-
# "output": result.stdout,
320-
# "error": result.stderr if not passed else None,
321-
# }
322-
323285
def teardown(self):
324286
pass

0 commit comments

Comments
 (0)