Compare commits

...

3 Commits

Author SHA1 Message Date
Windrow14
4e346b1c53
Merge d3ab94e73a into 418be9dfee 2025-11-27 14:59:10 +08:00
Yosh
418be9dfee
Update link to WASI Proposals.md (#4734) 2025-11-27 08:53:59 +08:00
Windrow14
d3ab94e73a
Support graph encoding backend auto-detection in wasi-nn. 2025-11-13 16:57:40 +08:00
2 changed files with 82 additions and 29 deletions

View File

@ -491,20 +491,50 @@ wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder,
goto fail; goto fail;
} }
res = ensure_backend(instance, encoding, wasi_nn_ctx); if (encoding == autodetect) {
if (res != success) for (graph_encoding e = openvino; e <= unknown_backend; e++) {
goto fail; if (wasi_nn_ctx->is_backend_ctx_initialized) {
call_wasi_nn_func(wasi_nn_ctx->backend, deinit, res,
wasi_nn_ctx->backend_ctx);
}
call_wasi_nn_func(wasi_nn_ctx->backend, load, res, wasi_nn_ctx->backend_ctx, res = ensure_backend(instance, e, wasi_nn_ctx);
&builder_native, encoding, target, g); if (res != success) {
if (res != success) NN_ERR_PRINTF("continue trying the next");
goto fail; continue;
}
call_wasi_nn_func(wasi_nn_ctx->backend, load, res,
wasi_nn_ctx->backend_ctx, &builder_native, e,
target, g);
if (res != success) {
NN_ERR_PRINTF("continue trying the next");
continue;
}
break;
}
}
else {
res = ensure_backend(instance, encoding, wasi_nn_ctx);
if (res != success)
goto fail;
call_wasi_nn_func(wasi_nn_ctx->backend, load, res,
wasi_nn_ctx->backend_ctx, &builder_native, encoding,
target, g);
if (res != success)
goto fail;
}
fail: fail:
// XXX: Free intermediate structure pointers // XXX: Free intermediate structure pointers
if (builder_native.buf) if (builder_native.buf) {
wasm_runtime_free(builder_native.buf); wasm_runtime_free(builder_native.buf);
unlock_ctx(wasi_nn_ctx); }
if (wasi_nn_ctx) {
unlock_ctx(wasi_nn_ctx);
}
return res; return res;
} }
@ -565,17 +595,29 @@ wasi_nn_load_by_name(wasm_exec_env_t exec_env, char *name, uint32_t name_len,
goto fail; goto fail;
} }
res = ensure_backend(instance, autodetect, wasi_nn_ctx); for (graph_encoding e = openvino; e <= unknown_backend; e++) {
if (res != success) if (wasi_nn_ctx->is_backend_ctx_initialized) {
goto fail; call_wasi_nn_func(wasi_nn_ctx->backend, deinit, res,
wasi_nn_ctx->backend_ctx);
}
call_wasi_nn_func(wasi_nn_ctx->backend, load_by_name, res, res = ensure_backend(instance, e, wasi_nn_ctx);
wasi_nn_ctx->backend_ctx, nul_terminated_name, name_len, if (res != success) {
g); NN_ERR_PRINTF("continue trying the next");
if (res != success) continue;
goto fail; }
call_wasi_nn_func(wasi_nn_ctx->backend, load_by_name, res,
wasi_nn_ctx->backend_ctx, nul_terminated_name,
name_len, g);
if (res != success) {
NN_ERR_PRINTF("continue trying the next");
continue;
}
break;
}
res = success;
fail: fail:
if (nul_terminated_name != NULL) { if (nul_terminated_name != NULL) {
wasm_runtime_free(nul_terminated_name); wasm_runtime_free(nul_terminated_name);
@ -627,18 +669,29 @@ wasi_nn_load_by_name_with_config(wasm_exec_env_t exec_env, char *name,
goto fail; goto fail;
} }
res = ensure_backend(instance, autodetect, wasi_nn_ctx); for (graph_encoding e = openvino; e <= unknown_backend; e++) {
if (res != success) if (wasi_nn_ctx->is_backend_ctx_initialized) {
goto fail; call_wasi_nn_func(wasi_nn_ctx->backend, deinit, res,
; wasi_nn_ctx->backend_ctx);
}
call_wasi_nn_func(wasi_nn_ctx->backend, load_by_name_with_config, res, res = ensure_backend(instance, e, wasi_nn_ctx);
wasi_nn_ctx->backend_ctx, nul_terminated_name, name_len, if (res != success) {
nul_terminated_config, config_len, g); NN_ERR_PRINTF("continue trying the next");
if (res != success) continue;
goto fail; }
call_wasi_nn_func(wasi_nn_ctx->backend, load_by_name_with_config, res,
wasi_nn_ctx->backend_ctx, nul_terminated_name,
name_len, nul_terminated_config, config_len, g);
if (res != success) {
NN_ERR_PRINTF("continue trying the next");
continue;
}
break;
}
res = success;
fail: fail:
if (nul_terminated_name != NULL) { if (nul_terminated_name != NULL) {
wasm_runtime_free(nul_terminated_name); wasm_runtime_free(nul_terminated_name);

View File

@ -2,7 +2,7 @@
This document is intended to describe the current status of WebAssembly proposals and WASI proposals in WAMR. This document is intended to describe the current status of WebAssembly proposals and WASI proposals in WAMR.
Only track proposals that are followed in the [WebAssembly proposals](https://github.com/WebAssembly/proposals) and [WASI proposals](https://github.com/WebAssembly/WASI/blob/main/Proposals.md). Only track proposals that are followed in the [WebAssembly proposals](https://github.com/WebAssembly/proposals) and [WASI proposals](https://github.com/WebAssembly/WASI/blob/main/docs/Proposals.md).
Normally, the document tracks proposals that are in phase 4. However, if a proposal in an earlier phase receives support, it will be added to the list below. Normally, the document tracks proposals that are in phase 4. However, if a proposal in an earlier phase receives support, it will be added to the list below.