RISC-V 공부) Gemmini 설치 - WSL (1)

Donghyun Kang·2024년 8월 23일

개요

Custom SoC 설계/개발을 위해, RISC-V는 점차 필수 소양이 되어 가는 것 같다.

AI System Design 수업에서 추천받은 Gemmini 라는 프로젝트부터 시작해 보려고 한다.

Gemmini

  • Gemmini is part of the Chipyard ecosystem, and was developed using the Chisel hardware description language.
    • Chipyard: an open source framework for agile development of Chisel-based systems-on-chip.
    • Chisel: The Constructing Hardware in a Scala Embedded Language (Chisel) is an open-source hardware description language (HDL) used to describe digital electronics and circuits at the register-transfer level.

Chipyard, Chisel에 대해서는 이 프로젝트부터 시작해서 하나씩 천천히 알아가 보면 될 것 같다.

설치

WSL을 활용해서 설치해 보았다.

WSL 환경 셋업

기존 환경이 너무 오래되어서, 새로 환경을 셋업함
(Windows App store -> Ubuntu 24.04 LTS)

필요 패키지 설치

$ sudo apt-get update & upgrade
$ sudo apt-get install make cpio

make이 설치되어 있지 않았던 것 의외였음.
cpio는 chipyard - FireSim 설치 시 필요.

Conda 설치

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

  • 마지막은 no해도 되는데, yes해야 conda 자동 환경변수 추가 및 activate 돼서 편함

Chipyard Requirements 설치

Chipyard Requirements 설치

  • Gemmini project는 Chipyard 1.9.1 버전을 기준으로 진행해야 하기 때문에, 다음 스크립트 활용
$ 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이 필요하지 않음

Chipyard & Spike for Gemmini 설치

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

Gemmini Setup

(이어서)

# 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

여기까지 하면 설치는 완료.

Test

$ 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

# 안끝나서 종료

마지막 스크립트는 너무 오래 걸려서 체크 포기

Error Handling

make: chipyard/common.mk:380: launch-sbt Killed

RAM이 부족한 문제라고 함
WSL에 더 높은 RAM 할당하여 해결

  • Windows + R: %userprofile% 실행
  • .wslconfig 생성 (혹은 수정) 후 다음과 같이 설정
[wsl2]
memory=8GB
swap=0
localhostForwarding=true

Failed to build workload br-base.json

여러 원인이 있을 수 있는듯

Warning: Your system does not support an open files limit ...

  • 다음 값이 16384 이상이어야 좋다고 함
    • ulimit -Sn
    • ulimit -Hn
  • Problem: 이 값은 쉘 별 적용인데, root에서만 해당 값 임시 변경 가능
  • 다음과 같이 해결
$ sudo -i
$ ulimit -Sn 16384
$ ulimit -Hn 16384
$ su ${original_id}

You must install 'cpio' on your build machine

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 설치.

TODO

RISC-V 기반 시스템 분석

  • 확장 ISA 활용 방법 확인
  • CPU-NPU 구성 방식 확인

0개의 댓글