spec.py 7.69 KB
Newer Older
Andreas Zwinkau's avatar
Andreas Zwinkau committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
import os
import platform
import optparse # TODO argparse from python 2.7 on

from zsnippets.shell import execute

SCRIPT_VERSION="0.1"
(KERNEL,HOSTNAME,KERNEL_VERSION,VERSION,ARCH,PROCESSOR) = platform.uname()
assert not PROCESSOR, PROCESSOR
LINUX_NAME, LINUX_VERSION, LINUX_CODENAME = platform.dist()
BITSIZE = {
	"i686": 32,
	"x86_64": 64,
}.get(ARCH, "unspecified for "+ARCH)

# assert spec dir
for subdir in "benchspec config bin result".split():
	assert os.path.isdir(subdir), "subdir missing: "+subdir
Andreas Zwinkau's avatar
Andreas Zwinkau committed
20
for filename in "shrc README LICENSE MANIFEST".split():
Andreas Zwinkau's avatar
Andreas Zwinkau committed
21
22
	assert os.path.isfile(filename), "file missing: "+filename

Andreas Zwinkau's avatar
Andreas Zwinkau committed
23
24
25
26
27
28
29
30
31
32
33
def identify_suite():
	"""Which SPEC suite are we in?"""
	for line in file("README"):
		possibilities = ["SPEC CPU2000", "SPEC CPU2006"]
		for p in possibilities:
			if p in line:
				return p
	print "Unknown SPEC suite (if at all)"
	exit(-1)
SPEC_SUITE = identify_suite()

Andreas Zwinkau's avatar
Andreas Zwinkau committed
34
parser = optparse.OptionParser(version=SCRIPT_VERSION)
Andreas Zwinkau's avatar
Andreas Zwinkau committed
35
36
parser.add_option("--config-only", action="store_true", default=False,
		help="Just generate config file, but do not build or run")
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
parser.add_option("-i", "--iterations", metavar="ITR", default=3,
		help="Evaluate ITR iterations per program, default=3")

parser.add_option("--c-compiler", metavar="CC", default="cparser",
		help="Use CC to build benchmark programs, default=cparser")
parser.add_option("--fortran-compiler", metavar="FC", default="gfortran",
		help="Use FC to build benchmark programs, default=gfortran")
parser.add_option("--cpp-compiler", metavar="CXX", default="g++",
		help="Use CXX to build benchmark programs, default=g++")

parser.add_option("--compiler-args", metavar="FLAGS", default="-O3",
		help="Append FLAGS to build benchmark programs for all compilers, default=-O3")
parser.add_option("--c-compiler-args", metavar="CFLAGS", default="",
		help="Append CFLAGS to build benchmark programs for C compiler, default empty")
parser.add_option("--fortran-compiler-args", metavar="FFLAGS", default="",
		help="Append FFLAGS to build benchmark programs for Fortran compiler, default empty")
parser.add_option("--cpp-compiler-args", metavar="CFLAGS", default="",
		help="Append CFLAGS to build benchmark programs for C++ compiler, default empty")
Andreas Zwinkau's avatar
Andreas Zwinkau committed
55
56
57
58
59
60
61
62
63

# http://www.spec.org/cpu2006/Docs/config.html

_CONFIG_HEAD = """\
#### Automatically generated by spec.py script ####

output_format = csv,html,raw,screen,config
ignore_errors = yes
makeflags = -j4        # allows multiple simultaneous compiles
Andreas Zwinkau's avatar
Andreas Zwinkau committed
64
test_sponsor = IPD Snelting
Andreas Zwinkau's avatar
Andreas Zwinkau committed
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

# just assuming:
hw_fpu = Integrated
sw_state = Multi-user
"""

def path_to_filesystem(path):
	for line in execute("stat -f ."):
		if "Type:" in line:
			i = line.index("Type:")
			return line[i+6:].strip()

