spec.py 21.8 KB
Newer Older
Andreas Zwinkau's avatar
Andreas Zwinkau committed
1
2
3
#!/usr/bin/env python
import os
import platform
4
import argparse
5
6
import subprocess
import resource
7
import socket
8
import sys
9
from collections import defaultdict
Andreas Zwinkau's avatar
Andreas Zwinkau committed
10
from datetime import datetime
Andreas Zwinkau's avatar
Andreas Zwinkau committed
11
12

SCRIPT_VERSION="0.1"
Andreas Zwinkau's avatar
Andreas Zwinkau committed
13
14
AUTHOR="Andreas Zwinkau <zwinkau@kit.edu>"

15
(KERNEL,HOSTNAME,KERNEL_VERSION,VERSION,HOST_ARCH,PROCESSOR) = platform.uname()
Andreas Zwinkau's avatar
Andreas Zwinkau committed
16
17
18
19
LINUX_NAME, LINUX_VERSION, LINUX_CODENAME = platform.dist()
BITSIZE = {
	"i686": 32,
	"x86_64": 64,
20
	"sparc" : 32,
Andreas Zwinkau's avatar
Andreas Zwinkau committed
21
	"sparc64": 64,
22
}.get(HOST_ARCH, "unspecified for "+HOST_ARCH)
Andreas Zwinkau's avatar
Andreas Zwinkau committed
23
24
25
26

# 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
27
for filename in "shrc README LICENSE MANIFEST".split():
Andreas Zwinkau's avatar
Andreas Zwinkau committed
28
29
	assert os.path.isfile(filename), "file missing: "+filename

Andreas Zwinkau's avatar
Andreas Zwinkau committed
30
31
32
def identify_suite():
	"""Which SPEC suite are we in?"""
	for line in file("README"):
sebastian.buchwald1's avatar
sebastian.buchwald1 committed
33
		possibilities = ["SPEC CPU2000", "SPEC CPU2006", "SPEC CPU2017", "SPEC OMP2001"]
Andreas Zwinkau's avatar
Andreas Zwinkau committed
34
35
36
		for p in possibilities:
			if p in line:
				return p
Andreas Zwinkau's avatar
Andreas Zwinkau committed
37
	print "Error: Unknown SPEC suite (if at all)"
Andreas Zwinkau's avatar
Andreas Zwinkau committed
38
39
40
	exit(-1)
SPEC_SUITE = identify_suite()

41
parser = argparse.ArgumentParser(prog=sys.argv[0], version=SCRIPT_VERSION, usage="Usage: %(prog)s [options] [programs]")
42
parser.add_argument("--config-only", action="store_true", default=False,
Andreas Zwinkau's avatar
Andreas Zwinkau committed
43
		help="Just generate config file, but do not build or run")
44
parser.add_argument("--build-only", action="store_true", default=False,
45
		help="Just generate config file and build benchmark programs, but do not run")
46
parser.add_argument("--no-cpp", action="store_true", default=False,
Andreas Zwinkau's avatar
Andreas Zwinkau committed
47
		help="Exclude benchmark programs using C++")
48
parser.add_argument("--no-fortran", action="store_true", default=False,
Andreas Zwinkau's avatar
Andreas Zwinkau committed
49
		help="Exclude benchmark programs using Fortran")
50
parser.add_argument("--no-floating-point", action="store_true", default=False,
51
		help="Exclude CFP subset containing floating point-heavy benchmark programs")
52
parser.add_argument("--no-integer", action="store_true", default=False,
53
		help="Exclude CINT subset containing integer-heavy benchmark programs")
54
parser.add_argument("--no-medium", action="store_true", default=False,
Andreas Zwinkau's avatar
Andreas Zwinkau committed
55
		help="Exclude OMPM programs")
56
parser.add_argument("--no-large", action="store_true", default=False,
Andreas Zwinkau's avatar
Andreas Zwinkau committed
57
		help="Exclude OMPL programs")
58
parser.add_argument("-i", "--iterations", metavar="ITR", default=3,
59
		help="Evaluate ITR iterations per program, default=3")
