test_pgo.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. POLYBENCH_CASES="2mm 3mm adi atax bicg cholesky correlation covariance \
  18. deriche doitgen durbin fdtd-2d floyd-warshall gemm gemver \
  19. gesummv gramschmidt heat-3d jacobi-1d jacobi-2d ludcmp lu \
  20. mvt nussinov seidel-2d symm syr2k syrk trisolv trmm"
  21. rm -f $REPORT
  22. touch $REPORT
  23. function print_bench_name()
  24. {
  25. name=$1
  26. echo -en "$name" >> $REPORT
  27. name_len=${#name}
  28. if [ $name_len -lt $BENCH_NAME_MAX_LEN ]
  29. then
  30. spaces=$(( $BENCH_NAME_MAX_LEN - $name_len ))
  31. for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done
  32. fi
  33. }
  34. pushd $OUT_DIR > /dev/null 2>&1
  35. for t in $POLYBENCH_CASES
  36. do
  37. if [ ! -e "${t}.wasm" ]; then
  38. echo "${t}.wasm doesn't exist, please run build.sh first"
  39. exit
  40. fi
  41. echo ""
  42. echo "Compile ${t}.wasm to ${t}.aot .."
  43. ${WAMRC_CMD} -o ${t}.aot ${t}.wasm
  44. echo ""
  45. echo "Compile ${t}.wasm to ${t}_pgo.aot .."
  46. ${WAMRC_CMD} --enable-llvm-pgo -o ${t}_pgo.aot ${t}.wasm
  47. echo ""
  48. echo "Run ${t}_pgo.aot to generate the raw profile data .."
  49. ${IWASM_CMD} --gen-prof-file=${t}.profraw --dir=. ${t}_pgo.aot
  50. echo ""
  51. echo "Merge the raw profile data to ${t}.profdata .."
  52. rm -f ${t}.profdata && llvm-profdata merge -output=${t}.profdata ${t}.profraw
  53. echo ""
  54. echo "Compile ${t}.wasm to ${t}_opt.aot with the profile data .."
  55. ${WAMRC_CMD} --use-prof-file=${t}.profdata -o ${t}_opt.aot ${t}.wasm
  56. done
  57. popd > /dev/null 2>&1
  58. echo "Start to run cases, the result is written to report.txt"
  59. #run benchmarks
  60. cd $OUT_DIR
  61. echo -en "\t\t\t\t\t native\tiwasm-aot\tiwasm-aot-pgo\n" >> $REPORT
  62. for t in $POLYBENCH_CASES
  63. do
  64. print_bench_name $t
  65. echo "run $t with native .."
  66. echo -en "\t" >> $REPORT
  67. $TIME -f "real-%e-time" ./${t}_native 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
  68. echo "run $t with iwasm aot .."
  69. echo -en "\t" >> $REPORT
  70. $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
  71. echo "run $t with iwasm aot opt .."
  72. echo -en "\t" >> $REPORT
  73. $TIME -f "real-%e-time" $IWASM_CMD ${t}_opt.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
  74. echo -en "\n" >> $REPORT
  75. done