-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessVector.py
184 lines (154 loc) · 4.67 KB
/
processVector.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
import glob
import os
import re
import subprocess
from subprocess import call
from pprint import pprint
def runCommand(command):
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
lines = p.stdout.readlines()
return lines
def getAverageCycles(file):
fileName = "./"+file
command = fileName + " ./input 1000"
commandOutput = runCommand(command)
if "Segmentation" in commandOutput[-1]:
print "Core dump for " + file
return None
lastLine = commandOutput[-1].split()
if len(lastLine)<3:
return None
meanCycle = unicode(lastLine[2], 'utf-8')
if meanCycle.isnumeric():
return meanCycle
else:
print "Failed for file: " + file + " --- " + commandOutput[-1]
return None
def verifyMakeOutput(lines):
return "main.optrpt" in lines[-1]
def getSpeed(lines):
reason = ""
for line in lines:
if "estimated potential speedup" in line:
reason = line.split()[-1]
return reason
def getDependency(fileName, plutoLocation, directory):
command = plutoLocation + " --moredebug " + fileName
commandOutput = runCommand(command)
listResult = []
mapResult = dict()
for line in commandOutput:
if "--- Dep" in line:
listResult.append(line.split()[-1])
os.system(command + ' > ' + directory + "/" + fileName)
if listResult:
mapResult["TotalNumberOfDependencies"] = len(listResult)
mapResult["WAW"] = listResult.count('WAW')
mapResult["RAW"] = listResult.count('RAW')
mapResult["RAR"] = listResult.count('RAR')
mapResult["WAR"] = listResult.count('WAR')
else:
mapResult["TotalNumberOfDependencies"] = 0
mapResult["WAW"] = 0
mapResult["RAW"] = 0
mapResult["RAR"] = 0
mapResult["WAR"] = 0
return mapResult
def getReason(str):
if "inefficient" in str:
return "Vectorization not profitable"
elif "vector dependence" in str:
return "Dependence present (Any type)"
elif "inner loop was already vectorized" in str:
return "Inner loop was already vectorized"
else:
return str
def isVectorized(fileName):
with open(fileName) as f:
content = f.readlines()
substringNotVectorized = "loop was not vectorized"
substringVectorized = "LOOP WAS VECTORIZED"
isVector = True
reason = ""
for s in content:
if substringNotVectorized in s:
isVector = False
reason = getReason(s)
break
elif substringVectorized in s:
reason = getSpeed(content)
break
if isVector:
reason = getSpeed(content)
return isVector, reason
def main(folder, plutoLocation):
os.chdir(folder)
makeClean = runCommand("make clean")
makeVec = runCommand("make vec CC=icc")
# Keep the dependency information (in a text file) it will serve you for future tasks.
directoryPluto = "plutoDependency"
runCommand("rm -rf " + directoryPluto)
os.makedirs(directoryPluto)
invalidFiles = []
fileMap = dict()
if not verifyMakeOutput(makeVec):
print "Make file not compiled correctly"
return
for file in glob.glob("*.optrpt"):
res, reason = isVectorized(file)
name = re.search('.*line[0-9]+', file)
if not name:
continue
name = name.group(0)
if name not in fileMap:
fileMap[name] = dict()
fileMap[name]["Vector"] = [res, reason]
for fileType in ["*.vec", "*.fvec", "*.novec"]:
makeClean = runCommand("make clean")
fType = fileType.split('.')[-1]
command = "make " + fType + " CC=icc"
runCommand(command)
for fileName in glob.glob(fileType):
meanCycle = getAverageCycles(fileName)
name = re.search('.*line[0-9]+', fileName)
if not name:
continue
name = name.group(0)
if not meanCycle:
invalidFiles.append(fileName)
if name not in fileMap:
fileMap[name] = dict()
fileMap[name]["MeanCycle_"+fType] = meanCycle
for fileName in glob.glob("*_loop.c"):
os.chdir(folder)
dependency = getDependency(fileName, plutoLocation, directoryPluto)
name = re.search('.*line[0-9]+', fileName)
if not name:
continue
name = name.group(0)
if name not in fileMap:
fileMap[name] = dict()
fileMap[name]["Dependency"] = dependency
commandOutput = runCommand("cat /proc/cpuinfo")
instructionSets = set()
for line in commandOutput:
if "sse" in line:
instructionSets.add("SSE")
if "avx" in line:
instructionSets.add("AVX")
if "avx2" in line:
instructionSets.add("AVX2")
print "\n\nResult:"
pprint(fileMap)
print "\n\nInvalid files: "
pprint(invalidFiles)
print "\n\nInstruction sets: "
pprint(instructionSets)
if __name__ == '__main__':
# Location of extractedLoops
#folder = "/home/rishabh/Desktop/HPA/test"
folder = "/Users/siddharthgupta/Desktop/UCI/Classes@UCI/2.1-Fall_2016/HPA/Project/extractedLoops"
# Location of polycc executable
#plutoLocation = "/home/rishabh/Downloads/pluto-0.11.4/polycc"
plutoLocation = "/Users/siddharthgupta/Softwares/pluto-0.11.4/polycc"
main(folder, plutoLocation)