Files
FastDeploy/benchmark/cpp
WJJ1995 5687cdfbea [Benchmark] Open collect_info in config (#1649)
* add GPL lisence

* add GPL-3.0 lisence

* add GPL-3.0 lisence

* add GPL-3.0 lisence

* support yolov8

* add pybind for yolov8

* add yolov8 readme

* add cpp benchmark

* add cpu and gpu mem

* public part split

* add runtime mode

* fixed bugs

* add cpu_thread_nums

* deal with comments

* deal with comments

* deal with comments

* rm useless code

* add FASTDEPLOY_DECL

* add FASTDEPLOY_DECL

* fixed for windows

* mv rss to pss

* mv rss to pss

* Update utils.cc

* use thread to collect mem

* Add ResourceUsageMonitor

* rm useless code

* fixed bug

* fixed typo

* update ResourceUsageMonitor

* fixed bug

* fixed bug

* add note for ResourceUsageMonitor

* deal with comments

* add macros

* deal with comments

* deal with comments

* deal with comments

* re-lint

* rm pmap and use mem api

* rm pmap and use mem api

* add mem api

* Add PrintBenchmarkInfo func

* Add PrintBenchmarkInfo func

* Add PrintBenchmarkInfo func

* deal with comments

* fixed enable_paddle_to_trt

* add log for paddle_trt

* support ppcls benchmark

* use new trt option api

* update benchmark info

* simplify benchmark.cc

* simplify benchmark.cc

* deal with comments

* Add ppseg && ppocr benchmark

* add OCR rec img

* add ocr benchmark

* fixed trt shape

* add trt shape

* resolve conflict

* add ENABLE_BENCHMARK define

* Add ClassifyDiff

* Add Resize for ClassifyResult

* deal with comments

* add convert info script

* resolve conflict

* Add SaveBenchmarkResult func

* fixed bug

* fixed bug

* fixed bug

* add config.txt for option

* fixed bug

* fixed bug

* fixed bug

* add benchmark.sh

* mv thread_nums from 8 to 1

* deal with comments

* deal with comments

* fixed readme

* deal with comments

* add all platform shell

* Update config.arm.txt

* Update config.gpu.txt

* Update config.x86.txt

* fixed printinfo bug

* rm proxy

* add more model support

* all backend config.txt

* deal with comments

* Add MattingDiff compare

* fixed predict bug

* adjust warmup/repeat times

* add e2e/mem configs

* fixed typo

* open collect_mem

---------

Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com>
2023-03-18 11:32:40 +08:00
..

FastDeploy C++ Benchmarks

1. 编译选项

以下选项为benchmark相关的编译选项在编译用来跑benchmark的sdk时必须开启。

选项 需要设置的值 说明
ENABLE_BENCHMARK ON 默认OFF, 是否打开BENCHMARK模式
ENABLE_VISION ON 默认OFF是否编译集成视觉模型的部署模块
ENABLE_TEXT ON 默认OFF是否编译集成文本NLP模型的部署模块

运行FastDeploy C++ Benchmark需先准备好相应的环境并在ENABLE_BENCHMARK=ON模式下从源码编译FastDeploy C++ SDK. 以下将按照硬件维度,来说明相应的系统环境要求。不同环境下的详细要求,请参考FastDeploy环境要求

2. Benchmark 设置说明

具体flags.h提供选项如下:

选项 作用
--model 模型路径
--image 图片路径
--config_path config.txt路径包含具体设备、后端等信息

具体config.txt包含信息含义如下:

参数 作用
device 选择 CPU/GPU/XPU默认为 CPU
device_id GPU/XPU 卡号,默认为 0
cpu_thread_nums CPU 线程数,默认为 1
warmup 跑benchmark的warmup次数默认为 200
repeat 跑benchmark的循环次数默认为 1000
backend 指定后端类型有default, ort, ov, trt, paddle, paddle_trt, lite 等为default时会自动选择最优后端推荐设置为显式设置明确的backend。默认为 default
profile_mode 指定需要测试性能的模式,可选值为[runtime, end2end],默认为 runtime
include_h2d_d2h 是否把H2D+D2H的耗时统计在内该参数只在profile_mode为runtime时有效默认为 false
use_fp16 是否开启fp16当前只对 trt, paddle-trt, lite后端有效默认为 false
collect_memory_info 是否记录 cpu/gpu memory信息默认 false
sampling_interval 记录 cpu/gpu memory信息采样时间间隔单位ms默认为 50
precision_compare 是否进行精度比较,默认为 false
result_path 记录 Benchmark 数据的 txt 文件路径
xpu_l3_cache 设置XPU L3 Cache大小默认值为0。设置策略对于 昆仑2 XPU R200L3 Cache可用的最大值为 62914560对于 昆仑1 XPU 则为 16776192

3. X86_64 CPU 和 NVIDIA GPU 环境下运行 Benchmark

3.1 环境准备

Linux上编译需满足:

  • gcc/g++ >= 5.4(推荐8.2)
  • cmake >= 3.18.0
  • CUDA >= 11.2
  • cuDNN >= 8.2
  • TensorRT >= 8.5

在GPU上编译FastDeploy需要准备好相应的CUDA环境以及TensorRT详细文档请参考GPU编译文档

3.2 编译FastDeploy C++ SDK

# 源码编译SDK
git clone https://github.com/PaddlePaddle/FastDeploy.git -b develop
cd FastDeploy
mkdir build && cd build
cmake .. -DWITH_GPU=ON \
         -DENABLE_ORT_BACKEND=ON \
         -DENABLE_PADDLE_BACKEND=ON \
         -DENABLE_OPENVINO_BACKEND=ON \
         -DENABLE_TRT_BACKEND=ON \
         -DENABLE_VISION=ON \
         -DENABLE_TEXT=ON \
         -DENABLE_BENCHMARK=ON \  # 开启benchmark模式
         -DTRT_DIRECTORY=/Paddle/TensorRT-8.5.2.2 \
         -DCUDA_DIRECTORY=/usr/local/cuda \
         -DCMAKE_INSTALL_PREFIX=${PWD}/compiled_fastdeploy_sdk

make -j12
make install  

# 配置SDK路径
cd ..  
export FD_GPU_SDK=${PWD}/build/compiled_fastdeploy_sdk

3.3 编译 Benchmark 示例

cd benchmark/cpp
mkdir build && cd build  
cmake .. -DFASTDEPLOY_INSTALL_DIR=${FD_GPU_SDK}  
make -j4

3.4 运行 Benchmark 示例

在X86 CPU + NVIDIA GPU下FastDeploy 目前支持多种推理后端,下面以 PaddleYOLOv8 为例,跑出多后端在 CPU/GPU 对应 benchmark 数据。

  • 下载模型文件和测试图片
wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov8_s_500e_coco.tgz  
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
tar -zxvf yolov8_s_500e_coco.tgz
  • 运行 yolov8 benchmark 示例

# 统计性能用户根据需求修改config.txt文件具体含义参考上表
# eg如果想测paddle gpu backend将device改为gpubackend修改为paddle即可
./benchmark_ppyolov8 --model yolov8_s_500e_coco --image 000000014439.jpg --config_path config.txt

注意为避免对性能统计产生影响测试性能时最好不要开启内存显存统计的功能当把collect_memory_info参数设置为true时只有内存显存参数是稳定可靠的。更多参数设置请参考参数设置说明

4. 各个硬件上的一键运行脚本

在准备好相关的环境配置和SDK后可以使用本目录提供的脚本一键运行后的benchmark数据。

  • 获取模型和资源文件
./get_models.sh
  • 运行benchmark脚本
# x86 CPU Paddle backend fp32
./benchmark_x86.sh config/config.x86.paddle.fp32.txt
# x86 CPU ONNXRuntime backend fp32
./benchmark_x86.sh config/config.x86.ort.fp32.txt
# x86 CPU OpenVIVO backend fp32
./benchmark_x86.sh config/config.x86.ov.fp32.txt
# NVIDIA GPU Paddle backend fp32
./benchmark_gpu.sh config/config.gpu.paddle.fp32.txt
# NVIDIA GPU ONNXRuntime backend fp32
./benchmark_gpu.sh config/config.gpu.ort.fp32.txt
# NVIDIA GPU Paddle-TRT backend fp32
./benchmark_gpu_trt.sh config/config.gpu.paddle_trt.fp32.txt
# NVIDIA GPU Paddle-TRT backend fp16
./benchmark_gpu_trt.sh config/config.gpu.paddle_trt.fp16.txt
# NVIDIA GPU TRT backend fp32
./benchmark_gpu_trt.sh config/config.gpu.trt.fp32.txt
# NVIDIA GPU TRT backend fp16
./benchmark_gpu_trt.sh config/config.gpu.trt.fp16.txt

# Arm CPU Paddle Lite backend fp32
./benchmark_arm.sh config/config.arm.lite.fp32.txt
# Arm CPU Paddle Lite backend fp16
./benchmark_arm.sh config/config.arm.lite.fp16.txt
# XPU Paddle Lite backend fp32
./benchmark_xpu.sh config/config.xpu.lite.fp32.txt