67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
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:
|
|
if "Avg. throughput" in line:
|
|
flops = float(line.split(" ")[2])
|
|
flops = min(max(flops, 0), 6000)
|
|
return flops / 6000 * 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/HW5"
|
|
|
|
usernames = [x.split(',')[1] for x in open('accounts.csv').readlines()[1:]]
|
|
print(usernames)
|
|
|
|
result = ""
|
|
|
|
# for user in usernames:
|
|
# submitpath1 = f"/home/{user}/submit/HW5/mat_mul.cpp"
|
|
# submitpath2 = f"/home/{user}/submit/HW5/kernel.cl"
|
|
|
|
# os.makedirs(f"{BASEDIR}/{user}", exist_ok=True)
|
|
# if os.path.exists(submitpath1):
|
|
# shutil.copyfile(submitpath1, f"{BASEDIR}/{user}/mat_mul.cpp")
|
|
# if os.path.exists(submitpath2):
|
|
# shutil.copyfile(submitpath2, f"{BASEDIR}/{user}/kernel.cl")
|
|
|
|
|
|
|
|
for user in usernames:
|
|
submitpath = f"/home/{user}/submit/HW5/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)
|