-
Notifications
You must be signed in to change notification settings - Fork 49
/
build.py
executable file
·141 lines (106 loc) · 4.52 KB
/
build.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
#!/usr/bin/env python3
#########################################################################################
# Author : Jaekyu Lee ([email protected])
# Description : wrapper script for scons build
#########################################################################################
import os
import sys
import itertools
from optparse import OptionParser
#########################################################################################
# argument parsing
#########################################################################################
def parse_arg():
parser = OptionParser(usage="usage: %prog [options] filename", version="%prog 1.0")
parser.add_option("-j", "--thread", action="store", dest="thread", default=1, help="-j option for the parallel build")
parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="debug build")
parser.add_option("-p", "--gprof", action="store_true", dest="gprof", default=False, help="gprof build")
parser.add_option("-c", "--clean", action="store_true", dest="clean", default=False, help="clean")
parser.add_option("-t", "--test", action="store_true", dest="test", default=False, help="clean")
parser.add_option("-v", "--val", action="store_true", dest="val", default=False, help="build version used for gpu validation")
parser.add_option("--newpin", action="store_true", dest="pin_3_13_trace", default=False, help="trace based on pin 3.13 ")
parser.add_option("-q", "--qsim", action="store_true", dest="qsim", default=False, help="use qsim to drive macsim")
parser.add_option("--dramsim", action="store_true", dest="dramsim", default=False, help="DRAMSim2")
parser.add_option("--power", action="store_true", dest="power", default=False, help="EI Power")
parser.add_option("--iris", action="store_true", dest="iris", default=False, help="IRIS")
parser.add_option("--ramulator", action="store_true", dest="ramulator", default=False, help="Ramulator")
return parser
#########################################################################################
# build test for all possible build combinations
#########################################################################################
def build_test():
build_option = ['', 'debug=1', 'gprof=1', 'qsim=1', 'pin_3_13_trace=1']
build_dir = ['.opt_build', '.dbg_build', '.gpf_build']
build_libs = ['dram=1', 'power=1', 'iris=1', 'ramulator=1']
for ii in range(0, len(build_option)):
os.system('rm -rf %s' % build_dir[ii])
for jj in range(0, len(build_libs)+1):
for opt in itertools.combinations(build_libs, jj):
cmd = 'scons -j 4 %s %s' % (build_option[ii], ' '.join(opt))
redir = '> /dev/null 2>&1'
if os.path.exists('%s/macsim' % build_dir[ii]):
os.system('rm -f %s/macsim' % build_dir[ii])
os.system('%s %s' % (cmd, redir))
if os.path.exists('%s/macsim' % build_dir[ii]):
print('%s %s successful' % (build_option[ii], ' '.join(opt)))
else:
print('%s %s failed' % (build_option[ii], ' '.join(opt)))
#########################################################################################
# main function
#########################################################################################
def main():
parser = parse_arg()
(options, args) = parser.parse_args()
## Build test
if options.test:
build_test()
sys.exit(0)
## Prepare scons command
cmd = 'scons '
## Main build options (opt, dbg, gpf)
if options.debug:
cmd += 'debug=1 '
elif options.gprof:
cmd += 'gprof=1 '
if options.val:
cmd += 'val=1 '
## External libraries (dramsim, ei, iris)
# DRAMSim2
if options.dramsim:
cmd += 'dram=1 '
# EI power
if options.power:
cmd += 'power=1 '
# IRIS
if options.iris:
cmd += 'iris=1 '
# Qsim
if options.qsim:
cmd += 'qsim=1 '
# NEW PIN
if options.pin_3_13_trace:
cmd += 'pin_3_13_trace=1 '
# Ramulator
if options.ramulator:
cmd += 'ramulator=1 '
## Parallel building
cmd += '-j %s ' % options.thread
if options.clean:
cmd += '-c'
## run scons command
os.system(cmd)
## Create a symbolic link
if not options.clean:
if options.debug:
build_dir = '.dbg_build'
elif options.gprof:
build_dir = '.gpf_build'
else:
build_dir = '.opt_build'
if os.path.exists('%s/macsim' % build_dir):
os.chdir('bin')
if os.path.exists('macsim'):
os.system('rm -f macsim')
os.system('ln -s ../%s/macsim' % build_dir)
if __name__ == '__main__':
main()