60
parser.add_argument("--time-limit", metavar="TIMELIMIT", default=0,
61
		help="Set cpu time limit for each program run to TIMELIMIT seconds.")
62
63
parser.add_argument("--submit", metavar="SUBMIT", default=[], action="append",
		help="Start compiled programs with SUBMIT")
64

65
parser.add_argument("--target-architecture", metavar="TARGET_ARCH", default=HOST_ARCH,
66
		help="Set target architecture, default=" + HOST_ARCH)
67
parser.add_argument("--c-compiler", metavar="CC", default="gcc",
Andreas Zwinkau's avatar
Andreas Zwinkau committed
68
		help="Use CC to build benchmark programs, default=gcc")
69
parser.add_argument("--fortran-compiler", metavar="FC", default="gfortran",
70
		help="Use FC to build benchmark programs, default=gfortran")
71
parser.add_argument("--cpp-compiler", metavar="CXX", default="g++",
72
73
		help="Use CXX to build benchmark programs, default=g++")

74
75
76
77
78
79
80
parser.add_argument("--c-compiler-version-option", metavar="FLAG", default=["--version"], action="append",
		help="Flag that causes the CC to print its version, default=--version")
parser.add_argument("--cpp-compiler-version-option", metavar="FLAG", default=["--version"], action="append",
		help="Flag that causes the CXX to print its version, default=--version")
parser.add_argument("--fortran-compiler-version-option", metavar="FLAG", default=["--version"], action="append",
		help="Flag that causes the FC to print its version, default=--version")

81
parser.add_argument("--compiler-args", metavar="FLAGS", default=["-O3"], action="append",
82
		help="Append FLAGS to build benchmark programs for all compilers, default=-O3")
83
parser.add_argument("--c-compiler-args", metavar="CFLAGS", default=[], action="append",
Andreas Zwinkau's avatar
Andreas Zwinkau committed
84
		help="Append CFLAGS to build benchmark programs for C compiler, default march=native")
85
parser.add_argument("--fortran-compiler-args", metavar="FFLAGS", default=[], action="append",
86
		help="Append FFLAGS to build benchmark programs for Fortran compiler, default empty")
87
88
parser.add_argument("--cpp-compiler-args", metavar="CPPFLAGS", default=[], action="append",
		help="Append CPPFLAGS to build benchmark programs for C++ compiler, default march=native")
89
90
parser.add_argument("--force-64", action="store_true", default=False,
		help="Actually produce amd64 code (experimental cparser backend")
91
92
parser.add_argument(dest="benchmarks", metavar="BENCHMARK", nargs="*",
                    help="only run benchmark BENCHMARK")
Andreas Zwinkau's avatar
Andreas Zwinkau committed
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
class SigKill(Exception):
	def __init__(self, retcode, name):
		self.retcode = retcode
		self.name = name

_EXIT_CODES = {
	-2: "keyboard interrupt",
	-3: "keyboard quit",
	-4: "illegal instruction",
	-6: "aborted",
	-8: "floating point exception",
	-9: "kill",
	-11: "segfault",
	-13: "broken pipe",
	-14: "timeout",
	-15: "termination",
}

def execute(cmd, env=None, timeout=0):
	"""Execute a command and return stderr and/or stdout data"""
	preexec_fn = None
	if timeout > 0.0:
		def set_timeout():
			 resource.setrlimit(resource.RLIMIT_CPU, (timeout, timeout))
		preexec_fn = set_timeout
	cmd = filter(lambda x: x, cmd.split(' '))
	proc = subprocess.Popen(cmd,
							stdout=subprocess.PIPE,
							stderr=subprocess.STDOUT,
							preexec_fn = preexec_fn,
							env=env)
	out, err = proc.communicate()
	try:
		for line in out.splitlines():
			yield line
	except Exception, e:
		print "'%s' -> %s" % (c, e)
	if proc.returncode in _EXIT_CODES:
		raise SigKill(proc.returncode, _EXIT_CODES[proc.returncode])
	elif proc.returncode < 0: # program aborted
		raise Exception(proc.returncode, cmd)

