wasm compilation #108
-
hi @martinjrobins - thanks for this interesting library! I was doing some light experimentation to attempt to get the PK example to compile via wasm with the eventual hope/direction of getting it to run in the browser. In looking at your other contributions you are clearly very aware of wasm/some of the limitations and was hoping you could shed some light. This question might be more relevant for the diffsl repo, as it doesn't seem that this is a diffsol problem per say, rather using it with diffsl for the codegen.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @dpastoor, yes I have come across this error when I tried to compile to wasm. The Cranelift is one of two backends that you can use with diffsl, the other being based on LLVM. Cranelift I've not had success compiling to wasm, there is an 3 year old issue about this on their repo bytecodealliance/wasmtime#2566. LLVM (and Enzyme) I can compile to wasm outside a rust build system using emscripten and CMake, but I've not been able to integrate this into a cargo build in such a way that I could link diffsl to it. I would like to provide an easy way to compile diffsol to wasm, but currently those are the blockers, either getting the LLVM or Cranelift dependencies to compile to wasm. If you are happy with fixed equations using rust (instead of diffsl), you can just turn off the diffsl feature and compile your equations + diffsol to wasm, I've not actually tried this but it should in theory work, let me know if not. I do have a workaround if you want to use diffsl. I've setup a server that will return wasm if you post a request with diffsl code, and written a basic javascript library that uses this (https://www.npmjs.com/package/@martinjrobins/diffeq-js). You can then use this to solve your equations in the browser, see this demonstrator: https://martinjrobins.github.io/diffeq-web/. This doesn't actually use diffsol (I wrote it before I started diffsol), but instead uses the Sundials library, so the wasm you get from the server is "diffsl compiled to wasm" linked to "Sundials solver + KLU compiled to wasm". Its very fast, currently I think the fastest way to solve odes in the browser (take that with a big grain of salt as no benchmarking has been done!!) |
Beta Was this translation helpful? Give feedback.
-
Thanks @martinjrobins - this context is super helpful. I had seen your diffeq-web and indeed could go that direction. to give you some flavor - for day-to-day work we use github.com/metrumresearchgroup/mrgsolve for all our diffeq/PKPD simulation needs, however I am looking to build a number of visualizations to explain interactively PK concepts. In particular, i'm hoping to rebuild a number of the educational concepts built on the boomer.org PK website such as https://boomer.org/c/p4/c06/c0604.php as a starting point. Of course there are also a number of actual business cases too around moving our simulation-based applications off the server into the browser only, though I figured we'd start with some low risk experimentation :-) I will keep you updated if I'm able to make some progress! |
Beta Was this translation helpful? Give feedback.
-
ok, sounds great :) Let me know how you go and if you run into any problems feel free to reach out. |
Beta Was this translation helpful? Give feedback.
Hi @dpastoor, yes I have come across this error when I tried to compile to wasm. The
region-2.2.0
crate is brought in bycranelift_jit
, which doesn't currently seem to support compilation to a wasm target.Cranelift is one of two backends that you can use with diffsl, the other being based on LLVM. Cranelift I've not had success compiling to wasm, there is an 3 year old issue about this on their repo bytecodealliance/wasmtime#2566. LLVM (and Enzyme) I can compile to wasm outside a rust build system using emscripten and CMake, but I've not been able to integrate this into a cargo build in such a way that I could link diffsl to it.
I would like to provide an easy way to compile diffsol to w…