forked from accel-sim/accel-sim-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-accel-sim-traces.py
executable file
·164 lines (145 loc) · 5.94 KB
/
get-accel-sim-traces.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
#!/usr/bin/env python
from optparse import OptionParser
import re
import os
import math
import sys
from subprocess import Popen, STDOUT
VERSION = "1.1.0"
WEB_DIRECTORY = "ftp://ftp.ecn.purdue.edu/tgrogers/accel-sim/traces/"
this_directory = os.path.dirname(os.path.realpath(__file__)) + "/"
millnames = ['',' K',' M',' G',' T']
def getNumRaw(n):
try:
return float(n)
except ValueError:
count = 0
for name in millnames:
if n[-1].strip() == name.strip():
n = float(n[:-1].strip()) * 10**(3*count)
break
count += 1
return float(n)
def millify(n):
n = getNumRaw(n)
if math.isnan(n):
return "NaN"
if math.isinf(n):
return "inf"
millidx = max(0,min(len(millnames)-1,
int(math.floor(0 if n == 0 else math.log10(abs(n))/3))))
return '{:.2f}{}'.format(n / 10**(3 * millidx), millnames[millidx])
class Suite:
def __init__(self, name):
self.name = name
self.uncompressedSize = None
self.compressedSize = None
class Card:
def __init__(self, name):
self.name = name
self.suites = {}
def getTotalCompressed(self):
total = 0.0
for name,suite in self.suites.iteritems():
try:
total += suite.compressedSize
except TypeError:
sys.exit("Problem with compressed size in suite {0}".format(name))
return total
def getTotalUncompressed(self):
total = 0.0
for name,suite in self.suites.iteritems():
total += suite.uncompressedSize
return total
def downloadTrace(cardName, suiteName):
webFile = os.path.join(WEB_DIRECTORY, cardName, VERSION + ".latest", suiteName + ".tgz")
print "\n\nDownloading {0}".format(webFile)
wget = Popen(["wget " + webFile], stderr=STDOUT, shell=True)
wget.communicate()
if wget.returncode != 0:
sys.exit("wget {0} returned {1}".format(webFile, wget.returncode))
def main():
parser = OptionParser()
parser.add_option("-a", "--apps", dest="apps", default = None,
help="Pass the comma seperated input list instead of asking "\
"from stdin. Example: -a tesla-v100/rodinia-3.1,tesla-v100/cudasdk")
(options, args) = parser.parse_args()
hw_run_dir = os.path.join(this_directory, "hw_run")
if not os.path.exists(hw_run_dir):
os.makedirs(hw_run_dir)
os.chdir(hw_run_dir)
# Parse the trace summary
trace_summary = os.path.join(hw_run_dir, VERSION + ".trace.summary.txt")
try:
os.remove(trace_summary)
except OSError:
pass
Popen(["wget " + " " +
WEB_DIRECTORY + VERSION + ".trace.summary.txt" ],
stderr=STDOUT, shell=True).communicate()
lineFormat = re.compile(r"(.*)\t(.*)/" + VERSION + ".latest/(.*)")
sizeDict = {}
for line in open(trace_summary):
lineMatch = lineFormat.match(line)
if lineMatch != None:
size = lineMatch.group(1)
cardName = lineMatch.group(2)
fileName = lineMatch.group(3)
suiteName = re.sub(r"(.*)\.tgz", r"\1", fileName)
if cardName not in sizeDict:
sizeDict[cardName] = Card(cardName)
card = sizeDict[cardName]
if suiteName not in card.suites:
newSuite = Suite(suiteName)
card.suites[suiteName] = Suite(suiteName)
suite = sizeDict[cardName].suites[suiteName]
if suiteName != fileName:
suite.compressedSize = getNumRaw(size)
else:
suite.uncompressedSize = getNumRaw(size)
# Infor the user what is available - ask them what they want to do
print "\n\nCurrently Available Traces:"
for cardName, card in sizeDict.iteritems():
print "GPU Name: {0}. All Apps Compressed (Download size): {1}, All Apps Uncompressed (Size on disk when used): {2}"\
.format(card.name, millify(card.getTotalCompressed()), millify(card.getTotalUncompressed()))
for name, suite in card.suites.iteritems():
print "\t{0}: Compressed = {1}, Uncompressed = {2}".format(suite.name,\
millify(suite.compressedSize), millify(suite.uncompressedSize))
selectionValid = False
while not selectionValid:
if options.apps == None:
selection = raw_input("\n-------\nWhat do you want to download?"\
"\n<card/suite>,<card/suite> (i.e. tesla-v100/rodinia-3.1,tesla-v100/cudasdk)"\
"\n(Default=all/all) : ")
if selection == "" or selection == None:
selection = "all/all"
else:
selection = options.apps
try:
for item in selection.split(","):
cardName = item.split(r"/")[0]
suiteName = item.split(r"/")[1]
if cardName == "all":
for cardName, card in sizeDict.iteritems():
if suiteName == "all":
for suiteName, suite in card.suites.iteritems():
downloadTrace(cardName, suiteName)
else:
downloadTrace(cardName, suiteName)
else:
card = sizeDict[cardName]
if suiteName == "all":
for suiteName, suite in card.suites.iteritems():
downloadTrace(cardName, suiteName)
else:
downloadTrace(cardName, suiteName)
selectionValid = True
except Exception as e:
selectionValid = False
print "Invalid Input: {0}".format(e)
if options.apps != None:
sys.exit(1)
print "\n\nDownload successful to {0}.\nFiles must be uncompressed with tar -xzvf <filename> to be usable by accel-sim"\
.format(hw_run_dir)
if __name__ == '__main__':
main()