Efficiency-of-Neural-Archit.../run_service.py

91 lines
2.1 KiB
Python
Raw Normal View History

2023-06-01 08:20:51 +00:00
import arguments
2022-04-17 16:18:54 +00:00
from time import sleep
2022-04-16 12:20:44 +00:00
import subprocess as sub
2023-06-01 08:20:51 +00:00
from arguments import makeArguments
2022-04-16 12:20:44 +00:00
2023-06-01 08:20:51 +00:00
args = makeArguments(arguments.all_args)
2022-04-17 16:18:54 +00:00
check = list(args.values())
if all(v is None for v in check):
raise Exception("One argument required")
elif None in check:
if args['f'] is not None:
cmd = ["python", "main_frequentist.py"]
elif args['b'] is not None:
cmd = ["python", "main_bayesian.py"]
else:
raise Exception("Only one argument allowed")
wide = args["f"] or args["b"]
with open("tmp", "w") as file:
file.write(str(wide))
2023-06-01 08:20:51 +00:00
if args['EarlyStopping']:
with open("stp", "w") as file:
file.write('2')
elif args['EnergyBound']:
with open("stp", "w") as file:
file.write('3')
elif args['AccuracyBound']:
with open("stp", "w") as file:
file.write('4')
else:
with open("stp", "w") as file:
file.write('1')
if args['Save']:
with open("sav", "w") as file:
file.write('1')
else:
with open("sav", "w") as file:
file.write('0')
2022-04-17 16:18:54 +00:00
sleep(3)
if cmd[1] == "main_frequentist.py":
cmd2 = ["./cpu_watt.sh", "freq_{}_cpu_watts".format(wide)]
cmd3 = ["./mem_free.sh", "freq_{}_ram_use".format(wide)]
with open("frq", "w") as file:
file.write(str(1))
with open("bay", "w") as file:
file.write(str(0))
elif cmd[1] == "main_bayesian.py":
cmd2 = ["./cpu_watt.sh", "bayes_{}_cpu_watts".format(wide)]
cmd3 = ["./mem_free.sh", "bayes_{}_ram_use".format(wide)]
with open("bay", "w") as file:
file.write(str(1))
2023-06-01 08:20:51 +00:00
with open("frq", "w") as file:
2022-04-17 16:18:54 +00:00
file.write(str(0))
2022-04-16 12:20:44 +00:00
path = sub.check_output(['pwd'])
path = path.decode()
path = path.replace('\n', '')
2023-06-01 08:20:51 +00:00
startWattCounter = 'python ' + path + '/amd_sample_draw.py'
2022-04-16 12:20:44 +00:00
#test = startNODE.split()
#test.append(pythonEnd)
#test.append(pythonEnd2)
#startNODE = test
2023-06-01 08:20:51 +00:00
#print(startNODE)
#print(startWattCounter)
2022-04-16 12:20:44 +00:00
p1 = sub.Popen(cmd)
2023-06-01 08:20:51 +00:00
p2 = sub.Popen(startWattCounter.split())
2022-04-16 12:20:44 +00:00
p3 = sub.Popen(cmd2)
p4 = sub.Popen(cmd3)
retcode = p1.wait()
2022-04-17 16:18:54 +00:00
print("Return code: {}".format(retcode))
2022-04-16 12:20:44 +00:00
p1.kill()
2023-06-01 08:20:51 +00:00
p2.kill()
2022-04-16 12:20:44 +00:00
p3.kill()
p4.kill()