diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index d132c742..de90eb39 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -294,7 +294,7 @@ wasm_runtime_register_module_internal(const char *module_name, node = wasm_runtime_find_module_registered_by_reference(module); if (node) { /* module has been registered */ if (node->module_name) { /* module has name */ - if (strcmp(node->module_name, module_name)) { + if (!module_name || strcmp(node->module_name, module_name)) { /* module has different name */ LOG_DEBUG("module(%p) has been registered with name %s", module, node->module_name); @@ -3094,17 +3094,9 @@ fail: #undef v128 #endif -#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) -#include -/* unaligned */ -#define v128 __m128i_u -#else -#warning "Include header files for v128 to support SIMD feature" -#endif +typedef long long v128 __attribute__ ((__vector_size__ (16), + __may_alias__, __aligned__ (1))); -#ifndef v128 -#error "v128 type isn't defined" -#endif #endif /* end of WASM_ENABLE_SIMD != 0 */ typedef void (*GenericFunctionPointer)(); diff --git a/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c b/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c index 83186c40..0f9a3564 100644 --- a/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c +++ b/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c @@ -7,7 +7,7 @@ #include "bh_log.h" #include "wasm_export.h" #include "../interpreter/wasm.h" -#ifndef _DEFAULT_SOURCE +#if !defined(_DEFAULT_SOURCE) && !defined(BH_PLATFORM_LINUX_SGX) #include "sys/syscall.h" #endif @@ -267,7 +267,7 @@ getentropy_wrapper(wasm_exec_env_t exec_env, void *buffer, uint32 length) { if (buffer == NULL) return -1; -#ifdef _DEFAULT_SOURCE +#if defined(_DEFAULT_SOURCE) || defined(BH_PLATFORM_LINUX_SGX) return getentropy(buffer, length); #else return syscall(SYS_getrandom, buffer, length, 0); diff --git a/product-mini/platforms/linux-sgx/CMakeLists.txt b/product-mini/platforms/linux-sgx/CMakeLists.txt index 4ea38792..286d9059 100644 --- a/product-mini/platforms/linux-sgx/CMakeLists.txt +++ b/product-mini/platforms/linux-sgx/CMakeLists.txt @@ -67,6 +67,11 @@ if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD) set (WAMR_BUILD_LIB_PTHREAD 1) endif () +if (NOT DEFINED WAMR_BUILD_SIMD) + # Disable SIMD by default + set (WAMR_BUILD_SIMD 0) +endif () + if (COLLECT_CODE_COVERAGE EQUAL 1) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") endif () diff --git a/samples/workload/tensorflow/build.sh b/samples/workload/tensorflow/build.sh index ec942484..f3c10be3 100755 --- a/samples/workload/tensorflow/build.sh +++ b/samples/workload/tensorflow/build.sh @@ -76,12 +76,8 @@ fi if [ -d "${TF_LITE_BUILD_DIR}/gen" ]; then rm -fr ${TF_LITE_BUILD_DIR}/gen fi -if [[ $1 == '--sgx' ]]; then - make -j 4 -C "${TENSORFLOW_DIR}" -f ${TF_LITE_BUILD_DIR}/Makefile -else - export BUILD_WITH_SIMD=true - make -j 4 -C "${TENSORFLOW_DIR}" -f ${TF_LITE_BUILD_DIR}/Makefile -fi + +make -j 4 -C "${TENSORFLOW_DIR}" -f ${TF_LITE_BUILD_DIR}/Makefile # remove patch file and recover emcc libc.a after building Clear_Before_Exit @@ -102,7 +98,7 @@ make WAMRC_CMD="$(pwd)/wamrc" cd ${OUT_DIR} if [[ $1 == '--sgx' ]]; then - ${WAMRC_CMD} -sgx -o benchmark_model.aot benchmark_model.wasm + ${WAMRC_CMD} --enable-simd -sgx -o benchmark_model.aot benchmark_model.wasm else ${WAMRC_CMD} --enable-simd -o benchmark_model.aot benchmark_model.wasm fi @@ -114,7 +110,7 @@ fi if [[ $1 == '--sgx' ]]; then cd ${WAMR_PLATFORM_DIR}/linux-sgx rm -fr build && mkdir build - cd build && cmake .. -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1 + cd build && cmake .. -DWAMR_BUILD_SIMD=1 -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1 make cd ../enclave-sample make diff --git a/samples/workload/tensorflow/tf_lite.patch b/samples/workload/tensorflow/tf_lite.patch index b76dd521..f83c1d95 100644 --- a/samples/workload/tensorflow/tf_lite.patch +++ b/samples/workload/tensorflow/tf_lite.patch @@ -1,5 +1,5 @@ diff --git a/tensorflow/lite/tools/make/Makefile b/tensorflow/lite/tools/make/Makefile -index c7ddff5844..17146868f7 100644 +index c7ddff58440..ed69c452b67 100644 --- a/tensorflow/lite/tools/make/Makefile +++ b/tensorflow/lite/tools/make/Makefile @@ -48,11 +48,7 @@ INCLUDES += -I/usr/local/include @@ -15,15 +15,12 @@ index c7ddff5844..17146868f7 100644 -ldl # There are no rules for compiling objects for the host system (since we don't -@@ -84,14 +80,24 @@ endif # ifeq ($(HOST_ARCH),$(TARGET_ARCH)) +@@ -84,14 +80,21 @@ endif # ifeq ($(HOST_ARCH),$(TARGET_ARCH)) endif # ifeq ($(HOST_OS),$(TARGET)) endif -+BUILD_WITH_SIMD ?= false -+ifeq ($(BUILD_WITH_SIMD), true) +CFLAGS+=-msimd128 +CXXFLAGS+=-msimd128 -+endif + +LIBFLAGS += -s TOTAL_STACK=1048576 \ + -Wl,--export=__data_end -Wl,--export=__heap_base \ @@ -42,7 +39,7 @@ index c7ddff5844..17146868f7 100644 # A small example program that shows how to link against the library. MINIMAL_SRCS := \ -@@ -277,12 +283,16 @@ LIB_PATH := $(LIBDIR)$(LIB_NAME) +@@ -277,12 +280,16 @@ LIB_PATH := $(LIBDIR)$(LIB_NAME) BENCHMARK_LIB := $(LIBDIR)$(BENCHMARK_LIB_NAME) BENCHMARK_BINARY := $(BINDIR)$(BENCHMARK_BINARY_NAME) BENCHMARK_PERF_OPTIONS_BINARY := $(BINDIR)$(BENCHMARK_PERF_OPTIONS_BINARY_NAME) @@ -64,7 +61,7 @@ index c7ddff5844..17146868f7 100644 MINIMAL_OBJS := $(addprefix $(OBJDIR), \ $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(MINIMAL_SRCS)))) diff --git a/tensorflow/lite/tools/make/targets/linux_makefile.inc b/tensorflow/lite/tools/make/targets/linux_makefile.inc -index 222cef9e5f..eea89a38f0 100644 +index 222cef9e5ff..eea89a38f01 100644 --- a/tensorflow/lite/tools/make/targets/linux_makefile.inc +++ b/tensorflow/lite/tools/make/targets/linux_makefile.inc @@ -2,12 +2,10 @@