-
Notifications
You must be signed in to change notification settings - Fork 578
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
module instance context api #2460
Comments
Let me share our understanding and please correct me if I was wrong. I though there are two scenarios about when to use the new capability:
I believe "alternative 1` is a better option for the first scenario instead of the new feature. technically, "Host* and Wasm app is fully able to transfer data w/o involving runtime. In second scenario, runtime is a producer instead of the storage. So, the new feature is necessary. A big concern is how to let users to realize the limitation and to prevent applying the new feature to the first scenarios, passing data between host and wasm app. |
@lum1n0us thanks for the comment! Although we can implement WASI libraries and implement context handling in WAMR, I think it is better to let these extensions handle the context by themselves without the need to modify the code. For example, wasm-micro-runtime/core/iwasm/interpreter/wasm_runtime.c Lines 2239 to 2241 in ff151fb
This could be handled via the proposed API. This way, without needing to modify the WAMR's core code, we could enable wasi-nn through flags at build time or as a native library. |
by "host", do you mean the embedder like iwasm main.c?
i don't understand your "producer" "storage" classification. i'm not sure what you mean by "transfer" either.
what limitation are you talking about? |
Introduce module instance context APIs which can set one or more contexts created by the embedder for a wasm module instance: ```C wasm_runtime_create_context_key wasm_runtime_destroy_context_key wasm_runtime_set_context wasm_runtime_set_context_spread wasm_runtime_get_context ``` And make libc-wasi use it and set wasi context as the first context bound to the wasm module instance. Also add samples. Refer to #2460.
closed by #2436 |
Introduce module instance context APIs which can set one or more contexts created by the embedder for a wasm module instance: ```C wasm_runtime_create_context_key wasm_runtime_destroy_context_key wasm_runtime_set_context wasm_runtime_set_context_spread wasm_runtime_get_context ``` And make libc-wasi use it and set wasi context as the first context bound to the wasm module instance. Also add samples. Refer to bytecodealliance#2460.
motivation
some native functions (eg. wasi) need to maintain some execution context. (eg. wasi file table)
for the in-tree code, the relevant logic can be hardcoded in the runtime. (eg. wasm_runtime_set_wasi_ctx, wasm_runtime_destroy_wasi)
however, it would be nice to have some api to maintain such a state a bit more dynamically because:
proposed api
proposed implementation
#2436
Alternative 1
make the embedder to maintain the state. it probably works well if the embedder and native functions are provided by the same group.
Alternative 2
use
wasm_runtime_set_custom_data
.it would work if only single state is necessary on the system.
it's easy to re-implement
wasm_runtime_set_custom_data
on the top of the proposed api.the opposite is difficult.
Alternative 3
(ab?)use externref api with #2455
The text was updated successfully, but these errors were encountered: