test_serving_infer_cpp.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/bin/bash
  2. source test_tipc/common_func.sh
  3. function func_parser_model_config(){
  4. strs=$1
  5. IFS="/"
  6. array=(${strs})
  7. tmp=${array[-1]}
  8. echo ${tmp}
  9. }
  10. FILENAME=$1
  11. dataline=$(awk 'NR==1, NR==19{print}' $FILENAME)
  12. MODE=$2
  13. # parser params
  14. IFS=$'\n'
  15. lines=(${dataline})
  16. # parser serving
  17. model_name=$(func_parser_value "${lines[1]}")
  18. python_list=$(func_parser_value "${lines[2]}")
  19. trans_model_py=$(func_parser_value "${lines[3]}")
  20. det_infer_model_dir_key=$(func_parser_key "${lines[4]}")
  21. det_infer_model_dir_value=$(func_parser_value "${lines[4]}")
  22. model_filename_key=$(func_parser_key "${lines[5]}")
  23. model_filename_value=$(func_parser_value "${lines[5]}")
  24. params_filename_key=$(func_parser_key "${lines[6]}")
  25. params_filename_value=$(func_parser_value "${lines[6]}")
  26. det_serving_server_key=$(func_parser_key "${lines[7]}")
  27. det_serving_server_value=$(func_parser_value "${lines[7]}")
  28. det_serving_client_key=$(func_parser_key "${lines[8]}")
  29. det_serving_client_value=$(func_parser_value "${lines[8]}")
  30. rec_infer_model_dir_key=$(func_parser_key "${lines[9]}")
  31. rec_infer_model_dir_value=$(func_parser_value "${lines[9]}")
  32. rec_serving_server_key=$(func_parser_key "${lines[10]}")
  33. rec_serving_server_value=$(func_parser_value "${lines[10]}")
  34. rec_serving_client_key=$(func_parser_key "${lines[11]}")
  35. rec_serving_client_value=$(func_parser_value "${lines[11]}")
  36. det_server_value=$(func_parser_model_config "${lines[7]}")
  37. det_client_value=$(func_parser_model_config "${lines[8]}")
  38. rec_server_value=$(func_parser_model_config "${lines[10]}")
  39. rec_client_value=$(func_parser_model_config "${lines[11]}")
  40. serving_dir_value=$(func_parser_value "${lines[12]}")
  41. web_service_py=$(func_parser_value "${lines[13]}")
  42. op_key=$(func_parser_key "${lines[14]}")
  43. op_value=$(func_parser_value "${lines[14]}")
  44. port_key=$(func_parser_key "${lines[15]}")
  45. port_value=$(func_parser_value "${lines[15]}")
  46. gpu_key=$(func_parser_key "${lines[16]}")
  47. gpu_value=$(func_parser_value "${lines[16]}")
  48. cpp_client_py=$(func_parser_value "${lines[17]}")
  49. image_dir_key=$(func_parser_key "${lines[18]}")
  50. image_dir_value=$(func_parser_value "${lines[18]}")
  51. LOG_PATH="$(pwd)/test_tipc/output/${model_name}/${MODE}/cpp"
  52. mkdir -p ${LOG_PATH}
  53. status_log="${LOG_PATH}/results_cpp_serving.log"
  54. function func_serving(){
  55. IFS='|'
  56. _python=$1
  57. _script=$2
  58. _model_dir=$3
  59. # pdserving
  60. set_model_filename=$(func_set_params "${model_filename_key}" "${model_filename_value}")
  61. set_params_filename=$(func_set_params "${params_filename_key}" "${params_filename_value}")
  62. # trans det
  63. set_dirname=$(func_set_params "--dirname" "${det_infer_model_dir_value}")
  64. set_serving_server=$(func_set_params "--serving_server" "${det_serving_server_value}")
  65. set_serving_client=$(func_set_params "--serving_client" "${det_serving_client_value}")
  66. python_list=(${python_list})
  67. trans_det_log="${LOG_PATH}/cpp_trans_model_det.log"
  68. trans_model_cmd="${python_list[0]} ${trans_model_py} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_serving_server} ${set_serving_client} > ${trans_det_log} 2>&1 "
  69. eval $trans_model_cmd
  70. cp "deploy/pdserving/serving_client_conf.prototxt" ${det_serving_client_value}
  71. # trans rec
  72. set_dirname=$(func_set_params "--dirname" "${rec_infer_model_dir_value}")
  73. set_serving_server=$(func_set_params "--serving_server" "${rec_serving_server_value}")
  74. set_serving_client=$(func_set_params "--serving_client" "${rec_serving_client_value}")
  75. python_list=(${python_list})
  76. trans_rec_log="${LOG_PATH}/cpp_trans_model_rec.log"
  77. trans_model_cmd="${python_list[0]} ${trans_model_py} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_serving_server} ${set_serving_client} > ${trans_rec_log} 2>&1 "
  78. eval $trans_model_cmd
  79. last_status=${PIPESTATUS[0]}
  80. status_check $last_status "${trans_model_cmd}" "${status_log}" "${model_name}" "${trans_rec_log}"
  81. set_image_dir=$(func_set_params "${image_dir_key}" "${image_dir_value}")
  82. python_list=(${python_list})
  83. cd ${serving_dir_value}
  84. # cpp serving
  85. for gpu_id in ${gpu_value[*]}; do
  86. if [ ${gpu_id} = "null" ]; then
  87. server_log_path="${LOG_PATH}/cpp_server_cpu.log"
  88. web_service_cpp_cmd="nohup ${python_list[0]} ${web_service_py} --model ${det_server_value} ${rec_server_value} ${op_key} ${op_value} ${port_key} ${port_value} > ${server_log_path} 2>&1 &"
  89. eval $web_service_cpp_cmd
  90. last_status=${PIPESTATUS[0]}
  91. status_check $last_status "${web_service_cpp_cmd}" "${status_log}" "${model_name}" "${server_log_path}"
  92. sleep 5s
  93. _save_log_path="${LOG_PATH}/cpp_client_cpu.log"
  94. cpp_client_cmd="${python_list[0]} ${cpp_client_py} ${det_client_value} ${rec_client_value} > ${_save_log_path} 2>&1"
  95. eval $cpp_client_cmd
  96. last_status=${PIPESTATUS[0]}
  97. eval "cat ${_save_log_path}"
  98. status_check $last_status "${cpp_client_cmd}" "${status_log}" "${model_name}" "${_save_log_path}"
  99. ps ux | grep -i ${port_value} | awk '{print $2}' | xargs kill -s 9
  100. else
  101. server_log_path="${LOG_PATH}/cpp_server_gpu.log"
  102. web_service_cpp_cmd="nohup ${python_list[0]} ${web_service_py} --model ${det_server_value} ${rec_server_value} ${op_key} ${op_value} ${port_key} ${port_value} ${gpu_key} ${gpu_id} > ${server_log_path} 2>&1 &"
  103. eval $web_service_cpp_cmd
  104. sleep 5s
  105. _save_log_path="${LOG_PATH}/cpp_client_gpu.log"
  106. cpp_client_cmd="${python_list[0]} ${cpp_client_py} ${det_client_value} ${rec_client_value} > ${_save_log_path} 2>&1"
  107. eval $cpp_client_cmd
  108. last_status=${PIPESTATUS[0]}
  109. eval "cat ${_save_log_path}"
  110. status_check $last_status "${cpp_client_cmd}" "${status_log}" "${model_name}" "${_save_log_path}"
  111. ps ux | grep -i ${port_value} | awk '{print $2}' | xargs kill -s 9
  112. fi
  113. done
  114. }
  115. #set cuda device
  116. GPUID=$3
  117. if [ ${#GPUID} -le 0 ];then
  118. env="export CUDA_VISIBLE_DEVICES=0"
  119. else
  120. env="export CUDA_VISIBLE_DEVICES=${GPUID}"
  121. fi
  122. eval $env
  123. echo $env
  124. echo "################### run test ###################"
  125. export Count=0
  126. IFS="|"
  127. func_serving "${web_service_cpp_cmd}"