Andreas Zwinkau's avatar
Andreas Zwinkau committed
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
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"""
163
164
165
166
167
168
	try:
		d = execute(compiler+" --version")
		for line in d:
			return line
	except OSError:
		return "No compiler '%s' found." % compiler
Andreas Zwinkau's avatar
Andreas Zwinkau committed
169

170
171
172
173
174
175
176
# Target architecture-dependent flags
TARGET_ARCH_FLAGS = dict()

i686_flags = dict()
i686_flags["186.crafty"] = "-DLINUX_i386"
i686_flags["253.perlbmk"] = "-DSPEC_CPU2000_LINUX_I386"
i686_flags["400.perlbench"] = "-DSPEC_CPU_LINUX_IA32"
177
i686_flags["600.perlbench"] = "-DSPEC_LINUX_IA32"
178
179
TARGET_ARCH_FLAGS["i686"] = i686_flags

180
x86_64_flags = defaultdict(str)
181
182
x86_64_flags["176.gcc"] = "-DSPEC_CPU2000_LP64"
x86_64_flags["186.crafty"] = "-DSPEC_CPU2000_LP64 -DHAS_LONGLONG -DLITTLE_ENDIAN_ARCH -DUNIX -DLINUX"
183
x86_64_flags["253.perlbmk"] = "-DSPEC_CPU2000_LP64 -DHAS_LONG_LONG -DSPEC_CPU2000_LINUX_IA64" # LINUX_IA64 should work also for x86_64
184
x86_64_flags["254.gap"] = "-DSPEC_CPU2000_LP64"
185
x86_64_flags["255.vortex"] = "-DSPEC_CPU2000_LP64"
186
x86_64_flags["400.perlbench"] = "-DSPEC_CPU_LINUX_X64"
187
x86_64_flags["600.perlbench"] = "-DSPEC_LINUX_IA64"
Manuel Mohr's avatar
Manuel Mohr committed
188
for bench in ["400.perlbench", "403.gcc", "436.cactusADM", "453.povray",
189
190
              "481.wrf"]:
    x86_64_flags[bench] += " -DSPEC_CPU_LP64"
191
192
TARGET_ARCH_FLAGS["x86_64"] = x86_64_flags

193
194
195
196
197
198
199
200
201
202
203
sparc_flags = dict()
sparc_flags["176.gcc"] = "-DHOST_WORDS_BIG_ENDIAN"
sparc_flags["186.crafty"] = "-DLINUX_SPARC"
sparc_flags["253.perlbmk"] = "-DSPEC_CPU2000_LINUX_SPARC"
TARGET_ARCH_FLAGS["sparc"] = sparc_flags


# Compiler-dependent flags
COMPILER_FLAGS = dict()
cparser_flags = dict()
cparser_flags["176.gcc"] = "-std=gnu89"
204
cparser_flags["403.gcc"] = "-std=gnu89"
205
206
COMPILER_FLAGS["cparser"] = cparser_flags

207
208
209
210
211
212
213
214
215
clang_flags = dict()
clang_flags["254.gap"] = "-fwrapv"
clang_flags["300.twolf"] = "-Wno-return-type"
COMPILER_FLAGS["clang"] = clang_flags

gcc_flags = dict()
gcc_flags["254.gap"] = "-fwrapv"
COMPILER_FLAGS["gcc"] = gcc_flags

216
217
218
219

# Compatibility/SPEC-specific flags, always needed
compat_flags = dict()
compat_flags["176.gcc"] = "-fno-strict-aliasing"
220
compat_flags["186.crafty"] = "-DSPEC_CPU2000"
221
compat_flags["252.eon"] = "-DHAS_ERRLIST"
222
compat_flags["253.perlbmk"] = "-DSPEC_CPU2000_NEED_BOOL -DSPEC_CPU2000_LINUX -DHASATTRIBUTE"
223
compat_flags["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"
224
225
compat_flags["400.perlbench"] = "-DPERL_CORE -DSPEC_CPU"
compat_flags["403.gcc"] = "-DSPEC_CPU -DSPEC_CPU_HAVE_BOOL"
226
227
228
229
230
compat_flags["462.libquantum"] = "-DSPEC_CPU_LINUX"
compat_flags["481.wrf"] = "-DSPEC_CPU_CASE_FLAG -DSPEC_CPU_LINUX"
compat_flags["483.xalancbmk"] = "-DSPEC_CPU_LINUX"
# Fortran stuff
compat_flags["187.facerec"] = "-I../src"
Manuel Mohr's avatar
Manuel Mohr committed
231
compat_flags["310.wupwise_m"] = "-ffixed-form"
232
233
234
235
236
237
238
239
compat_flags["312.swim_m"] = "-ffixed-form"
compat_flags["314.mgrid_m"] = "-ffixed-form"
compat_flags["316.applu_m"] = "-ffixed-form"
compat_flags["318.galgel_m"] = "-ffixed-form -ffixed-line-length-80"
compat_flags["324.apsi_m"] = "-ffixed-form"
compat_flags["326.gafort_m"] = "-qsuffix=f=f90"
compat_flags["328.fma3d_m"] = "-qsuffix=f=f90"
COMPATIBILITY_FLAGS = compat_flags
Andreas Zwinkau's avatar
Andreas Zwinkau committed
240

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
BENCHMARK_PROPERTIES = [
	("SPEC CPU2000", "CINT", "164.gzip", "c"),
	("SPEC CPU2000", "CINT", "175.vpr", "c"),
	("SPEC CPU2000", "CINT", "176.gcc", "c"),
	("SPEC CPU2000", "CINT", "181.mcf", "c"),
	("SPEC CPU2000", "CINT", "186.crafty", "c"),
	("SPEC CPU2000", "CINT", "197.parser", "c"),
	("SPEC CPU2000", "CINT", "252.eon", "cpp"),
	("SPEC CPU2000", "CINT", "253.perlbmk", "c"),
	("SPEC CPU2000", "CINT", "254.gap", "c"),
	("SPEC CPU2000", "CINT", "255.vortex", "c"),
	("SPEC CPU2000", "CINT", "256.bzip2", "c"),
	("SPEC CPU2000", "CINT", "300.twolf", "c"),
	("SPEC CPU2000", "CFP", "168.wupwise", "fortran77"),
	("SPEC CPU2000", "CFP", "171.swim", "fortran77"),
	("SPEC CPU2000", "CFP", "172.mgrid", "fortran77"),
	("SPEC CPU2000", "CFP", "173.applu", "fortran77"),
	("SPEC CPU2000", "CFP", "177.mesa", "c"),
	("SPEC CPU2000", "CFP", "178.galgel", "fortran90"),
	("SPEC CPU2000", "CFP", "179.art", "c"),
	("SPEC CPU2000", "CFP", "183.equake", "c"),
	("SPEC CPU2000", "CFP", "187.facerec", "fortran90"),
	("SPEC CPU2000", "CFP", "188.ammp", "c"),
	("SPEC CPU2000", "CFP", "189.lucas", "fortran90"),
	("SPEC CPU2000", "CFP", "191.fma3d", "fortran90"),
	("SPEC CPU2000", "CFP", "200.sixtrack", "fortran77"),
	("SPEC CPU2000", "CFP", "301.apsi", "fortran77"),
	("SPEC OMP2001", "?", "310.wupwise_m", "?"),
	("SPEC OMP2001", "?", "311.wupwise_l", "?"),
	("SPEC OMP2001", "?", "312.swim_m", "?"),
	("SPEC OMP2001", "?", "313.swim_l", "?"),
	("SPEC OMP2001", "?", "314.mgrid_m", "?"),
	("SPEC OMP2001", "?", "315.mgrid_l", "?"),
	("SPEC OMP2001", "?", "316.applu_m", "?"),
	("SPEC OMP2001", "?", "317.applu_l", "?"),
	("SPEC OMP2001", "?", "318.galgel_m", "?"),
	("SPEC OMP2001", "?", "330.art_m", "?"),
	("SPEC OMP2001", "?", "331.art_l", "?"),
	("SPEC OMP2001", "?", "320.equake_m", "?"),
	("SPEC OMP2001", "?", "321.equake_l", "?"),
	("SPEC OMP2001", "?", "332.ammp_m", "?"),
	("SPEC OMP2001", "?", "328.fma3d_m", "?"),
	("SPEC OMP2001", "?", "329.fma3d_l", "?"),
	("SPEC OMP2001", "?", "324.apsi_m", "?"),
	("SPEC OMP2001", "?", "325.apsi_l", "?"),
	("SPEC OMP2001", "?", "326.gafort_m", "?"),
	("SPEC OMP2001", "?", "327.gafort_l", "?"),
	("SPEC CPU2006", "CINT", "400.perlbench", "c"),
	("SPEC CPU2006", "CINT", "401.bzip2", "c"),
	("SPEC CPU2006", "CINT", "403.gcc", "c"),
	("SPEC CPU2006", "CINT", "429.mcf", "c"),
	("SPEC CPU2006", "CINT", "445.gobmk", "c"),
	("SPEC CPU2006", "CINT", "456.hmmer", "c"),
	("SPEC CPU2006", "CINT", "458.sjeng", "c"),
	("SPEC CPU2006", "CINT", "462.libquantum", "c"),
	("SPEC CPU2006", "CINT", "464.h264ref", "c"),
	("SPEC CPU2006", "CINT", "471.omnetpp", "cpp"),
	("SPEC CPU2006", "CINT", "473.astar", "cpp"),
	("SPEC CPU2006", "CINT", "483.xalancbmk", "cpp"),
	("SPEC CPU2006", "CFP", "410.bwaves", "fortran"),
	("SPEC CPU2006", "CFP", "416.gamess", "fortran"),
	("SPEC CPU2006", "CFP", "433.milc", "c"),
	("SPEC CPU2006", "CFP", "434.zeusmp", "fortran"),
	("SPEC CPU2006", "CFP", "435.gromacs", "c,fortran"),
	("SPEC CPU2006", "CFP", "436.cactusADM", "c,fortran"),
	("SPEC CPU2006", "CFP", "437.leslie3d", "fortran"),
	("SPEC CPU2006", "CFP", "444.namd", "cpp"),
	("SPEC CPU2006", "CFP", "447.dealII", "cpp"),
	("SPEC CPU2006", "CFP", "450.soplex", "cpp"),
	("SPEC CPU2006", "CFP", "453.povray", "cpp"),
	("SPEC CPU2006", "CFP", "454.calculix", "c,fortran"),
	("SPEC CPU2006", "CFP", "459.GemsFDTD", "fortran"),
	("SPEC CPU2006", "CFP", "465.tonto", "fortran"),
	("SPEC CPU2006", "CFP", "470.lbm", "c"),
	("SPEC CPU2006", "CFP", "481.wrf", "c,fortran"),
	("SPEC CPU2006", "CFP", "482.sphinx3", "c"),
sebastian.buchwald1's avatar
sebastian.buchwald1 committed
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
	("SPEC CPU2017", "SPECspeed 2017 Integer", "600.perlbench_s", "c"),
	("SPEC CPU2017", "SPECspeed 2017 Integer", "602.gcc_s", "c"),
	("SPEC CPU2017", "SPECspeed 2017 Integer", "605.mcf_s", "c"),
	("SPEC CPU2017", "SPECspeed 2017 Integer", "620.omnetpp_s", "cpp"),
	("SPEC CPU2017", "SPECspeed 2017 Integer", "623.xalancbmk_s", "cpp"),
	("SPEC CPU2017", "SPECspeed 2017 Integer", "625.x264_s", "c"),
	("SPEC CPU2017", "SPECspeed 2017 Integer", "631.deepsjeng_s", "cpp"),
	("SPEC CPU2017", "SPECspeed 2017 Integer", "641.leela_s", "cpp"),
	("SPEC CPU2017", "SPECspeed 2017 Integer", "648.exchange2_s", "fortran"),
	("SPEC CPU2017", "SPECspeed 2017 Integer", "657.xz_s", "c"),
	("SPEC CPU2017", "SPECspeed 2017 Floating Point", "603.bwaves_s", "fortran"),
	("SPEC CPU2017", "SPECspeed 2017 Floating Point", "607.cactuBSSN_s", "cpp,c,fortran"),
	("SPEC CPU2017", "SPECspeed 2017 Floating Point", "619.lbm_s", "c"),
	("SPEC CPU2017", "SPECspeed 2017 Floating Point", "621.wrf_s", "fortran,c"),
	("SPEC CPU2017", "SPECspeed 2017 Floating Point", "627.cam4_s", "fortran,c"),
	("SPEC CPU2017", "SPECspeed 2017 Floating Point", "628.pop2_s", "fortran,c"),
	("SPEC CPU2017", "SPECspeed 2017 Floating Point", "638.imagick_s", "c"),
	("SPEC CPU2017", "SPECspeed 2017 Floating Point", "644.nab_s", "c"),
	("SPEC CPU2017", "SPECspeed 2017 Floating Point", "649.fotonik3d_s", "fortran"),
	("SPEC CPU2017", "SPECspeed 2017 Floating Point", "654.roms_s", "fortran"),
337
338
]

339
340
341
def filter_progs(options,args):
	if args:
		programs = list()
342
343
		for progt in BENCHMARK_PROPERTIES:
			suite, subset, prog, langs = progt
344
345
346
			if prog in args:
				programs.append(progt)
	else:
347
348
		programs = BENCHMARK_PROPERTIES
	for suite, subset, prog, langs in programs:
349
350
351
352
353
354
		if suite != SPEC_SUITE:
			continue
		if options.no_cpp and "cpp" in langs:
			continue
		if options.no_fortran and "fortran" in langs:
			continue
355
356
357
358
		if options.no_floating_point and subset == "CFP":
			continue
		if options.no_integer and subset == "CINT":
			continue
359
360
361
362
363
364
		if options.no_medium and prog.endswith("_m"):
			continue
		if options.no_large and prog.endswith("_l"):
			continue
		yield prog

365
366
367
368
369
370
# 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
371
372
setprocgroup = yes
ignore_sigint = no
373
374
test_sponsor = IPD Snelting
"""
375
376
377
378
379
380
381
382
383
384
385
386
387
388

