From 910c4d82e6376c2c814e05705dc48aa44374ce66 Mon Sep 17 00:00:00 2001 From: Zhao Zhili Date: Thu, 27 Jun 2024 20:22:13 +0800 Subject: [PATCH] Add wasi support 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 --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 5 +++-- src/cpu.cpp | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0b6cfc8b589..309e3b8fbd0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 35e46535a3b7..60ba6a0e5d63 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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() diff --git a/src/cpu.cpp b/src/cpu.cpp index 370aeeb610c7..b1afbba3f651 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -17,8 +17,10 @@ #include "platform.h" #include +#ifndef __wasi__ #include #include +#endif // __wasi__ #include #include