Files
FastDeploy/docs/cn/build_and_install/gpu.md
2022-11-14 20:50:01 +08:00

143 lines
4.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# GPU部署库编译
FastDeploy当前在GPU环境支持Paddle Inference、ONNX Runtime和TensorRT但同时在Linux&Windows的GPU环境也同时支持CPU硬件因此编译时也可以同步将CPU的推理后端OpenVINO编译集成
| 后端 | 平台 | 支持模型格式 | 说明 |
| :--- | :---- | :----------- | :--- |
| Paddle&nbsp;Inference | Windows(x64)<br>Linux(x64) | Paddle | 同时支持CPU/GPU编译开关`ENABLE_PADDLE_BACKEND`为ON或OFF控制, 默认OFF |
| ONNX&nbsp;Runtime | Windows(x64)<br>Linux(x64/aarch64)<br>Mac(x86/arm64) | Paddle/ONNX | 同时支持CPU/GPU编译开关`ENABLE_ORT_BACKEND`为ON或OFF控制默认OFF |
| TensorRT | Windows(x64)<br>Linux(x64) | Paddle/ONNX | 仅支持GPU编译开关`ENABLE_TRT_BACKEND`为ON或OFF控制默认OFF |
| OpenVINO | Windows(x64)<br>Linux(x64) | Paddle/ONNX | 仅支持CPU编译开关`ENABLE_OPENVINO_BACKEND`为ON或OFF控制默认OFF |
注意编译GPU环境时需额外指定`WITH_GPU`为ON设定`CUDA_DIRECTORY`如若需集成TensorRT还需同时设定`TRT_DIRECTORY`
## C++ SDK编译安装
### Linux
Linux上编译需满足
- gcc/g++ >= 5.4(推荐8.2)
- cmake >= 3.18.0
- cuda >= 11.2
- cudnn >= 8.2
```bash
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy
mkdir build && cd build
cmake .. -DENABLE_ORT_BACKEND=ON \
-DENABLE_PADDLE_BACKEND=ON \
-DENABLE_OPENVINO_BACKEND=ON \
-DENABLE_TRT_BACKEND=ON \
-DWITH_GPU=ON \
-DTRT_DIRECTORY=/Paddle/TensorRT-8.4.1.5 \
-DCUDA_DIRECTORY=/usr/local/cuda \
-DCMAKE_INSTALL_PREFIX=${PWD}/compiled_fastdeploy_sdk \
-DENABLE_VISION=ON \
-DENABLE_TEXT=ON
make -j12
make install
```
### Windows
Windows编译需要满足条件
- Windows 10/11 x64
- Visual Studio 2019
- cuda >= 11.2
- cudnn >= 8.2
注意安装CUDA时需要勾选`Visual Studio Integration`, 或者手动将`C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\extras\visual_studio_integration\MSBuildExtensions\`文件夹下的4个文件复制到`C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\`文件夹。否则执行cmake命令时可能会遇到`No CUDA toolset found`报错。
在Windows菜单中找到`x64 Native Tools Command Prompt for VS 2019`打开,执行如下命令
```bat
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy
mkdir build && cd build
cmake .. -G "Visual Studio 16 2019" -A x64 ^
-DENABLE_ORT_BACKEND=ON ^
-DENABLE_PADDLE_BACKEND=ON ^
-DENABLE_OPENVINO_BACKEND=ON ^
-DENABLE_TRT_BACKEND=ON ^
-DENABLE_VISION=ON ^
-DENABLE_TEXT=ON ^
-DWITH_GPU=ON ^
-DTRT_DIRECTORY="D:\Paddle\TensorRT-8.4.1.5" ^
-DCUDA_DIRECTORY="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2" ^
-DCMAKE_INSTALL_PREFIX="D:\Paddle\compiled_fastdeploy"
msbuild fastdeploy.sln /m /p:Configuration=Release /p:Platform=x64
msbuild INSTALL.vcxproj /m /p:Configuration=Release /p:Platform=x64
```
编译完成后,即在`CMAKE_INSTALL_PREFIX`指定的目录下生成C++推理库
如您使用CMake GUI可参考文档[Windows使用CMakeGUI + Visual Studio 2019 IDE编译](../faq/build_on_win_with_gui.md)
## Python编译安装
### Linux
编译过程需要满足
- gcc/g++ >= 5.4(推荐8.2)
- cmake >= 3.18.0
- python >= 3.6
- cuda >= 11.2
- cudnn >= 8.2
Python打包依赖`wheel`,编译前请先执行`pip install wheel`
所有编译选项通过环境变量导入
```bash
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/python
export ENABLE_ORT_BACKEND=ON
export ENABLE_PADDLE_BACKEND=ON
export ENABLE_OPENVINO_BACKEND=ON
export ENABLE_VISION=ON
export ENABLE_TEXT=ON
export ENABLE_TRT_BACKEND=ON
export WITH_GPU=ON
export TRT_DIRECTORY=/Paddle/TensorRT-8.4.1.5
export CUDA_DIRECTORY=/usr/local/cuda
python setup.py build
python setup.py bdist_wheel
```
### Windows
编译过程同样需要满足
- Windows 10/11 x64
- Visual Studio 2019
- python >= 3.6
- cuda >= 11.2
- cudnn >= 8.2
在Windows菜单中找到`x64 Native Tools Command Prompt for VS 2019`打开,执行如下命令
```bat
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/python
set ENABLE_ORT_BACKEND=ON
set ENABLE_PADDLE_BACKEND=ON
set ENABLE_OPENVINO_BACKEND=ON
set ENABLE_VISION=ON
set ENABLE_TEXT=ON
set ENABLE_TRT_BACKEND=ON
set WITH_GPU=ON
set TRT_DIRECTORY=D:\Paddle\TensorRT-8.4.1.5
set CUDA_DIRECTORY=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2
python setup.py build
python setup.py bdist_wheel
```
编译完成即会在`FastDeploy/python/dist`目录下生成编译后的`wheel`直接pip install即可
编译过程中,如若修改编译参数,为避免带来缓存影响,可删除`FastDeploy/python`目录下的`build``.setuptools-cmake-build`两个子目录后再重新编译