"""
Program names may end with a _s or _t suffix.
If a dictionary doesn't contain an entry for those specific keys, we want
to trim that suffix from the program name and try again.
"""
def get_by_prog(d, prog, default=None):
	if prog in d:
		return d[prog]
	suf = prog.rfind("_")
	if suf >= 0:
		return d.get(prog[:suf], default)
	return default

389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
def get_portability(options, prog, lang):
	if lang == "c":
		port = "CPORTABILITY"
		compiler = os.path.basename(options.c_compiler)
	elif lang == "cpp":
		port = "CXXPORTABILITY"
		compiler = os.path.basename(options.cpp_compiler)
	# Currently no real handling of multi-language benchmarks
	elif "fortran" in lang:
		port = "FPORTABILITY"
		compiler = os.path.basename(options.fortran_compiler)
	else:
		print "Unknown benchmark language: ", lang
		exit(1)

	target_arch = options.target_architecture

406
	compat_flags = get_by_prog(COMPATIBILITY_FLAGS, prog, "")
407
408
409
410

	if not TARGET_ARCH_FLAGS.has_key(target_arch):
		print "No architecture-dependent flags defined for architecture '%s'" % target_arch
		exit(1)
411
	target_flags = get_by_prog(TARGET_ARCH_FLAGS[target_arch], prog, "")
412
413
414
415

	compiler_flags = ""
	for comp in COMPILER_FLAGS:
		if comp in compiler: # Also allow stuff like sparc-leon-linux-gnu-gcc or cparser-test
416
			compiler_flags = get_by_prog(COMPILER_FLAGS[comp], prog, "")
417
			break
418
	# filter(None, list) == filter(id, list)
419
420
421
422
423
424
425
426
	flags = ' '.join(filter(None, [compat_flags, target_flags, compiler_flags]))
	if flags == '':
		return None
	return "%s = %s" % (port, flags)

def check_options(options):
	# Convenience: always compile to 32-bit x86 code with cparser
	target_x86 = options.target_architecture == "i686" or options.target_architecture == "x86_64"
427
	if HOST_ARCH == "x86_64" and target_x86 and not options.force_64:
428
429
430
		options.target_architecture = "i686"

def generate_spec_config(options, progs):
Andreas Zwinkau's avatar
Andreas Zwinkau committed
431
432
433
434
	"""Generate a config file for SPEC"""
	contents = [_CONFIG_HEAD]
	cpuinfo = get_cpu_info()
	meminfo = get_mem_info()
435
	notes = 0
436
437
438
	if SPEC_SUITE != "SPEC CPU2017":
		contents.append("tester_name = IPD Snelting")
		contents.append("company_name = Karlsruhe Institute of Technology KIT")
