Gemmini 介绍说明源地址:https://github.com/ucb-bar/gemmini/blob/master/README.md
一、安装依赖
1. 安装 conda
基于Miniconda 进行安装
# 下载最新版 Miniconda3(64 位)
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
# 赋予执行权限
chmod +x Miniconda3-latest-Linux-x86_64.sh
# 开始安装(按提示操作)
bash Miniconda3-latest-Linux-x86_64.sh
安装完后记得要更新一下环境变量
source ~/.bashrc # 或 .zshrc(若使用 zsh)
2. 创建conda 编译环境
创建一个“干净”的编译环境,可以有效的提高chipyard工程编译成功的概率。
# 创建新环境(指定 Python 版本)
conda create -n my_chipyard
# 激活环境(进入环境)
conda activate my_chipyard
二、安装Chipyard and Spike
1. 下载chipyard 代码工程
从github仓库下载 chipyard 源码
git clone https://github.com/ucb-bar/chipyard.git
2. 编译
修改编译参数
由于我的编译服务器只有8G内存大小,在实际的编译过程会出现因内存耗光,导致卡死的现象,因此需要手工调整一下编译参数。将JAVA_HEAP_SIZE 改为了6G
打开 vi chipyar/variables.mk 文件,找到 JAVA_HEAP_SIZE 字段,修改为如下图中的内容。
查看编译help
通过多 ./build-setup.sh --help 的查看,发现 实际上模块间是相互独立的。比方说因为用不着FPGA 仿真平台,就可以先跳过 6,7,8,9 这几章节。
(base) :~/Source/chipyard$ ./build-setup.sh --help
Usage: ./build-setup.sh [OPTIONS] [riscv-tools]
Installation Types
riscv-tools: if set, builds the riscv toolchain (this is also the default)
Helper script to fully initialize repository that wraps other scripts.
By default it initializes/installs things in the following order:
1. Conda environment
2. Chipyard submodules
3. Toolchain collateral (Spike, PK, tests, libgloss)
4. Ctags
5. Chipyard pre-compile sources
6. FireSim
7. FireSim pre-compile sources
8. FireMarshal
9. FireMarshal pre-compile default buildroot Linux sources
10. Install CIRCT
11. Runs repository clean-up
**See below for options to skip parts of the setup. Skipping parts of the setup is not guaranteed to be tested/working.**
Options
--help -h : Display this message
--verbose -v : Verbose printout
--use-unpinned-deps -ud : Use unpinned conda environment
--use-lean-conda : Install a leaner version of the repository (smaller conda env, no FireSim, no FireMarshal)
--build-circt : Builds CIRCT from source, instead of downloading the precompiled binary
--conda-env-name NAME : Optionally use a global conda env name instead of storing env in Chipyard directory
--github-token TOKEN : Optionally use a Github token to download CIRCT
--skip -s N : Skip step N in the list above. Use multiple times to skip multiple steps ('-s N -s M ...').
--skip-conda : Skip Conda initialization (step 1)
--skip-submodules : Skip submodule initialization (step 2)
--skip-toolchain : Skip toolchain collateral (step 3)
--skip-ctags : Skip ctags (step 4)
--skip-precompile : Skip precompiling sources (steps 5/7)
--skip-firesim : Skip Firesim initialization (steps 6/7)
--skip-marshal : Skip firemarshal initialization (steps 8/9)
--skip-circt : Skip CIRCT install (step 10)
--skip-clean : Skip repository clean-up (step 11)
安装依赖
安装有可能需要用到的依赖
sudo apt install -y libguestfs-tools qemu-system-x86 supermin dmsetup parted e2fsprogs dosfstools
执行编译命令
跳过 FireSim 相关模块在编译过程中碰到问题。
cd chipyard
./build-setup.sh -s 6 -s 7 -s 8 -s 9
安装gemmini 库
source env.sh
cd $CY_DIR/generators/gemmini
make -C software/libgemmini install
三、编译Gemmini Software
cd $CY_DIR/generators/gemmini/software/gemmini-rocc-tests
rm -rf build
./build.sh
四、运行Simulators
编译模拟器
cd $CY_DIR/sims/verilator
#make CONFIG=GemminiRocketConfig
# Or, if you want a simulator that can generate waveforms, run this:
make -j$(nproc) debug CONFIG=GemminiRocketConfig
运行spike 的仿真程序
cd $CY_DIR/sims/verilator
# Run a small DNN workload in the functional simulator
spike --extension=gemmini ../../generators/gemmini/software/gemmini-rocc-tests/build/imagenet/resnet50-baremetal
并输出如下日志信息
Gemmini extension configured with:
dim = 16
conv 1 cycles: 234800
matmul 2 cycles: 19520
conv 3 cycles: 91887
matmul 4 cycles: 77447
matmul 5 cycles: 77445
matmul 6 cycles: 19520
conv 7 cycles: 91887
matmul 8 cycles: 77447
matmul 9 cycles: 19522
conv 10 cycles: 91887
matmul 11 cycles: 77447
matmul 12 cycles: 54842
conv 13 cycles: 68652
matmul 14 cycles: 37884
conv 15 cycles: 105872
matmul 16 cycles: 14243
^Econv 17 cycles: 108589
matmul 18 cycles: 37883
matmul 19 cycles: 14243
conv 20 cycles: 108589
matmul 21 cycles: 37883
matmul 22 cycles: 14243
conv 23 cycles: 108589
matmul 24 cycles: 37883
matmul 25 cycles: 20000
conv 26 cycles: 55104
matmul 27 cycles: 17198
conv 28 cycles: 76192
matmul 29 cycles: 10910
conv 30 cycles: 94097
matmul 31 cycles: 17197
matmul 32 cycles: 10910
conv 33 cycles: 94097
matmul 34 cycles: 17197
matmul 35 cycles: 10910
conv 36 cycles: 94097
matmul 37 cycles: 17197
matmul 38 cycles: 10910
conv 39 cycles: 94097
matmul 40 cycles: 17197
matmul 41 cycles: 10910
conv 42 cycles: 94097
matmul 43 cycles: 17197
matmul 44 cycles: 18506
conv 45 cycles: 42745
matmul 46 cycles: 10346
conv 47 cycles: 273531
matmul 48 cycles: 8002
conv 49 cycles: 84369
matmul 50 cycles: 10346
matmul 51 cycles: 8002
conv 52 cycles: 84369
matmul 53 cycles: 10346
matmul 54 cycles: 3371
Prediction: 75 (score: 45)
Prediction: 900 (score: 43)
Prediction: 641 (score: 40)
Prediction: 897 (score: 57)
Total cycles: 3118111 (100%)
Matmul cycles: 864104 (27%)
Im2col cycles: 0 (0%)
Conv cycles: 2097547 (67%)
Pooling cycles: 0 (0%)
Depthwise convolution cycles: 0 (0%)
Res add cycles: 119515 (3%)
Other cycles: 36945 (1%)
PASS
五、仿真结果分析
1. Gemmini 配置与运行概况
- 配置参数:
- Gemmini 扩展维度(dim)设置为 16,即处理单元规模为 16×16。
- 运行模式:
- 通过 Spike 模拟器执行 ResNet50 模型的裸机(baremetal)推理任务,输入为 ImageNet 数据集。
2. 关键操作周期统计
- 总周期数:3,118,111 周期(100%)。
- 周期占比分析:
- 卷积(Conv):2,097,547 周期(67%),为主要耗时操作。
- 矩阵乘法(Matmul):864,104 周期(27%),次核心操作。
- 残差连接(Res add):119,515 周期(3%),用于跨层特征融合。
- 其他操作:36,945 周期(1%),包括数据搬运、控制逻辑等。
- 关键操作耗时示例:
- 最大单次卷积操作(conv 1):234,800 周期。
- 最大单次矩阵乘法(matmul 2):195,20 周期。
3. 模型推理预测结果
- 前 4 名预测类别及分数:
- 类别 75:分数 45
- 类别 900:分数 43
- 类别 641:分数 40
- 类别 897:分数 57
- 说明:
- 分数代表模型对类别的置信度,数值越高表示匹配度越高。
- 由于未提供 ImageNet 类别映射表,无法直接对应具体物体类别(如 “狗”“汽车” 等)。
4. 测试结论
- 状态:测试流程完成,最终显示 PASS,表明仿真过程无异常。
- 性能特征:
- 计算密集型操作(卷积 + 矩阵乘法)占总周期的 94%,验证了 Gemmini 在深度学习推理中的高效性。
- 残差连接等控制流操作耗时较低,说明架构对复杂网络结构的支持性良好。
5. 潜在优化方向
- 卷积操作占比高,可针对卷积算法(如 Winograd 变换)或内存访问模式进一步优化。
- 矩阵乘法周期占比仍有优化空间,可调整 Gemmini 数据分块策略以提升缓存命中率。
总结:Gemmini 加速器在 ResNet50 推理任务中表现出计算密集型优势,核心操作周期分布符合深度学习模型特征,推理预测流程完整且测试通过,为后续硬件优化和模型部署提供了有效参考。