Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an implementation using Wasm SIMD #187

Open
oconnor663 opened this issue Jul 29, 2021 · 3 comments · May be fixed by #341
Open

add an implementation using Wasm SIMD #187

oconnor663 opened this issue Jul 29, 2021 · 3 comments · May be fixed by #341

Comments

@oconnor663
Copy link
Member

Rust just shipped version 1.54, which stabilizes Wasm SIMD intrinsics. We should port the SSE4.1 implementation to use these. First I should add Wasm to CI and make sure benchmarks work there.

@oconnor663
Copy link
Member Author

oconnor663 commented Jul 29, 2021

Looks like the current easiest way to run benchmarks is:

cargo +nightly build --benches --release --target wasm32-wasi
wasmer ./target/wasm32-wasi/release/deps/bench-*.wasm -- --bench

(Though that wildcard doesn't do what I want when I build multiple versions of the bench binary. I need something simpler...)

At the moment, this requires getting rid of the line where we use page_size:

diff --git a/Cargo.toml b/Cargo.toml
index a43f000..eadf73c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -89,7 +89,6 @@ crypto-mac = { version = "0.11.0", optional = true }
 
 [dev-dependencies]
 hex = "0.4.2"
-page_size = "0.4.1"
 rand = "0.8.0"
 rand_chacha = "0.3.0"
 reference_impl = { path = "./reference_impl" }
diff --git a/benches/bench.rs b/benches/bench.rs
index 5efb9e6..c53278e 100644
--- a/benches/bench.rs
+++ b/benches/bench.rs
@@ -25,7 +25,7 @@ pub struct RandomInput {
 impl RandomInput {
     pub fn new(b: &mut Bencher, len: usize) -> Self {
         b.bytes += len as u64;
-        let page_size: usize = page_size::get();
+        let page_size: usize = 65536;
         let mut buf = vec![0u8; len + page_size];
         let mut rng = rand::thread_rng();
         rng.fill_bytes(&mut buf);

But once Elzair/page_size_rs#3 lands upstream this workaround shouldn't be necessary anymore.

monoid added a commit to monoid/BLAKE3 that referenced this issue Sep 10, 2023
This code is based on rust_sse2.rs of the same distribution, and is
subject to further improvements. Some comments are left intact even if
their applicability is questioned.

Performance measurements with a primitive benchmark with ~16Kb of data:

| M1 native     | 11,610 ns |
| M1 WASM SIMD  | 13,355 ns |
| M1 WASM       | 22,037 ns |
| x64 native    |  6,713 ns |
| x64 WASM SIMD | 11,985 ns |
| x64 WASM      | 25,978 ns |

wasmtime v12.0.1 was used on both platforms.

Closes BLAKE3-team#187.
monoid added a commit to monoid/BLAKE3 that referenced this issue Sep 10, 2023
This code is based on rust_sse2.rs of the same distribution, and is
subject to further improvements. Some comments are left intact even if
their applicability is questioned.

SIMD implementation is gated by `wasm32-simd` feature, portable version
is used otherwise.

Performance measurements with a primitive benchmark with ~16Kb of data:

| M1 native     | 11,610 ns |
| M1 WASM SIMD  | 13,355 ns |
| M1 WASM       | 22,037 ns |
| x64 native    |  6,713 ns |
| x64 WASM SIMD | 11,985 ns |
| x64 WASM      | 25,978 ns |

wasmtime v12.0.1 was used on both platforms.

Closes BLAKE3-team#187.
@monoid monoid linked a pull request Sep 10, 2023 that will close this issue
monoid added a commit to monoid/BLAKE3 that referenced this issue Sep 11, 2023
This code is based on rust_sse2.rs of the same distribution, and is
subject to further improvements. Some comments are left intact even if
their applicability is questioned.

SIMD implementation is gated by `wasm32-simd` feature, portable version
is used otherwise.

Performance measurements with a primitive benchmark with ~16Kb of data:

| M1 native     | 11,610 ns |
| M1 WASM SIMD  | 13,355 ns |
| M1 WASM       | 22,037 ns |
| x64 native    |  6,713 ns |
| x64 WASM SIMD | 11,985 ns |
| x64 WASM      | 25,978 ns |

wasmtime v12.0.1 was used on both platforms.

Closes BLAKE3-team#187.
@monoid
Copy link

monoid commented Nov 9, 2023

Hi, @oconnor663! Is there anything you would like me to improve in this PR?

@oconnor663
Copy link
Member Author

Apologies, I've been distracted by other things. I'll make a calendar note to come back to this PR this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants