Skip to content

Commit bbfa66e

Browse files
authored
Merge pull request #1592 from bytecodealliance/main
Merge main into dev/refactor_llvm_jit
2 parents 918e06e + 2e77626 commit bbfa66e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2652
-138
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.cache
22
.vs
33
.vscode
4+
.venv
45
/.idea
56
**/cmake-build-*/
67
**/*build/

assembly-script/wamr_app_lib/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function not_expire(trans: wamr_transaction, index: i32, array: Array<wamr_trans
137137
var elapsed_ms = (now < trans.time) ?
138138
(now + (0xFFFFFFFF - trans.time) + 1) : (now - trans.time);
139139

140-
return elapsed_ms >= TRANSACTION_TIMEOUT_MS;
140+
return elapsed_ms < TRANSACTION_TIMEOUT_MS;
141141
}
142142

143143
function transaction_timeout_handler(): void {

build-scripts/config_common.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,6 @@ if (WAMR_BUILD_SGX_IPFS EQUAL 1)
303303
add_definitions (-DWASM_ENABLE_SGX_IPFS=1)
304304
message (" SGX IPFS enabled")
305305
endif ()
306+
if (WAMR_BUILD_WASI_NN EQUAL 1)
307+
message (" WASI-NN enabled")
308+
endif ()

build-scripts/runtime_lib.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1)
9191
set (WAMR_BUILD_LIB_PTHREAD 1)
9292
endif ()
9393

94+
if (WAMR_BUILD_WASI_NN EQUAL 1)
95+
execute_process(COMMAND ${WAMR_ROOT_DIR}/core/deps/install_tensorflow.sh
96+
RESULT_VARIABLE TENSORFLOW_RESULT
97+
)
98+
set(TENSORFLOW_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src")
99+
include_directories (${CMAKE_CURRENT_BINARY_DIR}/flatbuffers/include)
100+
include_directories (${TENSORFLOW_SOURCE_DIR})
101+
add_subdirectory(
102+
"${TENSORFLOW_SOURCE_DIR}/tensorflow/lite"
103+
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL)
104+
include (${IWASM_DIR}/libraries/wasi-nn/wasi_nn.cmake)
105+
endif ()
106+
94107
if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
95108
include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake)
96109
# Enable the dependent feature if lib pthread is enabled
@@ -152,6 +165,7 @@ set (source_all
152165
${UTILS_SHARED_SOURCE}
153166
${LIBC_BUILTIN_SOURCE}
154167
${LIBC_WASI_SOURCE}
168+
${LIBC_WASI_NN_SOURCE}
155169
${IWASM_COMMON_SOURCE}
156170
${IWASM_INTERP_SOURCE}
157171
${IWASM_AOT_SOURCE}

core/deps/install_tensorflow.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
DEPS_ROOT=$(cd "$(dirname "$0")/" && pwd)
4+
cd ${DEPS_ROOT}
5+
6+
echo "Downloading tensorflow in ${PWD}..."
7+
8+
git clone https://github.com/tensorflow/tensorflow.git tensorflow-src \
9+
--branch v2.9.2
10+
11+
exit 0

core/iwasm/common/wasm_native.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ get_spectest_export_apis(NativeSymbol **p_libc_builtin_apis);
3333
uint32
3434
get_libc_wasi_export_apis(NativeSymbol **p_libc_wasi_apis);
3535

36+
uint32_t
37+
get_wasi_nn_export_apis(NativeSymbol **p_libc_wasi_apis);
38+
3639
uint32
3740
get_base_lib_export_apis(NativeSymbol **p_base_lib_apis);
3841

@@ -425,6 +428,13 @@ wasm_native_init()
425428
goto fail;
426429
#endif /* WASM_ENABLE_LIB_RATS */
427430

431+
#if WASM_ENABLE_WASI_NN != 0
432+
n_native_symbols = get_wasi_nn_export_apis(&native_symbols);
433+
if (!wasm_native_register_natives("wasi_nn", native_symbols,
434+
n_native_symbols))
435+
return false;
436+
#endif
437+
428438
return true;
429439
fail:
430440
wasm_native_destroy();

