目录
目录README.md

SPEC2006 测试 LLVM on RISCV 性能

目标

  1. 测试 LLVM19.1.0 在两个RISC-V平台(C910/C920)上的SPECcpu2006 int speed性能
  2. 测试 LLVM20.1.0 在两个RISC-V平台(C910/C920)上的SPECcpu2006 int speed性能
  3. 测试 LLVM19.1.0 在两个RISC-V平台(C910/C920)上的SPECcpu2006 int rate性能
  4. 测试 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

  1. 解压speccpu2006-v1.0.1.tar.gz
    tar -zxvf speccpu2006-v1.0.1.tar.gz
  2. 安装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
  3. 设置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*

几个主要的目录

  • benchspec/:SPECcpu2006 的基准测试程序
  • config/:SPECcpu2006 的配置文件
  • result/:SPECcpu2006 的结果文件

    SPECcpu2006 基准测试程序

    speccpu2006-v1.0.1/benchspec/CPU2006/
    ├── 400.perlbench/
    │   ├── data/
    │   ├── Docs/
    │   ├── Spec/
    │   ├── src/
    │   └── version.txt*
    ├── 401.bzip2/
    ├── 403.gcc/
    ├── 410.bwaves/
    ├── 416.gamess/
    ├── 429.mcf/
    ├── 433.milc/
    ├── 434.zeusmp/
    ├── 435.gromacs/
    ├── 436.cactusADM/
    ├── 437.leslie3d/
    ├── 444.namd/
    ├── 445.gobmk/
    ├── 447.dealII/
    ├── 450.soplex/
    ├── 453.povray/
    ├── 454.calculix/
    ├── 456.hmmer/
    ├── 458.sjeng/
    ├── 459.GemsFDTD/
    ├── 462.libquantum/
    ├── 464.h264ref/
    ├── 465.tonto/
    ├── 470.lbm/
    ├── 471.omnetpp/
    ├── 473.astar/
    ├── 481.wrf/
    ├── 482.sphinx3/
    ├── 483.xalancbmk/
    ├── 998.specrand/
    ├── 999.specrand/
    ...

    SPECcpu2006 子项

    Benchmark Documentation

    Integer Benchmarks

    400.perlbench C PERL Programming Language
    401.bzip2 C Compression
    403.gcc C C Compiler
    429.mcf C Combinatorial Optimization
    445.gobmk C Artificial Intelligence: go
    456.hmmer C Search Gene Sequence
    458.sjeng C Artificial Intelligence: chess
    462.libquantum C Physics: Quantum Computing
    464.h264ref C Video Compression
    471.omnetpp C++ Discrete Event Simulation
    473.astar C++ Path-finding Algorithms
    483.xalancbmk C++ XML Processing

    Floating Point Benchmarks

    410.bwaves Fortran Fluid Dynamics
    416.gamess Fortran Quantum Chemistry
    433.milc C Physics: Quantum Chromodynamics
    434.zeusmp Fortran Physics / CFD
    435.gromacs C/Fortran Biochemistry/Molecular Dynamics
    436.cactusADM C/Fortran Physics / General Relativity
    437.leslie3d Fortran Fluid Dynamics
    444.namd C++ Biology / Molecular Dynamics
    447.dealII C++ Finite Element Analysis
    450.soplex C++ Linear Programming, Optimization
    453.povray C++ Image Ray-tracing
    454.calculix C/Fortran Structural Mechanics
    459.GemsFDTD Fortran Computational Electromagnetics
    465.tonto Fortran Quantum Chemistry
    470.lbm C Fluid Dynamics
    481.wrf C/Fortran Weather Prediction
    482.sphinx3 C Speech recognition

子项的四个目录

初始化状态
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 测试机器的图片:
SIPEED LicheePi 4A

C920 (Milk-V Pioneer Box with SOPHGO SG2042)

Milk-V Pioneer Box 官网:Milk-V Pioneer SOPHGO SG2042 官网:SOPHGO SG2042

C920 RISC-V 测试机器的图片:
Milk-V Pioneer Box

测试准备流程

本教程目的是在C910/C920平台上测试SPECcpu2006的性能,由于SPECcpu2006官方不支持在RISC-V平台上运行SPEC命令,因此我们需要一种特殊的测试方法,具体步骤如下:

  1. 使用SPEC命令中的setup命令来编译SPECcpu2006的基准测试程序,设置好运行目录。
  2. 通过PackSPEC脚本来打包所有运行目录,生成测试脚本。
  3. 将打包好的测试包传到待测试的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
关于
564.3 MB
邀请码