WebAssembly / wasi-nn

Neural Network proposal for WASI
429 stars 34 forks source link

Question about handle lifetime #22

Closed yamt closed 1 year ago

yamt commented 2 years ago

how long will handles (graphs and execution context) be valid? there seems to be no way to close them explicitly. otoh, keeping them forever is not desirable i guess.

abrown commented 2 years ago

I guess implicitly they are tied to a WebAssembly instance. For users that may want instances that outlive the graph and execution context handles, however, it does make sense to add a way to close them. I briefly considered whether resource destruction should be handled at some other level (e.g., canonical ABI) but with the help of this presentation came to the conclusion that the destructors should be explicit. @sunfishcode, is my understanding of those slides still correct?

yamt commented 2 years ago

wit-bindgen c -i generates wasi_nn_graph_free, which calls canonical_abi.resource_drop_graph. ditto for graph-execution-context. is it supposed to serve the purpose?

abrown commented 2 years ago

Hm, that sounds like it validates my earlier hunch; maybe the slides are out of date!

tonibofarull commented 1 year ago

With wit-bindgen-cli 0.3.0 (04da8c228 2022-12-12) if I execute wit-bindgen guest c wasi-nn.wit I get the following error:

failed to parse wit file wasi-nn.wit

Caused by: expected default, world or interface, found keyword type --> wasi-nn.wit:5:1 | 5 | type tensor-dimensions = list | ^--- error: Invalid value 'wasi-nn.wit' for '': failed to parse wit file wasi-nn.wit

abrown commented 1 year ago

@tonibofarull, I think my response over here refers to this.

@yamt, I believe the original question has been answered — wit-bindgen should provide a way to destroy resources — so I'm going to close this.