chundoong-lab-ta/SamsungDS22/submissions/HW4/score.py

68 lines
1.8 KiB
Python
Raw Normal View History

2022-09-29 18:01:45 +09:00
import os
import shutil
import subprocess
import sys
def performance_score(s):
if not ("Result: VALID" in str(s, "utf-8")):
return 0
s = str(s, "utf-8").splitlines()
for line in s:
# print(line, "Avg. throughput" in line)
if "Avg. throughput" in line:
print(line, line.replace("[rank 0] ","").split(" ")[2])
flops = float(line.replace("[rank 0] ","").split(" ")[2])
flops = min(max(flops, 0), 525)
return flops / 525 * 50
return 0
def validation_score(s):
s = str(s, "utf-8")
cnt = s.count("Result: VALID")
return float(cnt * 5)
BASEDIR = "/home/kjp4155/submissions/HW4"
usernames = [x.split(',')[1] for x in open('accounts.csv').readlines()[1:]]
print(usernames)
result = ""
# for user in usernames:
# submitpath = f"/home/{user}/submit/HW4/mat_mul.cpp"
# os.makedirs(f"{BASEDIR}/{user}", exist_ok=True)
# if os.path.exists(submitpath):
# shutil.copyfile(submitpath, f"{BASEDIR}/{user}/mat_mul.cpp")
# # sys.exit(0)
result = ""
for user in usernames:
submitpath = f"/home/{user}/submit/HW4/mat_mul.cpp"
if not os.path.isfile(f"{BASEDIR}/{user}/mat_mul.cpp"):
print(f"{user},0,0,-1")
result += f"{user},0,0,-1\n"
continue
# Prepare files
shutil.copytree(f"{BASEDIR}/skel", f"{BASEDIR}/{user}", dirs_exist_ok=True)
# Compile
subprocess.run(["make" ,"clean"], cwd=f"{BASEDIR}/{user}")
subprocess.run(["make" ,"-j"], cwd=f"{BASEDIR}/{user}")
# Run
sperf = subprocess.run(["./run_performance.sh"], cwd=f"{BASEDIR}/{user}", capture_output=True)
sval = subprocess.run(["./run_validate.sh"], cwd=f"{BASEDIR}/{user}", capture_output=True)
perf_score = performance_score(sperf.stdout)
val_score = validation_score(sval.stdout)
print(f"{user},{perf_score},{val_score}")
result += f"{user},{perf_score},{val_score}\n"
print(result)