wasm-micro-runtime/build-scripts
YAMAMOTO Takashi 70c39bae77
wasi-nn: fix context lifetime issues (#4396)
* wasi-nn: fix context lifetime issues

use the module instance context api instead of trying to roll
our own with a hashmap. this fixes context lifetime problems mentioned in
https://github.com/bytecodealliance/wasm-micro-runtime/issues/4313.

namely,

* wasi-nn resources will be freed earlier now. before this change,
  they used to be kept until the runtime shutdown. (wasm_runtime_destroy)
  after this change, they will be freed together with the associated
  instances.

* wasm_module_inst_t pointer uniqueness assumption (which is wrong
  after wasm_runtime_deinstantiate) was lifted.

as a side effect, this change also makes a context shared among threads
within a cluster. note that this is a user-visible api/abi breaking change.
before this change, wasi-nn "handles" like wasi_ephemeral_nn_graph were
thread-local. after this change, they are shared among threads within
a cluster, similarly to wasi file descriptors. spec-wise, either behavior
should be ok simply because wasi officially doesn't have threads yet.
althogh i feel the latter semantics is more intuitive, if your application
depends on the thread-local behavior, this change breaks your application.

tested with wamr-wasi-extensions/samples/nn-cli, modified to
call each wasi-nn operations on different threads. (if you are
interested, you can find the modification at
https://github.com/yamt/wasm-micro-runtime/tree/yamt-nn-wip-20250619.)

cf.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/4313
https://github.com/bytecodealliance/wasm-micro-runtime/issues/2430

* runtime_lib.cmake: enable WAMR_BUILD_MODULE_INST_CONTEXT for wasi-nn

as we do for wasi (WAMR_BUILD_LIBC_WASI)
2025-06-24 20:37:56 +08:00
..
esp-idf feat(yml): Add ESP32-P4 and ESP32-C5 support (#4270) 2025-05-19 10:33:09 +08:00
build_llvm.py build-scripts/build_llvm.py: bump to llvm 18 (#4259) 2025-05-09 17:14:02 +08:00
config_common.cmake enable WAMR_BUILD_WASI_EPHEMERAL_NN by default (#4381) 2025-06-19 14:30:44 +08:00
involve_boringssl.cmake Use boringssl instead of openssl to implement wasm cache loading (#1804) 2022-12-13 14:23:37 +08:00
iwasmConfig.cmake.in Cmake improvements (#4076) 2025-02-21 15:29:49 +08:00
lldb_wasm.patch Fix issues in releasing wamr-lldb (#2497) 2023-08-23 12:56:11 +08:00
package.cmake Replace CMAKE_CURRENT_FUNCTION_LIST_DIR (#4200) 2025-04-17 00:07:25 +08:00
requirements.txt build(deps): Bump requests from 2.32.3 to 2.32.4 in /build-scripts (#4349) 2025-06-12 09:29:33 +08:00
runtime_lib.cmake wasi-nn: fix context lifetime issues (#4396) 2025-06-24 20:37:56 +08:00
SConscript Support more features for rt-thread (#3661) 2024-07-26 10:34:15 +08:00
SConscript_config Support more features for rt-thread (#3661) 2024-07-26 10:34:15 +08:00
version.cmake Bump version to 2.3.1 and update release notes (#4303) 2025-06-02 10:45:50 +08:00