Skip to content

Commit

Permalink
Update sample workload's scripts to align with latest emcc (#609)
Browse files Browse the repository at this point in the history
And enable auxiliary stack overflow/underflow check in JIT mode
  • Loading branch information
wenyongh authored Apr 13, 2021
1 parent ee97618 commit 8b96f4f
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 23 deletions.
1 change: 1 addition & 0 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2458,6 +2458,7 @@ aot_convert_wasm_module(WASMModule *wasm_module,
#if WASM_ENABLE_SIMD != 0
option.enable_simd = true;
#endif
option.enable_aux_stack_check = true;
#if (WASM_ENABLE_PERF_PROFILING != 0) || (WASM_ENABLE_DUMP_CALL_STACK != 0)
option.enable_aux_stack_frame = true;
#endif
Expand Down
13 changes: 13 additions & 0 deletions core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,18 @@ emscripten_notify_memory_growth_wrapper(wasm_exec_env_t exec_env, int i)
(void)i;
}

static void
emscripten_thread_sleep_wrapper(wasm_exec_env_t exec_env, double timeout_ms)
{
uint64 ms = (uint64)timeout_ms;
uint64 sec = ms / 1000, us = (ms % 1000) * 1000;

if (sec > 0)
sleep(sec);
if (us > 0)
usleep(us);
}

#endif /* end of BH_PLATFORM_LINUX_SGX */

#define REG_NATIVE_FUNC(func_name, signature) \
Expand Down Expand Up @@ -543,6 +555,7 @@ static NativeSymbol native_symbols_libc_emcc[] = {
REG_NATIVE_FUNC(__sys_getcwd, "(*~)i"),
REG_NATIVE_FUNC(__sys_uname, "(*)i"),
REG_NATIVE_FUNC(emscripten_notify_memory_growth, "(i)"),
REG_NATIVE_FUNC(emscripten_thread_sleep, "(F)"),
#endif /* end of BH_PLATFORM_LINUX_SGX */
};

Expand Down
2 changes: 2 additions & 0 deletions samples/workload/XNNPACK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ ExternalProject_Add(xnnpack
UPDATE_COMMAND git checkout .bazelrc BUILD.bazel emscripten.bzl
&& git apply ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack.patch
&& cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/toolchain ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/toolchain
# replace string "$ENV{HOME}" with actual home directory
&& sed -i "s|\$ENV{HOME}|$ENV{HOME}|g" ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/toolchain/emscripten_toolchain_config.bzl
CONFIGURE_COMMAND ""
BUILD_COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack
&& bazel build -c opt --sandbox_writable_path=$ENV{HOME} --config=emscripten_wasm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def _impl(ctx):
"STANDALONE_WASM=1",
"-Wl,--export=__heap_base",
"-Wl,--export=__data_end",
"-Wl,--export=malloc",
"-Wl,--export=free",
],
),
]),
Expand All @@ -112,12 +114,15 @@ def _impl(ctx):
ctx = ctx,
features = features, # NEW
cxx_builtin_include_directories = [
"/opt/emsdk/upstream/emscripten/system/include/libcxx",
"/opt/emsdk/upstream/emscripten/system/lib/libcxxabi/include",
"/opt/emsdk/upstream/emscripten/system/include",
"/opt/emsdk/upstream/emscripten/system/include/libc",
"/opt/emsdk/upstream/emscripten/system/lib/libc/include",
"/opt/emsdk/upstream/emscripten/system/lib/libcxx/include",
"/opt/emsdk/upstream/emscripten/system/lib/libcxxabi/include",
"/opt/emsdk/upstream/emscripten/system/lib/libc/musl/arch/emscripten",
"/opt/emsdk/upstream/lib/clang/12.0.0/include/",
"/opt/emsdk/upstream/emscripten/system/include/compat",
"/opt/emsdk/upstream/emscripten/cache/sysroot/include",
"/opt/emsdk/upstream/lib/clang/13.0.0/include",
"$ENV{HOME}/.emscripten_cache/sysroot/include",
],
toolchain_identifier = "wasm-emsdk",
host_system_name = "i686-unknown-linux-gnu",
Expand Down
20 changes: 10 additions & 10 deletions samples/workload/bwa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,28 @@ include(ExternalProject)
################ HEADERS ################
ExternalProject_Add(headers_from_emcc
PREFIX headers
SOURCE_DIR "$ENV{EMSDK}/upstream/emscripten/system/include/SSE"
SOURCE_DIR "$ENV{EM_CACHE}/sysroot/include"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND mkdir -p ${CMAKE_CURRENT_SOURCE_DIR}/include/SSE
&& ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys
&& ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/emscripten
# copy emscripten SSE header files
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/SSE/immintrin.h ${CMAKE_CURRENT_SOURCE_DIR}/include/SSE/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/compat/immintrin.h ${CMAKE_CURRENT_SOURCE_DIR}/include/SSE/
# SSE
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/SSE/xmmintrin.h ${CMAKE_CURRENT_SOURCE_DIR}/include/SSE/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/compat/xmmintrin.h ${CMAKE_CURRENT_SOURCE_DIR}/include/SSE/
# SSE2
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/SSE/emmintrin.h ${CMAKE_CURRENT_SOURCE_DIR}/include/SSE/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/compat/emmintrin.h ${CMAKE_CURRENT_SOURCE_DIR}/include/SSE/
# SSE4.1
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/SSE/smmintrin.h ${CMAKE_CURRENT_SOURCE_DIR}/include/SSE/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/compat/smmintrin.h ${CMAKE_CURRENT_SOURCE_DIR}/include/SSE/
# a fake empty header to aovid further depenency
&& ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_SOURCE_DIR}/include/emscripten/emscripten.h
# copy emscripten pthread related header files
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/pthread.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/signal.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/netdb.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/sys/wait.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/sys/socket.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/pthread.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/signal.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/netdb.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/sys/wait.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/sys/socket.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys/
)