439
		contents.append("prepared_by = spec.py script")
440
441
442
443
	contents.append("")
	contents.append("## just assuming:")
	if SPEC_SUITE != "SPEC CPU2017":
		contents.append("hw_fpu = Integrated")
444
		contents.append("sw_state = Multi-user")
445
446
447
448
	if options.build_only:
		contents.append("action = build")
	else:
		contents.append("action = validate") # includes run
Matthias Braun's avatar
Matthias Braun committed
449
	contents.append("runlist = %s" % (" ".join(progs)))
Andreas Zwinkau's avatar
Andreas Zwinkau committed
450
	contents.append("iterations = %d" % int(options.iterations))
451
	if SPEC_SUITE != "SPEC CPU2006" and SPEC_SUITE != "SPEC CPU2017":
Andreas Zwinkau's avatar
Andreas Zwinkau committed
452
		contents.append("test_date = %s" % datetime.now())
453
	contents.append("")
Andreas Zwinkau's avatar
Andreas Zwinkau committed
454
	contents.append("sw_os = %s %s %s" % (LINUX_NAME, LINUX_VERSION, LINUX_CODENAME))
455
456
457
	contents.append("sw_compiler1 = %s" % get_compiler_version(options.c_compiler))
	contents.append("sw_compiler2 = %s" % get_compiler_version(options.cpp_compiler))
	contents.append("sw_compiler3 = %s" % get_compiler_version(options.fortran_compiler))
