-
Notifications
You must be signed in to change notification settings - Fork 750
add a set of apis to configure wasi-nn via InstantiationArgs2 #4764
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
base: main
Are you sure you want to change the base?
Changes from all commits
96cdfa6
60a8011
6dc9d01
d42581b
1cca0b8
9e03970
cd1c7f9
c73e4aa
0234fe0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -545,6 +545,17 @@ typedef struct WASMModuleInstMemConsumption { | |
| uint32 exports_size; | ||
| } WASMModuleInstMemConsumption; | ||
|
|
||
| #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 | ||
| typedef struct WASINNGlobalContext { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in what sense is this "global"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. InstantiationArgs2 will be freed soon after wasm_runtime_instantiate_ex2()(in posix/main.c for example), and user cannot use InstantiationArgs2 in wasm app later. So I add this new struct to handle these command line options, so load_by_name() can get these information(like target, encoding) through WASINNGlobalContext. WASINNGlobalContext will be registered into WASMModuleInstanceExtraCommon->context by wasm_native_set_context() after init. |
||
| char *encoding; | ||
| char *target; | ||
|
|
||
| uint32_t n_graphs; | ||
| uint32_t *loaded; | ||
| char **graph_paths; | ||
| } WASINNGlobalContext; | ||
| #endif | ||
|
|
||
| #if WASM_ENABLE_LIBC_WASI != 0 | ||
| #if WASM_ENABLE_UVWASI == 0 | ||
| typedef struct WASIContext { | ||
|
|
@@ -612,11 +623,30 @@ WASMExecEnv * | |
| wasm_runtime_get_exec_env_tls(void); | ||
| #endif | ||
|
|
||
| #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 | ||
| typedef struct WASINNArguments { | ||
| char *encoding; | ||
| char *target; | ||
|
|
||
| char **graph_paths; | ||
| uint32_t n_graphs; | ||
| } WASINNArguments; | ||
|
|
||
| WASM_RUNTIME_API_EXTERN int | ||
| wasi_nn_graph_registry_create(WASINNArguments **registryp); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN void | ||
| wasi_nn_graph_registry_destroy(WASINNArguments *registry); | ||
| #endif | ||
|
|
||
| struct InstantiationArgs2 { | ||
| InstantiationArgs v1; | ||
| #if WASM_ENABLE_LIBC_WASI != 0 | ||
| WASIArguments wasi; | ||
| #endif | ||
| #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 | ||
| WASINNArguments nn_registry; | ||
| #endif | ||
| }; | ||
|
|
||
| void | ||
|
|
@@ -775,6 +805,17 @@ wasm_runtime_instantiation_args_set_wasi_ns_lookup_pool( | |
| struct InstantiationArgs2 *p, const char *ns_lookup_pool[], | ||
| uint32 ns_lookup_pool_size); | ||
|
|
||
| #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 | ||
| WASM_RUNTIME_API_EXTERN void | ||
| wasm_runtime_instantiation_args_set_wasi_nn_graph_registry( | ||
| struct InstantiationArgs2 *p, WASINNArguments *registry); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN bool | ||
| wasi_nn_graph_registry_set_args(WASINNArguments *registry, const char *encoding, | ||
| const char *target, uint32_t n_graphs, | ||
| const char **graph_paths); | ||
| #endif | ||
|
|
||
| /* See wasm_export.h for description */ | ||
| WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon * | ||
| wasm_runtime_instantiate_ex2(WASMModuleCommon *module, | ||
|
|
@@ -1427,6 +1468,46 @@ wasm_runtime_check_and_update_last_used_shared_heap( | |
| uint8 **shared_heap_base_addr_adj_p, bool is_memory64); | ||
| #endif | ||
|
|
||
| #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 | ||
| WASM_RUNTIME_API_EXTERN bool | ||
| wasm_runtime_init_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst, | ||
| const char *encoding, const char *target, | ||
| const uint32_t n_graphs, | ||
| char *graph_paths[], char *error_buf, | ||
| uint32_t error_buf_size); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN void | ||
| wasm_runtime_destroy_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN void | ||
| wasm_runtime_set_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst, | ||
| WASINNGlobalContext *wasi_ctx); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN uint32_t | ||
| wasm_runtime_get_wasi_nn_global_ctx_ngraphs( | ||
| WASINNGlobalContext *wasi_nn_global_ctx); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN char * | ||
| wasm_runtime_get_wasi_nn_global_ctx_graph_paths_i( | ||
| WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN uint32_t | ||
| wasm_runtime_get_wasi_nn_global_ctx_loaded_i( | ||
| WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN uint32_t | ||
| wasm_runtime_set_wasi_nn_global_ctx_loaded_i( | ||
| WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx, uint32_t value); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN char * | ||
| wasm_runtime_get_wasi_nn_global_ctx_encoding( | ||
| WASINNGlobalContext *wasi_nn_global_ctx); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN char * | ||
| wasm_runtime_get_wasi_nn_global_ctx_target( | ||
| WASINNGlobalContext *wasi_nn_global_ctx); | ||
| #endif | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?