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] Add Huawei Ascend NPU deploy using PaddleLite CANN. (Paddle…
…Paddle#757) * Add Huawei Ascend NPU deploy through PaddleLite CANN * Add NNAdapter interface for paddlelite * Modify Huawei Ascend Cmake * Update way for compiling Huawei Ascend NPU deployment * remove UseLiteBackend in UseCANN * Support compile python whlee * Change names of nnadapter API * Add nnadapter pybind and remove useless API * Support Python deployment on Huawei Ascend NPU * Add models suppor for ascend * Add PPOCR rec reszie for ascend * fix conflict for ascend * Rename CANN to Ascend * Rename CANN to Ascend * Improve ascend * fix ascend bug * improve ascend docs * improve ascend docs * improve ascend docs * Improve Ascend * Improve Ascend * Move ascend python demo * Imporve ascend * Improve ascend * Improve ascend * Improve ascend * Improve ascend * Imporve ascend * Imporve ascend * Improve ascend
- Loading branch information
Showing
42 changed files
with
713 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") | ||
message(FATAL_ERROR "Huawei Ascend NPU is supported on Linux aarch64 platform for now.") | ||
endif() | ||
|
||
if(NOT ${ENABLE_LITE_BACKEND}) | ||
set(ENABLE_LITE_BACKEND ON) | ||
endif() | ||
|
||
if (NOT BUILD_FASTDEPLOY_PYTHON) | ||
message(STATUS "Build FastDeploy Ascend C++ library.") | ||
if(NOT PADDLELITE_URL) | ||
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/test/lite-linux_arm64_huawei_ascend_npu_1121.tgz") | ||
endif() | ||
else () | ||
message(STATUS "Build FastDeploy Ascend Python library.") | ||
if(NOT PADDLELITE_URL) | ||
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/test/lite-linux_arm64_huawei_ascend_npu_python_1207.tgz") | ||
endif() | ||
execute_process(COMMAND sh -c "ls *.so*" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/paddlelite/lib | ||
COMMAND sh -c "xargs ${PATCHELF_EXE} --set-rpath '$ORIGIN'" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/paddlelite/lib | ||
RESULT_VARIABLE result | ||
OUTPUT_VARIABLE curr_out | ||
ERROR_VARIABLE curr_out) | ||
if(ret EQUAL "1") | ||
message(FATAL_ERROR "Failed to patchelf Paddle Lite libraries when using Ascend.") | ||
endif() | ||
message(STATUS "result:${result} out:${curr_out}") | ||
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
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,48 @@ | ||
[简体中文](README_CN.md)| English | ||
|
||
# Tutorials | ||
|
||
## Install | ||
|
||
- [Install FastDeploy Prebuilt Libraries](en/build_and_install/download_prebuilt_libraries.md) | ||
- [Build and Install FastDeploy Library on GPU Platform](en/build_and_install/gpu.md) | ||
- [Build and Install FastDeploy Library on CPU Platform](en/build_and_install/cpu.md) | ||
- [Build and Install FastDeploy Library on IPU Platform](en/build_and_install/ipu.md) | ||
- [Build and Install FastDeploy Library on KunlunXin XPU Platform](en/build_and_install/xpu.md) | ||
- [Build and Install on RV1126 Platform](en/build_and_install/rv1126.md) | ||
- [Build and Install on RK3588 Platform](en/build_and_install/rknpu2.md) | ||
- [Build and Install on A311D Platform](en/build_and_install/a311d.md) | ||
- [Build and Install on Huawei Ascend Platform](en/build_and_install/huawei_ascend.md) | ||
- [Build and Install FastDeploy Library on Nvidia Jetson Platform](en/build_and_install/jetson.md) | ||
- [Build and Install FastDeploy Library on Android Platform](en/build_and_install/android.md) | ||
- [Build and Install FastDeploy Serving Deployment Image](../serving/docs/EN/compile-en.md) | ||
|
||
## A Quick Start - Demos | ||
|
||
- [Python Deployment Demo](en/quick_start/models/python.md) | ||
- [C++ Deployment Demo](en/quick_start/models/cpp.md) | ||
- [A Quick Start on Runtime Python](en/quick_start/runtime/python.md) | ||
- [A Quick Start on Runtime C++](en/quick_start/runtime/cpp.md) | ||
|
||
## API | ||
|
||
- [Python API](https://baidu-paddle.github.io/fastdeploy-api/python/html/) | ||
- [C++ API](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/) | ||
- [Android Java API](../java/android) | ||
|
||
## Performance Optimization | ||
|
||
- [Quantization Acceleration](en/quantize.md) | ||
|
||
## Frequent Q&As | ||
|
||
- [1. How to Change Inference Backends](en/faq/how_to_change_backend.md) | ||
- [2. How to Use FastDeploy C++ SDK on Windows Platform](en/faq/use_sdk_on_windows.md) | ||
- [3. How to Use FastDeploy C++ SDK on Android Platform](en/faq/use_cpp_sdk_on_android.md) | ||
- [4. Tricks of TensorRT](en/faq/tensorrt_tricks.md) | ||
- [5. How to Develop a New Model](en/faq/develop_a_new_model.md) | ||
|
||
## More FastDeploy Deployment Module | ||
|
||
- [Deployment AI Model as a Service](../serving) | ||
- [Benchmark Testing](../benchmark) |
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,99 @@ | ||
# 华为昇腾NPU 部署环境编译准备 | ||
|
||
FastDeploy基于 Paddle-Lite 后端, 支持在华为昇腾NPU上进行部署推理。 | ||
更多详细的信息请参考:[Paddle Lite部署示例](https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/docs/demo_guides/huawei_ascend_npu.md)。 | ||
|
||
本文档介绍如何在ARM Linux操作系统环境下, 编译基于 Paddle Lite 的 C++ 与 Python 的FastDeploy源码, 生成目标硬件为华为昇腾NPU的预测库。 | ||
|
||
更多编译选项请参考[FastDeploy编译选项说明](./README.md) | ||
|
||
|
||
## 一.华为昇腾环境准备 | ||
- Atlas 300I Pro 推理卡, 详情见[规格说明书](https://e.huawei.com/cn/products/cloud-computing-dc/atlas/atlas-300i-pro) | ||
- 安装Atlas 300I Pro 推理卡的驱动和固件包(Driver 和 Firmware) | ||
- 配套驱动和固件包下载: | ||
- https://www.hiascend.com/hardware/firmware-drivers?tag=community(社区版) | ||
- https://www.hiascend.com/hardware/firmware-drivers?tag=commercial(商业版) | ||
- 驱动:Atlas-300i-pro-npu-driver_5.1.rc2_linux-aarch64.run | ||
- 固件:Atlas-300i-pro-npu-firmware_5.1.rc2.run | ||
- 安装驱动和固件包: | ||
|
||
```shell | ||
# 增加可执行权限 | ||
$ chmod +x *.run | ||
# 安装驱动和固件包 | ||
$ ./Atlas-300i-pro-npu-driver_5.1.rc2_linux-aarch64.run --full | ||
$ ./Atlas-300i-pro-npu-firmware_5.1.rc2.run --full | ||
# 重启服务器 | ||
$ reboot | ||
# 查看驱动信息,确认安装成功 | ||
$ npu-smi info | ||
``` | ||
- 更多系统和详细信息见[昇腾硬件产品文档](https://www.hiascend.com/document?tag=hardware) | ||
|
||
|
||
## 二.编译环境搭建 | ||
|
||
### 宿主机环境需求 | ||
- os:ARM-Linux | ||
- gcc、g++、git、make、wget、python、pip、python-dev、patchelf | ||
- cmake(建议使用 3.10 或以上版本) | ||
|
||
### 使用Docker开发环境 | ||
为了保证和FastDeploy验证过的编译环境一致,建议使用Docker开发环境进行配置. | ||
|
||
```shell | ||
# 下载 Dockerfile | ||
$ wget https://bj.bcebos.com/fastdeploy/test/Ascend_ubuntu18.04_aarch64_5.1.rc2.Dockerfile | ||
# 通过 Dockerfile 生成镜像 | ||
$ docker build --network=host -f Ascend_ubuntu18.04_aarch64_5.1.rc2.Dockerfile -t Paddle Lite/ascend_aarch64:cann_5.1.rc2 . | ||
# 创建容器 | ||
$ docker run -itd --privileged --name=ascend-aarch64 --net=host -v $PWD:/Work -w /Work --device=/dev/davinci0 --device=/dev/davinci_manager --device=/dev/hisi_hdc --device /dev/devmm_svm -v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi -v /usr/local/Ascend/driver/:/usr/local/Ascend/driver/ Paddle Lite/ascend_aarch64:cann_5.1.rc2 /bin/bash | ||
# 进入容器 | ||
$ docker exec -it ascend-aarch64 /bin/bash | ||
# 确认容器的 Ascend 环境是否创建成功 | ||
$ npu-smi info | ||
``` | ||
以上步骤成功后,用户可以直接在docker内部开始FastDeploy的编译. | ||
|
||
注意: | ||
- 如果用户在Docker内想使用其他的CANN版本,请自行更新 Dockerfile 文件内的 CANN 下载路径, 同时更新相应的驱动和固件. 当前Dockerfile内默认为[CANN 5.1.RC2](https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/CANN/CANN%205.1.RC2/Ascend-cann-toolkit_5.1.RC2_linux-aarch64.run). | ||
- 如果用户不想使用docker,可以参考由Paddle Lite提供的[ARM Linux环境下的编译环境准备](https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/docs/source_compile/arm_linux_compile_arm_linux.rst)自行配置编译环境, 之后再自行下载并安装相应的CANN软件包来完成配置. | ||
|
||
## 三.基于 Paddle Lite 的 C++ FastDeploy 库编译 | ||
搭建好编译环境之后,编译命令如下: | ||
```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 -DWITH_ASCEND=ON \ | ||
-DCMAKE_INSTALL_PREFIX=fastdeploy-ascend \ | ||
-DENABLE_VISION=ON \ | ||
.. | ||
|
||
# Build FastDeploy Ascend C++ SDK | ||
make -j8 | ||
make install | ||
``` | ||
编译完成之后,会在当前的build目录下生成 fastdeploy-ascend 目录,表示基于 Paddle Lite 的 FastDeploy 库编译完成。 | ||
|
||
## 四.基于 Paddle Lite 的 Python FastDeploy 库编译 | ||
搭建好编译环境之后,编译命令如下: | ||
```bash | ||
# Download the latest source code | ||
git clone https://github.com/PaddlePaddle/FastDeploy.git | ||
cd FastDeploy/python | ||
export WITH_ASCEND=ON | ||
export ENABLE_VISION=ON | ||
|
||
python setup.py build | ||
python setup.py bdist_wheel | ||
|
||
#编译完成后,请用户自行安装当前目录的dist文件夹内的whl包. | ||
``` | ||
|
||
- 华为昇腾NPU 上使用C++部署 PaddleClas 分类模型请参考:[PaddleClas 华为升腾NPU C++ 部署示例](../../../examples/vision/classification/paddleclas/ascend/cpp/README.md) | ||
- 华为昇腾NPU 上使用Python部署 PaddleClas 分类模型请参考:[PaddleClas 华为升腾NPU Python 部署示例](../../../examples/vision/classification/paddleclas/ascend/python/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[English](../../en/faq/use_sdk_on_linux.md) | 中文 | ||
|
||
|
||
# Linux上使用C++在华为昇腾部署 | ||
|
||
在完成部署示例的编译之后, 在运行程序之前, 由于我们需要借助华为昇腾工具包的功能, 所以还需要导入一些环境变量来初始化部署环境. | ||
用户可以直接使用如下脚本(位于编译好的FastDeploy库的目录下), 来初始化华为昇腾部署的环境. | ||
|
||
|
||
``` | ||
# 我们默认的昇腾工具包的路径如下, | ||
# HUAWEI_ASCEND_TOOLKIT_HOME="/usr/local/Ascend/ascend-toolkit/latest" | ||
# HUAWEI_ASCEND_DRIVER_PATH="/usr/local/Ascend/driver" | ||
# 如果用户的安装目录与他不同, 需要自己先手动export. | ||
# export HUAWEI_ASCEND_TOOLKIT_HOME="Your_ascend_toolkit_path" | ||
# export HUAWEI_ASCEND_DRIVER_PATH="Your_ascend_driver_path" | ||
source fastdeploy-ascend/fastdeploy_init.sh | ||
``` | ||
|
||
注意此命令执行后仅在当前的命令环境中生效(切换一个新的终端窗口,或关闭窗口重新打开后会无效),如若需要在系统中持续生效,可将这些环境变量加入到`~/.bashrc`文件中。 |
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,98 @@ | ||
# How to build Huawei Ascend Deployment Environment | ||
|
||
Based on the Paddle-Lite backend, FastDeploy supports model inference on Huawei's Ascend NPU. | ||
For more detailed information, please refer to: [Paddle Lite Deployment Example](https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/docs/demo_guides/huawei_ascend_npu.md). | ||
|
||
This document describes how to compile C++ and Python FastDeploy source code under ARM Linux OS environment to generate prediction libraries for Huawei Sunrise NPU as the target hardware. | ||
|
||
For more compilation options, please refer to the [FastDeploy compilation options description](./README.md) | ||
|
||
## Huawei Ascend Environment Preparation | ||
- Atlas 300I Pro, see detailes at [Spec Sheet](https://e.huawei.com/cn/products/cloud-computing-dc/atlas/atlas-300i-pro) | ||
- Install the driver and firmware package (Driver and Firmware) for the Atlas 300I Pro | ||
- Download the matching driver and firmware package at: | ||
- https://www.hiascend.com/hardware/firmware-drivers?tag=community(Community Edition) | ||
- https://www.hiascend.com/hardware/firmware-drivers?tag=commercial(Commercial version) | ||
- driver:Atlas-300i-pro-npu-driver_5.1.rc2_linux-aarch64.run | ||
- firmware:Atlas-300i-pro-npu-firmware_5.1.rc2.run | ||
- Installing drivers and firmware packages: | ||
|
||
```shell | ||
$ chmod +x *.run | ||
|
||
$ ./Atlas-300i-pro-npu-driver_5.1.rc2_linux-aarch64.run --full | ||
$ ./Atlas-300i-pro-npu-firmware_5.1.rc2.run --full | ||
|
||
$ reboot | ||
# Check the driver information to confirm successful installation | ||
$ npu-smi info | ||
``` | ||
- More system and detailed information is available in the [Ascend Hardware Product Documentation](https://www.hiascend.com/document?tag=hardware) | ||
|
||
## Compilation environment construction | ||
|
||
### Host environment requirements | ||
- os: ARM-Linux | ||
- gcc, g++, git, make, wget, python, pip, python-dev, patchelf | ||
- cmake (version 3.10 or above recommended) | ||
|
||
### Using Docker development environment | ||
In order to ensure consistency with the FastDeploy verified build environment, it is recommended to use the Docker development environment for configuration. | ||
|
||
```shell | ||
# Download Dockerfile | ||
$ wget https://bj.bcebos.com/fastdeploy/test/Ascend_ubuntu18.04_aarch64_5.1.rc2.Dockerfile | ||
# Create docker images | ||
$ docker build --network=host -f Ascend_ubuntu18.04_aarch64_5.1.rc2.Dockerfile -t Paddle Lite/ascend_aarch64:cann_5.1.rc2 . | ||
# Create container | ||
$ docker run -itd --privileged --name=ascend-aarch64 --net=host -v $PWD:/Work -w /Work --device=/dev/davinci0 --device=/dev/davinci_manager --device=/dev/hisi_hdc --device /dev/devmm_svm -v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi -v /usr/local/Ascend/driver/:/usr/local/Ascend/driver/ Paddle Lite/ascend_aarch64:cann_5.1.rc2 /bin/bash | ||
# Enter the container | ||
$ docker exec -it ascend-aarch64 /bin/bash | ||
# Verify that the Ascend environment for the container is created successfully | ||
$ npu-smi info | ||
``` | ||
Once the above steps are successful, the user can start compiling FastDeploy directly from within docker. | ||
|
||
Note: | ||
- If you want to use another CANN version in Docker, please update the CANN download path in the Dockerfile file, and update the corresponding driver and firmware. The current default in Dockerfile is [CANN 5.1.RC2](https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/CANN/CANN%205.1.RC2/Ascend-cann-toolkit_5.1.RC2_linux-aarch64.run). | ||
- If users do not want to use docker, you can refer to [Compile Environment Preparation for ARM Linux Environments](https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/docs/source_compile/arm_linux_compile_arm_linux.rst) provided by Paddle Lite and configure your own compilation environment, and then download and install the proper CANN packages to complete the configuration. | ||
|
||
## C++ FastDeploy library compilation based on Paddle Lite | ||
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 -DWITH_ASCEND=ON \ | ||
-DCMAKE_INSTALL_PREFIX=fastdeploy-ascend \ | ||
-DENABLE_VISION=ON \ | ||
.. | ||
|
||
# Build FastDeploy Ascend C++ SDK | ||
make -j8 | ||
make install | ||
``` | ||
When the compilation is complete, the fastdeploy-ascend directory is created in the current build directory, indicating that the FastDeploy library has been compiled. | ||
|
||
## Compiling Python FastDeploy Libraries Based on Paddle Lite | ||
|
||
```bash | ||
# Download the latest source code | ||
git clone https://github.com/PaddlePaddle/FastDeploy.git | ||
cd FastDeploy/python | ||
export WITH_ASCEND=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. | ||
``` | ||
|
||
Deploying PaddleClas Classification Model on Huawei Ascend NPU using C++ please refer to: [PaddleClas Huawei Ascend NPU C++ Deployment Example](../../../examples/vision/classification/paddleclas/ascend/cpp/README.md) | ||
|
||
Deploying PaddleClas classification model on Huawei Ascend NPU using Python please refer to: [PaddleClas Huawei Ascend NPU Python Deployment Example](../../../examples/vision/classification/paddleclas/ascend/python/README.md) |
Oops, something went wrong.