Skip to content

Commit

Permalink
caffe on riscv64
Browse files Browse the repository at this point in the history
  • Loading branch information
Peeeeanut committed Jul 12, 2024
1 parent 8b3d8b1 commit 9d8959a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 38 additions & 2 deletions 24-07/caffe-riscv64.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,44 @@

## 1-环境搭建

### dnf install
### step1:安装依赖包

```
sudo dnf install leveldb-devel snappy-devel opencv boost-devel hdf5-devel gflags-devel glog-devel lmdb-devel openblas
sudo dnf install -y leveldb-devel snappy-devel opencv.riscv64 boost-devel hdf5-devel gflags-devel glog-devel lmdb-devel openblas.riscv64 protobuf-devel.riscv64
sudo dnf install -y git wget tar gcc-c++ unzip automake libtool autocon
```

在riscv平台上,采用dnf install的方式对protobuf进行了安装,原因是可以通过修改caffe的源码来完成caffe对高版本protobuf的适配。

### step2:编译caffe

```
git clone https://github.com/BVLC/caffe.git
cd caffe
# 这一步用来解决高版本protobuf和caffe不适配的问题
sed -i 's/coded_input->SetTotalBytesLimit(kProtoReadBytesLimit, 536870912);/coded_input->SetTotalBytesLimit(kProtoReadBytesLimit);/g' src/caffe/util/io.cpp
# 下载适配于riscv64的Makefile.config
wget https://raw.githubusercontent.com/6eanut/NOTEBOOK/main/24-07/caffe/makefiles/riscv64-Makefile.config
mv riscv64-Makefile.config Makefile.config
# 修改caffe源码以适配opencv4.x
sed -i 's/CV_LOAD_IMAGE_COLOR/cv::IMREAD_COLOR/g' src/caffe/layers/window_data_layer.cpp
sed -i 's/CV_LOAD_IMAGE_COLOR/cv::IMREAD_COLOR/g' src/caffe/util/io.cpp
sed -i 's/CV_LOAD_IMAGE_GRAYSCALE/cv::ImreadModes::IMREAD_GRAYSCALE/g' src/caffe/util/io.cpp
sed -i 's/CV_LOAD_IMAGE_COLOR/cv::IMREAD_COLOR/g' src/caffe/test/test_io.cpp
sed -i 's/CV_LOAD_IMAGE_GRAYSCALE/cv::ImreadModes::IMREAD_GRAYSCALE/g' src/caffe/test/test_io.cpp
# 设置LDFLAGS环境变量,否则在make test时会出现链接器未能正确地找到libgfortran.so.5库的报错
export LDFLAGS="-L/usr/lib -Wl,-rpath=/usr/lib -lgfortran"
make all -j $(nproc)
make test -j $(nproc)
make runtest -j $(nproc)
```

在aarch64上,采用降低protobuf版本的方式解决了caffe和protobuf版本不适配的问题;在riscv64上,采用修改caffe源码的方式解决了两者不适配的问题。

> 环境搭建自动化[脚本](caffe/shell/caffe-riscv64.sh)
## 2-用例运行

下载deploy文件->下载perf测试脚本->对deploy文件分别进行time

> 用例运行自动化[脚本](caffe/shell/caffe-test.sh)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
[00 Caffe on Aarch64](24-07/caffe-aarch64.md)

[01 Tensorflow on Aarch64 (Full edition)](24-07/tensorflow-aarch64.md)

[02 Caffe on RISC-V](24-07/caffe-riscv64.md)

0 comments on commit 9d8959a

Please sign in to comment.