458
459
	if SPEC_SUITE != "SPEC CPU2017":
		contents.append("sw_file = %s" % path_to_filesystem("."))
Andreas Zwinkau's avatar
Andreas Zwinkau committed
460
	assert int(BITSIZE), "bitsize is "+BITSIZE
Andreas Zwinkau's avatar
Andreas Zwinkau committed
461
462
463
	contents.append("sw_base_ptrsize = %d-bit" % BITSIZE)
	contents.append("sw_peak_ptrsize = %d-bit" % BITSIZE)
	contents.append("")
Andreas Zwinkau's avatar
Andreas Zwinkau committed
464
465
	chips = (1+int(cpuinfo.get("processor", 0)))
	cores_per_chip = int(cpuinfo.get("cpu cores", cpuinfo.get("cpu cores", 1)))
Andreas Zwinkau's avatar
Andreas Zwinkau committed
466
	cores = cores_per_chip * chips
467
468
	if SPEC_SUITE == "SPEC CPU2006":
		contents.append("hw_cpu_name = %s" % cpuinfo["model name"])
Andreas Zwinkau's avatar
Andreas Zwinkau committed
469
470
		contents.append("hw_ncores = %d" % cores)
	elif SPEC_SUITE == "SPEC CPU2000":
471
		contents.append("hw_model = %s" % cpuinfo["model name"])
Andreas Zwinkau's avatar
Andreas Zwinkau committed
472
		contents.append("hw_ncpu = %d" % cores)
473
474
	if SPEC_SUITE != "SPEC CPU2017":
		contents.append("hw_cpu_mhz = %s" % cpuinfo.get("cpu MHz", "?"))
475
		contents.append("hw_nchips = %d" % chips)
476
477
	if SPEC_SUITE != "SPEC CPU2017":
		contents.append("hw_ncoresperchip = %d" % cores_per_chip)
Andreas Zwinkau's avatar
Andreas Zwinkau committed
478
	contents.append("hw_vendor = %s" % cpuinfo.get("vendor_id", "?"))
Andreas Zwinkau's avatar
Andreas Zwinkau committed
479
	contents.append("hw_memory = %s" % meminfo["MemTotal"])
Andreas Zwinkau's avatar
Andreas Zwinkau committed
480
	contents.append("hw_pcache = %s" % cpuinfo.get("cache size", "?"))
