-
Notifications
You must be signed in to change notification settings - Fork 190
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
Accessing caller function / memory from Wasmtime implementation #130
Comments
The theory is that this isn't necessary because the interface types conversion should theoretically convey all the module was willing to convey, and consumers don't get anything further beyond the interface types boundary (in the same sense that you can't get un-exported functions from a wasm module through the That being said there's nothing stopping one-off functions from having access to internals like this. It shouldn't be too hard to thread things along if there's a use case. |
I'm trying to build an implementation for |
Hm ok for this it might be good to do two things in parallel, one is to bring this up with interface-types/wasi-parallel in that the interface currently desired by wasi-parallel isn't implementable with interface-types vanilla, and two would be adding a form of escape hatch to wit-bindgen to forward along the store if configured to do so (or something like that) |
I think that that's something we should treat as either blocking wasi-parallel or Interface Types: we want all WASI interfaces to be virtualizable without breaking encapsulation, so while we can work around limitations like this in wit-bindgen, that's not workable more generally, I think |
The wasi-parallel interface was designed under the assumption that there would be some way to express (e.g., interface types, component model, etc.) that the API must receive a "function" to execute. This did not seem like a crazy assumption several months ago: one could imagine how a WASI threading API would require a function to fork or how some API would require a function to handle callbacks. Does this assumption no longer hold?
@tschneidereit, surely passing a "function" must does not necessarily mean that it will break encapsulation: sure, a We purposely left this area vague in the design but since then have explored several possibilities: function indices, funcrefs, strings, fat binaries, components (WebAssembly/wasi-parallel#3). None seem satisfactory yet in their current form so more work is needed. But I am at a loss as to how to proceed: who else is interested in enabling this and how would something like this be standardized in a way acceptable to wit-bindgen? @lukewagner? |
On another note - what is the relationship between |
If we're talking about shared-memory parallelism for wasi-parallel (my suggestion in wasi-parallel/#3 was thinking more about non-shared-memory parallelism), I think a good way to express this in a way that is virtualizable and compatible with the overall component model goals is as a core module import where the wasi-parallel module imports memory from its client component (and thus there is never a need to ask for the "caller's memory"). E.g., a component importing wasi-parallel might look like:
Thus, this client component explicitly wires up I think the remaining question is how to specify the interface of wasi-parallel. Normally wit is used to describe component instance interfaces (using interface types), but what we want here is a core module interface (using core types). Because wasi-parallel isn't using interface types, it doesn't need the normal
Does that make sense? |
I think I understand the module-linking part of this ("thread the memory through to the instantiated module, etc.") and I would be fine with that approach if I felt the second question was resolved.
The issue with moduletype s-expressions is that it is quite unclear to me how users will consume this API. If there is no way to express the API in WIT, then presumably
[edit: tweaked question since clearly there is no way currently to express this type of thing in WIT] |
I might be misunderstanding, but it seems like if wasi-parallel offers shared-memory-multi-threading, |
@lukewagner, is that a temporary limitation, will memory sharing be coming to On a side note, I feel that there are two different use cases here: for external interface it might not be necessary to support core features that the other language or middleware can't express, while it might be necessary for a host API like WASI. |
Well, my hypothesis is that: when doing memory sharing, you don't need/want |
For me, that the tooling might not work for wasi-parallel seems like a major issue. The interface already has |
Oh, sorry, maybe I'm misunderstanding the fundamental interface here. When I heard "caller's memory", I assumed that was because the interfaces were passing pointers (offsets) relative to a linear memory shared between the caller and callee (and closed over by all the |
In |
Ah, that helps, thanks. Could you describe in a bit more detail how you're imagining to declare the memory that the callback needs and how it gets passed to/from the callback in the GPU and non-GPU cases? |
Ok, since the last comment on this thread, @penzn, @lukewagner, @egalli, and I met to discuss the issue in more detail. Here is my summary of what we discussed (others can supplement if they want):
|
I'm going to close this issue in an effort to help clean up the wit-bindgen issue tracker for now. The component model support in Wasmtime will not provide access to the caller's function or memory, by design. I think that a number of other features might be necessary for |
There doesn't appear to be a way in the
wit-bindgen-wasmtime
implementation for accessing a caller's export function or memory from a host implementation.Is this a valid scenario for this crate, or should something that needs low-level access use something else?
Thanks!
The text was updated successfully, but these errors were encountered: