forked from PaddlePaddle/FastDeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backend] A311D support (PaddlePaddle#825)
* add A311D support * update code * update toolchain * update opencv_armhf lib * update libs * update code * add install script * update bos link * update toolchain
- Loading branch information
1 parent
f6e8fe7
commit 6a1a3d0
Showing
36 changed files
with
1,094 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,45 @@ | ||
if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) | ||
set(CMAKE_SYSTEM_NAME Linux) | ||
set(CMAKE_SYSTEM_PROCESSOR arm) | ||
set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") | ||
set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++") | ||
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}") | ||
set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_C_FLAGS}" ) | ||
set(CMAKE_BUILD_TYPE MinSizeRel) | ||
else() | ||
if(NOT ${ENABLE_LITE_BACKEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_LITE_BACKEND=ON") | ||
set(ENABLE_LITE_BACKEND ON) | ||
endif() | ||
if(${ENABLE_PADDLE_FRONTEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_PADDLE_FRONTEND=OFF") | ||
set(ENABLE_PADDLE_FRONTEND OFF) | ||
endif() | ||
if(${ENABLE_ORT_BACKEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_ORT_BACKEND=OFF") | ||
set(ENABLE_ORT_BACKEND OFF) | ||
endif() | ||
if(${ENABLE_PADDLE_BACKEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_PADDLE_BACKEND=OFF") | ||
set(ENABLE_PADDLE_BACKEND OFF) | ||
endif() | ||
if(${ENABLE_OPENVINO_BACKEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_OPENVINO_BACKEND=OFF") | ||
set(ENABLE_OPENVINO_BACKEND OFF) | ||
endif() | ||
if(${ENABLE_TRT_BACKEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_TRT_BACKEND=OFF") | ||
set(ENABLE_TRT_BACKEND OFF) | ||
endif() | ||
|
||
if(${WITH_GPU}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DWITH_GPU=OFF") | ||
set(WITH_GPU OFF) | ||
endif() | ||
if(NOT ${ENABLE_LITE_BACKEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_LITE_BACKEND=ON") | ||
set(ENABLE_LITE_BACKEND ON) | ||
endif() | ||
if(${ENABLE_PADDLE_FRONTEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_PADDLE_FRONTEND=OFF") | ||
set(ENABLE_PADDLE_FRONTEND OFF) | ||
endif() | ||
if(${ENABLE_ORT_BACKEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_ORT_BACKEND=OFF") | ||
set(ENABLE_ORT_BACKEND OFF) | ||
endif() | ||
if(${ENABLE_PADDLE_BACKEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_PADDLE_BACKEND=OFF") | ||
set(ENABLE_PADDLE_BACKEND OFF) | ||
endif() | ||
if(${ENABLE_OPENVINO_BACKEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_OPENVINO_BACKEND=OFF") | ||
set(ENABLE_OPENVINO_BACKEND OFF) | ||
endif() | ||
if(${ENABLE_TRT_BACKEND}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_TRT_BACKEND=OFF") | ||
set(ENABLE_TRT_BACKEND OFF) | ||
endif() | ||
|
||
if(${ENABLE_OPENCV_CUDA}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_OPENCV_CUDA=OFF") | ||
set(ENABLE_OPENCV_CUDA OFF) | ||
endif() | ||
if(${WITH_GPU}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DWITH_GPU=OFF") | ||
set(WITH_GPU OFF) | ||
endif() | ||
|
||
if(${ENABLE_TEXT}) | ||
set(ENABLE_TEXT OFF CACHE BOOL "Force ENABLE_TEXT OFF" FORCE) | ||
message(STATUS "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_TEXT=OFF") | ||
endif() | ||
if (DEFINED CMAKE_INSTALL_PREFIX) | ||
install(FILES ${PROJECT_SOURCE_DIR}/cmake/timvx.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}) | ||
endif() | ||
if(${ENABLE_OPENCV_CUDA}) | ||
message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_OPENCV_CUDA=OFF") | ||
set(ENABLE_OPENCV_CUDA OFF) | ||
endif() | ||
|
||
if(${ENABLE_TEXT}) | ||
set(ENABLE_TEXT OFF CACHE BOOL "Force ENABLE_TEXT OFF" FORCE) | ||
message(STATUS "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_TEXT=OFF") | ||
endif() | ||
|
||
install(FILES ${PROJECT_SOURCE_DIR}/cmake/timvx.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}) | ||
install(FILES ${PROJECT_SOURCE_DIR}/cmake/toolchain.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
if (DEFINED TARGET_ABI) | ||
set(CMAKE_SYSTEM_NAME Linux) | ||
set(CMAKE_BUILD_TYPE MinSizeRel) | ||
if(${TARGET_ABI} MATCHES "armhf") | ||
set(CMAKE_SYSTEM_PROCESSOR arm) | ||
set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") | ||
set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++") | ||
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}") | ||
set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_C_FLAGS}" ) | ||
set(OPENCV_URL "https://bj.bcebos.com/fastdeploy/third_libs/opencv-linux-armv7hf-4.6.0.tgz") | ||
set(OPENCV_FILENAME "opencv-linux-armv7hf-4.6.0") | ||
if(WITH_TIMVX) | ||
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-armhf-timvx-1130.tgz") | ||
else() | ||
message(STATUS "PADDLELITE_URL will be configured if WITH_TIMVX=ON.") | ||
endif() | ||
set(THIRD_PARTY_PATH ${CMAKE_CURRENT_BINARY_DIR}/third_libs) | ||
set(OpenCV_DIR ${THIRD_PARTY_PATH}/install/opencv/lib/cmake/opencv4) | ||
elseif(${TARGET_ABI} MATCHES "arm64") | ||
set(CMAKE_SYSTEM_PROCESSOR aarch64) | ||
set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc") | ||
set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++") | ||
set(CMAKE_CXX_FLAGS "-march=armv8-a ${CMAKE_CXX_FLAGS}") | ||
set(CMAKE_C_FLAGS "-march=armv8-a ${CMAKE_C_FLAGS}") | ||
set(OPENCV_URL "https://bj.bcebos.com/fastdeploy/third_libs/opencv-linux-aarch64-4.6.0.tgz") | ||
set(OPENCV_FILENAME "opencv-linux-aarch64-4.6.0") | ||
if(WITH_TIMVX) | ||
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-aarch64-timvx-20221209.tgz") | ||
else() | ||
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-arm64-20221209.tgz") | ||
endif() | ||
set(THIRD_PARTY_PATH ${CMAKE_CURRENT_BINARY_DIR}/third_libs) | ||
set(OpenCV_DIR ${THIRD_PARTY_PATH}/install/opencv/lib/cmake/opencv4) | ||
else() | ||
message(FATAL_ERROR "When cross-compiling, please set the -DTARGET_ABI to arm64 or armhf.") | ||
endif() | ||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# 晶晨 A311D 部署环境编译安装 | ||
|
||
FastDeploy 基于 Paddle-Lite 后端支持在晶晨 NPU 上进行部署推理。 | ||
更多详细的信息请参考:[PaddleLite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html)。 | ||
|
||
本文档介绍如何编译基于 PaddleLite 的 C++ FastDeploy 交叉编译库。 | ||
|
||
相关编译选项说明如下: | ||
|编译选项|默认值|说明|备注| | ||
|:---|:---|:---|:---| | ||
|ENABLE_LITE_BACKEND|OFF|编译A311D部署库时需要设置为ON| - | | ||
|WITH_TIMVX|OFF|编译A311D部署库时需要设置为ON| - | | ||
|
||
更多编译选项请参考[FastDeploy编译选项说明](./README.md) | ||
|
||
## 交叉编译环境搭建 | ||
|
||
### 宿主机环境需求 | ||
- os:Ubuntu == 16.04 | ||
- cmake: version >= 3.10.0 | ||
|
||
### 环境搭建 | ||
可以进入 FastDeploy/tools/timvx 目录,使用如下命令一键安装: | ||
```bash | ||
cd FastDeploy/tools/timvx | ||
bash install.sh | ||
``` | ||
也可以按照如下命令安装: | ||
```bash | ||
# 1. Install basic software | ||
apt update | ||
apt-get install -y --no-install-recommends \ | ||
gcc g++ git make wget python unzip | ||
|
||
# 2. Install arm gcc toolchains | ||
apt-get install -y --no-install-recommends \ | ||
g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \ | ||
g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \ | ||
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | ||
|
||
# 3. Install cmake 3.10 or above | ||
wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \ | ||
tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \ | ||
mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \ | ||
ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \ | ||
ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake | ||
``` | ||
|
||
## 基于 PaddleLite 的 FastDeploy 交叉编译库编译 | ||
搭建好交叉编译环境之后,编译命令如下: | ||
```bash | ||
# Download the latest source code | ||
git clone https://github.com/PaddlePaddle/FastDeploy.git | ||
cd FastDeploy | ||
mkdir build && cd build | ||
|
||
# CMake configuration with A311D toolchain | ||
cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \ | ||
-DWITH_TIMVX=ON \ | ||
-DTARGET_ABI=arm64 \ | ||
-DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \ | ||
-DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启 | ||
-Wno-dev .. | ||
|
||
# Build FastDeploy A311D C++ SDK | ||
make -j8 | ||
make install | ||
``` | ||
编译完成之后,会生成 fastdeploy-tmivx 目录,表示基于 PadddleLite TIM-VX 的 FastDeploy 库编译完成。 | ||
|
||
## 准备设备运行环境 | ||
部署前要保证晶晨 Linux Kernel NPU 驱动 galcore.so 版本及所适用的芯片型号与依赖库保持一致,在部署前,请登录开发板,并通过命令行输入以下命令查询 NPU 驱动版本,晶晨建议的驱动版本为:6.4.4.3 | ||
```bash | ||
dmesg | grep Galcore | ||
``` | ||
|
||
如果当前版本不符合上述,请用户仔细阅读以下内容,以保证底层 NPU 驱动环境正确。 | ||
|
||
有两种方式可以修改当前的 NPU 驱动版本: | ||
1. 手动替换 NPU 驱动版本。(推荐) | ||
2. 刷机,刷取 NPU 驱动版本符合要求的固件。 | ||
|
||
### 手动替换 NPU 驱动版本 | ||
1. 使用如下命令下载解压 PaddleLite demo,其中提供了现成的驱动文件 | ||
```bash | ||
wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz | ||
tar -xf PaddleLite-generic-demo.tar.gz | ||
``` | ||
2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本, | ||
3. 将 `PaddleLite-generic-demo/libs/PaddleLite/linux/arm64/lib/verisilicon_timvx/viv_sdk_6_4_4_3/lib/a311d/4.9.113` 路径下的 `galcore.ko` 上传至开发板。 | ||
|
||
4. 登录开发板,命令行输入 `sudo rmmod galcore` 来卸载原始驱动,输入 `sudo insmod galcore.ko` 来加载传上设备的驱动。(是否需要 sudo 根据开发板实际情况,部分 adb 链接的设备请提前 adb root)。此步骤如果操作失败,请跳转至方法 2。 | ||
5. 在开发板中输入 `dmesg | grep Galcore` 查询 NPU 驱动版本,确定为:6.4.4.3 | ||
|
||
### 刷机 | ||
根据具体的开发板型号,向开发板卖家或官网客服索要 6.4.4.3 版本 NPU 驱动对应的固件和刷机方法。 | ||
|
||
更多细节请参考:[PaddleLite准备设备环境](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing) | ||
|
||
## 基于 FastDeploy 在 A311D 上的部署示例 | ||
1. A311D 上部署 PaddleClas 分类模型请参考:[PaddleClas 分类模型在 A311D 上的 C++ 部署示例](../../../examples/vision/classification/paddleclas/a311d/README.md) | ||
|
||
2. A311D 上部署 PPYOLOE 检测模型请参考:[PPYOLOE 检测模型在 A311D 上的 C++ 部署示例](../../../examples/vision/detection/paddledetection/a311d/README.md) | ||
|
||
3. A311D 上部署 YOLOv5 检测模型请参考:[YOLOv5 检测模型在 A311D 上的 C++ 部署示例](../../../examples/vision/detection/yolov5/a311d/README.md) | ||
|
||
4. A311D 上部署 PP-LiteSeg 分割模型请参考:[PP-LiteSeg 分割模型在 A311D 上的 C++ 部署示例](../../../examples/vision/segmentation/paddleseg/a311d/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# PaddleClas 量化模型在 A311D 上的部署 | ||
目前 FastDeploy 已经支持基于 PaddleLite 部署 PaddleClas 量化模型到 A311D 上。 | ||
|
||
模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) | ||
|
||
|
||
## 详细部署文档 | ||
|
||
在 A311D 上只支持 C++ 的部署。 | ||
|
||
- [C++部署](cpp) |
Oops, something went wrong.