Skip to content
Snippets Groups Projects
Commit 37e1f530 authored by Yifan Zhao's avatar Yifan Zhao
Browse files

Move away from dataclass (python 3.7+)

parent 49397dc3
No related branches found
No related tags found
No related merge requests found
from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from subprocess import PIPE, CalledProcessError from subprocess import PIPE, CalledProcessError
from typing import Iterable, List, Tuple, Union from typing import Iterable, List, Tuple, Union
...@@ -39,7 +38,12 @@ def profile_config_file( ...@@ -39,7 +38,12 @@ def profile_config_file(
raise ValueError("Config file with no configs is unsupported.") raise ValueError("Config file with no configs is unsupported.")
# Modifies configs in place. # Modifies configs in place.
profile_configs( profile_configs(
binary_path, configs[1:], configs[0], progress_bar, profile_filename, qos_filename binary_path,
configs[1:],
configs[0],
progress_bar,
profile_filename,
qos_filename,
) )
write_hpvm_configs(header, configs, Path(output_config_path)) write_hpvm_configs(header, configs, Path(output_config_path))
...@@ -57,10 +61,10 @@ def profile_configs( ...@@ -57,10 +61,10 @@ def profile_configs(
from tqdm import tqdm from tqdm import tqdm
baseline_time, baseline_acc = profile_config(binary_path, baseline_config) baseline_time, baseline_acc = measure_config(binary_path, baseline_config)
iterable = tqdm(configs, desc="Configs profiled") if progress_bar else configs iterable = tqdm(configs, desc="Configs profiled") if progress_bar else configs
for idx in iterable: for config in iterable:
time, acc = profile_config(binary_path, config, profile_filename, qos_filename) time, acc = measure_config(binary_path, config, profile_filename, qos_filename)
speedup = baseline_time / time speedup = baseline_time / time
config.update_profile_results(speedup, acc, baseline_acc) config.update_profile_results(speedup, acc, baseline_acc)
return configs return configs
...@@ -127,15 +131,23 @@ def plot_hpvm_configs( ...@@ -127,15 +131,23 @@ def plot_hpvm_configs(
return fig return fig
@dataclass
class Config: class Config:
conf_name: str def __init__(
speedup: float self,
energy: float conf_name: str,
qos: float speedup: float,
qos_loss: float energy: float,
# We don't care about the information in this part, and we don't parse this. qos: float,
config_body: List[str] qos_loss: float,
config_body: List[str],
):
self.conf_name = conf_name
self.speedup = speedup
self.energy = energy
self.qos = qos
self.qos_loss = qos_loss
# We don't care about the information in this part, and we don't parse this.
self.config_body = config_body
def update_profile_results(self, speedup: float, qos: float, base_qos: float): def update_profile_results(self, speedup: float, qos: float, base_qos: float):
recorded_base_qos = self.qos + self.qos_loss recorded_base_qos = self.qos + self.qos_loss
...@@ -189,7 +201,6 @@ def write_hpvm_configs(header: str, configs: Iterable[Config], to_file: PathLike ...@@ -189,7 +201,6 @@ def write_hpvm_configs(header: str, configs: Iterable[Config], to_file: PathLike
f.flush() f.flush()
def _read_profile_file(profile_file_path: Path): def _read_profile_file(profile_file_path: Path):
with profile_file_path.open() as f: with profile_file_path.open() as f:
target_lines = [line.strip() for line in f if "Total Time" in line] target_lines = [line.strip() for line in f if "Total Time" in line]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment