import os import shutil import subprocess import sys def performance_score(s): s = str(s, "utf-8").splitlines() for line in s: if "Avg. throughput" in line: l = line.split(' ') for i in range(len(l)): if l[i] == 'throughput:': return float(l[i+1]) return 0 def validation_score(s): s = str(s, "utf-8") cnt = s.count("Result: VALID") return float(cnt * 5) # Avg. throughput: 4926.239883 GFLOPS BASEDIR = "/home/kjp4155/submissions/final" usernames = [x.split(',')[1] for x in open('accounts.csv').readlines()[1:]] result = "" # for user in usernames: # submitpath1 = f"/home/{user}/submit/HW6/mat_mul.cpp" # submitpath2 = f"/home/{user}/submit/HW6/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") print(usernames) for user in usernames: if not os.path.isfile(f"{BASEDIR}/{user}/A/convolution.cpp"): print(f"{user},0,0,0,0,-1") result += f"{user},0,0,0,0,-1\n" continue # if not os.path.isfile(f"{BASEDIR}/{user}/A/convolution.cpp"): # print(f"{user},0,0,0,0,-1") # result += f"{user},0,0,0,0,-1\n" # continue # Prepare files shutil.rmtree(f"{BASEDIR}/{user}/tmp-A", ignore_errors=True) shutil.copytree(f"{BASEDIR}/skel", f"{BASEDIR}/{user}/tmp-A", dirs_exist_ok=True) shutil.copytree(f"{BASEDIR}/{user}/A", f"{BASEDIR}/{user}/tmp-A", dirs_exist_ok=True) subprocess.run(["make" ,"clean"], cwd=f"{BASEDIR}/{user}/tmp-A") subprocess.run(["make" ,"-j"], cwd=f"{BASEDIR}/{user}/tmp-A") sperfA = subprocess.run(["./run_performance_A.sh"], cwd=f"{BASEDIR}/{user}/tmp-A", capture_output=True) svalA = subprocess.run(["./run_validate_A.sh"], cwd=f"{BASEDIR}/{user}/tmp-A", capture_output=True) perf_scoreA = performance_score(sperfA.stdout) val_scoreA = validation_score(svalA.stdout) shutil.rmtree(f"{BASEDIR}/{user}/tmp-B", ignore_errors=True) shutil.copytree(f"{BASEDIR}/skel", f"{BASEDIR}/{user}/tmp-B", dirs_exist_ok=True) shutil.copytree(f"{BASEDIR}/{user}/B", f"{BASEDIR}/{user}/tmp-B", dirs_exist_ok=True) subprocess.run(["make" ,"clean"], cwd=f"{BASEDIR}/{user}/tmp-B") subprocess.run(["make" ,"-j"], cwd=f"{BASEDIR}/{user}/tmp-B") sperfB = subprocess.run(["./run_performance_B.sh"], cwd=f"{BASEDIR}/{user}/tmp-B", capture_output=True) svalB = subprocess.run(["./run_validate_B.sh"], cwd=f"{BASEDIR}/{user}/tmp-B", capture_output=True) perf_scoreB = performance_score(sperfB.stdout) val_scoreB = validation_score(svalB.stdout) print(f"{user},{perf_scoreA},{val_scoreA},{perf_scoreB},{val_scoreB}") result += f"{user},{perf_scoreA},{val_scoreA},{perf_scoreB},{val_scoreB}\n" print(result)