test_pgo.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. CUR_DIR=$PWD
  5. OUT_DIR=$CUR_DIR/out
  6. REPORT=$CUR_DIR/report.txt
  7. TIME=/usr/bin/time
  8. PLATFORM=$(uname -s | tr A-Z a-z)
  9. if [ "$1" = "--sgx" ] && [ "$PLATFORM" = "linux" ]; then
  10. IWASM_CMD="$CUR_DIR/../../../product-mini/platforms/${PLATFORM}-sgx/enclave-sample/iwasm"
  11. WAMRC_CMD="$CUR_DIR/../../../wamr-compiler/build/wamrc -sgx"
  12. else
  13. IWASM_CMD="$CUR_DIR/../../../product-mini/platforms/${PLATFORM}/build/iwasm"
  14. WAMRC_CMD="$CUR_DIR/../../../wamr-compiler/build/wamrc"
  15. fi
  16. BENCH_NAME_MAX_LEN=20
  17. SHOOTOUT_CASES="base64 fib2 gimli heapsort matrix memmove nestedloop \
  18. nestedloop2 nestedloop3 random seqhash sieve strchr \
  19. switch2"
  20. rm -f $REPORT
  21. touch $REPORT
  22. function print_bench_name()
  23. {
  24. name=$1
  25. echo -en "$name" >> $REPORT
  26. name_len=${#name}
  27. if [ $name_len -lt $BENCH_NAME_MAX_LEN ]
  28. then
  29. spaces=$(( $BENCH_NAME_MAX_LEN - $name_len ))
  30. for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done
  31. fi
  32. }
  33. pushd $OUT_DIR > /dev/null 2>&1
  34. for t in $SHOOTOUT_CASES
  35. do
  36. if [ ! -e "${t}.wasm" ]; then
  37. echo "${t}.wasm doesn't exist, please run build.sh first"
  38. exit
  39. fi
  40. echo ""
  41. echo "Compile ${t}.wasm to ${t}.aot .."
  42. ${WAMRC_CMD} -o ${t}.aot ${t}.wasm
  43. echo ""
  44. echo "Compile ${t}.wasm to ${t}_pgo.aot .."
  45. ${WAMRC_CMD} --enable-llvm-pgo -o ${t}_pgo.aot ${t}.wasm
  46. echo ""
  47. echo "Run ${t}_pgo.aot to generate the raw profile data .."
  48. ${IWASM_CMD} --gen-prof-file=${t}.profraw --dir=. ${t}_pgo.aot
  49. echo ""
  50. echo "Merge the raw profile data to ${t}.profdata .."
  51. rm -f ${t}.profdata && llvm-profdata merge -output=${t}.profdata ${t}.profraw
  52. echo ""
  53. echo "Compile ${t}.wasm to ${t}_opt.aot with the profile data .."
  54. ${WAMRC_CMD} --use-prof-file=${t}.profdata -o ${t}_opt.aot ${t}.wasm
  55. done
  56. popd > /dev/null 2>&1
  57. echo "Start to run cases, the result is written to report.txt"
  58. #run benchmarks
  59. cd $OUT_DIR
  60. echo -en "\t\t\t\t\t native\tiwasm-aot\tiwasm-aot-pgo\n" >> $REPORT
  61. for t in $SHOOTOUT_CASES
  62. do
  63. print_bench_name $t
  64. echo "run $t with native .."
  65. echo -en "\t" >> $REPORT
  66. $TIME -f "real-%e-time" ./${t}_native 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
  67. echo "run $t with iwasm aot .."
  68. echo -en "\t" >> $REPORT
  69. $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
  70. echo "run $t with iwasm aot opt .."
  71. echo -en "\t" >> $REPORT
  72. $TIME -f "real-%e-time" $IWASM_CMD ${t}_opt.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
  73. echo -en "\n" >> $REPORT
  74. done