MLIR (+Python bindings) entirely in the browser

For fun I built/compiled MLIR and the Python bindings into a wasm-emscripten wheel using Pyodide:

https://makslevental.github.io/mlir-python-wasm

Just to be clear - this is running entirely in the browser - no phoning home to some Jupyter server.

It went better than expected, in terms of how much of a lift it was, and in terms of functionality. Pyodide tooling did most of the work (hats off to those people for gluing all of this together…). The hardest part was finding a place to “host” the wheel so it could be “pip installed” due to the CORS requirements on the browser.

Everything seems to work but one thing that currently doesn’t work is ExecutionEngine (i.e., jitting) - you get Failed to create a TargetMachine for the host. But there should be a path forward there too since clang-repl already figured this part out. Hopefully I’ll have some free time soon to get that part to work too. Then we can do E2E in the browser or maybe even GPU execution via the SPIR-V path? Not sure.

So this is LLVM/MLIR and the Python bindings and the Python interpreter running entirely in the browser JS runtime. Reminds me of a meme…

Oh and if [RFC] MLIR Dialect for WebAssembly lands we can take the inception one level deeper (or something like that) and use the bindings for that dialect to write and compile wasm.

Anyway, here are all the scripts to repro. And once this lands the wheel will be distributed as well at https://makslevental.github.io/wheels.

11 Likes