benchmark.sh 2.2 KB
Newer Older
G
fix  
gentelyang 已提交
1
rm profile_log*
M
MRXLT 已提交
2 3 4
export CUDA_VISIBLE_DEVICES=0,1,2,3
export FLAGS_profile_server=1
export FLAGS_profile_client=1
M
MRXLT 已提交
5
export FLAGS_serving_latency=1
G
fix  
gentelyang 已提交
6

G
gentelyang 已提交
7
gpu_id=0
G
fix  
gentelyang 已提交
8 9 10 11 12 13 14 15 16
#save cpu and gpu utilization log
if [ -d utilization ];then
    rm -rf utilization
else
    mkdir utilization
fi
#start server
$PYTHONROOT/bin/python3 -m paddle_serving_server_gpu.serve --model $1 --port 9292 --thread 4 --gpu_ids 0,1,2,3 --mem_optim  --ir_optim >  elog  2>&1 &
sleep 5
M
MRXLT 已提交
17 18

#warm up
G
fix  
gentelyang 已提交
19 20 21
$PYTHONROOT/bin/python3 benchmark.py --thread 4 --batch_size 1 --model $2/serving_client_conf.prototxt --request rpc > profile 2>&1
echo -e "import psutil\ncpu_utilization=psutil.cpu_percent(1,False)\nprint('CPU_UTILIZATION:', cpu_utilization)\n" > cpu_utilization.py
for thread_num in 1 4 8 16
M
MRXLT 已提交
22
do
G
fix  
gentelyang 已提交
23
for batch_size in 1 4 16 64
M
MRXLT 已提交
24
do
G
gentelyang 已提交
25
    job_bt=`date '+%Y%m%d%H%M%S'`
G
fix  
gentelyang 已提交
26 27
    nvidia-smi --id=0 --query-compute-apps=used_memory --format=csv -lms 100 > gpu_use.log 2>&1 &
    nvidia-smi --id=0 --query-gpu=utilization.gpu --format=csv -lms 100 > gpu_utilization.log 2>&1 &
G
gentelyang 已提交
28
    gpu_memory_pid=$!
G
fix  
gentelyang 已提交
29
    $PYTHONROOT/bin/python3 benchmark.py --thread $thread_num --batch_size $batch_size --model $2/serving_client_conf.prototxt --request rpc > profile 2>&1
G
gentelyang 已提交
30
    kill ${gpu_memory_pid}
G
fix  
gentelyang 已提交
31
    kill `ps -ef|grep used_memory|awk '{print $2}'`
G
gentelyang 已提交
32 33 34
    echo "model_name:" $1
    echo "thread_num:" $thread_num
    echo "batch_size:" $batch_size
M
MRXLT 已提交
35
    echo "=================Done===================="
G
gentelyang 已提交
36 37
    echo "model_name:$1" >> profile_log_$1
    echo "batch_size:$batch_size" >> profile_log_$1
G
fix  
gentelyang 已提交
38
    $PYTHONROOT/bin/python3 cpu_utilization.py >> profile_log_$1
G
gentelyang 已提交
39
    job_et=`date '+%Y%m%d%H%M%S'`
G
fix  
gentelyang 已提交
40 41 42 43
    awk 'BEGIN {max = 0} {if(NR>1){if ($1 > max) max=$1}} END {print "MAX_GPU_MEMORY:", max}' gpu_use.log >> profile_log_$1
    awk 'BEGIN {max = 0} {if(NR>1){if ($1 > max) max=$1}} END {print "GPU_UTILIZATION:", max}' gpu_utilization.log >> profile_log_$1
    rm -rf gpu_use.log gpu_utilization.log
    $PYTHONROOT/bin/python3 ../util/show_profile.py profile $thread_num >> profile_log_$1
M
MRXLT 已提交
44 45
    tail -n 8 profile >> profile_log_$1
    echo "" >> profile_log_$1
M
MRXLT 已提交
46
done
M
MRXLT 已提交
47
done
M
MRXLT 已提交
48

G
fix  
gentelyang 已提交
49 50 51
#Divided log
awk 'BEGIN{RS="\n\n"}{i++}{print > "bert_log_"i}' profile_log_$1
mkdir bert_log && mv bert_log_* bert_log
M
MRXLT 已提交
52
ps -ef|grep 'serving'|grep -v grep|cut -c 9-15 | xargs kill -9