Skip to content

Commit 8c5b83d

Browse files
committed
Reduce the number of unnecessary experiment runs
1 parent 7b89363 commit 8c5b83d

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

build.py

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def double_quoted_str_representer(dumper, data):
2929
REBENCH_EXEC = Path(".venv/bin/rebench").resolve()
3030
REBENCH_CONF = Path("rebench.conf").resolve()
3131
RESULTS_DIR = Path("results").resolve()
32+
PATCH_DIR = Path("patch").resolve()
3233
DEFAULT_PEXECS = 30
3334
PEXECS = 30
3435
DEFAULT_MEASUREMENTS = ["perf"]
@@ -82,7 +83,7 @@ def path(self) -> Path:
8283
@classmethod
8384
def experiments(cls, pexecs=DEFAULT_PEXECS) -> List["Experiment"]:
8485
return [
85-
Experiment(list(set(cls) & set(suite.profiles)), m, suite, pexecs)
86+
Experiment(tuple(set(cls) & set(suite.profiles)), m, suite, pexecs)
8687
for suite in BenchmarkSuite.all()
8788
for m in cls.measurements
8889
]
@@ -210,9 +211,9 @@ def all(cls) -> Set["BenchmarkSuite"]:
210211
}
211212

212213

213-
@dataclass
214+
@dataclass(frozen=True)
214215
class Experiment:
215-
profiles: List[ExperimentProfile]
216+
profiles: Tuple[ExperimentProfile]
216217
measurement: Metric
217218
suite: "BenchmarkSuite"
218219
pexecs: int = 0
@@ -235,11 +236,6 @@ def _rebench(self, config, pexecs):
235236
self.name,
236237
]
237238

238-
@property
239-
def steps(self):
240-
bms = len(self.suite.benchmarks)
241-
return bms * len(self.configurations()) * self.pexecs
242-
243239
def run(self, c, pexecs, config):
244240
self.results.parent.mkdir(parents=True, exist_ok=True)
245241
if self.suite.setup:
@@ -266,12 +262,7 @@ def run(self, c, pexecs, config):
266262

267263
@property
268264
def results(self) -> Path:
269-
return (
270-
RESULTS_DIR
271-
/ self.measurement.value
272-
/ self.experiment
273-
/ f"{self.suite.name}.csv"
274-
)
265+
return RESULTS_DIR / self.suite.name / self.measurement.value / "results.data"
275266

276267
@property
277268
def experiment(self):
@@ -301,6 +292,7 @@ def build_steps(self) -> int:
301292

302293
@dataclass(frozen=True)
303294
class Executor:
295+
experiment: "Experiment"
304296
suite: "BenchmarkSuite"
305297
metric: "Metric"
306298
id: str
@@ -324,15 +316,15 @@ def install_prefix(self) -> Path:
324316

325317
@property
326318
def path(self) -> Path:
327-
return self.install_prefix / self.id
319+
return self.install_prefix / self.name
328320

329321
@property
330-
def stats_dir(self) -> Path:
331-
return self.experiment.results.parent / "stats" / self.suite.name
322+
def metrics_data(self) -> Path:
323+
return self.experiment.results.parent / f"{self.id}"
332324

333325
@property
334326
def build_dir(self) -> Path:
335-
return BUILD_DIR / "benchmarks" / self.suite.name / self.id
327+
return BUILD_DIR / "benchmarks" / self.suite.name / self.name
336328

337329
@property
338330
def installed(self) -> bool:
@@ -434,6 +426,7 @@ def results(self) -> Path:
434426

435427
@dataclass
436428
class Experiments:
429+
pexecs: int
437430
experiments: List[Experiment]
438431
_config: Optional[Path] = None
439432

@@ -474,6 +467,12 @@ def alloy_variants(self, only_installed=False, only_missing=False):
474467
def build_steps(self):
475468
return sum(cfg.build_steps for cfg in self.configurations(only_missing=True))
476469

470+
@property
471+
def total_iters(self):
472+
unique = sum(len(cfg.suite.benchmarks) for cfg in self.configurations())
473+
print(self.pexecs)
474+
return unique * self.pexecs
475+
477476
@property
478477
def config(self) -> Path:
479478
if self._config and self._config.exists():
@@ -483,19 +482,31 @@ def config(self) -> Path:
483482
exec_part = {}
484483
bm_part = {}
485484

485+
executors = self.configurations()
486+
for cfg in executors:
487+
exec_part[cfg.name] = {
488+
"path": str(cfg.install_prefix),
489+
"executable": cfg.path.name,
490+
}
491+
if cfg.metric == Metric.METRICS:
492+
exec_part[cfg.name].update(
493+
{
494+
"env": {
495+
"GC_LOG_DIR": str(cfg.metrics_data),
496+
"LD_PRELOAD": str(
497+
cfg.alloy.install_prefix / "lib" / "libgc.so"
498+
),
499+
}
500+
}
501+
)
502+
486503
for e in self.experiments:
487504
exp_part[e.name] = {
488505
"suites": [e.suite.name],
489-
"executions": [cfg.name for cfg in e.configurations()],
506+
"executions": [cfg.name for cfg in executors if cfg.experiment == e],
490507
"data_file": str(e.results),
491508
}
492509

493-
for cfg in e.configurations():
494-
exec_part[cfg.name] = {
495-
"path": str(cfg.install_prefix),
496-
"executable": cfg.path.name,
497-
}
498-
499510
bm_part[e.suite.name] = {
500511
"gauge_adapter": e.gauge_adapter,
501512
"command": DoubleQuotedStr(e.suite.args),
@@ -523,10 +534,6 @@ def config(self) -> Path:
523534
self._config = REBENCH_CONF
524535
return self._config
525536

526-
@property
527-
def run_steps(self) -> int:
528-
return sum([e.steps for e in self.experiments])
529-
530537
def configurations(
531538
self, only_installed=False, only_missing=False
532539
) -> List["Executor"]:
@@ -541,14 +548,18 @@ def configurations(
541548
name = "default" if p in identical else p.full
542549
is_metrics = e.measurement == Metric.METRICS
543550
alloy = Alloy(p, metrics=is_metrics)
544-
executors.add(Executor(e.suite, e.measurement, name, alloy))
551+
executors.add(Executor(e, e.suite, e.measurement, name, alloy))
545552

553+
if only_installed:
554+
executors = [e for e in executors if e.installed]
555+
elif only_missing:
556+
executors = [e for e in executors if not e.installed]
546557
return executors
547558

548559
@classmethod
549560
def all(cls, pexecs: int = 30) -> "Experiments":
550561
profiles = [GCVS, PremOpt, Elision]
551-
return cls([e for p in profiles for e in p.experiments(pexecs)])
562+
return cls(pexecs, [e for p in profiles for e in p.experiments(pexecs)])
552563

553564

554565
@dataclass

0 commit comments

Comments
 (0)