spec2006-usage

介绍spec2006

Basic flow

spec2006使用的流程是:

  • install

    安装spec2006,这步会生成一个目录,里面会包含spec2006所需要的工具集、spec2006 test的源码。

    • destination selection

      选择要生成的目标目录

    • toolset selection

      选择工具集。这步spec会根据当前platform来自动选择,甚至不能跨平台选择。这就导致要交叉编译spec变得困难。最好的办法是放到目标platform来编译。然后打包出来,下次就不用重新编译了。

    • the files are unpacked and tested

      拷贝所需要的文件到目标目录

  • build

    编译benchmark用例。

  • run

    运行benchmark用例。

install

install.sh有两个重要的选项:

  • -d

    指定目标目录

  • -u

    指定platform

比如以下命令:

1
$ ./install.sh -d /home/francis.zheng/spec2006_installed_x64 -u linux-suse10-amd64

runspec

跑之前要source一下环境变量

1
$ source shrc

修改绝对路径

1
2
$ bin/relocate
Top of SPEC benchmark tree is 'xxxxxx'

使用runspec命令运行用例。

1
$ runspec [options] [list of benchmarks to run]

其中list of benchmarks to run包括int、fp、all、或者某个用例。

有如下几个常用参数:

  • -c FILE

    –config FILE

    指定配置文件,常见配置文件在config目录下。

  • -i SET[,SET…]

    –size SET[,SET…]

    指定测试规模。主要分test、train、ref三种(还有一种all)。其中test最短,其次是train,最长的是ref。最终要得到分数,需要跑的是ref。(从benchspec/CPU2006/400.perlbench/data/*/reftime中可以看出用例长短)

  • -T TUNE[,TUNE…]

    –tune TUNE[,TUNE]

    指定测试模式。主要分base、peak两种(还有一种all)。base代表基准测试,peak代表峰值测试。report首先跑base,再跑peak

  • -n N

    每个测试项目运行的次数。如果需要自动计算分数,需要指定运行次数大于等于3。

  • –reportable

    产生报告。

  • –noreportable

    不产生报告。

  • –nobuild

    不进行编译。

  • –action=ACTION

    指定action。ACTION有:build、buildstep、clean、clobber、configpp、scrub、report、run,setup,trash、validate。

  • -o FORMAT[,…]

    指定输出格式。FORMAT有:all、cfg、check、csv、flags、html、mail、pdf、ps、raw、screen、text

  • -r [N]

    –rate [N]

    Do a throughput (rate) run of [N] copies (if [N] is specified)

  • –parallel_setup=N

    For rate runs, do per-benchmark run directory setup in parallel (N jobs at a time)

  • –parallel_setup_type=X

    For parallel setup, set the job creation method. (X may be one of ‘fork’, ‘submit’, or ‘none’)

  • –parallel_test=N

    For the mandatory test and train portion of a reportable run, run N jobs at a time.

举几个常用的命令的例子。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 只编译base int用例
$ runspec -c linux64-riscv64.cfg --action=build -T base int

# 运行单核整形
$ runspec -c linux64-riscv64.cfg -i ref -T peak -n 1 -r 1 int --noreportable

# 运行多核整形
$ runspec -c linux64-riscv64.cfg -i ref -T peak -n 1 -r 4 int --noreportable

# 运行单核浮点
$ runspec -c linux64-riscv64.cfg -i ref -T peak -n 1 -r 1 fp --noreportable

# 运行多核浮点
$ runspec -c linux64-riscv64.cfg -i ref -T peak -n 1 -r 4 fp --noreportable

RISCV

build RISCV environment

参考之前的文章。

build toolset

参考下面转载的文章。

install

1
$ ./install.sh -d /home/francis.zheng/spec2006_installed_riscv -u linux-riscv64

build

需要编译base和peak两种。

1
2
$ runspec -c linux64-riscv64.cfg --action=build -T base int
$ runspec -c linux64-riscv64.cfg --action=build -T peak int

run

见上面runspec的使用。


以下为转载。


移植SPEC2006

(samin.guo, 2019.10, sifive-china chengdu.)

spec运行的流程install -> build-> run

其中,在install阶段,需要使用arch相关的tools,这部分需要自己使用编译器自己编译出来;

buidl阶段就是对各个测试集进行编译,这个阶段可以通过配置文件指定各种优化选项;

run阶段进行测试题的运行,并得到分数。

由于spec使用的语法比较老,而我们的编译器比较新,有些老的语法在新的编译器中已经默认不支持了,需要使用某些特定的编译选型打开,或者其他相关的工作,使编译器能够正常编译。

编译spec tools

spec tools会使用到__alloca宏, 但是新的glibc中已经没有提供,需要手动添加。

1、编辑 /usr/include/alloca.h,新增__alloca的宏定义。

1
2
3
4
    #ifdef  GUNC
define alloca(size) __builtin_alloca (size)
+ define __alloca(size) alloca(size)
#endif

2、手动创建和处理一些缺少的文件。

1
2
3
4
$cd /usr/bin  && ln -s gcc cc
$cd /bin && mv sh sh.bak && ln -s bash sh #必须使用bash,sh和dash都不能正常工作
$touch /usr/include/riscv64-linux-gnu/asm/page.h #新的glibc不提供asm/page文件,需要创建
$echo export TZ='CST-8' >> /etc/bash.bashrc #配置时区,不然时间设置会有问题

3、编辑 /usr/include/stdio.h,屏蔽__getdelim ,getdelim, getline三个函数的声明,否则会报函数冲突。

注意,tools编译完成之后,请将屏蔽去掉,恢复文件。

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
+#if 0                                     
#if defined USE_XOPEN2K8 || GLIBC_USE (LIB_EXT2)
/* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
(and null-terminate it). *LINEPTR is a pointer returned from malloc (or
NULL), pointing to *N characters of space. It is realloc'd as
necessary. Returns the number of characters read (not including the
null terminator), or -1 on error or EOF.
These functions are not part of POSIX and therefore no official
cancellation point. But due to similarity with an POSIX interface
or due to the implementation they are cancellation points and
therefore not marked with THROW. */
extern ssize_t getdelim (char restrict lineptr,
size_t *restrict n, int delimiter,
FILE *restrict stream) wur;
extern ssize_t getdelim (char restrict lineptr,
size_t *restrict n, int delimiter,
FILE *restrict stream) wur;
/* Like `getdelim', but reads up to a newline.
This function is not part of POSIX and therefore no official
cancellation point. But due to similarity with an POSIX interface
or due to the implementation it is a cancellation point and
therefore not marked with THROW. */
extern ssize_t getline (char **restrict lineptr,
size_t *restrict n,
FILE *restrict stream) __wur;
#endif
+#endif

3、安装dld库

源码编译dld库,该库比较老,软件仓库不提供下载。不安装此库会导致perl不会开启动态加载功能。

1
2
3
$ tar -xvf dld-3.3.tar.gz && cd dld-3.3
$ ./configure --prefix=/usr
$ make && make install

4、编辑配置文件,加上对libm.a和libdl.a的的链接,否则会检测不到dlopen导致perl动态链接功能失效。

vim SPEC2006/tools/src/perl-5.8.7/Configure

1
2
3
4
5
6
 xlibpth=''
ignore_versioned_solibs=''
-libs=''
+libs='-ldl'
libsdirs=''
libsfiles=''

vim SPEC2006/tools/src/perl-5.8.7/Makefile.SH

1
2
3
4
5
6
  ext = \$(dynamic_ext) \$(static_ext) \$(nonxs_ext)
DYNALOADER = lib/auto/DynaLoader/DynaLoader\$(LIB_EXT)
- libs = $perllibs $cryptlib
+ libs = $perllibs $cryptlib -lm -ldl
public = perl\$(EXE_EXT) $suidperl utilities translators
shellflags = $shellflags

5、屏蔽libwww-perl,打开该模块会导致编译不过,并且后面不会使用到此功能

vim SPEC2006/tools/src/perl-5.8.7/Configure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 for i in \
Compress-Zlib-* \
Compress-Bzip2-* \
IO-stringy* \
GD-* \
MailTools-* \
MIME-tools-* \
PDF-API2-* \
Text-CSV_XS-* \
HTML-Tagset-* \
HTML-Parser-* \
XML-NamespaceSupport-* \
XML-SAX-[0-9]* \
URI-* \
- libwww-perl-* \
Algorithm-Diff-* \
Font-AFM-*
do

6、替换src内的config.guess config.sub

将支持riscv的config.guess、config.sub替换到源码中(可以从gcc源码中获取)

1
2
3
4
$cp config.{guess,sub}  tools/src/expat-1.95.8/conftools/
$cp config.{guess,sub} tools/src/specinvoke/
$cp config.{guess,sub} tools/src/tar-1.15.1/config/
$cp config.{guess,sub} tools/src/make-3.80/config/

7、编译

1
2
$ cd SPEC2006/tools/src/
$ ./buildtools

8、buildtools运行成功后,将之前在 /usr/include/stdio.h文件中对__getdelim ,getdelim, getline三个函数的声明的屏蔽解开,恢复文件。

1
2
3
4
5
6
7
8
9
10
11
12
- #if 0 
#if defined USE_XOPEN2K8 || GLIBC_USE (LIB_EXT2)
/* Read up to (and including) a DELIMITER from STREAM into *LINEPTR

xxx
xxx
xxx
extern ssize_t getline (char **restrict lineptr,
size_t *restrict n,
FILE *restrict stream) __wur;
#endif
- #end if

9、进入spec根目录,运行下面命令 ,打包工具。

1
2
3
4
5
6
7
8
9
$ cd SPEC2006
$ . ./shrc
$ which runspec
$ export MYTOOLS=linux-riscv64
$ mkdir tools/bin/$MYTOOLS
$ echo "spec tools for riscv linux" tools/bin/$MYTOOLS/description
$ runspec -V > $MYTOOLS.runspec-V.txt 2>&1
$ runspec --test > $MYTOOLS.runspec--test.txt 2>&1
$ packagetools $MYTOOLS $MYTOOLS.runsp*txt

在spec根目录就会生成linux-riscv64-XX.tar的一个压缩包,包含所有的工具。

检测校验压缩包内的文件是否能够正常工作,确保没有问题,将该压缩包用spectar解压。

1
2
3
4
5
6
$cd SPEC2006
$cp tools/output/bin/specmd5sum .
$cp tools/output/bin/spectar .
$./specmd5sum linux-riscv64-XX.tar > linux-riscv64-XX.tar.md5
$./specmd5sum -c linux-riscv64-XX.tar.md5
$./spectar -xvf linux-riscv64-XX.tar

spectar会将压缩包内新的tools解压到tools/bin/${os}-${arch} 目录下。

10、安装spec tools

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ ./install.sh
SPEC CPU2006 Installation
Top of the CPU2006 tree is '/root/SPEC2006'
There appears to be only one valid toolset:

linux-riscv64

Use this? (y/n)
y
Checking the integrity of your source tree...

Checksums are all okay.
Unpacking binary tools for linux-riscv64...
Checking the integrity of your binary tools...

Checksums are all okay.
Top of SPEC benchmark tree is '/root/SPEC2006'
Everything looks okay. cd to /root/SPEC2006,
source the shrc file and have at it!

运行SPEC

1
2
3
4
5
$ . ./shrc
$runspec -c linux64-riscv64.cfg -i ref -T peak -n 1 -r 1 int --noreportable #单核整形
$runspec -c linux64-riscv64.cfg -i ref -T peak -n 1 -r 4 int --noreportable #多核整形
$runspec -c linux64-riscv64.cfg -i ref -T peak -n 1 -r 1 fp --noreportable #单核浮点
$runspec -c linux64-riscv64.cfg -i ref -T peak -n 1 -r 4 fp --noreportable #多核浮点

tips:

1、上面命令只会运行一遍,如想得到分数,需要自己手动计算(题目总分/题目个数)。如想得到有分数的报告文件,可以将–noreportable去掉,这样会运行三遍,得到分数。

2、运行如果报找不到specxxx命令的问题,手动运行下 ./bin/relocate,重新设置下顶层路径即可。

3、更详细的命令请参考Docs/runspec.html

编译运行问题记录

1、400.perlbench在开启编译优化后,编译时报库函数无法找到的问题:

修改配置文件,增加-std=gnu89选项

1
2
3
4
  400.perlbench=default=default=default:
notes35 = 400.perlbench: -DSPEC_CPU_LINUX_X64
- CPORTABILITY= -DSPEC_CPU_LINUX_X64
+ CPORTABILITY= -DSPEC_CPU_LINUX_X64 -std=gnu89

2、464.h264ref在运行时报错。

编译器默认将char配置成unsigned类型,需要将char配置成sigend类型。

修改配置文件,新增下列内容:

1
2
+ 464.h264ref=default=default=default:
+ CPORTABILITY= -fsigned-char

3、483.xalancbmk编译时报文件未定义

链接时缺少头文件,修改配置文件,新增下列内容:

1
2
+ 483.xalancbmk=default=default=default:
+ CXXPORTABILITY= -DSPEC_CPU_LINUX -include cstring

4、416.gamess编译报错

spec的416.gamess使用,fortran在编译时不能解析老的语法格式。

修改配置文件,新增下列内容:

1
2
+ 416.gamess=default=default=default:
+ FPORTABILITY= -std=legacy

5、447.dealII编译报错

缺少头文件包含,语法书写不严谨,用-fpermissive忽略。

修改配置文件,新增下列内容:

1
2
+ 447.dealII=default=default=default:
+ CXXPORTABILITY= -fpermissive -include cstring

6、450.sopex编译报错

老的c++语法,新编译器需要加入兼容选项。

修改配置文件,新增下列内容:

1
2
+ 450.soplex=default=default=default:
+ CXXPORTABILITY= -std=c++98

7、416.games 运行报浮点异常

优化导致触发了IEEE_UNDERFLOW_FLAG。这是spec的一个bug,bug编号:69368

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69368

-fno-aggressive-loop-optimizations

8、481.wrf运行包下列错误:

Runtime: At line 6744 of file module_ra_rrtm.fppized.f90 (unit = 10, file = ‘RRTM_DATA’)

去掉wrf_data_header_size = 8编译选项。

1
2
481.wrf=default=default=default:
- wrf_data_header_size = 8

9、482.sphinx3运行时报错:

FATAL_ERROR: “mdef.c”, line 427: Duplicate base phone: +BREATH+ - - - filler 0 0 1 2 N

与464.h264ref原因一样,需要将char配置成signed

1
2
+482.sphinx3=default=default=default:
+ CPORTABILITY= -fsigned-char

10、gcc 10下,481.wrf编译报错

添加编译选项:

1
2
3
 481.wrf=default=default=default:
CPORTABILITY = -DSPEC_CPU_CASE_FLAG -DSPEC_CPU_LINUX
+EXTRA_OPTIMIZE = -fallow-argument-mismatch

附:配置文件

config/linux64-riscv64.cfg

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
185
186
187
188
189
190
191
192
# This is a sample config file. It was tested with:
#
# Operating system version: [linux for RISCV]
# Hardware: [Opteron]
#
# If your platform uses different versions, different
# hardware or operates in a different mode (for
# example, 32- vs. 64-bit mode), there is the possibiliy
# that this configuration file may not work as-is.
#
# Note that issues with compilation should be directed
# to the compiler vendor. Information about SPEC techncial
# support can be found in the techsupport document in the
# Docs directory of your benchmark installation.
#
# Also note that this is a sample configuration. It
# is expected to work for the environment in which
# it was tested; it is not guaranteed that this is
# the config file that will provide the best performance.
#
# Note that you might find a more recent config file for
# your platform with the posted results at
# www.spec.org/cpu2006
####################################################################
# linux64-RISCV64.cfg
# config file for
# RISCV64 64-bit (64 bit binaries on 64 bit host)
# Config file for CPU2006 int and fp
#####################################################################
ignore_errors = yes
tune = peak
size = ref
ext = riscv
output_format = asc, pdf, Screen
reportable = 1
teeout = yes
teerunout = yes
hw_avail = Dec-9999
license_num = 9999
test_sponsor = SFC
prepared_by =
tester =
#test_date = Dec-9999
default=default=default=default:
#####################################################################
#
# Compiler selection
#
#####################################################################
CC = gcc
CXX = c++
FC = gfortran

## HW config
hw_model = EVB-V1
hw_cpu_name = U74-V7100
hw_cpu_char =
hw_cpu_mhz = 1000
hw_fpu = Integrated
hw_nchips = 1
hw_ncores = 1
hw_ncoresperchip = 2
hw_nthreadspercore = 1
hw_ncpuorder = 1 chip
hw_pcache = 32 KiB 8-way
hw_scache = 128KiB 16-way
#hw_tcache = None
#hw_ocache = None
hw_memory = 8 GB (DDR4)
hw_disk = MMC
hw_vendor = starfive

## SW config
sw_os = linux (for RISCV)
sw_file = ext3
sw_state = runlevel 3
sw_compiler = gcc , g++ & gfortran
sw_avail = Dec-9999
sw_other = None
sw_auto_parallel = No
sw_base_ptrsize = 64-bit
sw_peak_ptrsize = 64-bit

#####################################################################
# Optimization
#####################################################################
## Base is low opt
default=base=default=default:
COPTIMIZE = -static -O3
CXXOPTIMIZE = -static -O3
FOPTIMIZE = -static -O3

notes0100= C base flags: $[COPTIMIZE]
notes0110= C++ base flags: $[CXXOPTIMIZE]
notes0120= Fortran base flags: $[FOPTIMIZE]

#####################################################################
# Optimization
#####################################################################
##peak
default=peak=default=default:
COPTIMIZE = -static -O3
CXXOPTIMIZE = -static -O3
FOPTIMIZE = -static -O3

notes0100= C base flags: $[COPTIMIZE]
notes0110= C++ base flags: $[CXXOPTIMIZE]
notes0120= Fortran base flags: $[FOPTIMIZE]
#####################################################################
# 32/64 bit Portability Flags - all
#####################################################################
default=default=default=default:
notes25= PORTABILITY=-DSPEC_CPU_LP64 is applied to all benchmarks in base.
PORTABILITY = -DSPEC_CPU_LP64

#####################################################################
# Portability Flags - INT
#####################################################################

400.perlbench=default=default=default:
notes35 = 400.perlbench: -DSPEC_CPU_LINUX_X64
CPORTABILITY= -DSPEC_CPU_LINUX_X64 -std=gnu89
EXTRA_OPTIMIZE = -flto -fpeel-loops -funroll-loops -ffast-math -ftree-vectorize

403.gcc=default=default=default:
EXTRA_OPTIMIZE = -funroll-loops -flto

462.libquantum=default=default=default:
notes60= 462.libquantum: -DSPEC_CPU_LINUX
CPORTABILITY= -DSPEC_CPU_LINUX
#EXTRA_OPTIMIZE = -funroll-loops -ftree-parallelize-loops=4
EXTRA_OPTIMIZE = -funroll-loops

464.h264ref=default=default=default:
CPORTABILITY= -fsigned-char

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


#####################################################################
# Portability Flags - FP
#####################################################################
410.bwaves=default=default=default:
EXTRA_OPTIMIZE = -flto -fpeel-loops -funroll-loops -ffast-math -ftree-vectorize

416.gamess=default=default=default:
FOPTIMIZE= -static -O2
FPORTABILITY= -std=legacy -fno-aggressive-loop-optimizations -flto

433.milc=default=default=default:
EXTRA_OPTIMIZE = -flto

434.zeusmp=default=default=default:
EXTRA_OPTIMIZE = -fpeel-loops -funroll-loops -ffast-math -ftree-vectorize

435.gromacs=default=default=default:
EXTRA_OPTIMIZE =

436.cactusADM=default=default=default:
EXTRA_OPTIMIZE = -ffinite-math-only

437.leslie3d=default=default=default:
EXTRA_OPTIMIZE = -O3

444.namd=default=default=default:
EXTRA_OPTIMIZE = -O3 -fnon-call-exceptions

447.dealII=default=default=default:
CXXPORTABILITY= -flto -fpermissive -include cstring

450.soplex=default=default=default:
CXXPORTABILITY= -flto -std=c++98

454.calculix=default=default=default:
EXTRA_OPTIMIZE =

459.GemsFDTD=default=default=default:
EXTRA_OPTIMIZE = -fpeel-loops -funroll-loops -ffast-math -ftree-vectorize

465.tonto=default=default=default:
EXTRA_OPTIMIZE = -flto -fpeel-loops -funroll-loops -ffast-math -ftree-vectorize

470.lbm=default=default=default:
EXTRA_OPTIMIZE =

481.wrf=default=default=default:
CPORTABILITY = -DSPEC_CPU_CASE_FLAG -DSPEC_CPU_LINUX
EXTRA_OPTIMIZE = -fallow-argument-mismatch

482.sphinx3=default=default=default:
CPORTABILITY= -fsigned-char

tips

可以根据每个题目,添加特定的优化选项。