-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinaries.py
155 lines (122 loc) · 5.46 KB
/
binaries.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
from __future__ import print_function
import os
from os import path
import shlex, subprocess, sys, errno
# set-up workspace
Debug=int(os.getenv("RVT_DEBUG", 0)) != 0
libRV="../lib/libRV.so"
def assureDir(path):
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
assureDir("logs")
assureDir("build")
def shellCmd(cmdText, envModifier=None, logPrefix=None):
if Debug:
print("CMD {}".format(cmdText))
processEnv=os.environ
if envModifier:
processEnv=dict(os.environ, **envModifier)
cmd = shlex.split(cmdText)
if logPrefix is None:
# stdout
proc = subprocess.Popen(cmd, env=processEnv)
else:
# write to log streams
with open(logPrefix + ".out", "w") as fOut:
with open(logPrefix + ".err", "w") as fErr:
proc = subprocess.Popen(cmd, stdout=fOut, stderr=fErr, env=processEnv)
retCode=proc.wait()
if retCode != 0:
print("Ret Code " + str(retCode))
print(cmdText)
return retCode
def runForOutput(cmdText):
if Debug:
print("CMD {}".format(cmdText))
cmd = shlex.split(cmdText)
try:
return True, subprocess.check_output(cmd, stderr=subprocess.STDOUT, timeout=600)
except subprocess.CalledProcessError as err:
return False, err.output
except subprocess.TimeoutExpired as err:
return False, err.output
rvToolLine="rvTool"
# use a 1.0 ULP error bound for SLEEF math
testULPBound = 10
def rvClang(clangArgs):
return shellCmd(clangLine + " -fplugin=" + libRV + " -O3 " + clangArgs)
def primaryName(fileName):
return path.basename(fileName).split(".")[0]
def rvToolOuterLoop(scalarLL, destFile, scalarName = "foo", options = {}, logPrefix=None):
baseName = primaryName(scalarLL)
cmd = rvToolLine + " -loopvec -i " + scalarLL
if destFile:
cmd = cmd + " -o " + destFile
if scalarName:
cmd = cmd + " -k " + scalarName
if options['loopHint']:
cmd = cmd + " -l " + options['loopHint']
if options['width']:
cmd = cmd + " -w " + str(options['width'])
if options["ulp_math_prec"]:
cmd += " --math-prec {}".format(options["ulp_math_prec"])
if 0 < len(options['extraShapes'].items()):
cmd = cmd + " -x " + ",".join("{}={}".format(k,v) for k,v in options['extraShapes'].items())
return shellCmd(cmd, None, logPrefix)
def rvToolWFV(scalarLL, destFile, scalarName = "foo", options = {}, logPrefix=None):
cmd = rvToolLine + " -wfv -lower -i " + scalarLL
if destFile:
cmd = cmd + " -o " + destFile
if scalarName:
cmd = cmd + " -k " + scalarName + " -t " + scalarName + "_SIMD"
if options['shapes']:
cmd = cmd + " -s " + options['shapes']
if options['width']:
cmd = cmd + " -w " + str(options['width'])
if options["ulp_math_prec"]:
cmd += " --math-prec {}".format(options["ulp_math_prec"])
if 0 < len(options['extraShapes'].items()):
cmd = cmd + " -x " + ",".join("{}={}".format(k,v) for k,v in options['extraShapes'].items())
cmd += " --math-prec {}".format(testULPBound)
return shellCmd(cmd, None, logPrefix)
############ Clang / LLVM tooling ############
class LLVMTools(object):
def __init__(self, commonFlags="", cFlags="", libs=""):
self.optcClangLine="clang -O3 -c -emit-llvm -S " + commonFlags
self.optClangLine="clang++ -std=c++14 -O3 -c -emit-llvm -S " + commonFlags
self.clangLine="clang++ -std=c++14 -m64 -O2 -fno-vectorize -fno-slp-vectorize " + commonFlags
self.cClangLine="clang -m64 -O2 -fno-vectorize -fno-slp-vectorize " + commonFlags
self.CLine="c++ -std=c++14 -m64 -O2 " + cFlags
self.cCLine="c -std=c++14 -m64 -O2 " + cFlags
self.libs = libs
def compileC(self, destFile, srcFiles, extraFlags=""):
return 0 == shellCmd(self.cClangLine + " " + (" ".join(srcFiles)) + " " + extraFlags + " -o " + destFile)
def compileCPP(self, destFile, srcFiles, extraFlags=""):
return 0 == shellCmd(self.clangLine + " " + (" ".join(srcFiles)) + " " + extraFlags + " -o " + destFile)
def optimizeIR(self, destFile, srcFile, extraFlags=""):
return shellCmd(self.optClangLine + " " + srcFile + " -S -o " + destFile)
def compileOptimized(self, srcFile, destFile, extraFlags=""):
if not path.exists(srcFile):
return False
if srcFile[-2:] == ".c":
retCode = shellCmd(self.optcClangLine + " " + srcFile + " " + extraFlags + " -o " + destFile)
else:
retCode = shellCmd(self.optClangLine + " " + srcFile + " " + extraFlags + " -o " + destFile)
return retCode == 0
def compileToIR(self, srcFile, destFile, extraFlags=""):
if not path.exists(srcFile):
return False
if srcFile[-2:] == ".c":
retCode = shellCmd(self.cClangLine + " " + srcFile + " -fno-unroll-loops -S -emit-llvm -c " + extraFlags + " -o " + destFile)
else:
retCode = shellCmd(self.clangLine + " " + srcFile + " -fno-unroll-loops -S -emit-llvm -c " + extraFlags + "-o " + destFile)
return retCode == 0
def disassemble(self, bcFile, suffix):
return shellCmd("llvm-dis " + bcFile, "logs/dis_" + suffix) == 0
def build_launcher(self, launcherBin, launcherLL, fooFile, suffix):
return shellCmd(self.clangLine + " -fno-slp-vectorize -o " + launcherBin + " " + launcherLL + " " + fooFile, "logs/clang-launcher_" + suffix) == 0
def linkCPP(self, destFile, srcFiles, extraFlags=""):
return shellCmd(self.CLine + " " + (" ".join(srcFiles)) + " " + extraFlags + " -o " + destFile + " " + self.libs) == 0