[Backend] add sophgo backend (#1015)

* Add Sophgo Device

add sophgo backend in fastdeploy

add resnet50, yolov5s, liteseg examples.

* replace sophgo lib with download links; fix model.cc bug

* modify CodeStyle

* remove unuseful files;change the names of sophgo device and sophgo
backend

* sophgo support python and add python examples

* remove unuseful rows in cmake according pr

Co-authored-by: Zilong Xing <zilong.xing@sophgo.com>
This commit is contained in:
Dantès
2023-01-04 15:49:17 +08:00
committed by GitHub
parent 0c292c0766
commit 34bea7649d
41 changed files with 1583 additions and 9 deletions

View File

@@ -26,6 +26,7 @@
| ENABLE_PADDLE_BACKEND | 默认OFF是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) |
| ENABLE_LITE_BACKEND | 默认OFF是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) |
| ENABLE_RKNPU2_BACKEND | 默认OFF是否编译集成RKNPU2后端(RK3588/RK3568/RK3566上推荐打开) |
| ENABLE_SOPHGO_BACKEND | 默认OFF是否编译集成SOPHGO后端, 当在SOPHGO TPU上部署时需要设置为ON |
| WITH_ASCEND | 默认OFF当在华为昇腾NPU上部署时, 需要设置为ON |
| WITH_KUNLUNXIN | 默认OFF当在昆仑芯XPU上部署时需设置为ON |
| WITH_TIMVX | 默认OFF需要在RV1126/RV1109/A311D上部署时需设置为ON |

View File

@@ -0,0 +1,78 @@
# SOPHGO 部署库编译
## SOPHGO 环境准备
SOPHGO支持linux下进行编译,系统为Debian/Ubuntu
安装包由三个文件构成
- [sophon-driver\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/KWqbmEcKp)
- [sophon-libsophon\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/PlvlBXhWY)
- [sophon-libsophon-dev\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/zTErLlpS7)
其中“$arch”为当前机器的硬件架构使用以下命令可以获取当前的服务器arch
```shell
uname -m
```
通常x86_64 机器对应的硬件架构为amd64,arm64 机器对应的硬件架构为 arm64:
```text
- sophon-driver_0.4.2_$arch.deb
- sophon-libsophon_0.4.2_$arch.deb
- sophon-libsophon-dev_0.4.2_$arch.deb
```
其中:sophon-driver 包含了 PCIe 加速卡驱动;sophon-libsophon 包含了运行时环境(库文
件、工具等);sophon-libsophon-dev 包含了开发环境(头文件等)。如果只是在部署环境上安
装,则不需要安装 sophon-libsophon-dev。
可以通过如下步骤安装:
```shell
#安装依赖库,只需要执行一次:
sudo apt install dkms libncurses5
#安装 libsophon:
sudo dpkg -i sophon-*.deb
#在终端执行如下命令,或者登出再登入当前用户后即可使用 bm-smi 等命令:
source /etc/profile
```
安装位置为:
```text
/opt/sophon/
├── driver-0.4.2
├── libsophon-0.4.2
| ├──bin
| ├──data
| ├──include
| └──lib
└── libsophon-current->/opt/sophon/libsophon-0.4.2
```
## C++ SDK编译安装
搭建好编译环境之后,编译命令如下:
```bash
# Download the latest source code
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy
mkdir build && cd build
# CMake configuration with Ascend
cmake -DENABLE_SOPHGO_BACKEND=ON \
-DCMAKE_INSTALL_PREFIX=${PWD}/fastdeploy-sophgo \
-DENABLE_VISION=ON \
..
# Build FastDeploy Ascend C++ SDK
make -j8
make install
```
编译完成之后会在当前的build目录下生成 fastdeploy-sophgo 目录,编译完成。
## Python FastDeploy 库编译
搭建好编译环境之后,编译命令如下:
```bash
# Download the latest source code
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/python
export ENABLE_SOPHGO_BACKEND=ON
export ENABLE_VISION=ON
python setup.py build
python setup.py bdist_wheel
#编译完成后,请用户自行安装当前目录的dist文件夹内的whl包.
```

View File

@@ -0,0 +1,77 @@
# How to Build SOPHGO Deployment Environment
## SOPHGO Environment Preparation
SOPHGO supports compilation on linux, using Debian/Ubuntu as an example
The installation package consists of three files
- [sophon-driver\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/KWqbmEcKp)
- [sophon-libsophon\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/PlvlBXhWY)
- [sophon-libsophon-dev\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/zTErLlpS7)
$arch indicates the hardware architecture of the current machine. Run the following command to obtain the current server arch:
```shell
uname -m
```
Generally, the hardware architecture of x86_64 machines is amd64, so the hardware architecture is arm64:
```text
- sophon-driver_0.4.2_$arch.deb
- sophon-libsophon_0.4.2_$arch.deb
- sophon-libsophon-dev_0.4.2_$arch.deb
```
sophon-driver contains PCIe acceleration card drivers; sophon-libsophon contains the runtime environment (librarys, tools, etc); sophon-libsophon-dev contains the development environment (header files, etc.). If you install packages only on a deployment environment, you do not need to install sophon-libsophon-dev.
You can perform the following steps to install:
```shell
#To install a dependency library, you only need to do this once:
sudo apt install dkms libncurses5
#install libsophon:
sudo dpkg -i sophon-*.deb
#Run the following command on the terminal, log out and then log in the current user to use commands such as bm-smi:
source /etc/profile
```
The position of installation:
```text
/opt/sophon/
├── driver-0.4.2
├── libsophon-0.4.2
| ├──bin
| ├──data
| ├──include
| └──lib
└── libsophon-current->/opt/sophon/libsophon-0.4.2
```
## How to Build and Install C++ SDK
After setting up the compilation environment, the compilation command is as follows
```bash
# Download the latest source code
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy
mkdir build && cd build
# CMake configuration with Ascend
cmake -DENABLE_SOPHGO_BACKEND=ON \
-DCMAKE_INSTALL_PREFIX=${PWD}/fastdeploy-sophgo \
-DENABLE_VISION=ON \
..
# Build FastDeploy Ascend C++ SDK
make -j8
make install
```
When the compilation is complete, the fastdeploy-sophgo directory is created in the current build directory, indicating that the FastDeploy library has been compiled.
## Compiling Python FastDeploy Libraries
After setting up the compilation environment, the compilation command is as follows
```bash
# Download the latest source code
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/python
export ENABLE_SOPHGO_BACKEND=ON
export ENABLE_VISION=ON
python setup.py build
python setup.py bdist_wheel
#After the compilation is complete, please install the whl package in the dist folder of the current directory.
```