I am seeing some weird wasmtime/cranelift behavior that hopefully someone can help explain. I have a debug build of wasmtime and I am attempting to run a SIMD wasm file. I can track down the SIMD issues, but what is weird is that back-to-back invocations result in completely different errors:
$ ../wasmtime/target/debug/wasmtime --enable-simd simd.wasm thread '<unnamed>' panicked at 'assertion failed: ok', cranelift/codegen/src/postopt.rs:353:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. $ ../wasmtime/target/debug/wasmtime --enable-simd simd.wasm Error: failed to run main module `codecbench-simd.wasm` Caused by: 0: WebAssembly failed to compile 1: Compilation error: function u0:26(i64 vmctx, i64) -> i32 system_v { ... ; 20 verifier errors detected (see above). Compilation aborted.
Any idea what is going on?
Is it connected to the compilation cache? Does --disable-cache affect it?
Hm, no; when I add --disable-cache
I still get the above error pattern on multiple invocations
And it's not exactly "one of the postop error, one of the verifier errors;" when I run it a bunch of times sometimes I see more of one or the other
is there any threading in wasmtime?
What if you set env RAYON_NUM_THREADS=1?
:)
Ok, I ran that about 10 times and each time I see the verifier errors
so is this something we need to fix in wasmtime or just something to be aware of?
Also, I thought the verifier was turned off by default? How am I getting verifier errors?
We enable the verifier when cfg!(debug_assertions)
(see the .cranelift_debug_verifier(cfg!(debug_assertions))
in src/lib.rs)
I think this isn't anything we need to fix. If there's a bug somewhere in the wasm->cranelift->machine code pipeline, that bug can trigger at different times because we do parallel compilation.
And we should just fix the bug :-).
ok, sounds good
@Dan Gohman, thanks for the help above; I made the necessary fixes to get past the verification and postopt errors above but now run into another mysterious issue that may be thread-related:
when I run the Wasm SIMD code in wasmtime, wasmtime hangs; from strace
read(3, "\0asm\1\0\0\0\1\204\1\24`\1\177\1\177`\1\177\0`\3\177\177\177\1\177`\4\177\177"..., 37987) = 37986 read(3, "", 1) = 0 close(3) = 0 brk(NULL) = 0x55c08423d000 brk(0x55c084265000) = 0x55c084265000 futex(0x55c0842034a8, FUTEX_WAKE_PRIVATE, 2147483647) = 8 futex(0x55c084203450, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x55c084232d58, FUTEX_WAIT_PRIVATE, 0, NULL
what could wasmtime be waiting for after loading the Wasm code?
I don't know. Is some compilation thread entering an infinite loop?
Hm, how could I tell?
Can you run wasmtime under a debugger?
yes, and then break a few times while running it?
to see if it is in the same general region?
Let it run until it's hung, and then look at all the threads to see where they are
ok, looks like it is in wasmtime_environ...cranelift:rs:210
probably the par_iter
there?
That's the thing running all the threads. Are their any worker threads doing work?
yes, two: one is in cranelift-codegen doing some layout renumbering (?) and the other is in WorkerThread::run
so codegen is stuck in a loop somehow
That sounds likely, yes.
ok, let me go down that rabbit hole for a while
Last updated: Dec 23 2024 at 13:07 UTC