Commit 70c39ba
authored
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
#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.
#4313
#2430
* runtime_lib.cmake: enable WAMR_BUILD_MODULE_INST_CONTEXT for wasi-nn
as we do for wasi (WAMR_BUILD_LIBC_WASI)1 parent 92e5f5f commit 70c39ba
File tree
2 files changed
+22
-57
lines changed- build-scripts
- core/iwasm/libraries/wasi-nn/src
2 files changed
+22
-57
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 58 | + | |
90 | 59 | | |
91 | 60 | | |
92 | 61 | | |
93 | 62 | | |
94 | | - | |
95 | | - | |
96 | 63 | | |
97 | | - | |
98 | | - | |
99 | 64 | | |
100 | 65 | | |
| 66 | + | |
101 | 67 | | |
102 | 68 | | |
103 | 69 | | |
| |||
116 | 82 | | |
117 | 83 | | |
118 | 84 | | |
119 | | - | |
| 85 | + | |
120 | 86 | | |
121 | | - | |
| 87 | + | |
122 | 88 | | |
123 | 89 | | |
124 | 90 | | |
| |||
131 | 97 | | |
132 | 98 | | |
133 | 99 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
140 | 103 | | |
141 | 104 | | |
142 | 105 | | |
| |||
170 | 133 | | |
171 | 134 | | |
172 | 135 | | |
173 | | - | |
| 136 | + | |
174 | 137 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
| 138 | + | |
| 139 | + | |
184 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
185 | 151 | | |
186 | 152 | | |
187 | | - | |
188 | 153 | | |
189 | 154 | | |
190 | 155 | | |
| |||
220 | 185 | | |
221 | 186 | | |
222 | 187 | | |
223 | | - | |
224 | | - | |
| 188 | + | |
225 | 189 | | |
226 | 190 | | |
227 | 191 | | |
| |||
0 commit comments