-
Notifications
You must be signed in to change notification settings - Fork 763
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
4b93110
6bc7512
12d8a18
8dbba46
c024c94
736f357
878c8ec
c43fbeb
6501e4b
b122451
a85079a
7b62ec8
01641bf
eb55c28
ccee194
5357fb5
4747d61
9e89828
7822544
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,18 @@ typedef struct WASMModuleInstMemConsumption { | |
| uint32 exports_size; | ||
| } WASMModuleInstMemConsumption; | ||
|
|
||
| #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 | ||
| typedef struct WASINNRegistry { | ||
| char **model_names; | ||
| uint32_t **encoding; | ||
| uint32_t **target; | ||
|
|
||
| uint32_t n_graphs; | ||
| uint32_t **loaded; | ||
| char **graph_paths; | ||
| } WASINNRegistry; | ||
| #endif | ||
|
|
||
| #if WASM_ENABLE_LIBC_WASI != 0 | ||
| #if WASM_ENABLE_UVWASI == 0 | ||
| typedef struct WASIContext { | ||
|
|
@@ -612,11 +624,22 @@ WASMExecEnv * | |
| wasm_runtime_get_exec_env_tls(void); | ||
| #endif | ||
|
|
||
| #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 | ||
| WASM_RUNTIME_API_EXTERN int | ||
| wasm_runtime_wasi_nn_registry_create(WASINNRegistry **registryp); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN void | ||
| wasm_runtime_wasi_nn_registry_destroy(WASINNRegistry *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 | ||
| WASINNRegistry nn_registry; | ||
| #endif | ||
| }; | ||
|
|
||
| void | ||
|
|
@@ -775,6 +798,20 @@ 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_registry( | ||
| struct InstantiationArgs2 *p, WASINNRegistry *registry); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN bool | ||
| wasm_runtime_wasi_nn_registry_set_args(WASINNRegistry *registry, | ||
| const char **model_names, | ||
| const uint32_t **encoding, | ||
| const uint32_t **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 +1464,19 @@ 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 void | ||
| wasm_runtime_set_wasi_nn_registry(WASMModuleInstanceCommon *module_inst, | ||
| WASINNRegistry *wasi_ctx); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN WASINNRegistry * | ||
| wasm_runtime_get_wasi_nn_registry(WASMModuleInstanceCommon *module_inst_comm); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN void | ||
| wasm_runtime_set_wasi_nn_registry(WASMModuleInstanceCommon *module_inst_comm, | ||
| WASINNRegistry *wasi_nn_ctx); | ||
|
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. two duplicated wasm_runtime_set_wasi_nn_registry prototypes in this file. |
||
| #endif | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -290,6 +290,7 @@ typedef struct InstantiationArgs { | |
| #endif /* INSTANTIATION_ARGS_OPTION_DEFINED */ | ||
|
|
||
| struct InstantiationArgs2; | ||
| typedef struct WASINNRegistry WASINNRegistry; | ||
|
|
||
| #ifndef WASM_VALKIND_T_DEFINED | ||
| #define WASM_VALKIND_T_DEFINED | ||
|
|
@@ -796,6 +797,19 @@ wasm_runtime_instantiation_args_set_wasi_ns_lookup_pool( | |
| struct InstantiationArgs2 *p, const char *ns_lookup_pool[], | ||
| uint32_t ns_lookup_pool_size); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN struct WASINNRegistry * | ||
| wasm_runtime_get_wasi_nn_registry(const wasm_module_inst_t module_inst); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN void | ||
| wasm_runtime_set_wasi_nn_registry(wasm_module_inst_t module_inst, | ||
| struct WASINNRegistry *wasi_ctx); | ||
|
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. wasm_runtime_get_wasi_nn_registry/wasm_runtime_set_wasi_nn_registry are not supposed to be used by applications, are they? in wasm_export.h, put only api which is used directly by application. (eg. iwasm) |
||
|
|
||
| WASM_RUNTIME_API_EXTERN int | ||
| wasm_runtime_wasi_nn_registry_create(struct WASINNRegistry **registryp); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN void | ||
| wasm_runtime_wasi_nn_registry_destroy(struct WASINNRegistry *registry); | ||
|
|
||
| /** | ||
| * Instantiate a WASM module, with specified instantiation arguments | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,3 @@ | |
| #define WASI_NN_NAME(name) wasi_ephemeral_nn_##name | ||
|
|
||
| #include "wasi_nn.h" | ||
|
|
||
| #undef WASM_ENABLE_WASI_EPHEMERAL_NN | ||
| #undef WASI_NN_NAME | ||
|
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. why?
Contributor
Author
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 wasi_ephemeral_nn.h, macros are defined and then wasi_nn.h is included immediately after, but these macro definitions are later undefined (#undef). This means that in utils.h, the macros might be in an undefined state, leading to compilation errors( if WASM_ENABLE_WASI_EPHEMERAL_NN != 0).
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. wasi_ephemeral_nn.h header is meant to be used by applications which uses this version of api. |
||
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.
i suppose these should be in wasm_export.h as it's used by the embedding applications like iwasm.