Skip to content

Commit 5fd2793

Browse files
committed
Rename some parameters
1 parent 4de9fa4 commit 5fd2793

File tree

10 files changed

+65
-58
lines changed

10 files changed

+65
-58
lines changed

core/iwasm/common/wasm_native.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static NativeSymbolsList g_native_symbols_list = NULL;
2525
static void *g_wasi_context_key;
2626
#endif /* WASM_ENABLE_LIBC_WASI */
2727

28-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
28+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
2929
static void *g_wasi_nn_context_key;
3030
#endif
3131

@@ -477,7 +477,7 @@ wasi_context_dtor(WASMModuleInstanceCommon *inst, void *ctx)
477477
}
478478
#endif /* end of WASM_ENABLE_LIBC_WASI */
479479

480-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
480+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
481481
WASINNGlobalContext *
482482
wasm_runtime_get_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst_comm)
483483
{

core/iwasm/common/wasm_runtime_common.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,20 +1696,19 @@ wasm_runtime_instantiation_args_destroy(struct InstantiationArgs2 *p)
16961696
wasm_runtime_free(p);
16971697
}
16981698

1699-
#if (WASM_ENABLE_WASI_EPHEMERAL_NN != 0)
1700-
struct wasi_nn_graph_registry;
1699+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
1700+
WASINNArguments;
17011701

17021702
void
1703-
wasm_runtime_wasi_nn_graph_registry_args_set_defaults(
1704-
struct wasi_nn_graph_registry *args)
1703+
wasm_runtime_wasi_nn_graph_registry_args_set_defaults(WASINNArguments *args)
17051704
{
17061705
memset(args, 0, sizeof(*args));
17071706
}
17081707

17091708
bool
1710-
wasi_nn_graph_registry_set_args(struct wasi_nn_graph_registry *registry,
1711-
const char *encoding, const char *target,
1712-
uint32_t n_graphs, const char **graph_paths)
1709+
wasi_nn_graph_registry_set_args(WASINNArguments *registry, const char *encoding,
1710+
const char *target, uint32_t n_graphs,
1711+
const char **graph_paths)
17131712
{
17141713
if (!registry || !encoding || !target || !graph_paths) {
17151714
return false;
@@ -1725,10 +1724,10 @@ wasi_nn_graph_registry_set_args(struct wasi_nn_graph_registry *registry,
17251724
return true;
17261725
}
17271726

1728-
static int
1729-
wasi_nn_graph_registry_create(struct wasi_nn_graph_registry **registryp)
1727+
int
1728+
wasi_nn_graph_registry_create(WASINNArguments **registryp)
17301729
{
1731-
struct wasi_nn_graph_registry *args = wasm_runtime_malloc(sizeof(*args));
1730+
WASINNArguments *args = wasm_runtime_malloc(sizeof(*args));
17321731
if (args == NULL) {
17331732
return -1;
17341733
}
@@ -1738,7 +1737,7 @@ wasi_nn_graph_registry_create(struct wasi_nn_graph_registry **registryp)
17381737
}
17391738

17401739
void
1741-
wasi_nn_graph_registry_destroy(struct wasi_nn_graph_registry *registry)
1740+
wasi_nn_graph_registry_destroy(WASINNArguments *registry)
17421741
{
17431742
if (registry) {
17441743
for (uint32_t i = 0; i < registry->n_graphs; i++)
@@ -1854,10 +1853,10 @@ wasm_runtime_instantiation_args_set_wasi_ns_lookup_pool(
18541853
wasi_args->set_by_user = true;
18551854
}
18561855
#endif /* WASM_ENABLE_LIBC_WASI != 0 */
1857-
#if (WASM_ENABLE_WASI_EPHEMERAL_NN != 0)
1856+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
18581857
void
18591858
wasm_runtime_instantiation_args_set_wasi_nn_graph_registry(
1860-
struct InstantiationArgs2 *p, struct wasi_nn_graph_registry *registry)
1859+
struct InstantiationArgs2 *p, WASINNArguments *registry)
18611860
{
18621861
p->nn_registry = *registry;
18631862
}
@@ -8149,7 +8148,7 @@ wasm_runtime_check_and_update_last_used_shared_heap(
81498148
}
81508149
#endif
81518150

8152-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
8151+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
81538152
bool
81548153
wasm_runtime_init_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst,
81558154
const char *encoding, const char *target,

core/iwasm/common/wasm_runtime_common.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ typedef struct WASMModuleInstMemConsumption {
545545
uint32 exports_size;
546546
} WASMModuleInstMemConsumption;
547547

548-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
548+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
549549
typedef struct WASINNGlobalContext {
550550
char *encoding;
551551
char *target;
@@ -623,29 +623,29 @@ WASMExecEnv *
623623
wasm_runtime_get_exec_env_tls(void);
624624
#endif
625625

626-
#if (WASM_ENABLE_WASI_EPHEMERAL_NN != 0)
627-
struct wasi_nn_graph_registry {
626+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
627+
typedef struct WASINNArguments {
628628
char *encoding;
629629
char *target;
630630

631631
char **graph_paths;
632632
uint32_t n_graphs;
633-
};
633+
} WASINNArguments;
634634

635635
WASM_RUNTIME_API_EXTERN int
636-
wasi_nn_graph_registry_create(struct wasi_nn_graph_registry **registryp);
636+
wasi_nn_graph_registry_create(WASINNArguments **registryp);
637637

638638
WASM_RUNTIME_API_EXTERN void
639-
wasi_nn_graph_registry_destroy(struct wasi_nn_graph_registry *registry);
639+
wasi_nn_graph_registry_destroy(WASINNArguments *registry);
640640
#endif
641641

642642
struct InstantiationArgs2 {
643643
InstantiationArgs v1;
644644
#if WASM_ENABLE_LIBC_WASI != 0
645645
WASIArguments wasi;
646646
#endif
647-
#if (WASM_ENABLE_WASI_EPHEMERAL_NN != 0)
648-
struct wasi_nn_graph_registry nn_registry;
647+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
648+
WASINNArguments nn_registry;
649649
#endif
650650
};
651651

@@ -805,15 +805,15 @@ wasm_runtime_instantiation_args_set_wasi_ns_lookup_pool(
805805
struct InstantiationArgs2 *p, const char *ns_lookup_pool[],
806806
uint32 ns_lookup_pool_size);
807807

808-
#if (WASM_ENABLE_WASI_EPHEMERAL_NN != 0)
808+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
809809
WASM_RUNTIME_API_EXTERN void
810810
wasm_runtime_instantiation_args_set_wasi_nn_graph_registry(
811-
struct InstantiationArgs2 *p, struct wasi_nn_graph_registry *registry);
811+
struct InstantiationArgs2 *p, WASINNArguments *registry);
812812

813813
WASM_RUNTIME_API_EXTERN bool
814-
wasi_nn_graph_registry_set_args(struct wasi_nn_graph_registry *registry,
815-
const char *encoding, const char *target,
816-
uint32_t n_graphs, const char **graph_paths);
814+
wasi_nn_graph_registry_set_args(WASINNArguments *registry, const char *encoding,
815+
const char *target, uint32_t n_graphs,
816+
const char **graph_paths);
817817
#endif
818818

819819
/* See wasm_export.h for description */
@@ -1468,7 +1468,7 @@ wasm_runtime_check_and_update_last_used_shared_heap(
14681468
uint8 **shared_heap_base_addr_adj_p, bool is_memory64);
14691469
#endif
14701470

1471-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
1471+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
14721472
WASM_RUNTIME_API_EXTERN bool
14731473
wasm_runtime_init_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst,
14741474
const char *encoding, const char *target,

core/iwasm/include/wasm_export.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -798,22 +798,6 @@ wasm_runtime_instantiation_args_set_wasi_ns_lookup_pool(
798798
struct InstantiationArgs2 *p, const char *ns_lookup_pool[],
799799
uint32_t ns_lookup_pool_size);
800800

801-
// WASM_RUNTIME_API_EXTERN int
802-
// wasi_nn_graph_registry_create(struct wasi_nn_graph_registry **registryp);
803-
804-
// WASM_RUNTIME_API_EXTERN void
805-
// wasi_nn_graph_registry_destroy(struct wasi_nn_graph_registry *registry);
806-
807-
// WASM_RUNTIME_API_EXTERN void
808-
// wasm_runtime_instantiation_args_set_wasi_nn_graph_registry(
809-
// struct InstantiationArgs2 *p, struct wasi_nn_graph_registry *registry);
810-
811-
// WASM_RUNTIME_API_EXTERN bool
812-
// wasi_nn_graph_registry_set_args(struct wasi_nn_graph_registry *registry,
813-
// const char* encoding,
814-
// const char* target, uint32_t n_graphs,
815-
// const char** graph_paths);
816-
817801
WASM_RUNTIME_API_EXTERN bool
818802
wasm_runtime_init_wasi_nn_global_ctx(wasm_module_inst_t module_inst,
819803
const char *encoding, const char *target,

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,11 +3300,10 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
33003300
}
33013301
#endif
33023302

3303-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
3303+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
33043304
/* Store graphs' path into ctx. Graphs will be loaded until user app calls
33053305
* load_by_name */
3306-
// Do not consider load() for now
3307-
struct wasi_nn_graph_registry *nn_registry = &args->nn_registry;
3306+
WASINNArguments *nn_registry = &args->nn_registry;
33083307
if (!wasm_runtime_init_wasi_nn_global_ctx(
33093308
(WASMModuleInstanceCommon *)module_inst, nn_registry->encoding,
33103309
nn_registry->target, nn_registry->n_graphs,

core/iwasm/libraries/wasi-nn/include/wasi_ephemeral_nn.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@
77
#define WASI_NN_NAME(name) wasi_ephemeral_nn_##name
88

99
#include "wasi_nn.h"
10-
11-
// #undef WASM_ENABLE_WASI_EPHEMERAL_NN
12-
// #undef WASI_NN_NAME

core/iwasm/libraries/wasi-nn/test/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ CURR_PATH=$(cd $(dirname $0) && pwd -P)
2222

2323
/opt/wasi-sdk/bin/clang \
2424
--target=wasm32-wasi \
25+
-DWASM_ENABLE_WASI_NN=1 \
26+
-DWASM_ENABLE_WASI_EPHEMERAL_NN=1 \
2527
-DNN_LOG_LEVEL=1 \
2628
-Wl,--allow-undefined \
2729
-I../include -I../src/utils \

core/iwasm/libraries/wasi-nn/test/test_tensorflow.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ test_sum()
2323
run_inference(input.input_tensor, input.dim, &output_size, "sum", 1);
2424

2525
if (output) {
26+
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
2627
assert((output_size / sizeof(float)) == 1);
28+
#elif WASM_ENABLE_WASI_NN != 0
29+
assert(output_size == 1);
30+
#endif
2731
assert(fabs(output[0] - 300.0) < EPSILON);
2832
}
2933

@@ -43,7 +47,11 @@ test_max()
4347
run_inference(input.input_tensor, input.dim, &output_size, "max", 1);
4448

4549
if (output) {
50+
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
4651
assert((output_size / sizeof(float)) == 1);
52+
#elif WASM_ENABLE_WASI_NN != 0
53+
assert(output_size == 1);
54+
#endif
4755
assert(fabs(output[0] - 24.0) < EPSILON);
4856
NN_INFO_PRINTF("Result: max is %f", output[0]);
4957
}
@@ -64,7 +72,11 @@ test_average()
6472
"average", 1);
6573

6674
if (output) {
75+
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
6776
assert((output_size / sizeof(float)) == 1);
77+
#elif WASM_ENABLE_WASI_NN != 0
78+
assert(output_size == 1);
79+
#endif
6880
assert(fabs(output[0] - 12.0) < EPSILON);
6981
NN_INFO_PRINTF("Result: average is %f", output[0]);
7082
}
@@ -85,7 +97,11 @@ test_mult_dimensions()
8597
"mult_dim", 1);
8698

8799
if (output) {
100+
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
88101
assert((output_size / sizeof(float)) == 9);
102+
#elif WASM_ENABLE_WASI_NN != 0
103+
assert(output_size == 9);
104+
#endif
89105
for (int i = 0; i < 9; i++)
90106
assert(fabs(output[i] - i) < EPSILON);
91107
}
@@ -106,7 +122,11 @@ test_mult_outputs()
106122
"mult_out", 2);
107123

108124
if (output) {
125+
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
109126
assert((output_size / sizeof(float)) == 8);
127+
#elif WASM_ENABLE_WASI_NN != 0
128+
assert(output_size == 8);
129+
#endif
110130
// first tensor check
111131
for (int i = 0; i < 4; i++)
112132
assert(fabs(output[i] - (i * 4 + 24)) < EPSILON);

core/iwasm/libraries/wasi-nn/test/utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
#include <stdint.h>
1010

11+
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
1112
#include "wasi_ephemeral_nn.h"
13+
#elif WASM_ENABLE_WASI_NN != 0
14+
#include "wasi_nn.h"
15+
#endif
1216
#include "wasi_nn_types.h"
1317

1418
#define MAX_MODEL_SIZE 85000000

product-mini/platforms/posix/main.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
2222
#include "wasi_ephemeral_nn.h"
23+
#elif WASM_ENABLE_WASI_NN != 0
24+
#include "wasi_nn.h"
2325
#endif
2426

2527
#include "../common/wasm_proposal.c"
@@ -120,7 +122,7 @@ print_help(void)
120122
#if WASM_ENABLE_STATIC_PGO != 0
121123
printf(" --gen-prof-file=<path> Generate LLVM PGO (Profile-Guided Optimization) profile file\n");
122124
#endif
123-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
125+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
124126
printf(" --wasi-nn-graph=encoding:target:<model_path1>:<model_path2>:...:<model_pathn>\n");
125127
printf(" Set encoding, target and model_paths for wasi-nn. target can be\n");
126128
printf(" cpu|gpu|tpu, encoding can be tensorflowlite|openvino|llama|onnx|\n");
@@ -645,8 +647,8 @@ main(int argc, char *argv[])
645647
int timeout_ms = -1;
646648
#endif
647649

648-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
649-
struct wasi_nn_graph_registry *nn_registry;
650+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
651+
struct WASINNArguments *nn_registry;
650652
char *encoding, *target;
651653
uint32_t n_models = 0;
652654
char **model_paths;
@@ -842,7 +844,7 @@ main(int argc, char *argv[])
842844
wasm_proposal_print_status();
843845
return 0;
844846
}
845-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
847+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
846848
else if (!strncmp(argv[0], "--wasi-nn-graph=", 16)) {
847849
char *token;
848850
char *saveptr = NULL;
@@ -1022,7 +1024,7 @@ main(int argc, char *argv[])
10221024
libc_wasi_set_init_args(inst_args, argc, argv, &wasi_parse_ctx);
10231025
#endif
10241026

1025-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
1027+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
10261028
wasi_nn_graph_registry_create(&nn_registry);
10271029
wasi_nn_graph_registry_set_args(nn_registry, encoding, target, n_models,
10281030
model_paths);
@@ -1148,7 +1150,7 @@ main(int argc, char *argv[])
11481150
#if WASM_ENABLE_DEBUG_INTERP != 0
11491151
fail4:
11501152
#endif
1151-
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
1153+
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
11521154
wasi_nn_graph_registry_destroy(nn_registry);
11531155
for (uint32_t i = 0; i < n_models; i++)
11541156
if (model_paths[i])

0 commit comments

Comments
 (0)