4 ms·
When I implemented a WASM compiler, the only source of float-based non-determinism I found was in the exact byte representation of NaN. Floating point math is d
by kodablah 3y ago
When I implemented a WASM compiler, the only source of float-based non-determinism I found was in the exact byte representation of NaN. Floating point math is deterministic. See https://webassembly.org/docs/faq/#why-is-there-no-fast-math-mode-with-relaxed-floating-point-semantics https://webassembly.org/docs/faq/#why-is-there-no-fast-math-... and https://github.com/WebAssembly/design/blob/main/Nondeterminism.md https://github.com/WebAssembly/design/blob/main/Nondetermini....
- adgjlsfhk1 3y agoThe other common one is elementary functions from libm (i.e. exp/log etc)
- jcranmer 3y agoDo note that sqrt should return the same results on all libm implementations, as well as functions like nextafter or scalbn.
- ajb 3y agoIt may also be thread nondeterminism, eg relying on the commutativity of addition etc.
- aseipp 3y agoOn that note, Wasmtime has an option to enable NaN canonicalization, which should patch that hole, too: https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.cranelift_nan_canonicalization https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#...
- nextaccountic 3y ago> Floating point math is deterministic. It is deterministic in a single machine, but it unfortunately is not deterministic across machines (and specially not across architectures) ... however, if you restrict yourself to a subset of floating point, it's straightforward to provide cross-platform determinism. That's what's the Rapier physics engine does https://rapier.rs/docs/user_guides/rust/determinism/ https://rapier.rs/docs/user_guides/rust/determinism/