5
5
6
6
import os
7
7
import subprocess
8
- import tarfile
9
- import urllib .request
10
8
from pathlib import Path
11
9
from .base import Suite , Benchmark
12
10
from options import options
@@ -40,7 +38,7 @@ def name(self):
40
38
return "Gromacs Bench"
41
39
42
40
def benchmarks (self ) -> list [Benchmark ]:
43
- models = [
41
+ models_rf = [
44
42
"0001.5" ,
45
43
"0003" ,
46
44
"0006" ,
@@ -51,19 +49,30 @@ def benchmarks(self) -> list[Benchmark]:
51
49
"0192" ,
52
50
"0384" ,
53
51
]
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
55
68
56
69
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
+ )
67
76
68
77
# Build GROMACS
69
78
run (
@@ -101,18 +110,21 @@ def download_and_extract_grappa(self):
101
110
checksum = "cc02be35ba85c8b044e47d097661dffa8bea57cdb3db8b5da5d01cdbc94fe6c8902652cfe05fb9da7f2af0698be283a2" ,
102
111
untar = True ,
103
112
)
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 } " )
105
115
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 } " )
107
118
108
119
def teardown (self ):
109
120
pass
110
121
111
122
112
- class GromacsSystemBenchmark (Benchmark ):
113
- def __init__ (self , suite , model ):
123
+ class GromacsBenchmark (Benchmark ):
124
+ def __init__ (self , suite , model , type ):
114
125
self .suite = suite
115
126
self .model = model # The model name (e.g., "0001.5")
127
+ self .type = type
116
128
self .gromacs_src = suite .gromacs_src
117
129
self .grappa_dir = suite .grappa_dir
118
130
self .gmx_path = suite .gromacs_build_path / "bin" / "gmx"
@@ -121,51 +133,65 @@ def name(self):
121
133
return f"gromacs-{ self .model } "
122
134
123
135
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
+ )
125
171
126
172
def run (self , env_vars ):
127
173
if not self .gmx_path .exists ():
128
174
raise FileNotFoundError (f"gmx executable not found at { self .gmx_path } " )
129
175
130
- system_dir = self .grappa_dir / self .model
176
+ model_dir = self .grappa_dir / self .model
131
177
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 } " )
134
180
135
181
env_vars .update (
136
182
{
137
- "LD_LIBRARY_PATH" : str (self .grappa_dir )
138
- + os .pathsep
139
- + os .environ .get ("LD_LIBRARY_PATH" , "" ),
140
183
"SYCL_CACHE_PERSISTENT" : "1" ,
141
184
"GMX_CUDA_GRAPH" : "1" ,
142
185
}
143
186
)
144
187
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 = [
165
191
str (self .gmx_path ),
166
192
"mdrun" ,
167
193
"-s" ,
168
- str (system_dir / "rf.tpr" ),
194
+ str (model_dir / "rf.tpr" ),
169
195
"-nb" ,
170
196
"gpu" ,
171
197
"-update" ,
@@ -183,38 +209,12 @@ def run(self, env_vars):
183
209
"-pin" ,
184
210
"on" ,
185
211
]
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 = [
214
214
str (self .gmx_path ),
215
215
"mdrun" ,
216
216
"-s" ,
217
- str (system_dir / "pme.tpr" ),
217
+ str (model_dir / "pme.tpr" ),
218
218
"-pme" ,
219
219
"gpu" ,
220
220
"-pmefft" ,
@@ -237,53 +237,32 @@ def run(self, env_vars):
237
237
"-pin" ,
238
238
"on" ,
239
239
]
240
- pme_mdrun_result = run (
241
- pme_command ,
242
- add_sycl = True ,
243
- )
244
240
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 )
249
247
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" )
253
250
254
251
# Return results as a list of Result objects
255
252
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
+ )
272
264
]
273
265
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
-
287
266
def _extract_execution_time (self , log_content , benchmark_type ):
288
267
# Look for the line containing "Time:"
289
268
# and extract the first numeric value after it
@@ -303,22 +282,5 @@ def _extract_execution_time(self, log_content, benchmark_type):
303
282
f"No numeric value found in the 'Time:' line for { benchmark_type } ."
304
283
)
305
284
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
-
323
285
def teardown (self ):
324
286
pass
0 commit comments