未验证 提交 5bb12853 编写于 作者: P Peihan 提交者: GitHub

support test different infer_ut suite type (#35435)

* notest,test=inference;support test different suite type

* notest,test=inference;fix script bugs

* notest,test=inference;fix count time issue

* test=document_fix; fix readme grammar
上级 3c8eeb5d
# Inference Model UT
There are several model tests currently:
- test_ernie_text_cls.cc
- test_LeViT.cc
- test_ppyolo_mbv3.cc
- test_ppyolov2_r50vd.cc
- test_resnet50.cc
- test_resnet50_quant.cc
- test_yolov3.cc
To build and execute tests on Linux, simply run
```
./run.sh $PADDLE_ROOT $TURN_ON_MKL $TEST_GPU_CPU $DATA_DIR
```
To build on windows, run command with busybox
```
busybox bash ./run.sh $PADDLE_ROOT $TURN_ON_MKL $TEST_GPU_CPU $DATA_DIR
```
- After run command, it will build and execute tests and download to ${DATA_DIR} automatically.
- `$PADDLE_ROOT`: paddle library path
- `$TURN_ON_MKL`: use MKL or Openblas
- `$TEST_GPU_CPU`: test both GPU/CPU mode or only CPU mode
- `$DATA_DIR`: download data path
now only support 4 kinds of tests which controled by `--gtest_filter` argument, test suite name should be same as following.
- `TEST(gpu_tester_*, test_name)`
- `TEST(cpu_tester_*, test_name)`
- `TEST(mkldnn_tester_*, test_name)`
- `TEST(tensorrt_tester_*, test_name)`
skpied test suite name.
- `TEST(DISABLED_gpu_tester_*, test_name)`
- `TEST(DISABLED_cpu_tester_*, test_name)`
- `TEST(DISABLED_mkldnn_tester_*, test_name)`
- `TEST(DISABLED_tensorrt_tester_*, test_name)`
...@@ -24,6 +24,7 @@ MSVC_STATIC_CRT=$6 ...@@ -24,6 +24,7 @@ MSVC_STATIC_CRT=$6
inference_install_dir=${PADDLE_ROOT}/build/paddle_inference_install_dir inference_install_dir=${PADDLE_ROOT}/build/paddle_inference_install_dir
EXIT_CODE=0 # init default exit code EXIT_CODE=0 # init default exit code
WIN_DETECT=$(echo `uname` | grep "Win") # detect current platform WIN_DETECT=$(echo `uname` | grep "Win") # detect current platform
test_suite_list="cpu_tester*" # init test suite list, pass to --gtest_filter
export RED='\033[0;31m' # red color export RED='\033[0;31m' # red color
export NC='\033[0m' # no color export NC='\033[0m' # no color
...@@ -33,23 +34,30 @@ cd `dirname $0` ...@@ -33,23 +34,30 @@ cd `dirname $0`
current_dir=`pwd` current_dir=`pwd`
build_dir=${current_dir}/build build_dir=${current_dir}/build
log_dir=${current_dir}/log log_dir=${current_dir}/log
# check mkldnn installation
if [ $2 == ON ]; then if [ $2 == ON ]; then
# You can export yourself if move the install path # You can export yourself if move the install path
MKL_LIB=${inference_install_dir}/third_party/install/mklml/lib MKL_LIB=${inference_install_dir}/third_party/install/mklml/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${MKL_LIB} export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${MKL_LIB}
test_suite_list="${test_suite_list}:mkldnn_tester*"
fi fi
if [ $3 == ON ]; then if [ $3 == ON ]; then
use_gpu_list='true false' use_gpu_list='true false'
test_suite_list="${test_suite_list}:gpu_tester*"
else else
use_gpu_list='false' use_gpu_list='false'
fi fi
# check tensorrt installation
TENSORRT_COMPILED=$(cat "${inference_install_dir}/version.txt" | grep "WITH_TENSORRT")
USE_TENSORRT=OFF USE_TENSORRT=OFF
if [ -d "$TENSORRT_ROOT_DIR" ]; then if [ -d "$TENSORRT_ROOT_DIR" ] && [ ! -z "$TENSORRT_COMPILED" ] ; then
USE_TENSORRT=ON USE_TENSORRT=ON
test_suite_list="${test_suite_list}:tensorrt_tester*"
fi fi
function download() { function download() {
url_prefix=$1 url_prefix=$1
model_name=$2 model_name=$2
...@@ -146,104 +154,119 @@ mkdir -p ${log_dir} ...@@ -146,104 +154,119 @@ mkdir -p ${log_dir}
cd ${build_dir} cd ${build_dir}
rm -rf * rm -rf *
# ---------tensorrt gpu tests on linux--------- if [ $WIN_DETECT != "" ]; then
if [ $USE_TENSORRT == ON -a $TEST_GPU_CPU == ON ]; then exe_dir=${build_dir}/Release
rm -rf * else
exe_dir=${build_dir}
fi;
if [ $WIN_DETECT != "" ]; then printf "${YELLOW} start test_resnet50 ${NC} \n";
exe_dir=${build_dir}/Release compile_test "test_resnet50"
else ${exe_dir}/test_resnet50 \
exe_dir=${build_dir} --modeldir=$DATA_DIR/resnet50/resnet50 \
fi; --gtest_filter=${test_suite_list} \
--gtest_output=xml:${log_dir}/test_resnet50.xml
if [ $? -ne 0 ]; then
echo "${RED} test_resnet50 runs failed ${NC}" >> ${exe_dir}/test_summary.txt
EXIT_CODE=8
fi
printf "${YELLOW} start test_resnet50 ${NC} \n"; printf "${YELLOW} start test_det_mv3_db ${NC} \n";
compile_test "test_resnet50" compile_test "test_det_mv3_db"
${exe_dir}/test_resnet50 \ ${exe_dir}/test_det_mv3_db \
--modeldir=$DATA_DIR/resnet50/resnet50 \ --modeldir=$DATA_DIR/ocr_det_mv3_db/ocr_det_mv3_db \
--gtest_output=xml:${log_dir}/test_resnet50.xml --gtest_filter=${test_suite_list} \
if [ $? -ne 0 ]; then --gtest_output=xml:${log_dir}/test_det_mv3_db.xml
echo "${RED} test_resnet50 runs failed ${NC}" >> ${exe_dir}/test_summary.txt if [ $? -ne 0 ]; then
EXIT_CODE=8 echo "${RED} test_det_mv3_db runs failed ${NC}" >> ${exe_dir}/test_summary.txt
fi EXIT_CODE=8
fi
printf "${YELLOW} start test_det_mv3_db ${NC} \n"; printf "${YELLOW} start test_LeViT ${NC} \n";
compile_test "test_det_mv3_db" compile_test "test_LeViT"
${exe_dir}/test_det_mv3_db \ ${exe_dir}/test_LeViT \
--modeldir=$DATA_DIR/ocr_det_mv3_db/ocr_det_mv3_db \ --modeldir=$DATA_DIR/LeViT/LeViT \
--gtest_output=xml:${log_dir}/test_det_mv3_db.xml --gtest_filter=${test_suite_list} \
if [ $? -ne 0 ]; then --gtest_output=xml:${log_dir}/test_LeViT.xml
echo "${RED} test_det_mv3_db runs failed ${NC}" >> ${exe_dir}/test_summary.txt if [ $? -ne 0 ]; then
EXIT_CODE=8 echo "${RED} test_LeViT runs failed ${NC}" >> ${exe_dir}/test_summary.txt
fi EXIT_CODE=8
fi
printf "${YELLOW} start test_LeViT ${NC} \n"; if [ $WIN_DETECT != "" ]; then
compile_test "test_LeViT" #TODO(OliverLPH): enable test_ernie_text_cls on windows after fix compile issue
${exe_dir}/test_LeViT \ echo " skip test_ernie_text_cls "
--modeldir=$DATA_DIR/LeViT/LeViT \ else
--gtest_output=xml:${log_dir}/test_LeViT.xml printf "${YELLOW} start test_ernie_text_cls ${NC} \n";
compile_test "test_ernie_text_cls"
${exe_dir}/test_ernie_text_cls \
--modeldir=$DATA_DIR/ernie_text_cls/ernie_text_cls \
--gtest_filter=${test_suite_list} \
--gtest_output=xml:${log_dir}/test_ernie_text_cls.xml
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "${RED} test_LeViT runs failed ${NC}" >> ${exe_dir}/test_summary.txt echo "${RED} test_ernie_text_cls runs failed ${NC}" >> ${exe_dir}/test_summary.txt
EXIT_CODE=8 EXIT_CODE=8
fi fi
fi;
if [ $WIN_DETECT != "" ]; then printf "${YELLOW} start test_yolov3 ${NC} \n";
echo " skip test_ernie_text_cls " compile_test "test_yolov3"
else ${exe_dir}/test_yolov3 \
printf "${YELLOW} start test_ernie_text_cls ${NC} \n"; --modeldir=$DATA_DIR/yolov3/yolov3 \
compile_test "test_ernie_text_cls" --gtest_filter=${test_suite_list} \
${exe_dir}/test_ernie_text_cls \ --gtest_output=xml:${log_dir}/test_yolov3.xml
--modeldir=$DATA_DIR/ernie_text_cls/ernie_text_cls \ if [ $? -ne 0 ]; then
--gtest_output=xml:${log_dir}/test_ernie_text_cls.xml echo "${RED} test_yolov3 runs failed ${NC}" >> ${exe_dir}/test_summary.txt
if [ $? -ne 0 ]; then EXIT_CODE=8
echo "${RED} test_ernie_text_cls runs failed ${NC}" >> ${exe_dir}/test_summary.txt fi
EXIT_CODE=8
fi
fi;
printf "${YELLOW} start test_yolov3 ${NC} \n";
compile_test "test_yolov3"
${exe_dir}/test_yolov3 \
--modeldir=$DATA_DIR/yolov3/yolov3 \
--gtest_output=xml:${log_dir}/test_yolov3.xml
if [ $? -ne 0 ]; then
echo "${RED} test_yolov3 runs failed ${NC}" >> ${exe_dir}/test_summary.txt
EXIT_CODE=8
fi
printf "${YELLOW} start test_ppyolo_mbv3 ${NC} \n"; printf "${YELLOW} start test_ppyolo_mbv3 ${NC} \n";
compile_test "test_ppyolo_mbv3" compile_test "test_ppyolo_mbv3"
${exe_dir}/test_ppyolo_mbv3 \ ${exe_dir}/test_ppyolo_mbv3 \
--modeldir=$DATA_DIR/ppyolo_mbv3/ppyolo_mbv3 \ --modeldir=$DATA_DIR/ppyolo_mbv3/ppyolo_mbv3 \
--gtest_output=xml:${log_dir}/test_ppyolo_mbv3.xml --gtest_filter=${test_suite_list} \
if [ $? -ne 0 ]; then --gtest_output=xml:${log_dir}/test_ppyolo_mbv3.xml
echo "${RED} test_ppyolo_mbv3 runs failed ${NC}" >> ${exe_dir}/test_summary.txt if [ $? -ne 0 ]; then
EXIT_CODE=8 echo "${RED} test_ppyolo_mbv3 runs failed ${NC}" >> ${exe_dir}/test_summary.txt
fi EXIT_CODE=8
fi
printf "${YELLOW} start test_ppyolov2_r50vd ${NC} \n"; printf "${YELLOW} start test_ppyolov2_r50vd ${NC} \n";
compile_test "test_ppyolov2_r50vd" compile_test "test_ppyolov2_r50vd"
${exe_dir}/test_ppyolov2_r50vd \ ${exe_dir}/test_ppyolov2_r50vd \
--modeldir=$DATA_DIR/ppyolov2_r50vd/ppyolov2_r50vd \ --modeldir=$DATA_DIR/ppyolov2_r50vd/ppyolov2_r50vd \
--gtest_output=xml:${log_dir}/test_ppyolov2_r50vd.xml --gtest_filter=${test_suite_list} \
if [ $? -ne 0 ]; then --gtest_output=xml:${log_dir}/test_ppyolov2_r50vd.xml
echo "${RED} test_ppyolov2_r50vd runs failed ${NC}" >> ${exe_dir}/test_summary.txt if [ $? -ne 0 ]; then
EXIT_CODE=8 echo "${RED} test_ppyolov2_r50vd runs failed ${NC}" >> ${exe_dir}/test_summary.txt
fi EXIT_CODE=8
fi
printf "${YELLOW} start test_resnet50_quant ${NC} \n"; printf "${YELLOW} start test_resnet50_quant ${NC} \n";
compile_test "test_resnet50_quant" compile_test "test_resnet50_quant"
${exe_dir}/test_resnet50_quant \ ${exe_dir}/test_resnet50_quant \
--int8dir=$DATA_DIR/resnet50_quant/resnet50_quant/resnet50_quant \ --int8dir=$DATA_DIR/resnet50_quant/resnet50_quant/resnet50_quant \
--modeldir=$DATA_DIR/resnet50/resnet50 \ --modeldir=$DATA_DIR/resnet50/resnet50 \
--datadir=$DATA_DIR/resnet50_quant/resnet50_quant/imagenet-eval-binary/9.data \ --datadir=$DATA_DIR/resnet50_quant/resnet50_quant/imagenet-eval-binary/9.data \
--gtest_output=xml:${log_dir}/test_resnet50_quant.xml --gtest_filter=${test_suite_list} \
if [ $? -ne 0 ]; then --gtest_output=xml:${log_dir}/test_resnet50_quant.xml
echo "${RED} test_resnet50_quant runs failed ${NC}" >> ${exe_dir}/test_summary.txt if [ $? -ne 0 ]; then
EXIT_CODE=8 echo "${RED} test_resnet50_quant runs failed ${NC}" >> ${exe_dir}/test_summary.txt
fi EXIT_CODE=8
fi fi
set +x set +x
test_suites=$(echo ${test_suite_list} | sed 's/:/ /g')
echo " "
echo "CI Tested Following Patterns: "
echo "=====================test patterns======================"
for test_suite in ${test_suites}; do
echo " ${test_suite}"
done
echo "========================================================"
echo " "
if [[ -f ${exe_dir}/test_summary.txt ]];then if [[ -f ${exe_dir}/test_summary.txt ]];then
echo " " echo " "
echo "Summary Failed Tests ..." echo "Summary Failed Tests ..."
......
...@@ -32,7 +32,7 @@ paddle::test::Record PrepareInput(int batch_size) { ...@@ -32,7 +32,7 @@ paddle::test::Record PrepareInput(int batch_size) {
return image_Record; return image_Record;
} }
TEST(test_LeViT, analysis_gpu_bz1) { TEST(gpu_tester_LeViT, analysis_gpu_bz1) {
// init input data // init input data
std::map<std::string, paddle::test::Record> my_input_data_map; std::map<std::string, paddle::test::Record> my_input_data_map;
my_input_data_map["x"] = PrepareInput(1); my_input_data_map["x"] = PrepareInput(1);
...@@ -60,7 +60,7 @@ TEST(test_LeViT, analysis_gpu_bz1) { ...@@ -60,7 +60,7 @@ TEST(test_LeViT, analysis_gpu_bz1) {
std::cout << "finish test" << std::endl; std::cout << "finish test" << std::endl;
} }
TEST(test_LeViT, trt_fp32_bz2) { TEST(tensorrt_tester_LeViT, trt_fp32_bz2) {
// init input data // init input data
std::map<std::string, paddle::test::Record> my_input_data_map; std::map<std::string, paddle::test::Record> my_input_data_map;
my_input_data_map["x"] = PrepareInput(2); my_input_data_map["x"] = PrepareInput(2);
...@@ -91,7 +91,7 @@ TEST(test_LeViT, trt_fp32_bz2) { ...@@ -91,7 +91,7 @@ TEST(test_LeViT, trt_fp32_bz2) {
std::cout << "finish test" << std::endl; std::cout << "finish test" << std::endl;
} }
TEST(test_LeViT, serial_diff_batch_trt_fp32) { TEST(tensorrt_tester_LeViT, serial_diff_batch_trt_fp32) {
int max_batch_size = 5; int max_batch_size = 5;
// prepare groudtruth config // prepare groudtruth config
paddle_infer::Config config, config_no_ir; paddle_infer::Config config, config_no_ir;
...@@ -127,7 +127,7 @@ TEST(test_LeViT, serial_diff_batch_trt_fp32) { ...@@ -127,7 +127,7 @@ TEST(test_LeViT, serial_diff_batch_trt_fp32) {
std::cout << "finish test" << std::endl; std::cout << "finish test" << std::endl;
} }
TEST(test_LeViT, multi_thread4_trt_fp32_bz2) { TEST(tensorrt_tester_LeViT, multi_thread4_trt_fp32_bz2) {
int thread_num = 4; int thread_num = 4;
// init input data // init input data
std::map<std::string, paddle::test::Record> my_input_data_map; std::map<std::string, paddle::test::Record> my_input_data_map;
......
...@@ -77,7 +77,7 @@ void PrepareDynamicShape(paddle_infer::Config* config, int max_batch_size = 4) { ...@@ -77,7 +77,7 @@ void PrepareDynamicShape(paddle_infer::Config* config, int max_batch_size = 4) {
opt_input_shape); opt_input_shape);
} }
TEST(test_det_mv3_db, analysis_gpu_bz4) { TEST(gpu_tester_det_mv3_db, analysis_gpu_bz4) {
// init input data // init input data
std::map<std::string, paddle::test::Record> my_input_data_map; std::map<std::string, paddle::test::Record> my_input_data_map;
my_input_data_map["x"] = PrepareInput(4, 640); my_input_data_map["x"] = PrepareInput(4, 640);
...@@ -105,7 +105,7 @@ TEST(test_det_mv3_db, analysis_gpu_bz4) { ...@@ -105,7 +105,7 @@ TEST(test_det_mv3_db, analysis_gpu_bz4) {
std::cout << "finish test" << std::endl; std::cout << "finish test" << std::endl;
} }
TEST(test_det_mv3_db, multi_thread2_trt_fp32_dynamic_shape_bz2) { TEST(tensorrt_tester_det_mv3_db, multi_thread2_trt_fp32_dynamic_shape_bz2) {
int thread_num = 2; // thread > 2 may OOM int thread_num = 2; // thread > 2 may OOM
// init input data // init input data
std::map<std::string, paddle::test::Record> my_input_data_map; std::map<std::string, paddle::test::Record> my_input_data_map;
...@@ -149,7 +149,7 @@ TEST(test_det_mv3_db, multi_thread2_trt_fp32_dynamic_shape_bz2) { ...@@ -149,7 +149,7 @@ TEST(test_det_mv3_db, multi_thread2_trt_fp32_dynamic_shape_bz2) {
std::cout << "finish multi-thread test" << std::endl; std::cout << "finish multi-thread test" << std::endl;
} }
TEST(test_det_mv3_db, multi_thread2_mkl_fp32_bz2) { TEST(mkldnn_tester_det_mv3_db, multi_thread2_mkl_fp32_bz2) {
int thread_num = 2; // thread > 2 may OOM int thread_num = 2; // thread > 2 may OOM
// init input data // init input data
std::map<std::string, paddle::test::Record> my_input_data_map; std::map<std::string, paddle::test::Record> my_input_data_map;
......
...@@ -52,7 +52,7 @@ std::map<std::string, paddle::test::Record> PrepareInput(int batch_size) { ...@@ -52,7 +52,7 @@ std::map<std::string, paddle::test::Record> PrepareInput(int batch_size) {
return my_input_data_map; return my_input_data_map;
} }
TEST(test_ernie_text_cls, analysis_gpu_bz2_buffer) { TEST(gpu_tester_ernie_text_cls, analysis_gpu_bz2_buffer) {
// init input data // init input data
auto my_input_data_map = PrepareInput(2); auto my_input_data_map = PrepareInput(2);
// init output data // init output data
...@@ -84,7 +84,7 @@ TEST(test_ernie_text_cls, analysis_gpu_bz2_buffer) { ...@@ -84,7 +84,7 @@ TEST(test_ernie_text_cls, analysis_gpu_bz2_buffer) {
std::cout << "finish test" << std::endl; std::cout << "finish test" << std::endl;
} }
TEST(test_ernie_text_cls, multi_thread4_mkl_fp32_bz2) { TEST(mkldnn_tester_ernie_text_cls, multi_thread4_mkl_fp32_bz2) {
int thread_num = 4; int thread_num = 4;
// init input data // init input data
auto my_input_data_map = PrepareInput(2); auto my_input_data_map = PrepareInput(2);
......
...@@ -55,7 +55,7 @@ std::map<std::string, paddle::test::Record> PrepareInput(int batch_size) { ...@@ -55,7 +55,7 @@ std::map<std::string, paddle::test::Record> PrepareInput(int batch_size) {
return input_data_map; return input_data_map;
} }
TEST(test_ppyolo_mbv3, multi_thread4_trt_fp32_bz2) { TEST(tensorrt_tester_ppyolo_mbv3, multi_thread4_trt_fp32_bz2) {
int thread_num = 4; int thread_num = 4;
// init input data // init input data
auto input_data_map = PrepareInput(2); auto input_data_map = PrepareInput(2);
...@@ -101,7 +101,7 @@ TEST(test_ppyolo_mbv3, multi_thread4_trt_fp32_bz2) { ...@@ -101,7 +101,7 @@ TEST(test_ppyolo_mbv3, multi_thread4_trt_fp32_bz2) {
std::cout << "finish multi-thread test" << std::endl; std::cout << "finish multi-thread test" << std::endl;
} }
TEST(test_ppyolo_mbv3, multi_thread4_mkl_bz2) { TEST(mkldnn_tester_ppyolo_mbv3, multi_thread4_mkl_bz2) {
// TODO(OliverLPH): mkldnn multi thread will fail // TODO(OliverLPH): mkldnn multi thread will fail
int thread_num = 4; int thread_num = 4;
// init input data // init input data
......
...@@ -55,7 +55,7 @@ std::map<std::string, paddle::test::Record> PrepareInput(int batch_size) { ...@@ -55,7 +55,7 @@ std::map<std::string, paddle::test::Record> PrepareInput(int batch_size) {
return input_data_map; return input_data_map;
} }
TEST(test_ppyolov2_r50vd, multi_thread2_trt_fp32_bz1) { TEST(tensorrt_tester_ppyolov2_r50vd, multi_thread2_trt_fp32_bz1) {
int thread_num = 2; // thread > 2 may OOM int thread_num = 2; // thread > 2 may OOM
// init input data // init input data
auto input_data_map = PrepareInput(1); auto input_data_map = PrepareInput(1);
...@@ -100,7 +100,7 @@ TEST(test_ppyolov2_r50vd, multi_thread2_trt_fp32_bz1) { ...@@ -100,7 +100,7 @@ TEST(test_ppyolov2_r50vd, multi_thread2_trt_fp32_bz1) {
std::cout << "finish multi-thread test" << std::endl; std::cout << "finish multi-thread test" << std::endl;
} }
TEST(test_ppyolov2_r50vd, multi_thread2_mkl_bz2) { TEST(mkldnn_tester_ppyolov2_r50vd, multi_thread2_mkl_bz2) {
int thread_num = 2; int thread_num = 2;
// init input data // init input data
auto input_data_map = PrepareInput(2); auto input_data_map = PrepareInput(2);
......
...@@ -32,7 +32,7 @@ paddle::test::Record PrepareInput(int batch_size) { ...@@ -32,7 +32,7 @@ paddle::test::Record PrepareInput(int batch_size) {
return image_Record; return image_Record;
} }
TEST(test_resnet50, analysis_gpu_bz1) { TEST(gpu_tester_resnet50, analysis_gpu_bz1) {
// init input data // init input data
std::map<std::string, paddle::test::Record> my_input_data_map; std::map<std::string, paddle::test::Record> my_input_data_map;
my_input_data_map["inputs"] = PrepareInput(1); my_input_data_map["inputs"] = PrepareInput(1);
...@@ -60,7 +60,7 @@ TEST(test_resnet50, analysis_gpu_bz1) { ...@@ -60,7 +60,7 @@ TEST(test_resnet50, analysis_gpu_bz1) {
std::cout << "finish test" << std::endl; std::cout << "finish test" << std::endl;
} }
TEST(test_resnet50, trt_fp32_bz2) { TEST(tensorrt_tester_resnet50, trt_fp32_bz2) {
// init input data // init input data
std::map<std::string, paddle::test::Record> my_input_data_map; std::map<std::string, paddle::test::Record> my_input_data_map;
my_input_data_map["inputs"] = PrepareInput(2); my_input_data_map["inputs"] = PrepareInput(2);
...@@ -91,7 +91,7 @@ TEST(test_resnet50, trt_fp32_bz2) { ...@@ -91,7 +91,7 @@ TEST(test_resnet50, trt_fp32_bz2) {
std::cout << "finish test" << std::endl; std::cout << "finish test" << std::endl;
} }
TEST(test_resnet50, serial_diff_batch_trt_fp32) { TEST(tensorrt_tester_resnet50, serial_diff_batch_trt_fp32) {
int max_batch_size = 5; int max_batch_size = 5;
// prepare groudtruth config // prepare groudtruth config
paddle_infer::Config config, config_no_ir; paddle_infer::Config config, config_no_ir;
...@@ -127,7 +127,7 @@ TEST(test_resnet50, serial_diff_batch_trt_fp32) { ...@@ -127,7 +127,7 @@ TEST(test_resnet50, serial_diff_batch_trt_fp32) {
std::cout << "finish test" << std::endl; std::cout << "finish test" << std::endl;
} }
TEST(test_resnet50, multi_thread4_trt_fp32_bz2) { TEST(tensorrt_tester_resnet50, multi_thread4_trt_fp32_bz2) {
int thread_num = 4; int thread_num = 4;
// init input data // init input data
std::map<std::string, paddle::test::Record> my_input_data_map; std::map<std::string, paddle::test::Record> my_input_data_map;
...@@ -170,7 +170,7 @@ TEST(test_resnet50, multi_thread4_trt_fp32_bz2) { ...@@ -170,7 +170,7 @@ TEST(test_resnet50, multi_thread4_trt_fp32_bz2) {
std::cout << "finish multi-thread test" << std::endl; std::cout << "finish multi-thread test" << std::endl;
} }
TEST(test_resnet50, trt_int8_bz2) { TEST(tensorrt_tester_resnet50, trt_int8_bz2) {
// init input data // init input data
std::map<std::string, paddle::test::Record> my_input_data_map; std::map<std::string, paddle::test::Record> my_input_data_map;
my_input_data_map["inputs"] = PrepareInput(2); my_input_data_map["inputs"] = PrepareInput(2);
...@@ -199,6 +199,39 @@ TEST(test_resnet50, trt_int8_bz2) { ...@@ -199,6 +199,39 @@ TEST(test_resnet50, trt_int8_bz2) {
std::cout << "finish test" << std::endl; std::cout << "finish test" << std::endl;
} }
TEST(DISABLED_tensorrt_tester_resnet50, profile_multi_thread_trt_fp32) {
int batch_size = 2;
int thread_num = 4;
int repeat_time = 1000;
// init input data
std::map<std::string, paddle::test::Record> my_input_data_map;
my_input_data_map["inputs"] = PrepareInput(batch_size);
// init output data
std::map<std::string, paddle::test::Record> infer_output_data;
// prepare inference config
paddle_infer::Config config;
config.SetModel(FLAGS_modeldir + "/inference.pdmodel",
FLAGS_modeldir + "/inference.pdiparams");
config.EnableUseGpu(100, 0);
config.EnableTensorRtEngine(
1 << 20, 2, 3, paddle_infer::PrecisionType::kFloat32, false, false);
// get infer results from multi threads
services::PredictorPool pred_pool(config, thread_num);
std::vector<std::future<double>> calcs;
for (int i = 0; i < thread_num; ++i) {
calcs.push_back(std::async(&paddle::test::SingleThreadProfile,
pred_pool.Retrive(i), &my_input_data_map,
repeat_time));
}
double total_time_ = 0.0;
for (auto&& fut : calcs) {
total_time_ += fut.get();
}
std::cout << total_time_ << std::endl;
std::cout << "finish multi-thread profile" << std::endl;
}
} // namespace paddle_infer } // namespace paddle_infer
int main(int argc, char** argv) { int main(int argc, char** argv) {
......
...@@ -52,7 +52,7 @@ paddle::test::Record PrepareInput(int batch_size) { ...@@ -52,7 +52,7 @@ paddle::test::Record PrepareInput(int batch_size) {
return image_Record; return image_Record;
} }
TEST(DISABLED_test_resnet50_quant, multi_thread4_trt_int8_bz1) { TEST(DISABLED_tensorrt_tester_resnet50_quant, multi_thread4_trt_int8_bz1) {
int thread_num = 4; int thread_num = 4;
// init input data // init input data
std::map<std::string, paddle::test::Record> input_data_map; std::map<std::string, paddle::test::Record> input_data_map;
...@@ -94,7 +94,7 @@ TEST(DISABLED_test_resnet50_quant, multi_thread4_trt_int8_bz1) { ...@@ -94,7 +94,7 @@ TEST(DISABLED_test_resnet50_quant, multi_thread4_trt_int8_bz1) {
std::cout << "finish test" << std::endl; std::cout << "finish test" << std::endl;
} }
TEST(DISABLED_test_resnet50_quant, multi_thread_multi_instance) { TEST(DISABLED_tensorrt_tester_resnet50_quant, multi_thread_multi_instance) {
int thread_num = 4; int thread_num = 4;
// init input data // init input data
std::map<std::string, paddle::test::Record> input_data_fp32, input_data_quant; std::map<std::string, paddle::test::Record> input_data_fp32, input_data_quant;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <math.h> #include <math.h>
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <future>
#include <iostream> #include <iostream>
#include <numeric> #include <numeric>
#include <string> #include <string>
...@@ -148,5 +149,97 @@ void CompareRecord(std::map<std::string, Record> *truth_output_data, ...@@ -148,5 +149,97 @@ void CompareRecord(std::map<std::string, Record> *truth_output_data,
} }
} }
// Timer, count in ms
class Timer {
public:
Timer() { reset(); }
void start() { start_t = std::chrono::high_resolution_clock::now(); }
void stop() {
auto end_t = std::chrono::high_resolution_clock::now();
typedef std::chrono::microseconds ms;
auto diff = end_t - start_t;
ms counter = std::chrono::duration_cast<ms>(diff);
total_time += counter.count();
}
void reset() { total_time = 0.; }
double report() { return total_time / 1000.0; }
private:
double total_time;
std::chrono::high_resolution_clock::time_point start_t;
};
// single thread inference benchmark, return double time in ms
double SingleThreadProfile(paddle_infer::Predictor *predictor,
std::map<std::string, Record> *input_data_map,
int repeat_times = 2) {
// prepare input tensor
auto input_names = predictor->GetInputNames();
for (const auto & [ key, value ] : *input_data_map) {
switch (value.type) {
case paddle::PaddleDType::INT64: {
std::vector<int64_t> input_value =
std::vector<int64_t>(value.data.begin(), value.data.end());
auto input_tensor = predictor->GetInputHandle(key);
input_tensor->Reshape(value.shape);
input_tensor->CopyFromCpu(input_value.data());
break;
}
case paddle::PaddleDType::INT32: {
std::vector<int32_t> input_value =
std::vector<int32_t>(value.data.begin(), value.data.end());
auto input_tensor = predictor->GetInputHandle(key);
input_tensor->Reshape(value.shape);
input_tensor->CopyFromCpu(input_value.data());
break;
}
case paddle::PaddleDType::FLOAT32: {
std::vector<float> input_value =
std::vector<float>(value.data.begin(), value.data.end());
auto input_tensor = predictor->GetInputHandle(key);
input_tensor->Reshape(value.shape);
input_tensor->CopyFromCpu(input_value.data());
break;
}
}
}
Timer timer; // init prediction timer
timer.start();
// inference
for (size_t i = 0; i < repeat_times; ++i) {
CHECK(predictor->Run());
auto output_names = predictor->GetOutputNames();
for (auto &output_name : output_names) {
auto output_tensor = predictor->GetOutputHandle(output_name);
std::vector<int> output_shape = output_tensor->shape();
int out_num = std::accumulate(output_shape.begin(), output_shape.end(), 1,
std::multiplies<int>());
switch (output_tensor->type()) {
case paddle::PaddleDType::INT64: {
std::vector<int64_t> out_data;
out_data.resize(out_num);
output_tensor->CopyToCpu(out_data.data());
break;
}
case paddle::PaddleDType::FLOAT32: {
std::vector<float> out_data;
out_data.resize(out_num);
output_tensor->CopyToCpu(out_data.data());
break;
}
case paddle::PaddleDType::INT32: {
std::vector<int32_t> out_data;
out_data.resize(out_num);
output_tensor->CopyToCpu(out_data.data());
break;
}
}
}
}
timer.stop();
return timer.report();
}
} // namespace test } // namespace test
} // namespace paddle } // namespace paddle
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册