Custom SoC 설계/개발을 위해, RISC-V는 점차 필수 소양이 되어 가는 것 같다.
AI System Design 수업에서 추천받은 Gemmini 라는 프로젝트부터 시작해 보려고 한다.
Chipyard, Chisel에 대해서는 이 프로젝트부터 시작해서 하나씩 천천히 알아가 보면 될 것 같다.
WSL을 활용해서 설치해 보았다.
기존 환경이 너무 오래되어서, 새로 환경을 셋업함
(Windows App store -> Ubuntu 24.04 LTS)
$ sudo apt-get update & upgrade
$ sudo apt-get install make cpio
make이 설치되어 있지 않았던 것 의외였음.
cpio는 chipyard - FireSim 설치 시 필요.
Conda install 설명을 따랐음. 현재 (2024.08) 기준으로 다음의 스크립트 활용
$ wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
$ bash Miniforge3-Linux-x86_64.sh
나오는 [yes/no] 항목에는 모두 yes
Chipyard Requirements 설치
$ conda install -n base conda-libmamba-solver
$ conda config --set solver libmamba
$ conda install -n base conda-lock==1.4.0
$ conda activate base
(참고) 현재 latest 버전에는 conda-lock이 필요하지 않음
Gemmini README 를 따라 진행
1.9.1 버전을 사용한다. 바뀔 수 있기 때문에, 내가 사용한 스크립트 저장용
git clone https://github.com/ucb-bar/chipyard.git
cd chipyard
git checkout 1.9.1
./build-setup.sh riscv-tools
source env.sh
cd generators/gemmini
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch && git checkout v0.7.1
git submodule update --init --recursive
make -C software/libgemmini install
# The final step is only necessary if you want to run MIDAS simulations with
# realistic DRAM models
cd -
cd sims/firesim
source sourceme-f1-manager.sh --skip-ssh-setup # Ignore error messages from this command
./build-setup.sh --library --skip-validate
(이어서)
# go to chipyard home
$ cd -
# Setting Up Gemmini
$ cd generators/gemmini
$ ./scripts/setup-paths.sh
# Building Gemmini Software
$ cd software/gemmini-rocc-tests
$ ./build.sh
# Building Gemmini Hardware and Cycle-Accurate Simulators
$ cd -
$ ./scripts/build-verilator.sh
# Building Gemmini Functional Simulators
$ ./scripts/build-spike.sh
여기까지 하면 설치는 완료.
$ cd chipyard/generators/gemmini
# Run a large DNN workload in the functional simulator
$ ./scripts/run-spike.sh resnet50
...
Prediction: 75 (score: 45)
Prediction: 900 (score: 43)
Prediction: 641 (score: 40)
Prediction: 897 (score: 57)
Total cycles: 5607065 (100%)
Matmul cycles: 666820 (11%)
Im2col cycles: 0 (0%)
Conv cycles: 2505673 (44%)
Pooling cycles: 0 (0%)
Depthwise convolution cycles: 0 (0%)
Res add cycles: 2396862 (42%)
Other cycles: 37710 (0%)
PASS
# Run a smaller workload in baremetal mode, on a cycle-accurate simulator
$ ./scripts/run-verilator.sh template
...
Flush Gemmini TLB of stale virtual addresses
Initialize our input and output matrices in main memory
Calculate the scratchpad addresses of all our matrices
Note: The scratchpad is "row-addressed", where each address contains one matrix row
Move "In" matrix from main memory into Gemmini's scratchpad
Move "Identity" matrix from main memory into Gemmini's scratchpad
Multiply "In" matrix with "Identity" matrix with a bias of 0
Move "Out" matrix from Gemmini's scratchpad into main memory
Fence till Gemmini completes all memory operations
Check whether "In" and "Out" matrices are identical
Input and output matrices are identical, as expected
# Run a smaller workload with the proxy-kernel, on a cycle accurate simulator
$ ./scripts/run-verilator.sh --pk template
...
This emulator compiled with JTAG Remote Bitbang client. To enable, use +jtag_rbb_enable=1.
Listening on port 46287
[UART] UART0 is here (stdin/stdout).
bbl loader
# 안끝나서 종료
마지막 스크립트는 너무 오래 걸려서 체크 포기
RAM이 부족한 문제라고 함
WSL에 더 높은 RAM 할당하여 해결
[wsl2]
memory=8GB
swap=0
localhostForwarding=true
여러 원인이 있을 수 있는듯
ulimit -Sn ulimit -Hn$ sudo -i
$ ulimit -Sn 16384
$ ulimit -Hn 16384
$ su ${original_id}
2024-08-23 21:29:54,698 [run ] [DEBUG] You must install 'cpio' on your build machine
2024-08-23 21:29:54,701 [run ] [DEBUG] make[1]: *** [support/dependencies/dependencies.mk:27: dependencies] Error 1
2024-08-23 21:29:54,713 [run ] [DEBUG] make: *** [Makefile:84: _all] Error 2
2024-08-23 21:29:54,714 [main ] [ERROR] Failed to build workload br-base.json
2024-08-23 21:29:54,714 [main ] [INFO ] Log available at: /home/kangdongh/riscv/chipyard/software/firemarshal/logs/br-base-build-2024-08-23--12-29-47-UFX9W0VWZC70ICRE.log
2024-08-23 21:29:54,714 [main ] [ERROR] FAILURE: 1 builds failed
이 문제 때문에 cpio 설치.
RISC-V 기반 시스템 분석