def _get_proc_info(path):
	"""Extract data from proc files"""
	data = dict()
	for line in file(path):
		try:
			key, value = line.split(":")
		except ValueError:
			continue
		data[key.strip()] = value.strip()
	return data

def get_mem_info():
	"""Return data about Memory as dict"""
	return _get_proc_info("/proc/meminfo")

def get_cpu_info(): # TODO ignores multiple cpus
	"""Return data about CPU as dict"""
	return _get_proc_info("/proc/cpuinfo")

def get_compiler_version(compiler):
	"""Get the version from a compiler executable"""
	d = execute(compiler+" --version")
	for line in d:
		return line

def get_sw_compiler(options):
	"""Generate a string with all compiler versions"""
	return "; ".join([
		get_compiler_version(options.c_compiler),
		get_compiler_version(options.cpp_compiler),
		get_compiler_version(options.fortran_compiler)
	])

Andreas Zwinkau's avatar
Andreas Zwinkau committed
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
PORTABILITY_FLAGS = dict()
PORTABILITY_FLAGS[("SPEC CPU2000", "Ubuntu", 32)] = """\
176.gcc=default=default=default:
CPORTABILITY =
notes003 = CPORTABILITY 176.gcc: -fno-strict-aliasing

186.crafty=default=default=default:
CPORTABILITY = -DLINUX_i386
notes004 = CPORTABILITY 186.crafty: -DLINUX_i386

252.eon=default=default=default:
CXXPORTABILITY = -DHAS_ERRLIST
notes005 = CXXPORTABILITY 252.eon: -DHAS_ERRLIST

253.perlbmk=default=default=default: 
CPORTABILITY = -DSPEC_CPU2000_NEED_BOOL -DSPEC_CPU2000_LINUX_I386
notes006 = CPORTABILITY 253.perlbmk: -DSPEC_CPU2000_NEED_BOOL -DSPEC_CPU2000_LINUX_I386

254.gap=default=default=default:
CPORTABILITY = -DSYS_HAS_SIGNAL_PROTO -DSYS_HAS_MALLOC_PROTO -DSYS_HAS_CALLOC_PROTO -DSYS_IS_USG -DSYS_HAS_IOCTL_PROTO -DSYS_HAS_TIME_PROTO
notes007 = CPORTABILITY 254.gap: -DSYS_HAS_SIGNAL_PROTO -DSYS_HAS_MALLOC_PROTO -DSYS_HAS_CALLOC_PROTO -DSYS_IS_USG -DSYS_HAS_IOCTL_PROTO -DSYS_HAS_TIME_PROTO

255.vortex=default=default=default:
CPORTABILITY = -fno-strict-aliasing
notes008 = CPORTABILITY 255.vortex: -fno-strict-aliasing

187.facerec=default=default=default: 
EXTRA_FFLAGS= -I../src
"""
PORTABILITY_FLAGS[("SPEC CPU2006", "Ubuntu", 32)] = """\
Andreas Zwinkau's avatar
Andreas Zwinkau committed
140
141
142
143
144
145
146
147
148
149
150
400.perlbench=default=default=default:
CPORTABILITY= -DSPEC_CPU_LINUX_IA32

462.libquantum=default=default=default:
CPORTABILITY= -DSPEC_CPU_LINUX

483.xalancbmk=default=default=default:
CXXPORTABILITY= -DSPEC_CPU_LINUX

481.wrf=default=default=default:
CPORTABILITY = -DSPEC_CPU_CASE_FLAG -DSPEC_CPU_LINUX
Andreas Zwinkau's avatar
Andreas Zwinkau committed
151
152
"""
PORTABILITY_FLAGS[("SPEC CPU2006", "Ubuntu", 64)] = """\
Andreas Zwinkau's avatar
Andreas Zwinkau committed
153
154
155
156
157
158
159
160
161
162
163
164
165
166
default=base=default=default:
PORTABILITY = -DSPEC_CPU_LP64 

400.perlbench=default=default=default:
CPORTABILITY = -DSPEC_CPU_LINUX_X64

462.libquantum=default=default=default:
CPORTABILITY=  -DSPEC_CPU_LINUX

483.xalancbmk=default=default=default:
CXXPORTABILITY= -DSPEC_CPU_LINUX

481.wrf=default=default=default:
CPORTABILITY = -DSPEC_CPU_CASE_FLAG -DSPEC_CPU_LINUX
Andreas Zwinkau's avatar
Andreas Zwinkau committed
167
168
169
170
171
172
173
174
175
176
"""

