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.
[CVCUDA] CMake integration, vison processor CV-CUDA integration, Padd…
…leClas support CV-CUDA (PaddlePaddle#1074) * cvcuda resize * cvcuda center crop * cvcuda resize * add a fdtensor in fdmat * get cv mat and get tensor support gpu * paddleclas cvcuda preprocessor * fix compile err * fix windows compile error * rename reused to cached * address comment * remove debug code * add comment * add manager run * use cuda and cuda used * use cv cuda doc * address comment --------- Co-authored-by: Jason <[email protected]>
- Loading branch information
1 parent
0c735e9
commit 62e051e
Showing
26 changed files
with
814 additions
and
216 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
if(NOT WITH_GPU) | ||
message(FATAL_ERROR "ENABLE_CVCUDA is available on Linux and WITH_GPU=ON, but now WITH_GPU=OFF.") | ||
endif() | ||
|
||
if(APPLE OR ANDROID OR IOS OR WIN32) | ||
message(FATAL_ERROR "Cannot enable CV-CUDA in mac/ios/android/windows os, please set -DENABLE_CVCUDA=OFF.") | ||
endif() | ||
|
||
if(NOT (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")) | ||
message(FATAL_ERROR "CV-CUDA only support x86_64.") | ||
endif() | ||
|
||
set(CVCUDA_LIB_URL https://github.com/CVCUDA/CV-CUDA/releases/download/v0.2.0-alpha/nvcv-lib-0.2.0_alpha-cuda11-x86_64-linux.tar.xz) | ||
set(CVCUDA_LIB_FILENAME nvcv-lib-0.2.0_alpha-cuda11-x86_64-linux.tar.xz) | ||
set(CVCUDA_DEV_URL https://github.com/CVCUDA/CV-CUDA/releases/download/v0.2.0-alpha/nvcv-dev-0.2.0_alpha-cuda11-x86_64-linux.tar.xz) | ||
set(CVCUDA_DEV_FILENAME nvcv-dev-0.2.0_alpha-cuda11-x86_64-linux.tar.xz) | ||
|
||
download_and_decompress(${CVCUDA_LIB_URL} ${CMAKE_CURRENT_BINARY_DIR}/${CVCUDA_LIB_FILENAME} ${THIRD_PARTY_PATH}/cvcuda) | ||
download_and_decompress(${CVCUDA_DEV_URL} ${CMAKE_CURRENT_BINARY_DIR}/${CVCUDA_DEV_FILENAME} ${THIRD_PARTY_PATH}/cvcuda) | ||
|
||
execute_process(COMMAND rm -rf ${THIRD_PARTY_PATH}/install/cvcuda) | ||
execute_process(COMMAND mkdir -p ${THIRD_PARTY_PATH}/install/cvcuda) | ||
execute_process(COMMAND cp -r ${THIRD_PARTY_PATH}/cvcuda/opt/nvidia/cvcuda0/lib/x86_64-linux-gnu/ ${THIRD_PARTY_PATH}/install/cvcuda/lib) | ||
execute_process(COMMAND cp -r ${THIRD_PARTY_PATH}/cvcuda/opt/nvidia/cvcuda0/include/ ${THIRD_PARTY_PATH}/install/cvcuda/include) | ||
|
||
link_directories(${THIRD_PARTY_PATH}/install/cvcuda/lib) | ||
include_directories(${THIRD_PARTY_PATH}/install/cvcuda/include) | ||
|
||
set(CMAKE_CXX_STANDARD 17) |
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,39 @@ | ||
# 使用CV-CUDA/CUDA加速GPU端到端推理性能 | ||
|
||
FastDeploy集成了CV-CUDA来加速预/后处理,个别CV-CUDA不支持的算子使用了CUDA kernel的方式实现。 | ||
|
||
FastDeploy的Vision Processor模块对CV-CUDA的算子做了进一步的封装,用户不需要自己去调用CV-CUDA, | ||
使用FastDeploy的模型推理接口即可利用CV-CUDA的加速能力。 | ||
|
||
FastDeploy的Vision Processor模块在集成CV-CUDA时,做了以下工作来方便用户的使用: | ||
- GPU内存管理,缓存算子的输入、输出tensor,避免重复分配GPU内存 | ||
- CV-CUDA不支持的个别算子利用CUDA kernel实现 | ||
- CV-CUDA/CUDA不支持的算子可以fallback到OpenCV/FlyCV | ||
|
||
## 使用方式 | ||
编译FastDeploy时,开启CV-CUDA编译选项 | ||
```bash | ||
# 编译C++预测库时, 开启CV-CUDA编译选项. | ||
-DENABLE_CVCUDA=ON \ | ||
|
||
# 在编译Python预测库时, 开启CV-CUDA编译选项 | ||
export ENABLE_CVCUDA=ON | ||
``` | ||
|
||
只有继承了ProcessorManager类的模型预处理,才可以使用CV-CUDA,这里以PaddleClasPreprocessor为例 | ||
```bash | ||
# C++ | ||
# 创建model之后,调用model preprocessor的UseCuda接口即可打开CV-CUDA/CUDA预处理 | ||
# 第一个参数enable_cv_cuda,true代表使用CV-CUDA,false代表只使用CUDA(支持的算子较少) | ||
# 第二个参数是GPU id,-1代表不指定,使用当前GPU | ||
model.GetPreprocessor().UseCuda(true, 0); | ||
|
||
# Python | ||
model.preprocessor.use_cuda(True, 0) | ||
``` | ||
|
||
## 最佳实践 | ||
|
||
- 如果预处理第一个算子是resize,则要根据实际情况决定resize是否跑在GPU。因为当resize跑在GPU, | ||
且图片解码在CPU时,需要把原图copy到GPU内存,开销较大,而resize之后再copy到GPU内存,则往往只需要 | ||
copy较少的数据。 |
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
Oops, something went wrong.