Andreas Zwinkau's avatar
Andreas Zwinkau committed
481
	contents.append("")
482
483

	submit = ""
484
485
	time_limit = int(options.time_limit)
	if time_limit != 0:
486
487
488
489
490
		submit = "ulimit -t %d ; " % (time_limit,)
	if options.submit != []:
		submit += " ".join(options.submit) + " "
	if submit != "":
		submit += "$command"
491
		contents.append("use_submit_for_speed = 1")
492
		contents.append("submit = %s" % submit)
493
		contents.append("")
Andreas Zwinkau's avatar
Andreas Zwinkau committed
494
495
496
	contents.append("CC = %s" % options.c_compiler)
	contents.append("CXX = %s" % options.cpp_compiler)
	contents.append("FC = %s" % options.fortran_compiler)
497
498
499
500
	contents.append("CC_VERSION_OPTION = %s" % options.c_compiler_version_option)
	contents.append("CXX_VERSION_OPTION = %s" % options.cpp_compiler_version_option)
	contents.append("FC_VERSION_OPTION = %s" % options.fortran_compiler_version_option)

Andreas Zwinkau's avatar
Andreas Zwinkau committed
501
	contents.append("")
502
503
	contents.append("notes%03d = machine: %s" % (notes, socket.getfqdn()))
	notes += 1
504
	contents.append("OPTIMIZE = %s" % " ".join(options.compiler_args))
505
506
	contents.append("notes%03d = OPTIMIZE = %s" % (notes, " ".join(options.compiler_args)))
	notes += 1
507
	contents.append("COPTIMIZE = %s" % " ".join(options.c_compiler_args))
508
509
	contents.append("notes%03d = COPTIMIZE = %s" % (notes, " ".join(options.c_compiler_args)))
	notes += 1
510
	contents.append("CXXOPTIMIZE = %s" % " ".join(options.cpp_compiler_args))
511
512
	contents.append("notes%03d = CXXOPTIMIZE = %s" % (notes, " ".join(options.cpp_compiler_args)))
	notes += 1
513
	contents.append("FOPTIMIZE = %s" % " ".join(options.fortran_compiler_args))
514
515
	contents.append("notes%03d = FOPTIMIZE = %s" % (notes, " ".join(options.fortran_compiler_args)))
	notes += 1
516
517
518
519
520
521
522
523
	if HOST_ARCH == "x86_64" and options.target_architecture == "i686":
		contents.append("EXTRA_CFLAGS = -m32")
		contents.append("EXTRA_LDFLAGS = -m32")

	# Enforce big-endian for SPARC
	if options.target_architecture == "sparc":
		contents.append("\nendian = 4321")

524

525
526
527
528
529
	contents.append("\n\n#### Portability flags ####")
	for (suite, subset, prog, lang) in BENCHMARK_PROPERTIES:
		if prog in progs:
			port = get_portability(options, prog, lang)
			if port is not None:
530
				contents.append(prog + ":")
531
532
533
534
				contents.append(port)
				contents.append("notes%03d = %s: %s" % (notes, prog, port))
				notes = notes + 1

Andreas Zwinkau's avatar
Andreas Zwinkau committed
535
536
537
	return "\n".join(contents)

if __name__ == "__main__":
538
	options = parser.parse_args()
539
	check_options(options)
540
	progs = [prog for prog in filter_progs(options, options.benchmarks)]
541
	conf = generate_spec_config(options, progs)
Andreas Zwinkau's avatar
Andreas Zwinkau committed
542
	if options.config_only:
543
		sys.stdout.write(conf)
Andreas Zwinkau's avatar
Andreas Zwinkau committed
544
		exit(0)
545
546
547
548
	else:
		fh = open("config/generated.cfg", 'w')
		fh.write(conf)
		fh.close()
549
	strprogs = " ".join(progs)
sebastian.buchwald1's avatar
sebastian.buchwald1 committed
550
	cmd = "env bash -l -c 'source shrc && runcpu %s -c generated'" % strprogs
Manuel Mohr's avatar
Manuel Mohr committed
551
	exit(os.system(cmd))