mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-11 17:35:13 +00:00
![Wenyong Huang](/assets/img/avatar_default.png)
LLVM PGO (Profile-Guided Optimization) allows the compiler to better optimize code for how it actually runs. This PR implements the AOT static PGO, and is tested on Linux x86-64 and x86-32. The basic steps are: 1. Use `wamrc --enable-llvm-pgo -o <aot_file_of_pgo> <wasm_file>` to generate an instrumented aot file. 2. Compile iwasm with `cmake -DWAMR_BUILD_STATIC_PGO=1` and run `iwasm --gen-prof-file=<raw_profile_file> <aot_file_of_pgo>` to generate the raw profile file. 3. Run `llvm-profdata merge -output=<profile_file> <raw_profile_file>` to merge the raw profile file into the profile file. 4. Run `wamrc --use-prof-file=<profile_file> -o <aot_file> <wasm_file>` to generate the optimized aot file. 5. Run the optimized aot_file: `iwasm <aot_file>`. The test scripts are also added for each benchmark, run `test_pgo.sh` under each benchmark's folder to test the AOT static pgo.
88 lines
2.4 KiB
Bash
Executable File
88 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
CUR_DIR=$PWD
|
|
OUT_DIR=$CUR_DIR/out
|
|
REPORT=$CUR_DIR/report.txt
|
|
TIME=/usr/bin/time
|
|
|
|
PLATFORM=$(uname -s | tr A-Z a-z)
|
|
IWASM_CMD=$CUR_DIR/../../../product-mini/platforms/${PLATFORM}/build/iwasm
|
|
WAMRC_CMD=$CUR_DIR/../../../wamr-compiler/build/wamrc
|
|
|
|
BENCH_NAME_MAX_LEN=20
|
|
|
|
JETSTREAM_CASES="gcc-loops HashSet tsf float-mm quicksort"
|
|
|
|
rm -f $REPORT
|
|
touch $REPORT
|
|
|
|
function print_bench_name()
|
|
{
|
|
name=$1
|
|
echo -en "$name" >> $REPORT
|
|
name_len=${#name}
|
|
if [ $name_len -lt $BENCH_NAME_MAX_LEN ]
|
|
then
|
|
spaces=$(( $BENCH_NAME_MAX_LEN - $name_len ))
|
|
for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done
|
|
fi
|
|
}
|
|
|
|
pushd $OUT_DIR > /dev/null 2>&1
|
|
for t in $JETSTREAM_CASES
|
|
do
|
|
if [ ! -e "${t}.wasm" ]; then
|
|
echo "${t}.wasm doesn't exist, please run build.sh first"
|
|
exit
|
|
fi
|
|
|
|
echo ""
|
|
echo "Compile ${t}.wasm to ${t}.aot .."
|
|
${WAMRC_CMD} -o ${t}.aot ${t}.wasm
|
|
|
|
echo ""
|
|
echo "Compile ${t}.wasm to ${t}_pgo.aot .."
|
|
${WAMRC_CMD} --enable-llvm-pgo -o ${t}_pgo.aot ${t}.wasm
|
|
|
|
echo ""
|
|
echo "Run ${t}_pgo.aot to generate the raw profile data .."
|
|
${IWASM_CMD} --gen-prof-file=${t}.profraw --dir=. ${t}_pgo.aot
|
|
|
|
echo ""
|
|
echo "Merge the raw profile data to ${t}.profdata .."
|
|
rm -f ${t}.profdata && llvm-profdata merge -output=${t}.profdata ${t}.profraw
|
|
|
|
echo ""
|
|
echo "Compile ${t}.wasm to ${t}_opt.aot with the profile data .."
|
|
${WAMRC_CMD} --use-prof-file=${t}.profdata -o ${t}_opt.aot ${t}.wasm
|
|
done
|
|
popd > /dev/null 2>&1
|
|
|
|
echo "Start to run cases, the result is written to report.txt"
|
|
|
|
#run benchmarks
|
|
cd $OUT_DIR
|
|
echo -en "\t\t\t\t\t native\tiwasm-aot\tiwasm-aot-pgo\n" >> $REPORT
|
|
|
|
for t in $JETSTREAM_CASES
|
|
do
|
|
print_bench_name $t
|
|
|
|
echo "run $t with native .."
|
|
echo -en "\t" >> $REPORT
|
|
$TIME -f "real-%e-time" ./${t}_native 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
|
|
|
|
echo "run $t with iwasm aot .."
|
|
echo -en "\t" >> $REPORT
|
|
$TIME -f "real-%e-time" $IWASM_CMD --dir=. ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
|
|
|
|
echo "run $t with iwasm aot opt .."
|
|
echo -en "\t" >> $REPORT
|
|
$TIME -f "real-%e-time" $IWASM_CMD --dir=. ${t}_opt.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT
|
|
|
|
echo -en "\n" >> $REPORT
|
|
done
|