def get_portability():
	"""Get necessary portability flags"""
	contents = ["\n\n#### Portability Flags ####"]
	for (suite,os,bitsize),text in PORTABILITY_FLAGS.items():
		if suite != SPEC_SUITE: continue
		if os != LINUX_NAME: continue
		if bitsize != BITSIZE: continue
		contents.append(text)
Andreas Zwinkau's avatar
Andreas Zwinkau committed
177
178
179
180
181
182
183
	return "\n".join(contents)

def generate_spec_config(options):
	"""Generate a config file for SPEC"""
	contents = [_CONFIG_HEAD]
	cpuinfo = get_cpu_info()
	meminfo = get_mem_info()
184
185
	contents.append("iterations = %d" % options.iterations)
	contents.append("")
Andreas Zwinkau's avatar
Andreas Zwinkau committed
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
	contents.append("sw_os = %s %s %s" % (LINUX_NAME, LINUX_VERSION, LINUX_CODENAME))
	contents.append("sw_compiler = %s" % get_sw_compiler(options))
	contents.append("sw_file = %s" % path_to_filesystem("."))
	contents.append("sw_base_ptrsize = %d-bit" % BITSIZE)
	contents.append("sw_peak_ptrsize = %d-bit" % BITSIZE)
	contents.append("")
	contents.append("hw_cpu_name = %s" % cpuinfo["model name"])
	contents.append("hw_cpu_mhz = %s" % cpuinfo["cpu MHz"])
	contents.append("hw_nchips = %d" % (1+int(cpuinfo["processor"])))
	contents.append("hw_ncores = %d" % int(cpuinfo["cpu cores"]))
	contents.append("hw_vendor = %s" % cpuinfo["vendor_id"])
	contents.append("hw_memory = %s" % meminfo["MemTotal"])
	contents.append("")
	contents.append("CC = %s" % options.c_compiler)
	contents.append("CXX = %s" % options.cpp_compiler)
	contents.append("FC = %s" % options.fortran_compiler)
	contents.append("")
	contents.append("OPTIMIZE = %s" % options.compiler_args)
	contents.append("notes_comp_001 OPTIMIZE = %s" % options.compiler_args)
	contents.append("COPTIMIZE = %s" % options.c_compiler_args)
	contents.append("notes_comp_002 COPTIMIZE = %s" % options.c_compiler_args)
	contents.append("CXXOPTIMIZE = %s" % options.cpp_compiler_args)
	contents.append("notes_comp_003 CXXOPTIMIZE = %s" % options.cpp_compiler_args)
	contents.append("FOPTIMIZE = %s" % options.fortran_compiler_args)
	contents.append("notes_comp_004 FOPTIMIZE = %s" % options.fortran_compiler_args)
	contents.append(get_portability())
	return "\n".join(contents)

if __name__ == "__main__":
	(options, args) = parser.parse_args()
	conf = generate_spec_config(options)
	with open("config/generated.cfg", 'w') as fh:
		fh.write(conf)
Andreas Zwinkau's avatar
Andreas Zwinkau committed
219
220
	if options.config_only:
		exit(0)
Andreas Zwinkau's avatar
Andreas Zwinkau committed
221
222
223
	cmd = "bash -c 'source shrc && runspec all -c generated'"
	os.system(cmd)