Comments (7)
Thanks for opening this issue! I think you explained well (at least I have the feeling of understanding :D)
Is it alright to change the existing functions to accept a "byte offset" instead or should there be new functions?
We are still in the development phase and haven't stabilized yet (whatever that means). Changing the behavior of that function is OK as long as we properly update the package version and CHANGELOG.
Do you have an idea how to achieve this in the rust code other than to always start with the view and then recalculate the view from there?
Good question. We may have to look into wasmer internals - which, at this point in time, may not be the best idea. They are rewriting wasmer from scratch (see #45 ). I got access to a beta tester preview of their rewrite and currently adapt wasmex to work with it (it does not compile yet, sadly).
We could totally fix this issue now (feel free to attempt). But if you can wait for the rewrite, it may save some effort to start with the new version once it's available.
from wasmex.
Hmm, I think (if possible to do) offset
should always be bytes. If we do all the bytes-to-actual-values-conversion in elixir, I fear of performance impact for large chunks of memory.
If we're done with adapting to the wasmer rewrite, I will try to make offset
count bytes instead of arbitrary units. If that does not work, conversion in elixir is probably the next best solution.
from wasmex.
Since we're preparing the aforementioned wasmtime switch (having a different memory API), I believe this ticket can be closed.
Nathan, please feel free to reopen if you feel this is undeserved :)
from wasmex.
I have some code to work around it for now by doing the integer conversion in elixir:
@spec get_uint32(Wasmex.Memory.t(), non_neg_integer, non_neg_integer) :: non_neg_integer
defp get_uint32(memory, offset, index) do
<<value::little-32>> =
for i <- 0..3, into: <<>>, do: <<Wasmex.Memory.get(memory, :uint8, offset, index + i)>>
value
end
so I am fine with waiting a bit to change the rust. I am wondering if it makes sense to just do this work in elixir and have rust always see the memory as bytes? @tessi what do you think about that?
from wasmex.
@tessi I think your idea of the offset
always being in bytes makes sense and it would work for my use case. I can keep using my elixir code until you are ready to work on this 🙇
from wasmex.
@myobie I gave the whole memory API some thinking over the last couple of days and the more I look at it, the more I feel we shouldn't support all the different types (u8, u16, u32, ...) in the first place. At the wasmex layer, I think, we should closely follow WASMs linear memory model of a memory just being a couple of bytes.
In my experiment to rewrite wasmex to the wasmtime engine, I already made that change. And the memory API is soo much simpler and more consistent.
To properly interface with WASM programs, my feeling is the Elixir app that uses wasmex needs to decide for the ABI with the WASM program. This is not something wasmex can or should do 🤔 We can only make it simple by having clear APIs.
Maybe, we can solve that by having some elixir-side helper methods, or (very long term) utilize something like https://github.com/bytecodealliance/wit-bindgen to generate Elixir code that interfaces with WASM. Maybe something close to what wasm-bindgen is for the JS ecosystem.
What do you think?
from wasmex.
@tessi I think just a list of bytes is perfect.
For my use case, I can't use bindgen since I use the wasm binary on a lot of different platforms and not every platform has a bindgen, so my exported wasm functions are expected to be used directly and communicate with either ints or floats.
from wasmex.
Related Issues (20)
- Offer precompiled wasmex binaries HOT 3
- Require at least elixir 1.11 HOT 3
- Allow call_function to accept longer GenServer timeouts HOT 1
- Underlying Wasm runtime, wasmer -> wasmtime HOT 17
- Ability to cache compiled modules HOT 2
- How safe is it to run untrusted user wasm modules? HOT 2
- Example using WASI HOT 2
- Calls and execution model HOT 10
- Send and receive WASI std IO as Erlang messages HOT 1
- Switch to an async Rust runtime
- Seems like rust is a prerequisite? HOT 1
- Error during default engine config test and fuel consumption test HOT 4
- call_function example does not behave as expected HOT 2
- consume_fuel function example does not work as expected HOT 1
- unknown import: `wasi_snapshot_preview1::random_get` has not been defined HOT 4
- Compatibility with Lunatic.Solutions HOT 2
- Support for dynamic linking HOT 2
- WebAssembly component support
- Unable to run go code compiled to WASM HOT 1
- Unable to run Go code compiled for WASI HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasmex.