RReverser / wasm-bindgen-rayon

An adapter for enabling Rayon-based concurrency on the Web with WebAssembly.
https://docs.rs/wasm-bindgen-rayon
Apache License 2.0
156 stars 19 forks source link

Running in the Main Thread #5

Open mfranzs opened 8 months ago

mfranzs commented 8 months ago

To work around crossOriginIsolation issues coming from the SharedArrayBuffer, I'm trying to run this package in the main thread. I see that support was added for this recently.

However, when I remove the rustflags = '--cfg web_sys_unstable_apis -Ctarget-feature=+atomics,+bulk-memory,+mutable-globals' CLI setting suggested in the README, I get this error:

compile_error!("Did you forget to enable atomics and bulk-memory features as outlined in wasm-bindgen-rayon README?");

Do you know how I can get this running in the main thread, or how I can get rayon itself running in the main thread? For context, my goal is to run burn either in the main thread or in a worker, with crossOriginIsolation off.

Thank you very much!

AlexErrant commented 8 months ago

FYI this proj demos Rayon+Burn running in the main thread. I know this because the entire screen freezes when I run training. Despite being on the main thread, it still (empirically) requires +atomics,+bulk-memory. I guess a natural question is "are you sure you can't enable coop/coep?"

(I'm currently trying to figure out how to move it off the main thread, but I'm running into bundler issues. Bah.)

9SMTM6 commented 2 months ago

AFAICT that should (both @AlexErrant) work by simply dropping wasm-bindgen-rayon. Rayon readme:

By default, when building to WebAssembly, Rayon will treat it as any other platform without multithreading support and will fall back to sequential iteration. This allows existing code to compile and run successfully with no changes necessary, but it will run slower as it will only use a single CPU core.