-
Notifications
You must be signed in to change notification settings - Fork 12
/
run.py
executable file
·190 lines (158 loc) · 6.84 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import sys
import subprocess
import os
import shutil
import argparse
# python run.py -v [-build] [-run] [-submission=<folder>]
#
# Instructions:
# The script goes through all the folders in current dir and tries
# to build and run each submission.
# Use this script to track the progress of your experiments.
# I recommend to create a new folder for each new experiment.
# When you run the script for all the submissions in the folder,
# It will generate the score table for each of your experiments.
# Example:
# time(s) submission timings for 10 consecutive runs (s) speedup
# ([3.56, 'AVX2', [3.56, 3.56, 3.56, 3.56, 3.56, 3.56, 3.56, 3.56, 3.56, 3.56]], ' + 1.21x')
# ([4.29, 'baseline', [4.29, 4.29, 4.29, 4.29, 4.3, 4.3, 4.3, 4.3, 4.3, 4.33]], ' + 1.0x' )
# ([4.35, 'align loop', [4.35, 4.35, 4.35, 4.35, 4.35, 4.35, 4.35, 4.35, 4.35, 4.35]], ' + 0.99x')
parser = argparse.ArgumentParser(description='test submissions')
parser.add_argument("-v", help="verbose", action="store_true", default=False)
parser.add_argument("-build", help="only build", action="store_true", default=False)
parser.add_argument("-clean", help="do clean build", action="store_true", default=False)
parser.add_argument("-run", help="only run", action="store_true", default=False)
parser.add_argument("-submission", type=str, help="do single submission", default="")
args = parser.parse_args()
verbose = args.v
buildOnly = args.build
cleanBuild = args.clean
runOnly = args.run
buildAndRun = not runOnly and not buildOnly
doSubmission = args.submission
FNULL = open(os.devnull, 'w')
saveCwd = os.getcwd()
submissions = list(tuple())
if verbose:
print ("Submissions:")
for submission in os.listdir(os.getcwd()):
if not submission == ".git" and not submission == ".vs":
if not os.path.isfile(os.path.join(os.getcwd(), submission)):
submissions.append((submission, os.path.join(os.getcwd(), submission)))
if verbose:
print (" " + submission)
if buildOnly or buildAndRun:
if verbose:
print ("Building ...")
for submissionName, submissionDir in submissions:
if not doSubmission or (doSubmission and doSubmission == submissionName):
if verbose:
print ("Building " + submissionName + " ...")
submissionBuildDir = os.path.join(submissionDir, "build")
if cleanBuild and os.path.exists(submissionBuildDir):
shutil.rmtree(submissionBuildDir)
if not os.path.exists(submissionBuildDir):
os.mkdir(submissionBuildDir)
os.chdir(submissionBuildDir)
try:
subprocess.check_call("cmake ../", shell=True, stdout=FNULL, stderr=FNULL)
print(" cmake - OK")
except:
print(" cmake - Failed")
try:
if sys.platform != 'win32':
subprocess.check_call("make", shell=True, stdout=FNULL, stderr=FNULL)
else:
subprocess.check_call("cmake --build . --target canny --config Release", shell=True, stdout=FNULL, stderr=FNULL)
subprocess.check_call("cmake --build . --target validate --config Release", shell=True, stdout=FNULL, stderr=FNULL)
print(" make - OK")
except:
print(" make - Failed")
if sys.platform == 'win32':
try:
subprocess.check_call("copy .\\Release\\*.exe .", shell=True, stdout=FNULL, stderr=FNULL)
print(" copy .exe - OK")
except:
print(" copy .exe - Failed")
inputFileName = str(os.path.join(saveCwd, "221575.pgm"))
destDir = str(submissionBuildDir)
try:
if sys.platform != 'win32':
subprocess.check_call("cp " + inputFileName + " " + destDir, shell=True, stdout=FNULL, stderr=FNULL)
else:
subprocess.check_call("copy " + inputFileName + " " + destDir, shell=True, stdout=FNULL, stderr=FNULL)
print(" copy image - OK")
except:
print(" copy image - Failed")
os.chdir(saveCwd)
if runOnly or buildAndRun:
if verbose:
print ("Running ...")
scoretable = []
baseline = float(0)
for submissionName, submissionDir in submissions:
if not doSubmission or (doSubmission and doSubmission == submissionName):
if verbose:
print ("Running " + submissionName + " ...")
submissionBuildDir = os.path.join(submissionDir, "build")
os.chdir(submissionBuildDir)
scores = []
inputFileName = str(os.path.join(submissionBuildDir, "221575.pgm"))
if sys.platform != 'win32':
runCmd = "./canny " + inputFileName + " 0.5 0.7 0.9 2>&1"
else:
runCmd = ".\\canny.exe " + inputFileName + " 0.5 0.7 0.9"
valid = True
try:
subprocess.check_call(runCmd, shell=True, stdout=FNULL, stderr=FNULL)
except:
valid = False
if valid:
print(" run - OK")
if not valid:
print(" run - Failed")
print(" input file:" + inputFileName)
outputFileName = str(os.path.join(submissionBuildDir, "221575.pgm_s_0.50_l_0.70_h_0.90.pgm"))
goldenFileName = str(os.path.join(saveCwd, "221575-out-golden.pgm"))
valid = True
try:
if sys.platform != 'win32':
subprocess.check_call("./validate " + goldenFileName + " " + outputFileName, shell=True, stdout=FNULL, stderr=FNULL)
else:
subprocess.check_call(".\\validate.exe " + goldenFileName + " " + outputFileName, shell=True, stdout=FNULL, stderr=FNULL)
except:
valid = False
if valid:
print(" validation - OK")
if not valid:
print(" validation - Failed")
print(" validation - validate.exe " + goldenFileName + " " + outputFileName)
if verbose:
print ("Running 10 measurements loop ...")
for x in range(0, 10):
os.remove(outputFileName);
if sys.platform != 'win32':
output = subprocess.check_output("time -p " + runCmd, shell=True)
for row in output.split(b'\n'):
if b'real' in row:
real, time = row.split(b' ')
scores.append(float(time))
else:
print(" run - WIN 32")
output = subprocess.check_output("powershell -Command \"Measure-Command {" + runCmd + " | Out-Default}\" | findstr TotalSeconds" , shell=True)
for row in output.split(b'\n'):
if b'TotalSeconds' in row:
totalSeconds, colon, time = output.split()
scores.append(float(time.decode().replace(',','.')))
copyScores = scores
copyScores.sort()
minScore = copyScores[0]
scoretable.append([minScore, submissionName, scores])
if (submissionName == "canny_baseline"):
baseline = minScore
scoretable.sort()
for score in scoretable:
if (score[0] > 0):
print(score, " + " + str(round((baseline / score[0] - 1) * 100, 2)) + "%")
else:
print(score, " + inf")