From 05d7ec30b11871488d8339a8f64a6c8392adceaa Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Wed, 15 Mar 2023 08:24:08 +0800 Subject: [PATCH] Add libsodium benchmark (#2025) --- .../compilation_on_android_ubuntu.yml | 2 +- tests/benchmarks/coremark/README.md | 2 +- tests/benchmarks/coremark/build.sh | 4 +- tests/benchmarks/jetstream/README.md | 2 +- tests/benchmarks/libsodium/README.md | 23 ++++++++ tests/benchmarks/libsodium/build.sh | 42 +++++++++++++ tests/benchmarks/libsodium/test_aot.sh | 59 +++++++++++++++++++ tests/benchmarks/polybench/README.md | 2 +- tests/benchmarks/sightglass/README.md | 2 +- 9 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 tests/benchmarks/libsodium/README.md create mode 100755 tests/benchmarks/libsodium/build.sh create mode 100755 tests/benchmarks/libsodium/test_aot.sh diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 0fa9acb0..0cb961bc 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -515,7 +515,7 @@ jobs: git fetch https://github.com/WebAssembly/wasi-libc \ 8f5275796a82f8ecfd0833a4f3f444fa37ed4546 git checkout FETCH_HEAD - make \ + make -j \ AR=/opt/wasi-sdk/bin/llvm-ar \ NM=/opt/wasi-sdk/bin/llvm-nm \ CC=/opt/wasi-sdk/bin/clang \ diff --git a/tests/benchmarks/coremark/README.md b/tests/benchmarks/coremark/README.md index 2a36e9de..1631cc5c 100644 --- a/tests/benchmarks/coremark/README.md +++ b/tests/benchmarks/coremark/README.md @@ -8,7 +8,7 @@ Please build iwasm and wamrc, refer to: - [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos) -- [build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler) +- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler) And install WASI SDK, please download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`. diff --git a/tests/benchmarks/coremark/build.sh b/tests/benchmarks/coremark/build.sh index df6b9a30..14c179ce 100755 --- a/tests/benchmarks/coremark/build.sh +++ b/tests/benchmarks/coremark/build.sh @@ -13,7 +13,7 @@ cd coremark echo "Build coremark with gcc .." gcc -O3 -Iposix -I. -DFLAGS_STR=\""-O3 -DPERFORMANCE_RUN=1 -lrt"\" \ - -DITERATIONS=0 -DPERFORMANCE_RUN=1 \ + -DITERATIONS=400000 -DSEED_METHOD=SEED_VOLATILE -DPERFORMANCE_RUN=1 \ core_list_join.c core_main.c core_matrix.c core_state.c \ core_util.c posix/core_portme.c \ -o ../coremark.exe -lrt @@ -21,7 +21,7 @@ gcc -O3 -Iposix -I. -DFLAGS_STR=\""-O3 -DPERFORMANCE_RUN=1 -lrt"\" \ echo "Build coremark with wasi-sdk .." /opt/wasi-sdk/bin/clang -O3 -Iposix -I. -DFLAGS_STR=\""-O3 -DPERFORMANCE_RUN=1"\" \ -Wl,--export=main \ - -DITERATIONS=0 -DPERFORMANCE_RUN=1 \ + -DITERATIONS=400000 -DSEED_METHOD=SEED_VOLATILE -DPERFORMANCE_RUN=1 \ -Wl,--allow-undefined \ core_list_join.c core_main.c core_matrix.c core_state.c \ core_util.c posix/core_portme.c \ diff --git a/tests/benchmarks/jetstream/README.md b/tests/benchmarks/jetstream/README.md index 9e9bcb02..f6c593d1 100644 --- a/tests/benchmarks/jetstream/README.md +++ b/tests/benchmarks/jetstream/README.md @@ -8,7 +8,7 @@ Please build iwasm and wamrc, refer to: - [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos) -- [build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler) +- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler) And install emsdk, refer to [the guide](https://emscripten.org/docs/getting_started/downloads.html). Don't forget to activate emsdk and set up environment variables. For example, use instructions below to install it under /opt and activate it: diff --git a/tests/benchmarks/libsodium/README.md b/tests/benchmarks/libsodium/README.md new file mode 100644 index 00000000..19500afe --- /dev/null +++ b/tests/benchmarks/libsodium/README.md @@ -0,0 +1,23 @@ +# Introduction + +[libsodium](https://github.com/jedisct1/libsodium) is a new, easy-to-use software library for encryption, decryption, signatures, password hashing and more. + +**Source**: https://github.com/jedisct1/libsodium + +# Building + +Please build iwasm and wamrc, refer to: +- [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos) +- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler) + +And install [zig toolchain](https://ziglang.org/learn/getting-started), refer to [Install Zig from a Package Manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager) for how to install it. + +And then run `./build.sh` to build the source code, the libsodium source code will be cloned, and test benchmarks of native version, wasm files and AOT files will be generated under `libsodium/zig-out/bin`. + +# Running + +Run `./run_aot.sh` to test the benchmark, the native mode and iwasm aot mode will be tested respectively. + +# Others + +Refer to [Performance of WebAssembly runtimes in 2023](https://00f.net/2023/01/04/webassembly-benchmark-2023) for more about the performance comparison of wasm runtimes on running the libsodium benchmarks. diff --git a/tests/benchmarks/libsodium/build.sh b/tests/benchmarks/libsodium/build.sh new file mode 100755 index 00000000..1e9cc21a --- /dev/null +++ b/tests/benchmarks/libsodium/build.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chacha20poly1305 \ + aead_xchacha20poly1305 auth2 auth3 auth5 auth6 auth7 auth box2 box7 box8 \ + box_easy2 box_easy box_seal box_seed box chacha20 codecs core1 core2 core3 \ + core4 core5 core6 core_ed25519 core_ristretto255 ed25519_convert generichash2 \ + generichash3 generichash hash3 hash kdf keygen kx metamorphic misuse \ + onetimeauth2 onetimeauth7 onetimeauth pwhash_argon2id pwhash_argon2i \ + pwhash_scrypt_ll pwhash_scrypt randombytes scalarmult2 scalarmult5 \ + scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \ + scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \ + secretbox secretstream shorthash sign siphashx24 sodium_core sodium_utils2 \ + sodium_utils3 sodium_utils sodium_version stream2 stream3 stream4 stream verify1 \ + xchacha20" + +readonly WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc +readonly OUT_DIR=$PWD/libsodium/zig-out/bin + +if [ ! -d libsodium ]; then + git clone -b stable https://github.com/jedisct1/libsodium.git +fi + +cd libsodium + +echo "Build libsodium native" +zig build -Drelease-fast -Denable_benchmarks=true + +echo "Build libsodium wasm32-wasi" +zig build -Drelease-fast -Denable_benchmarks=true -Dtarget=wasm32-wasi + +for case in ${libsodium_CASES} +do + ${WAMRC_CMD} -o ${OUT_DIR}/${case}.aot ${OUT_DIR}/${case}.wasm + + if [ "$?" != 0 ]; then + echo -e "Error while compiling ${case}.wasm to ${case}.aot" + exit + fi +done diff --git a/tests/benchmarks/libsodium/test_aot.sh b/tests/benchmarks/libsodium/test_aot.sh new file mode 100755 index 00000000..2e4e3e35 --- /dev/null +++ b/tests/benchmarks/libsodium/test_aot.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chacha20poly1305 \ + aead_xchacha20poly1305 auth2 auth3 auth5 auth6 auth7 auth box2 box7 box8 \ + box_easy2 box_easy box_seal box_seed box chacha20 codecs core1 core2 core3 \ + core4 core5 core6 core_ed25519 core_ristretto255 ed25519_convert generichash2 \ + generichash3 generichash hash3 hash kdf keygen kx metamorphic misuse \ + onetimeauth2 onetimeauth7 onetimeauth pwhash_argon2id pwhash_argon2i \ + pwhash_scrypt_ll pwhash_scrypt randombytes scalarmult2 scalarmult5 \ + scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \ + scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \ + secretbox secretstream shorthash sign siphashx24 sodium_core sodium_utils2 \ + sodium_utils3 sodium_utils sodium_version stream2 stream3 stream4 stream verify1 \ + xchacha20" + +readonly OUT_DIR=$PWD/libsodium/zig-out/bin +readonly REPORT=$PWD/report.txt +readonly IWASM_CMD=$PWD/../../../product-mini/platforms/linux/build/iwasm + +BENCH_NAME_MAX_LEN=20 + +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 +} + +# run benchmarks +cd $OUT_DIR + +echo -en "\t\t\t\t\t\tnative\tiwasm-aot\n" >> $REPORT + +for t in $libsodium_CASES +do + print_bench_name $t + + echo "run $t with native..." + echo -en "\t" >> $REPORT + ./${t} | awk -F '-' 'BEGIN{FIELDWIDTHS="10"}{ORS=""; print $1 / 1000000.0}' >> $REPORT + + echo "run $t with iwasm aot..." + echo -en "\t \t" >> $REPORT + $IWASM_CMD ${t}.aot | awk -F '-' 'BEGIN{FIELDWIDTHS="10"}{ORS=""; print $1 / 1000000.0}' >> $REPORT + + echo -en "\n" >> $REPORT +done + diff --git a/tests/benchmarks/polybench/README.md b/tests/benchmarks/polybench/README.md index 191c6f9d..7808e17d 100644 --- a/tests/benchmarks/polybench/README.md +++ b/tests/benchmarks/polybench/README.md @@ -8,7 +8,7 @@ Please build iwasm and wamrc, refer to: - [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos) -- [build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler) +- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler) And install WASI SDK, please download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`. diff --git a/tests/benchmarks/sightglass/README.md b/tests/benchmarks/sightglass/README.md index 8ffef099..a446d80e 100644 --- a/tests/benchmarks/sightglass/README.md +++ b/tests/benchmarks/sightglass/README.md @@ -8,7 +8,7 @@ Please build iwasm and wamrc, refer to: - [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos) -- [build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler) +- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler) And install WASI SDK, please download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.