2024-05-10 09:59:24 +00:00
|
|
|
import pickle
|
2025-01-29 11:26:17 +00:00
|
|
|
|
|
|
|
# from pathlib import Path
|
2024-05-10 09:59:24 +00:00
|
|
|
import subprocess as sub
|
2025-01-29 11:26:17 +00:00
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
import psutil
|
|
|
|
|
|
|
|
import arguments
|
2024-05-10 09:59:24 +00:00
|
|
|
from arguments import makeArguments
|
|
|
|
|
|
|
|
|
|
|
|
def kill(proc_pid):
|
|
|
|
process = psutil.Process(proc_pid)
|
|
|
|
for proc in process.children(recursive=True):
|
|
|
|
proc.kill()
|
|
|
|
process.kill()
|
|
|
|
|
|
|
|
|
|
|
|
cfg = {
|
2025-01-29 11:26:17 +00:00
|
|
|
"model": {
|
|
|
|
"net_type": None,
|
|
|
|
"type": None,
|
|
|
|
"size": None,
|
|
|
|
"layer_type": "lrt",
|
|
|
|
"activation_type": "softplus",
|
|
|
|
"priors": {
|
|
|
|
"prior_mu": 0,
|
|
|
|
"prior_sigma": 0.1,
|
|
|
|
"posterior_mu_initial": (0, 0.1), # (mean,std) normal_
|
|
|
|
"posterior_rho_initial": (-5, 0.1), # (mean,std) normal_
|
|
|
|
},
|
|
|
|
"n_epochs": 100,
|
|
|
|
"sens": 1e-9,
|
|
|
|
"energy_thrs": 100000,
|
|
|
|
"acc_thrs": 0.99,
|
|
|
|
"lr": 0.001,
|
|
|
|
"num_workers": 4,
|
|
|
|
"valid_size": 0.2,
|
|
|
|
"batch_size": 256,
|
|
|
|
"train_ens": 1,
|
|
|
|
"valid_ens": 1,
|
|
|
|
"beta_type": 0.1, # 'Blundell','Standard',etc.
|
|
|
|
# Use float for const value
|
|
|
|
},
|
|
|
|
"data": None,
|
|
|
|
"noise_type": None,
|
|
|
|
"stopping_crit": None,
|
|
|
|
"save": None,
|
|
|
|
"pickle_path": None,
|
2024-05-10 09:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
args = makeArguments(arguments.all_args)
|
|
|
|
|
|
|
|
check = list(args.values())
|
|
|
|
if all(v is None for v in check):
|
|
|
|
raise Exception("One argument required")
|
|
|
|
elif None in check:
|
2025-01-29 11:26:17 +00:00
|
|
|
if args["f"] is not None:
|
2024-05-10 09:59:24 +00:00
|
|
|
cmd = ["python", "main_frequentist.py"]
|
|
|
|
cfg["model"]["type"] = "freq"
|
2025-01-29 11:26:17 +00:00
|
|
|
elif args["b"] is not None:
|
2024-05-10 09:59:24 +00:00
|
|
|
cmd = ["python", "main_bayesian.py"]
|
|
|
|
cfg["model"]["type"] = "bayes"
|
|
|
|
else:
|
|
|
|
raise Exception("Only one argument allowed")
|
|
|
|
|
|
|
|
|
|
|
|
wide = args["f"] or args["b"]
|
|
|
|
|
|
|
|
cfg["model"]["size"] = wide
|
|
|
|
cfg["data"] = args["dataset"]
|
2025-01-29 11:26:17 +00:00
|
|
|
cfg["noise_type"] = args["noise_type"]
|
2024-05-10 09:59:24 +00:00
|
|
|
cfg["model"]["net_type"] = args["net_type"]
|
|
|
|
|
|
|
|
|
2025-01-29 11:26:17 +00:00
|
|
|
if args["EarlyStopping"]:
|
2024-05-10 09:59:24 +00:00
|
|
|
cfg["stopping_crit"] = 2
|
2025-01-29 11:26:17 +00:00
|
|
|
elif args["EnergyBound"]:
|
2024-05-10 09:59:24 +00:00
|
|
|
cfg["stopping_crit"] = 3
|
2025-01-29 11:26:17 +00:00
|
|
|
elif args["AccuracyBound"]:
|
2024-05-10 09:59:24 +00:00
|
|
|
cfg["stopping_crit"] = 4
|
2025-01-29 11:26:17 +00:00
|
|
|
elif args["EfficiencyStopping"]:
|
|
|
|
cfg["stopping_crit"] = 5
|
2024-05-10 09:59:24 +00:00
|
|
|
else:
|
|
|
|
cfg["stopping_crit"] = 1
|
|
|
|
|
2025-01-29 11:26:17 +00:00
|
|
|
if args["Save"]:
|
2024-05-10 09:59:24 +00:00
|
|
|
cfg["save"] = 1
|
|
|
|
else:
|
|
|
|
cfg["save"] = 0
|
|
|
|
|
|
|
|
|
2025-01-29 11:26:17 +00:00
|
|
|
cfg["pickle_path"] = (
|
|
|
|
f"{cfg['model']['type']}_wattdata_{cfg['model']['size']}_{cfg['data']}.pkl"
|
|
|
|
)
|
2024-05-10 09:59:24 +00:00
|
|
|
|
|
|
|
with open("configuration.pkl", "wb") as f:
|
|
|
|
pickle.dump(cfg, f)
|
|
|
|
|
|
|
|
# print(args)
|
|
|
|
# print(cfg)
|
|
|
|
|
|
|
|
sleep(3)
|
|
|
|
|
|
|
|
cpu_watt = "cpu_watt.sh"
|
|
|
|
ram = "mem_free.sh"
|
|
|
|
gpu = "radeontop.sh"
|
|
|
|
|
2025-01-29 11:26:17 +00:00
|
|
|
# path_cpu_watt = Path(cpu_watt)
|
|
|
|
# path_ram = Path(ram)
|
|
|
|
# path_gpu = Path(gpu)
|
2024-05-10 09:59:24 +00:00
|
|
|
|
2025-01-29 11:26:17 +00:00
|
|
|
# path_cpu_watt = str(Path(cpu_watt).absolute()) + '/' + cpu_watt
|
|
|
|
# path_ram = str(Path(ram).absolute()) + '/' + ram
|
|
|
|
# path_gpu = str(Path(gpu).absolute()) + '/' + gpu
|
2024-05-10 09:59:24 +00:00
|
|
|
|
|
|
|
if cmd[1] == "main_frequentist.py":
|
2025-01-29 11:26:17 +00:00
|
|
|
cmd2 = ["./" + cpu_watt, f"freq_{wide}_cpu_watts_{cfg['data']}"]
|
|
|
|
cmd3 = ["./" + ram, f"freq_{wide}_ram_use_{cfg['data']}"]
|
|
|
|
cmd4 = ["./" + gpu, f"freq_{wide}_flop_app_{cfg['data']}"]
|
2024-05-10 09:59:24 +00:00
|
|
|
elif cmd[1] == "main_bayesian.py":
|
2025-01-29 11:26:17 +00:00
|
|
|
cmd2 = ["./" + cpu_watt, f"bayes_{wide}_cpu_watts_{cfg['data']}"]
|
|
|
|
cmd3 = ["./" + ram, f"bayes_{wide}_ram_use_{cfg['data']}"]
|
|
|
|
cmd4 = ["./" + gpu, f"bayes_{wide}_flop_app_{cfg['data']}"]
|
2024-05-10 09:59:24 +00:00
|
|
|
|
|
|
|
|
2025-01-29 11:26:17 +00:00
|
|
|
path = sub.check_output(["pwd"])
|
2024-05-10 09:59:24 +00:00
|
|
|
path = path.decode()
|
2025-01-29 11:26:17 +00:00
|
|
|
path = path.replace("\n", "")
|
2024-05-10 09:59:24 +00:00
|
|
|
|
2025-01-29 11:26:17 +00:00
|
|
|
startWattCounter = "python " + path + "/amd_sample_draw.py"
|
2024-05-10 09:59:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
p1 = sub.Popen(cmd)
|
2025-01-29 11:26:17 +00:00
|
|
|
p2 = sub.Popen(
|
|
|
|
startWattCounter.split(), stdin=sub.PIPE, stdout=sub.PIPE, stderr=sub.PIPE
|
|
|
|
)
|
2024-05-10 09:59:24 +00:00
|
|
|
p3 = sub.Popen(cmd2, stdin=sub.PIPE, stdout=sub.PIPE, stderr=sub.PIPE)
|
|
|
|
p4 = sub.Popen(cmd3, stdin=sub.PIPE, stdout=sub.PIPE, stderr=sub.PIPE)
|
|
|
|
p5 = sub.Popen(cmd4, stdin=sub.PIPE, stdout=sub.PIPE, stderr=sub.PIPE)
|
|
|
|
|
|
|
|
retcode = p1.wait()
|
|
|
|
print("Return code: {}".format(retcode))
|
|
|
|
|
|
|
|
p1.kill()
|
|
|
|
kill(p2.pid)
|
|
|
|
kill(p3.pid)
|
|
|
|
kill(p4.pid)
|
|
|
|
kill(p5.pid)
|