From 51330846fd3c79dfac0919d058f3fb9647cf695b Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 5 Jul 2024 16:36:35 +0200 Subject: [PATCH 1/7] carve tiny_keccak benchmark out of wasm_kernel --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 9 +++++++++ crates/wasmi/benches/benches.rs | 13 ++++++------- crates/wasmi/benches/rust/tiny_keccak.wasm | Bin 0 -> 9444 bytes 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 crates/wasmi/benches/rust/tiny_keccak.wasm diff --git a/Cargo.lock b/Cargo.lock index df4450964e..6019224967 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1591,6 +1591,15 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinytemplate" version = "1.2.1" @@ -1864,6 +1873,13 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "104a7f73be44570cac297b3035d76b169d6599637631cf37a1703326a0727073" +[[package]] +name = "wasmi_benches_tiny_keccak" +version = "0.0.0" +dependencies = [ + "tiny-keccak", +] + [[package]] name = "wasmi_cli" version = "0.33.1" diff --git a/Cargo.toml b/Cargo.toml index 4b334385ee..4c5615b925 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "crates/core", "crates/wasmi", "crates/wasi", + "crates/wasmi/benches/rust/tiny_keccak", "fuzz", ] exclude = [] @@ -32,3 +33,11 @@ num-traits = { version = "0.2.8", default-features = false } [profile.bench] lto = "fat" codegen-units = 1 + +[profile.wasm] +inherits = "release" +opt-level = 3 +lto = "fat" +codegen-units = 1 +panic = "abort" +strip = "symbols" diff --git a/crates/wasmi/benches/benches.rs b/crates/wasmi/benches/benches.rs index b95cf4afcf..48beb31789 100644 --- a/crates/wasmi/benches/benches.rs +++ b/crates/wasmi/benches/benches.rs @@ -696,14 +696,13 @@ fn bench_instantiate_erc1155(c: &mut Criterion) { fn bench_execute_tiny_keccak(c: &mut Criterion) { c.bench_function("execute/tiny_keccak", |b| { - let (mut store, instance) = load_instance_from_file(WASM_KERNEL); - let prepare = instance - .get_typed_func::<(), i32>(&store, "prepare_tiny_keccak") - .unwrap(); - let keccak = instance - .get_typed_func::(&store, "bench_tiny_keccak") + let (mut store, instance) = load_instance_from_file("benches/rust/tiny_keccak.wasm"); + let test_data_ptr = instance + .get_typed_func::<(), i32>(&store, "setup") + .unwrap() + .call(&mut store, ()) .unwrap(); - let test_data_ptr = prepare.call(&mut store, ()).unwrap(); + let keccak = instance.get_typed_func::(&store, "run").unwrap(); b.iter(|| { keccak.call(&mut store, test_data_ptr).unwrap(); }) diff --git a/crates/wasmi/benches/rust/tiny_keccak.wasm b/crates/wasmi/benches/rust/tiny_keccak.wasm new file mode 100644 index 0000000000000000000000000000000000000000..ab69fe6620b839e67d0acf96f1818e78a463da27 GIT binary patch literal 9444 zcmeHN&2L;+6~7;E-h8~7@z`}zJ0I>?q(XqYB5@KYv7OrS z*sW4gWrorxby^l(P^pV70u3dIBDE4A7A%a!B1i}!u>i59e*g;>T_DQu+&gycv`9tl z(2SKi@7{av`S{&)&O3J$vAFqy6hg>a_MGl^yRv&u?R<-KvMbE2I47_m#5o5n%wwp~ z#X?Fu+HsXktBev(N?wzWlhRU*x|6yqqh4=YcwG_w;yp{ZnWk$g_l2bw);ljNk=k6^ zdhwbNy7S_ikh!yGFD`B^o?TkIsHJ!I?3Ja(YiG|dZZ2t+%}NnTPp7k9?oLpMMf472 zO)K%Fvk=|JV?<3QqFem*@sG9z4{q|HXXcsNSc7@bZ1w(>liBVu5q+Rn134u~M)5af$@in>50!cru7bqQx$AkcpD?ys{>4NY)($ViFxvPN_y<#?`$&JL9odxjgh_!<_ zD}ko8<#&u=$aE>a;=7*`>smG$q$2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VFgKBn7m)&7ltl$p*(W$JUBh_W?6emdZ2GSUUE z64GqsJ^z6lp>HptXt8h;Mg+h(lv#uxwrWls<0A?(Uz7(vD(fSDr+D=Qel{_`!hC%E zU&GH3fgu7z1cnF<5f~ycL|}-(5P=~ALj;Bh3=tS2@PCg$xm>Q4tL0j`UT&0|<*?i; zw=3mJrBbcbD)maE(yWA)R;67nS1Z+OwN|ZH8`WktthTD{TDexKRcp0cz1FBTYhkTb zYuC&5O1)aI)$8>}y;%?It$MprZd4l8My*kAG#brD*l0D{&2qEStTt=Sdb81NHp6DC z*$&HLC9HSZM&~OY>XHYcJ2PE?u~=xH?;%E6-KUwyVqM=Q^80JPLi^g1(l- z4^*Ig#|QU}pT#+?s=P(=+siCkPhV!H%4-VIO`+ z+m-uMjQu_1cQHP`XM7jqlY7S77(aqBfADBNul6i`!_uDMKOuT=+A;H)r|%5rvv$7s z2AKHsx+MbhJ$}p$__5!N-{eWm^?R1;0aXKPiRk494}<-^9euq4-;Ny_E4TM=2f0=h literal 0 HcmV?d00001 From 061c0a59cadc976f26dbe6cbfa0901f7d8665a66 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 5 Jul 2024 16:49:15 +0200 Subject: [PATCH 2/7] update tiny_keccak benchmark --- crates/wasmi/benches/benches.rs | 11 ++++++++--- crates/wasmi/benches/rust/tiny_keccak.wasm | Bin 9444 -> 12291 bytes 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/wasmi/benches/benches.rs b/crates/wasmi/benches/benches.rs index 48beb31789..f5469d0be1 100644 --- a/crates/wasmi/benches/benches.rs +++ b/crates/wasmi/benches/benches.rs @@ -697,15 +697,20 @@ fn bench_instantiate_erc1155(c: &mut Criterion) { fn bench_execute_tiny_keccak(c: &mut Criterion) { c.bench_function("execute/tiny_keccak", |b| { let (mut store, instance) = load_instance_from_file("benches/rust/tiny_keccak.wasm"); - let test_data_ptr = instance + let data_ptr = instance .get_typed_func::<(), i32>(&store, "setup") .unwrap() .call(&mut store, ()) .unwrap(); let keccak = instance.get_typed_func::(&store, "run").unwrap(); b.iter(|| { - keccak.call(&mut store, test_data_ptr).unwrap(); - }) + keccak.call(&mut store, data_ptr).unwrap(); + }); + instance + .get_typed_func::(&store, "teardown") + .unwrap() + .call(&mut store, data_ptr) + .unwrap(); }); } diff --git a/crates/wasmi/benches/rust/tiny_keccak.wasm b/crates/wasmi/benches/rust/tiny_keccak.wasm index ab69fe6620b839e67d0acf96f1818e78a463da27..aef48b5d2f3ecf546f6b51b3732f9a71f3c12505 100644 GIT binary patch literal 12291 zcmbuFOKe=%dB@MW_s)YF4mpx(M-t`e+-o@!?MUKthD;iRcL2#zUDZL+M^=?-iMB+_ zlK8Nqw1LPZ9>h$t@WKI%LIn)eKvmRfT)-%d!V4A9LIu>q3l}vCF9OsBvdF>(vdF@y z`}?1BXZVneIIRfHchCEKpYQwbHFGO3SYwQx>U$<$TU)bh&qQl$Mn61Sp44leF}}r5 zLQ_K?nt14eQaO$j{n@But*x?KQnFWUl9Xa=c9-|XYc^kBzh!D`CjYM=2KcdH<%x3n zh4~jQFMm5SrIq>B7q1voU7ep>K6m+BmrN8dzj(=%cAYtMZf1Quv8|msbAEpA z%9&^9R_5cVug{v?*5Y0Lja@hX(T7?KNkGTo=#@-w;}FG zWU?r4&{tc?e;qIB;nZ+e%Hykef=L#d07L{_xd2Sz5>&;m{|CH89M1F?gl1i|VGdRM_pxn)v(bv28YBu4ea>=IO= zzA(dyPqh@<#HFeP5twBHi0G{OtzEf$y2k^SRTl?c&1%j^2+CI8b!0QHv)09 zkr`Bhhavxf`1ht2SqP`n=+DeaPty=q;dR3ddr{iD_4*fim8l{cj~rVCfkNTX0zZuf zXNIMVE>6o1%T~AX-8$1UMpL`n?#2ioQ}IerIZ;Q+bnt;5MH$E%=};waUV?^qcQ-G%oZI-&35Xz-KyhJkXlfAJopYB z2jxP?bE`=YaIDSf06w65y`@o(M#!rd*Q!(-q~z*!E6EDWYV`+D-A25V1{;4T zi2&K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tS2@PCg$xm>Q4tL0j`UT&0|<*?i; zw=3mJrBbcbD)maE(yWA)R;67nS1Z+OwN|ZH8`WktthTD{TDexKRcp0cz1FBTYhkTb zYuC&5O1)aI)$8>}y;%?It$MprZd4l8My*kAG#brD*l0D{&2qEStTt=Sdb81NHp6DC z*$&HLC9HSZM&~OY>XHYcJ2PE?u~=xH?;%E6-KUwyVqM=Q^80JPLi^g1(l- z4^*Ig#|QU}pT#+?s=P(=+siCkPhV!H%4-VIO`+ z+m-uMjQu_1cQHP`XM7jqlY7S77(aqBfADBNul6i`!_uDMKOuT=+A;H)r|%5rvv$7s z2AKHsx+MbhJ$}p$__5!N-{eWm^?R1;0aXKPiRk494}<-^9euq4-;Ny_E4TM=2f0=h From e5c3a9169f6e9134f9413da79267e8a0914a65f6 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 5 Jul 2024 17:06:04 +0200 Subject: [PATCH 3/7] add tiny_keccak sub project --- .../wasmi/benches/rust/tiny_keccak/Cargo.toml | 13 +++++++ .../wasmi/benches/rust/tiny_keccak/README.md | 35 +++++++++++++++++++ crates/wasmi/benches/rust/tiny_keccak/lib.rs | 24 +++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 crates/wasmi/benches/rust/tiny_keccak/Cargo.toml create mode 100644 crates/wasmi/benches/rust/tiny_keccak/README.md create mode 100644 crates/wasmi/benches/rust/tiny_keccak/lib.rs diff --git a/crates/wasmi/benches/rust/tiny_keccak/Cargo.toml b/crates/wasmi/benches/rust/tiny_keccak/Cargo.toml new file mode 100644 index 0000000000..caee06eef6 --- /dev/null +++ b/crates/wasmi/benches/rust/tiny_keccak/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "wasmi_benches_tiny_keccak" +version = "0.0.0" +publish = false +authors.workspace = true +edition.workspace = true + +[lib] +path = "lib.rs" +crate-type = ["cdylib"] + +[dependencies] +tiny-keccak = { version = "2.0.2", features = ["keccak"] } diff --git a/crates/wasmi/benches/rust/tiny_keccak/README.md b/crates/wasmi/benches/rust/tiny_keccak/README.md new file mode 100644 index 0000000000..4062879e90 --- /dev/null +++ b/crates/wasmi/benches/rust/tiny_keccak/README.md @@ -0,0 +1,35 @@ +## Benchmark - Tiny Keccak + +Rust based `tiny_keccak` benchmark test case. + +Build with + +``` +cargo build \ + --package wasmi_benches_tiny_keccak \ + --profile wasm \ + --target wasm32-unknown-unknown +``` + +Post-optimize with `wasm-opt` using: + +``` +wasm-opt \ + -O3 \ + target/wasm32-unknown-unknown/wasm/wasmi_benches_tiny_keccak.wasm \ + -o target/wasm32-unknown-unknown/wasm/wasmi_benches_tiny_keccak.opt.wasm +``` + +Finally move the post-optimized Wasm binary into the proper place: + +``` +cp \ + target/wasm32-unknown-unknown/wasm/wasmi_benches_tiny_keccak.opt.wasm \ + crates/wasmi/benches/rust/tiny_keccak.wasm +``` + +Benchmark with: + +``` +cargo bench --bench benches execute/tiny_keccak +``` diff --git a/crates/wasmi/benches/rust/tiny_keccak/lib.rs b/crates/wasmi/benches/rust/tiny_keccak/lib.rs new file mode 100644 index 0000000000..f2deb24727 --- /dev/null +++ b/crates/wasmi/benches/rust/tiny_keccak/lib.rs @@ -0,0 +1,24 @@ +use tiny_keccak::{Hasher, Keccak}; + +pub struct TinyKeccakData { + data: Box<[u8; 4096]>, + result: [u8; 32], +} + +#[no_mangle] +pub extern "C" fn setup() -> Box { + Box::new(TinyKeccakData { + data: Box::new([254_u8; 4096]), + result: [0x0_u8; 32], + }) +} + +#[no_mangle] +pub extern "C" fn teardown(_: Box) {} + +#[no_mangle] +pub extern "C" fn run(data: &mut TinyKeccakData) { + let mut keccak = Keccak::v256(); + keccak.update(&data.data[..]); + keccak.finalize(&mut data.result[..]); +} From bf55b78b2d9db471cdf1b5de30f04aa0370ac68a Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 5 Jul 2024 17:08:44 +0200 Subject: [PATCH 4/7] rename and add docs --- crates/wasmi/benches/rust/tiny_keccak/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/wasmi/benches/rust/tiny_keccak/lib.rs b/crates/wasmi/benches/rust/tiny_keccak/lib.rs index f2deb24727..8a35b238e7 100644 --- a/crates/wasmi/benches/rust/tiny_keccak/lib.rs +++ b/crates/wasmi/benches/rust/tiny_keccak/lib.rs @@ -1,14 +1,17 @@ use tiny_keccak::{Hasher, Keccak}; +/// The data required to run the `tiny_keccak` benchmark. pub struct TinyKeccakData { - data: Box<[u8; 4096]>, + /// The input data to the tiny keccak hasher. + input: Box<[u8; 4096]>, + /// The buffer to store the hash result. result: [u8; 32], } #[no_mangle] pub extern "C" fn setup() -> Box { Box::new(TinyKeccakData { - data: Box::new([254_u8; 4096]), + input: Box::new([254_u8; 4096]), result: [0x0_u8; 32], }) } @@ -19,6 +22,6 @@ pub extern "C" fn teardown(_: Box) {} #[no_mangle] pub extern "C" fn run(data: &mut TinyKeccakData) { let mut keccak = Keccak::v256(); - keccak.update(&data.data[..]); + keccak.update(&data.input[..]); keccak.finalize(&mut data.result[..]); } From 7171a8b193e22de91e38297a06995091e905a7f0 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 5 Jul 2024 17:10:23 +0200 Subject: [PATCH 5/7] remove unnecessary indirection --- crates/wasmi/benches/rust/tiny_keccak/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/wasmi/benches/rust/tiny_keccak/lib.rs b/crates/wasmi/benches/rust/tiny_keccak/lib.rs index 8a35b238e7..9a6cb754d2 100644 --- a/crates/wasmi/benches/rust/tiny_keccak/lib.rs +++ b/crates/wasmi/benches/rust/tiny_keccak/lib.rs @@ -3,7 +3,7 @@ use tiny_keccak::{Hasher, Keccak}; /// The data required to run the `tiny_keccak` benchmark. pub struct TinyKeccakData { /// The input data to the tiny keccak hasher. - input: Box<[u8; 4096]>, + input: [u8; 4096], /// The buffer to store the hash result. result: [u8; 32], } @@ -11,7 +11,7 @@ pub struct TinyKeccakData { #[no_mangle] pub extern "C" fn setup() -> Box { Box::new(TinyKeccakData { - input: Box::new([254_u8; 4096]), + input: [254_u8; 4096], result: [0x0_u8; 32], }) } From 80b83c1567ddfd1402eaece3ff25f69a040065df Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 5 Jul 2024 17:14:24 +0200 Subject: [PATCH 6/7] add wasmi_benches_tiny_keccak exception for CI --- .github/workflows/rust.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b9565ce6ec..52da6ea9a3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -29,9 +29,29 @@ jobs: - name: Build (no_std + no-hash-maps) run: cargo build --locked -p wasmi_collections --no-default-features --features no-hash-maps --verbose - name: Build (no_std) - run: cargo build --workspace --locked --lib --no-default-features --target x86_64-unknown-none --verbose --exclude wasmi_cli --exclude wasmi_wasi --exclude wasmi_fuzz + run: cargo build \ + --workspace \ + --locked \ + --lib \ + --no-default-features \ + --target x86_64-unknown-none \ + --verbose \ + --exclude wasmi_cli \ + --exclude wasmi_wasi \ + --exclude wasmi_fuzz \ + --exclude wasmi_benches_tiny_keccak - name: Build (wasm32) - run: cargo build --workspace --locked --lib --no-default-features --target wasm32-unknown-unknown --verbose --exclude wasmi_cli --exclude wasmi_wasi --exclude wasmi_fuzz + run: cargo build \ + --workspace \ + --locked \ + --lib \ + --no-default-features \ + --target wasm32-unknown-unknown \ + --verbose \ + --exclude wasmi_cli \ + --exclude wasmi_wasi \ + --exclude wasmi_fuzz \ + --exclude wasmi_benches_tiny_keccak test-asan: name: Test (Address Sanitizer) From b71bca7e5c49aaed05340e8ba677c73651428c92 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 5 Jul 2024 17:18:43 +0200 Subject: [PATCH 7/7] fix CI yml file --- .github/workflows/rust.yml | 44 ++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 52da6ea9a3..f45ef3b3c6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -29,28 +29,30 @@ jobs: - name: Build (no_std + no-hash-maps) run: cargo build --locked -p wasmi_collections --no-default-features --features no-hash-maps --verbose - name: Build (no_std) - run: cargo build \ - --workspace \ - --locked \ - --lib \ - --no-default-features \ - --target x86_64-unknown-none \ - --verbose \ - --exclude wasmi_cli \ - --exclude wasmi_wasi \ - --exclude wasmi_fuzz \ - --exclude wasmi_benches_tiny_keccak + run: >- + cargo build + --workspace + --locked + --lib + --no-default-features + --target x86_64-unknown-none + --verbose + --exclude wasmi_cli + --exclude wasmi_wasi + --exclude wasmi_fuzz + --exclude wasmi_benches_tiny_keccak - name: Build (wasm32) - run: cargo build \ - --workspace \ - --locked \ - --lib \ - --no-default-features \ - --target wasm32-unknown-unknown \ - --verbose \ - --exclude wasmi_cli \ - --exclude wasmi_wasi \ - --exclude wasmi_fuzz \ + run: >- + cargo build + --workspace + --locked + --lib + --no-default-features + --target wasm32-unknown-unknown + --verbose + --exclude wasmi_cli + --exclude wasmi_wasi + --exclude wasmi_fuzz --exclude wasmi_benches_tiny_keccak test-asan: