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

Setup compiler backend for producing wasm32 + simd executables #4019

Closed
benvanik opened this issue Nov 28, 2020 · 3 comments · Fixed by #8285
Closed

Setup compiler backend for producing wasm32 + simd executables #4019

benvanik opened this issue Nov 28, 2020 · 3 comments · Fixed by #8285
Assignees
Labels
compiler/dialects Relating to the IREE compiler dialects (flow, hal, vm) enhancement ➕ New feature or request hal/cpu Runtime Host/CPU-based HAL backend platform/web 🌐 Web-specific build, execution, benchmarking, and deployment

Comments

@benvanik
Copy link
Collaborator

I suspect we will be able to reuse a majority of the LLVM AOT infra for producing the wasm32 binaries: it's just an LLVM target arch/format.

The WAMR examples compile with LLVM with --target=wasm32-wasi -msimd128. That should give us a .wasm file (vs. a .dll or .so) we can embed in a wasm flatbuffer (along with the reflection information) or reference as a file.

@benvanik benvanik added compiler/dialects Relating to the IREE compiler dialects (flow, hal, vm) enhancement ➕ New feature or request hal/cpu Runtime Host/CPU-based HAL backend labels Nov 28, 2020
ScottTodd added a commit to ScottTodd/iree that referenced this issue Feb 6, 2021
@ScottTodd ScottTodd self-assigned this Feb 6, 2021
@ScottTodd
Copy link
Member

I've started on this. I have a WasmLinkerTool that finds wasm-ld and is able to link something with -iree-llvm-target-triple=wasm32-unknown-unknown. Will need to try out some flags and peek at what it generated to see if the output is usable.

@benvanik
Copy link
Collaborator Author

benvanik commented Feb 6, 2021

ooo cool! I think I played with adding a wamr submodule once; didn't get far though :P
image

ScottTodd added a commit that referenced this issue Mar 1, 2021
Progress on #4019. I can generate .wasm files using `iree-translate -iree-hal-target-backends=dylib-llvm-aot -iree-llvm-target-triple=wasm32-unknown-unknown -iree-llvm-keep-linker-artifacts` and can inspect the .wasm artifacts using `wasm-decompile` and the other tools from https://github.com/WebAssembly/wabt. I haven't yet been able to actually call a function from a generated .wasm file and inspect its output though, so we could be missing some configuration.

This PR also includes some supporting changes in the other linker tools, mostly playing cross-platform development whack-a-mole until the code is robust enough. As one side effect, I can now use `UnixLinkerTool` from Windows, by passing `-iree-llvm-target-triple=x86_64-linux-gnu`, which discovers `C:\Program Files\LLVM\bin\ld.lld` on my system, from having that `bin\` directory on my `PATH`.
@ScottTodd
Copy link
Member

The wasm executables we can produce now are usable. Here's a prototype proving that we can call into them and read back the expected outputs using WAMR, which I'll be integrating into IREE's HAL (tracked in other issues): https://gist.github.com/ScottTodd/4d01f92c434e6caebf1bf2b180f02840.

I haven't looked into simd codegen or runtime support yet, and there is still some room for tweaking flags (--allow-undefined in particular).

ScottTodd added a commit that referenced this issue Mar 12, 2021
#5079)

Progress on #4019

There's still more work to do with build/test configurations and filtering, but this at least gets us to the point where IREE's LLVM AOT compiler path can generate flatbuffers suitable for a `wasm` runtime HAL to handle.

I'm using these flags:
* compiler: `-iree-hal-target-backends=wasm-llvm-aot -iree-llvm-target-triple=wasm32-unknown-unknown`
* runtime: `--driver=wasm`
@ScottTodd ScottTodd added the platform/web 🌐 Web-specific build, execution, benchmarking, and deployment label Feb 9, 2022
ScottTodd added a commit that referenced this issue Feb 10, 2022
Fixes #4019 (the compiler backend is stable enough for demos and this seems to be all that is needed to enable SIMD in our codegen).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/dialects Relating to the IREE compiler dialects (flow, hal, vm) enhancement ➕ New feature or request hal/cpu Runtime Host/CPU-based HAL backend platform/web 🌐 Web-specific build, execution, benchmarking, and deployment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants