SPEC2006 测试 LLVM on RISCV 性能
目标
- 测试 LLVM19.1.0 在两个RISC-V平台(C910/C920)上的SPECcpu2006 int speed性能
- 测试 LLVM20.1.0 在两个RISC-V平台(C910/C920)上的SPECcpu2006 int speed性能
- 测试 LLVM19.1.0 在两个RISC-V平台(C910/C920)上的SPECcpu2006 int rate性能
- 测试 LLVM20.1.0 在两个RISC-V平台(C910/C920)上的SPECcpu2006 int rate性能
注:
- speed/rate: SPECcpu2006 测试的两种模式,分别是 speed 和 rate。
speed 模式测试的是处理器的单核性能,rate 模式测试的是处理器的多核与吞吐性能。
- int/fp/all: SPECcpu2006 测试的两种模式,分别是 int 和 fp。
int 模式测试的是处理器的整数运算性能,fp 模式测试的是处理器的浮点数运算性能。
all 模式是 int 和 fp 的组合。
安装编译环境
SPEC cpu 2006
官方文档:SPEC CPU2006 Documentation
安装 SPEC cpu 2006
- 解压
speccpu2006-v1.0.1.tar.gz
tar -zxvf speccpu2006-v1.0.1.tar.gz
- 安装
speccpu2006
cd speccpu2006-v1.0.1
./install.sh
# SPEC CPU2006 Installation
#
# Top of the CPU2006 tree is '/home/wll/SPEC06-llvm/speccpu2006-v1.0.1'
#
# These appear to be valid toolsets:
#
# linux-suse101-i386 For 32-bit i386 Linux systems.
# Built on SuSE Linux 10.1 with
# gcc V4.1.0 (SUSE Linux)
#
# linux-suse101-AMD64 For 64-bit AMD64 Linux systems.
# Built on SuSE Linux 10.1 with
# gcc V4.1.0 (SUSE Linux)
# Should also be usable on 64 bit EM64T systems
#
# linux-redhat62-ia32 For x86-based Linux systems with GLIBC 2.1.3+
# Built on RedHat 6.2 with gcc 2.95.3
#
#
# Enter the architecture you are using:
linux-suse101-AMD64
- 设置SPEC环境
注意: 每次使用SPEC时,都需要设置环境变量
cd speccpu2006-v1.0.1
source ./shrc
LLVM
官网: The LLVM Compiler Infrastructure
官方文档: LLVM Docs
Github代码仓库: llvm-project
GitLink镜像仓库: llvm-project
安装 LLVM
1. 克隆源代码
LLVM 的 release 版本有很多,这里以 20.1.0 为例。
注:其他版本可以通过 Tags 来查看。
git clone -b llvmorg-20.1.0 https://www.gitlink.org.cn/XSCC_Compiler_Team/llvm-project.git llvm-20.1.0
注:这里 llvm-project 使用的是 GitLink 镜像仓库,国内链接速度更快,但是仓库更新可能有延迟。
官方仓库:https://github.com/llvm/llvm-project.git
2. 配置编译环境
# 下载riscv64工具链,需要安装git-lfs
git lfs install
git clone https://gitlink.org.cn/XSCC_Compiler_Team/gnu-riscv64-12.2.git gnu-riscv64
RV64_TOOLCHAIN=`realpath gnu-riscv64`
# 下载 binutils
git clone https://gitlink.org.cn/XSCC_Compiler_Team/binutils-gdb.git binutils
cd binutils
git checkout c4c2b3bd171e4f963b6b3ae42ecde61a1438af63
export BINUTILS_PATH=`realpath binutils`
cd ..
# 创建安装目录
mkdir -p install-llvm-20.1.0
export INSTALL_PATH=`realpath install-llvm-20.1.0`
cd llvm-20.1.0
export $LLVM_PATH=$(pwd)
# 创建编译目录
mkdir -p build
export BUILD_PATH=`realpath build`
cd build
注:这里 binutils-gdb 使用的是 GitLink 镜像仓库,国内链接速度更快,但是仓库更新可能有延迟。
官方仓库:git://sourceware.org/git/binutils-gdb.git
3. 编译 LLVM
cd $BUILD_PATH
cmake -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} \
-DLLVM_TARGETS_TO_BUILD="X86;RISCV" \
-DLLVM_ENABLE_PROJECTS="clang;flang;lld;polly" \
-DLLVM_BINUTILS_INCDIR=$BINUTILS_PATH/include \
-DLLVM_ENABLE_DUMP=ON \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-unknown-linux-gnu" \
${LLVM_PATH}/llvm
make -j $(($(nproc)-2))
make install -j $(($(nproc)-2))
4. 编译compiler-rt (可选,用于支持PGO)
mkdir -p ${LLVM_PATH}/build-compiler-rt
cd ${LLVM_PATH}/build-compiler-rt
cmake -G "Unix Makefiles" \
-DLLVM_CMAKE_DIR=${BUILD_PATH} \
-DCMAKE_C_COMPILER=${RV64_TOOLCHAIN}/bin/riscv64-unknown-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=${RV64_TOOLCHAIN}/bin/riscv64-unknown-linux-gnu-g++ \
-DLLVM_ENABLE_RUNTIMES=compiler-rt \
-DCMAKE_BUILD_TYPE=Release \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DLLVM_TARGETS_TO_BUILD="RISCV" \
-DLLVM_MAIN_SRC_DIR=$LLVM_PATH \
-DLLVM_ENABLE_PROJECTS=clang \
-DCOMPILER_RT_BUILD_PROFILE=ON \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PATH}/lib/clang/$LLVM_VERSION_PERFIX \
${LLVM_PATH}/compiler-rt
make -j $(($(nproc)-2))
make install -j $(($(nproc)-2))
5. 下载 jemalloc
cd ${LLVM_PATH}/..
git clone https://gitlink.org.cn/XSCC_Compiler_Team/jemalloc-5.2.1-riscv64.git jemalloc-5.2.1-riscv64
6. 下载 PackSPEC 脚本
cd ${LLVM_PATH}/..
git clone https://gitlink.org.cn/XSCC_Compiler_Team/PackSPEC.git PackSPEC
SPECcpu2006简介
简单认识 SPECcpu2006
speccpu2006-v1.0.1/
├── benchspec/
├── bin/
├── config/
├── cshrc*
├── Docs/
├── Docs.txt/
├── install.bat*
├── install.sh*
├── LICENSE*
├── LICENSE.txt*
├── MANIFEST*
├── README*
├── README.txt*
├── redistributable_sources/
├── result/
├── Revisions*
├── shrc*
├── shrc.bat*
├── spec.log
├── SUMS.tools
├── tools/
├── uninstall.sh*
└── version.txt*
几个主要的目录
子项的四个目录
初始化状态
speccpu2006-v1.0.1/benchspec/CPU2006/400.perlbench/
├── data/
├── Docs/
├── Spec/
├── src/
└── version.txt*
data/
:SPECcpu2006 基准测试程序的输入数据与预期的输出结果
Docs/
:SPECcpu2006 基准测试程序的文档
Spec/
:SPECcpu2006 基准测试程序的配置文件
src/
:SPECcpu2006 基准测试程序的源代码
子项build/run/setup
过后
speccpu2006-v1.0.1/benchspec/CPU2006/400.perlbench/
|-- Docs/
|-- Spec/
|-- data/
|-- exe/
|-- run/
|-- src/
`-- version.txt*
exe/
:SPECcpu2006 基准测试程序的可执行文件
run/
:SPECcpu2006 基准测试程序的运行目录
998/999.specrand 是什么
q. What’s this specrand thing?
During a run, 998.specrand and 999.specrand are mentioned. Why? For example;
Benchmarks selected: 400.perlbench, 401.bzip2, 403.gcc, 429.mcf, 445.gobmk,
456.hmmer, 458.sjeng, 462.libquantum, 464.h264ref, 471.omnetpp, 473.astar,
483.xalancbmk, 999.specrand
.
.
.
Running 473.astar test peak submitted default (1 copy)
Running 483.xalancbmk test peak submitted default (1 copy)
Running 999.specrand test peak submitted default (1 copy)
a. Several of the benchmarks use a common random number generator. During development of CPU2006, it was often useful to have the random number generator as a separate pseudo-benchmark, to help with problem diagnosis. (“You miscompared on benchmark mumble? Hmmm. Do you also miscompare on specrand?”)
For the released version of the suite, SPEC decided to retain specrand, in case it comes in useful for later problem diagnosis. It is run with both the integer and floating point suites, but its time is not reported, and its performance does not contribute to the bottom line metrics.
You’ll find more information about specrand at http://www.spec.org/cpu2006/Docs/999.specrand.html.
认识测试环境
RISC-V测试机器
C910 (SIPEED LicheePi 4A with T-Head TH1520)
SIPEED LicheePi 4A 官方文档:LicheePi 4A
XuanTie C910 官网:XuanTie C910
C910 RISC-V 测试机器的图片:

C920 (Milk-V Pioneer Box with SOPHGO SG2042)
Milk-V Pioneer Box 官网:Milk-V Pioneer
SOPHGO SG2042 官网:SOPHGO SG2042
C920 RISC-V 测试机器的图片:

测试准备流程
本教程目的是在C910/C920平台上测试SPECcpu2006的性能,由于SPECcpu2006官方不支持在RISC-V平台上运行SPEC命令,因此我们需要一种特殊的测试方法,具体步骤如下:
- 使用SPEC命令中的
setup
命令来编译SPECcpu2006的基准测试程序,设置好运行目录。
- 通过PackSPEC脚本来打包所有运行目录,生成测试脚本。
- 将打包好的测试包传到待测试的RISC-V机器上,运行脚本进行测试。
使用SPEC的setup
命令
1. 编写配置文件
详见:ref_config/riscv64-xuantie-llvm-base.cfg
cp ref_config/riscv64-xuantie-llvm-base.cfg speccpu2006-v1.0.1/config/riscv64-xuantie-llvm-base.cfg
source set-llvm-env.sh
2. 运行 SPEC 命令
cd speccpu2006-v1.0.1
source ./shrc
runspec -c riscv64-xuantie-llvm-base.cfg -a setup --rebuild -i ref -T base --iterations=3 int
runspec
命令的参数说明:
-c
:指定配置文件
-a
:指定运行模式,常用的包括 build
, clean
, clobber
, run
, setup
--rebuild
:重新编译基准测试程序
-i
:指定基准测试程序的输入数据,包括 ref
, test
, train
-T
:指定基准测试程序的测试模式,包括 base
, peak
--iterations
:指定基准测试程序的迭代次数
int
:指定基准测试程序的测试模式
注:如果没有添加选项-r [N]
,则运行在speed测试模式下,添加-r [N]
选项表示运行在rate测试模式下,[N]
表示程序会复制[N]
份运行。
使用PackSPEC脚本
1. 配置PackSPEC脚本
cd PackSPEC
cp config.py.example config.py
cp ../ref_config/main.py main.py
pip install -r requirements.txt
2. 执行打包脚本
python main.py
在RISC-V机器上测试
1. 传输到目标RISC-V机器上
scp -r packed_files/run_riscv64-llvm-base.base_ref <user>@<ip>:<path>
2. 运行测试
一般测试时间较长,建议使用tmux来管理测试终端
tmux new -s run_test
cd run_riscv64-llvm-base.base_ref
bash run_all.sh
SPEC2006 测试 LLVM on RISCV 性能
目标
安装编译环境
SPEC cpu 2006
官方文档:SPEC CPU2006 Documentation
安装 SPEC cpu 2006
speccpu2006-v1.0.1.tar.gz
speccpu2006
LLVM
官网: The LLVM Compiler Infrastructure 官方文档: LLVM Docs Github代码仓库: llvm-project GitLink镜像仓库: llvm-project
安装 LLVM
1. 克隆源代码
LLVM 的 release 版本有很多,这里以 20.1.0 为例。
2. 配置编译环境
3. 编译 LLVM
4. 编译compiler-rt (可选,用于支持PGO)
5. 下载 jemalloc
6. 下载 PackSPEC 脚本
SPECcpu2006简介
简单认识 SPECcpu2006
几个主要的目录
benchspec/
:SPECcpu2006 的基准测试程序config/
:SPECcpu2006 的配置文件result/
:SPECcpu2006 的结果文件SPECcpu2006 基准测试程序
SPECcpu2006 子项
Benchmark Documentation
Integer Benchmarks
Floating Point Benchmarks
子项的四个目录
初始化状态
data/
:SPECcpu2006 基准测试程序的输入数据与预期的输出结果Docs/
:SPECcpu2006 基准测试程序的文档Spec/
:SPECcpu2006 基准测试程序的配置文件src/
:SPECcpu2006 基准测试程序的源代码子项
build/run/setup
过后exe/
:SPECcpu2006 基准测试程序的可执行文件run/
:SPECcpu2006 基准测试程序的运行目录998/999.specrand 是什么
q. What’s this specrand thing? During a run, 998.specrand and 999.specrand are mentioned. Why? For example;
Benchmarks selected: 400.perlbench, 401.bzip2, 403.gcc, 429.mcf, 445.gobmk, 456.hmmer, 458.sjeng, 462.libquantum, 464.h264ref, 471.omnetpp, 473.astar, 483.xalancbmk, 999.specrand . . . Running 473.astar test peak submitted default (1 copy) Running 483.xalancbmk test peak submitted default (1 copy) Running 999.specrand test peak submitted default (1 copy)
a. Several of the benchmarks use a common random number generator. During development of CPU2006, it was often useful to have the random number generator as a separate pseudo-benchmark, to help with problem diagnosis. (“You miscompared on benchmark mumble? Hmmm. Do you also miscompare on specrand?”)
For the released version of the suite, SPEC decided to retain specrand, in case it comes in useful for later problem diagnosis. It is run with both the integer and floating point suites, but its time is not reported, and its performance does not contribute to the bottom line metrics.
You’ll find more information about specrand at http://www.spec.org/cpu2006/Docs/999.specrand.html.
认识测试环境
RISC-V测试机器
C910 (SIPEED LicheePi 4A with T-Head TH1520)
SIPEED LicheePi 4A 官方文档:LicheePi 4A
XuanTie C910 官网:XuanTie C910
C910 RISC-V 测试机器的图片:

C920 (Milk-V Pioneer Box with SOPHGO SG2042)
Milk-V Pioneer Box 官网:Milk-V Pioneer SOPHGO SG2042 官网:SOPHGO SG2042
C920 RISC-V 测试机器的图片:

测试准备流程
本教程目的是在C910/C920平台上测试SPECcpu2006的性能,由于SPECcpu2006官方不支持在RISC-V平台上运行SPEC命令,因此我们需要一种特殊的测试方法,具体步骤如下:
setup
命令来编译SPECcpu2006的基准测试程序,设置好运行目录。使用SPEC的
setup
命令1. 编写配置文件
详见:ref_config/riscv64-xuantie-llvm-base.cfg
2. 运行 SPEC 命令
runspec
命令的参数说明:-c
:指定配置文件-a
:指定运行模式,常用的包括build
,clean
,clobber
,run
,setup
--rebuild
:重新编译基准测试程序-i
:指定基准测试程序的输入数据,包括ref
,test
,train
-T
:指定基准测试程序的测试模式,包括base
,peak
--iterations
:指定基准测试程序的迭代次数int
:指定基准测试程序的测试模式使用PackSPEC脚本
1. 配置PackSPEC脚本
2. 执行打包脚本
在RISC-V机器上测试
1. 传输到目标RISC-V机器上
2. 运行测试
一般测试时间较长,建议使用tmux来管理测试终端