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 wasm32 #11

Merged
merged 15 commits into from
Jan 24, 2023
Merged

Add wasm32 #11

merged 15 commits into from
Jan 24, 2023

Conversation

cdmurph32
Copy link
Contributor

@cdmurph32 cdmurph32 commented Jan 10, 2023

Methodology:

  1. Replace sse4 commands with wasm32 equivalents (https://emscripten.org/docs/porting/simd.html)
  2. Reverse shuffle array order.
  3. Improve efficiency
    a. Declare shuffle arrays as constants to avoid extra bounds checking instructions.
    b. Use f32x4_pmin instead of f32x4_min

Issues encountered:

  1. With Wasm, the SIMD instructions are determined at runtime depending on the system used. On x86 sse4 _mm_cvtps_epi32 converts inf to i32::MIN or 2_147_483_648u32, while its wasm32 equivalent (on AVX), u32x4_trunc_sat_f32x4, converts inf to u32::MAX. i32x4_trunc_sat_f32x4 converts inf to i32::MAX and cannot be used. This is corrected by capping the result of u32x4_trunc_sat_f32x4 at 2_147_483_648, but introduces an additional instruction.
  2. glassbench uses chrono instead of chrono-wasi with the wasm32-wasi target and cannot currently be used.

Test command:
CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime --dir=." cargo wasi test -- --nocapture

@cdmurph32 cdmurph32 mentioned this pull request Jan 10, 2023
@cdmurph32
Copy link
Contributor Author

FYI Glassbench does not work in webassembly for a multitude of reasons. I'm playing around with benchmark-simple, which works with WASM, but I don't know if that would be be something that should be merged.

@Cykooz
Copy link
Owner

Cykooz commented Jan 11, 2023

Thank you for your work. I will check it when I have more free time.

src/wasm32_utils.rs Outdated Show resolved Hide resolved
src/wasm32_utils.rs Outdated Show resolved Hide resolved
src/wasm32_utils.rs Outdated Show resolved Hide resolved
src/alpha/u16x2/wasm32.rs Show resolved Hide resolved
src/wasm32_utils.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/alpha/u16x2/wasm32.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/convolution/u16x1/wasm32.rs Show resolved Hide resolved
src/alpha/u16x2/wasm32.rs Outdated Show resolved Hide resolved
src/wasm32_utils.rs Outdated Show resolved Hide resolved
@cdmurph32
Copy link
Contributor Author

I removed the simple benchmark stuff. Looks good!

@Cykooz Cykooz merged commit b765af5 into Cykooz:main Jan 24, 2023
@Cykooz
Copy link
Owner

Cykooz commented Jan 24, 2023

How run benchmarks? I've got many errors:

[wasm-validator error in function 2164] unexpected false: SIMD operation (SIMD is disabled), on 
(v128.store align=1
 (local.get $1)
 (v128.load offset=1351328 align=1
  (i32.const 0)
 )
)

I use command:

CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime --dir=. --wasm-features all" cargo wasi bench --bench bench_resize

@cdmurph32
Copy link
Contributor Author

How run benchmarks? I've got many errors:

[wasm-validator error in function 2164] unexpected false: SIMD operation (SIMD is disabled), on 
(v128.store align=1
 (local.get $1)
 (v128.load offset=1351328 align=1
  (i32.const 0)
 )
)

I use command:

CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime --dir=. --wasm-features all" cargo wasi bench --bench bench_resize

CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime --dir=." cargo bench .

@cdmurph32
Copy link
Contributor Author

Thank you so much!

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 this pull request may close these issues.

2 participants