core/iwasm/common/wasm_shared_memory.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,13 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
323323
WASMModuleInstance *module_inst = (WASMModuleInstance *)module;
324324
/* Currently we have only one memory instance */
325325
if (!module_inst->memories[0]->is_shared) {
326-
wasm_runtime_set_exception(module, "wait on unshared memory");
326+
wasm_runtime_set_exception(module, "expected shared memory");
327+
return -1;
328+
}
329+
if ((uint8 *)address < module_inst->memories[0]->memory_data
330+
|| (uint8 *)address + (wait64 ? 8 : 4)
331+
> module_inst->memories[0]->memory_data_end) {
332+
wasm_runtime_set_exception(module, "out of bounds memory access");
327333
return -1;
328334
}
329335
}
@@ -335,7 +341,13 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
335341
((AOTMemoryInstance **)aot_inst->memories.ptr)[0];
336342
/* Currently we have only one memory instance */
337343
if (!aot_memory->is_shared) {
338-
wasm_runtime_set_exception(module, "wait on unshared memory");
344+
wasm_runtime_set_exception(module, "expected shared memory");
345+
return -1;
346+
}
347+
if ((uint8 *)address < (uint8 *)aot_memory->memory_data.ptr
348+
|| (uint8 *)address + (wait64 ? 8 : 4)
349+
> (uint8 *)aot_memory->memory_data_end.ptr) {
350+
wasm_runtime_set_exception(module, "out of bounds memory access");
339351
return -1;
340352
}
341353
}
@@ -424,6 +436,31 @@ wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address,
424436
uint32 notify_result;
425437
AtomicWaitInfo *wait_info;
426438

439+
#if WASM_ENABLE_INTERP != 0
440+
if (module->module_type == Wasm_Module_Bytecode) {
441+
WASMModuleInstance *module_inst = (WASMModuleInstance *)module;
442+
if ((uint8 *)address < module_inst->memories[0]->memory_data
443+
|| (uint8 *)address + 4
444+
> module_inst->memories[0]->memory_data_end) {
445+
wasm_runtime_set_exception(module, "out of bounds memory access");
446+
return -1;
447+
}
448+
}
449+
#endif
450+
#if WASM_ENABLE_AOT != 0
451+
if (module->module_type == Wasm_Module_AoT) {
452+
AOTModuleInstance *aot_inst = (AOTModuleInstance *)module;
453+
AOTMemoryInstance *aot_memory =
454+
((AOTMemoryInstance **)aot_inst->memories.ptr)[0];
455+
if ((uint8 *)address < (uint8 *)aot_memory->memory_data.ptr
456+
|| (uint8 *)address + 4
457+
> (uint8 *)aot_memory->memory_data_end.ptr) {
458+
wasm_runtime_set_exception(module, "out of bounds memory access");
459+
return -1;
460+
}
461+
}
462+
#endif
463+
427464
wait_info = acquire_wait_info(address, false);
428465

429466
/* Nobody wait on this address */

core/iwasm/compilation/aot_compiler.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,10 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index)
12171217
comp_ctx, func_ctx, align, offset, bytes))
12181218
return false;
12191219
break;
1220+
case WASM_OP_ATOMIC_FENCE:
1221+
/* Skip memory index */
1222+
frame_ip++;
1223+
break;
12201224
case WASM_OP_ATOMIC_I32_LOAD:
12211225
bytes = 4;
12221226
goto op_atomic_i32_load;

core/iwasm/fast-jit/jit_frontend.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,10 @@ jit_compile_func(JitCompContext *cc)
20522052
bytes))
20532053
return false;
20542054
break;
2055+
case WASM_OP_ATOMIC_FENCE:
2056+
/* Skip memory index */
2057+
frame_ip++;
2058+
break;
20552059
case WASM_OP_ATOMIC_I32_LOAD:
20562060
bytes = 4;
20572061
goto op_atomic_i32_load;

core/iwasm/include/wasm_export.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,12 @@ wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst,
922922
/**
923923
* Register native functions with same module name
924924
*
925+
* Note: The array `native_symbols` should not be read-only because the
926+
* library can modify it in-place.
927+
*
928+
* Note: After successful call of this function, the array `native_symbols`
929+
* is owned by the library.
930+
*
925931
* @param module_name the module name of the native functions
926932
* @param native_symbols specifies an array of NativeSymbol structures which
927933
* contain the names, function pointers and signatures

0 commit comments

Comments
 (0)