Skip to content

Commit

Permalink
Add wasi support
Browse files Browse the repository at this point in the history
cmake -B build -DCMAKE_BUILD_TYPE=Release \
	--toolchain ${wasi_sdk}/share/cmake/wasi-sdk.cmake \
	-DNCNN_RUNTIME_CPU=OFF \
	-DNCNN_DISABLE_EXCEPTION=ON \
	-DNCNN_THREADS=OFF

cmake --build build

After build, you can run benchncnn on cmdline with wasmtime:
wasmtime --dir . benchncnn
  • Loading branch information
quink-black committed Jun 27, 2024
1 parent 95c86a5 commit 910c4d8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ else()
unset(CMAKE_REQUIRED_FLAGS)
endif()

if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NCNN_COMPILER_SUPPORT_X86_AVX)
if(NOT CMAKE_SYSTEM_NAME MATCHES "Emscripten|WASI" AND NCNN_COMPILER_SUPPORT_X86_AVX)
option(NCNN_AVX "optimize x86 platform with avx extension" ON)
if(NCNN_COMPILER_SUPPORT_X86_FMA)
if(NCNN_AVX)
Expand Down
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,10 @@ if(NCNN_TARGET_ARCH STREQUAL "x86")
endif()
target_compile_options(ncnn PRIVATE /D__SSE2__)
else()
target_compile_options(ncnn PRIVATE -msse2 -msse)
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
if(CMAKE_SYSTEM_NAME MATCHES "Emscripten|WASI")
target_compile_options(ncnn PRIVATE -msimd128)
else()
target_compile_options(ncnn PRIVATE -msse2 -msse)
endif()
endif()
endif()
Expand Down
2 changes: 2 additions & 0 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#include "platform.h"

#include <limits.h>
#ifndef __wasi__
#include <setjmp.h>
#include <signal.h>
#endif // __wasi__
#include <stdio.h>
#include <string.h>

Expand Down

0 comments on commit 910c4d8

Please sign in to comment.