QmppmQ / riscv

12 stars 5 forks source link

riscv

介绍

本项目基于riscv指令集处理器ri5cy(https://github.com/openhwgroup/cv32e40p),通过添加自定义卷积指令加速卷积运算

硬件架构

ri5cy处理器采用了四级流水线设计,包括取指(Instruction Fetch,简称IF)、译码(Instruction Decode,简称ID)、执行(Instruction Execute,简称EX)和写回(Write-Back,简称WB)四个阶段 输入图片说明

通过在译码模块riscv_decoder中添加自定义卷积指令,并且在执行模块riscv_ex_stage中调用卷积加速模块riscv_mac_ops,使得处理器可以加速卷积运算。 输入图片说明

卷积加速模块使用winograd算法加速运算。

安装教程

需要的工具 1.Verilator 参考https://verilator.org/guide/latest/install.html 版本不能太老 这里用的4.211 下最新版一般没问题

下载&编译 verilator

git clone https://github.com/verilator/verilator # Only first time

Every time you need to build:

unsetenv VERILATOR_ROOT # For csh; ignore error if on bash

unset VERILATOR_ROOT # For bash cd ~/verilator git pull # Make sure git repository is up-to-date

git tag # See what versions exist

git checkout master # Use development branch (e.g. recent bug fixes)

git checkout stable # Use most recent stable release

git checkout v{version} # Switch to specified release version

autoconf # Create ./configure script ./configure # Configure and create Makefile sudo make -j nproc # Build Verilator itself (if error, try just 'make') sudo make install


* 检查 verilator 环境
```bash
verilator -V

2.riscv-gnu-toolchain: https://github.com/riscv-collab/riscv-gnu-toolchain 这里用的tag:2022.03.25或者2022.03.09的版本 某些版本会导致编译报错或者编译完的可执行文件不能被处理器正确运行

git clone https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain/
git checkout 2022.03.25 #或者选择下面版本
# git checkout 2022.03.09

riscv-gnu-toolchain中的qemu太大且编译并不需要,clone后可以排除qemu这个子仓库

cd riscv-gnu-toolchain/
git rm qemu

Git clone的主仓库并不包含子仓库的内容,所以需要继续更新子仓库。

git submodule init
git submodule update --progress

目前发现子模块的riscv-binutils2.38版本存在问题,会导致后续编译器报错找不到一些伪指令,建议使用2.37版本或者2.36.1版本,且更新riscv-dejagnu子模块

cd ~/riscv-gnu-toolchain/riscv-dejagnu/
git checkout
cd ~/riscv-gnu-toolchain/riscv-binutils/
git checkout riscv-binutils-2.37 #或者选择下面版本
# git checkout riscv-binutils-2.36.1

构建工具链需要几个标准包。在 Ubuntu 上,执行以下命令:

sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev

编译 riscv-gnu-toolchain

3.core-v-verif

下载 core-v-verif

实现

验证功能