################ libz ################
Expand Down
2 changes: 1 addition & 1 deletion samples/workload/tensorflow/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fi

set -xe

EMSDK_WASM_DIR="$EM_CACHE/wasm"
EMSDK_WASM_DIR="$EM_CACHE/sysroot/lib/wasm32-emscripten"
BUILD_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUT_DIR="${BUILD_SCRIPT_DIR}/out"
TENSORFLOW_DIR="${BUILD_SCRIPT_DIR}/tensorflow"
Expand Down
14 changes: 7 additions & 7 deletions samples/workload/wasm-av1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ include(ExternalProject)
################ HEADERS ################
ExternalProject_Add(headers_from_emcc
PREFIX headers
SOURCE_DIR "$ENV{EMSDK}/upstream/emscripten/system/"
SOURCE_DIR "$ENV{EM_CACHE}/sysroot/include"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys
&& ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/libc/bits
# copy emscripten pthread related header files
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/pthread.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/signal.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/netdb.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/sys/wait.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys/
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/sys/socket.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/pthread.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/signal.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/netdb.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/sys/wait.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys/
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/sys/socket.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread/sys/
# copy emscripten setjmp headers
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/include/libc/setjmp.h ${CMAKE_CURRENT_SOURCE_DIR}/include/libc/setjmp.h
&& ${CMAKE_COMMAND} -E copy $ENV{EM_CACHE}/sysroot/include/setjmp.h ${CMAKE_CURRENT_SOURCE_DIR}/include/libc/setjmp.h
&& ${CMAKE_COMMAND} -E copy $ENV{EMSDK}/upstream/emscripten/system/lib/libc/musl/arch/emscripten/bits/setjmp.h ${CMAKE_CURRENT_SOURCE_DIR}/include/libc/bits/setjmp.h
)

Expand Down
2 changes: 1 addition & 1 deletion samples/workload/wasm-av1/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fi

set -xe

EMSDK_WASM_DIR="$EM_CACHE/wasm"
EMSDK_WASM_DIR="$EM_CACHE/sysroot/lib/wasm32-emscripten"
BUILD_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUT_DIR="${BUILD_SCRIPT_DIR}/out"
WASM_AV1_DIR="${BUILD_SCRIPT_DIR}/wasm-av1"
Expand Down

0 comments on commit 8b96f4f

Please sign in to comment.