Stream: git-wasmtime

Topic: wasmtime / issue #4300 how to write Rust WASM code to tak...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2022 at 00:39):

sehz opened issue #4300:

It seem like wasmtime allow Instance to be created with multiple memories (including shared memory) https://docs.wasmtime.dev/api/wasmtime/struct.Instance.html#method.new. Is there examples on how to write Rust WebAssembly code to access those memories?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2022 at 08:22):

bjorn3 commented on issue #4300:

I don't believe LLVM exports the ability to use multiple memories.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2022 at 18:07):

Rochet2 commented on issue #4300:

https://bytecodealliance.zulipchat.com/#narrow/stream/206238-general/topic/Multiple.20memories.20without.20WAT
In this topic in Mar 4. 2021 it was said:

wasmtime supports running wat files directly, so that should work

Wasmtime should have runtime support for multi-module and the wasm-toolsrepo should have support for the text/binary format as well. I don't personally know of any toolchains which support using or emitting multi-memory at this time. I'm not sure if LLVM has plans to add support for it in the future either.

So you likely need to code directly in WAT and then maybe you can compile that into a module. I do not know if there are advancements in this area since then.

This may also be interesting: https://bytecodealliance.zulipchat.com/#narrow/stream/223391-wasm/topic/Multi-memory.20.2F.20shared.20memory

When looking into the matter a previously, it looked like LLVM supports multiple memories for some platforms through __attribute__((address_space(N)) extension https://clang.llvm.org/docs/AttributeReference.html#address-space
See http://openasip.org/user_manual/TCE/node15.html
But Wasm was not yet supported at that point and probably isnt yet either.


I previously had some ideas on making a separate module that would act as a separate memory area.
You could have three modules, where one module is hand written to import the memories of the other modules (and possibly to create its own memory). The hand written module would implement functions for copying memory from one to another and would implement operations to work on the memory directly without copying. This would allow the other two modules to leverage the hand written module to operate on each other's memory or on a shared memory.

Normal C and Rust and other modules can import the hand written module's functions and call them. Its not ideal, but it is a PoC idea at least. I understand that a similar functionality could be implemented with host functions alone, so without toolchain support the appeal of the PoC isnt high.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2022 at 19:30):

alexcrichton commented on issue #4300:

I think the answers here cover the current state of the space, and otherwise this is more of a toolchain issue than a Wasmtime issue so I'm going to close this.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2022 at 19:30):

alexcrichton closed issue #4300:

It seem like wasmtime allow Instance to be created with multiple memories (including shared memory) https://docs.wasmtime.dev/api/wasmtime/struct.Instance.html#method.new. Is there examples on how to write Rust WebAssembly code to access those memories?


Last updated: Nov 22 2024 at 16:03 UTC