-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c00ac7
commit 72ea103
Showing
13 changed files
with
941 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
name: wasm-simd | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
paths: | ||
- '.github/workflows/build-wasm-simd.yaml' | ||
- 'CMakeLists.txt' | ||
- 'cmake/**' | ||
- 'sherpa-ncnn/csrc/*' | ||
- 'wasm/*' | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- '.github/workflows/build-wasm-simd.yaml' | ||
- 'CMakeLists.txt' | ||
- 'cmake/**' | ||
- 'sherpa-ncnn/csrc/*' | ||
- 'wasm/*' | ||
|
||
release: | ||
types: | ||
- published | ||
|
||
workflow_dispatch: | ||
inputs: | ||
release: | ||
description: "Whether to release" | ||
type: boolean | ||
|
||
env: | ||
RELEASE: | ||
|- # Release if there is a release tag name or a release flag in workflow_dispatch | ||
${{ github.event.release.tag_name != '' || github.event.inputs.release == 'true' }} | ||
|
||
concurrency: | ||
group: linux-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
wasm-simd: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install emsdk | ||
uses: mymindstorm/setup-emsdk@v14 | ||
|
||
- name: View emsdk version | ||
shell: bash | ||
run: | | ||
emcc -v | ||
echo "--------------------" | ||
emcc --check | ||
- name: Download model files | ||
shell: bash | ||
run: | | ||
cd wasm/assets | ||
ls -lh | ||
echo "----------" | ||
wget -q https://github.com/k2-fsa/sherpa-ncnn/releases/download/models/sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13.tar.bz2 | ||
tar xvf sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13.tar.bz2 | ||
mv -v sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13/*pnnx.ncnn.param . | ||
mv -v sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13/*pnnx.ncnn.bin . | ||
mv -v sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13/tokens.txt . | ||
rm -rf sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13 | ||
rm -v sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13.tar.bz2 | ||
ls -lh | ||
- name: Build sherpa-ncnn for WebAssembly | ||
shell: bash | ||
run: | | ||
./build-wasm-simd.sh | ||
- name: collect files | ||
shell: bash | ||
run: | | ||
SHERPA_NCNN_VERSION=v$(grep "SHERPA_NCNN_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
mv build-wasm-simd/install/bin/wasm sherpa-ncnn-wasm-simd | ||
ls -lh sherpa-ncnn-wasm-simd | ||
tar cjfv sherpa-ncnn-wasm-simd-${SHERPA_NCNN_VERSION}.tar.bz2 ./sherpa-ncnn-wasm-simd | ||
- name: Upload wasm files | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: sherpa-ncnn-wasm-simd | ||
path: ./sherpa-ncnn-wasm-simd-*.tar.bz2 | ||
|
||
- name: Release wasm files | ||
if: env.RELEASE == 'true' | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
file_glob: true | ||
overwrite: true | ||
file: ./sherpa-ncnn-wasm-simd*.tar.bz2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,11 +48,18 @@ jobs: | |
go env GOPATH | ||
go env GOARCH | ||
- name: Set up MinGW | ||
if: matrix.os == 'windows-latest' | ||
uses: egor-tensin/setup-mingw@v2 | ||
- name: Set up MinGW for x64 | ||
if: matrix.os == 'windows-latest' && matrix.arch == 'x64' | ||
uses: csukuangfj/[email protected] | ||
with: | ||
platform: ${{ matrix.arch }} | ||
|
||
- name: Set up MinGW for x86 | ||
if: matrix.os == 'windows-latest' && matrix.arch == 'x86' | ||
uses: csukuangfj/[email protected] | ||
with: | ||
platform: ${{ matrix.arch }} | ||
version: '12.2.0' | ||
|
||
- name: Show gcc | ||
if: matrix.os == 'windows-latest' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env bash | ||
# Copyright (c) 2024 Xiaomi Corporation | ||
# | ||
# This script is to build sherpa-ncnn for WebAssembly | ||
# | ||
# See also | ||
# https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-webassembly | ||
# | ||
# Please refer to | ||
# https://k2-fsa.github.io/sherpa/ncnn/wasm/index.html | ||
# for more details. | ||
|
||
set -ex | ||
|
||
if [ x"$EMSCRIPTEN" == x"" ]; then | ||
if ! command -v emcc &> /dev/null; then | ||
echo "Please install emscripten first" | ||
echo "" | ||
echo "You can use the following commands to install it:" | ||
echo "" | ||
echo "git clone https://github.com/emscripten-core/emsdk.git" | ||
echo "cd emsdk" | ||
echo "git pull" | ||
echo "./emsdk install latest" | ||
echo "./emsdk activate latest" | ||
echo "source ./emsdk_env.sh" | ||
exit 1 | ||
else | ||
EMSCRIPTEN=$(dirname $(realpath $(which emcc))) | ||
fi | ||
fi | ||
|
||
export EMSCRIPTEN=$EMSCRIPTEN | ||
echo "EMSCRIPTEN: $EMSCRIPTEN" | ||
if [ ! -f $EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake ]; then | ||
echo "Cannot find $EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake" | ||
echo "Please make sure you have installed emsdk correctly" | ||
exit 1 | ||
fi | ||
|
||
mkdir -p build-wasm-simd | ||
pushd build-wasm-simd | ||
|
||
export SHERPA_NCNN_IS_USING_BUILD_WASM_SH=ON | ||
|
||
cmake \ | ||
-DCMAKE_INSTALL_PREFIX=./install \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake \ | ||
-DNCNN_THREADS=OFF \ | ||
-DNCNN_OPENMP=OFF \ | ||
-DNCNN_SIMPLEOMP=OFF \ | ||
-DNCNN_RUNTIME_CPU=OFF \ | ||
-DNCNN_SSE2=ON \ | ||
-DNCNN_AVX2=OFF \ | ||
-DNCNN_AVX=OFF \ | ||
-DNCNN_BUILD_TOOLS=OFF \ | ||
-DNCNN_BUILD_EXAMPLES=OFF \ | ||
-DNCNN_BUILD_BENCHMARK=OFF \ | ||
\ | ||
-DSHERPA_NCNN_ENABLE_WASM=ON \ | ||
-DBUILD_SHARED_LIBS=OFF \ | ||
-DSHERPA_NCNN_ENABLE_PYTHON=OFF \ | ||
-DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \ | ||
-DSHERPA_NCNN_ENABLE_JNI=OFF \ | ||
-DSHERPA_NCNN_ENABLE_BINARY=OFF \ | ||
-DSHERPA_NCNN_ENABLE_TEST=OFF \ | ||
-DSHERPA_NCNN_ENABLE_C_API=ON \ | ||
-DSHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE=OFF \ | ||
-DSHERPA_NCNN_ENABLE_FFMPEG_EXAMPLES=OFF \ | ||
.. | ||
|
||
make -j2 | ||
make install | ||
ls -lh install/bin/wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
if(NOT $ENV{SHERPA_NCNN_IS_USING_BUILD_WASM_SH}) | ||
message(FATAL_ERROR "Please use ./build-wasm.sh to build for wasm") | ||
endif() | ||
|
||
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/assets/decoder_jit_trace-pnnx.ncnn.bin") | ||
message(WARNING "${CMAKE_CURRENT_SOURCE_DIR}/assets/decoder_jit_trace-pnnx.ncnn.bin does not exist") | ||
message(FATAL_ERROR "Please read ${CMAKE_CURRENT_SOURCE_DIR}/assets/README.md before you continue") | ||
endif() | ||
|
||
set(exported_functions | ||
AcceptWaveform | ||
CreateRecognizer | ||
CreateStream | ||
Decode | ||
DestroyRecognizer | ||
DestroyResult | ||
DestroyStream | ||
GetResult | ||
InputFinished | ||
IsEndpoint | ||
IsReady | ||
Reset | ||
) | ||
set(mangled_exported_functions) | ||
foreach(x IN LISTS exported_functions) | ||
list(APPEND mangled_exported_functions "_${x}") | ||
endforeach() | ||
|
||
list(JOIN mangled_exported_functions "," all_exported_functions) | ||
|
||
include_directories(${CMAKE_SOURCE_DIR}) | ||
set(MY_FLAGS " -s FORCE_FILESYSTEM=1 -s INITIAL_MEMORY=512MB ") | ||
string(APPEND MY_FLAGS " -sEXPORTED_FUNCTIONS=[_CopyHeap,_malloc,_free,${all_exported_functions}] ") | ||
string(APPEND MY_FLAGS "--preload-file ${CMAKE_CURRENT_SOURCE_DIR}/assets@. ") | ||
string(APPEND MY_FLAGS " -sEXPORTED_RUNTIME_METHODS=['ccall','stringToUTF8','setValue','getValue'] ") | ||
message(STATUS "MY_FLAGS: ${MY_FLAGS}") | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_FLAGS}") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_FLAGS}") | ||
set(CMAKE_EXECUTBLE_LINKER_FLAGS "${CMAKE_EXECUTBLE_LINKER_FLAGS} ${MY_FLAGS}") | ||
|
||
add_executable(sherpa-ncnn-wasm-main sherpa-ncnn-wasm-main.cc) | ||
target_link_libraries(sherpa-ncnn-wasm-main sherpa-ncnn-core sherpa-ncnn-c-api) | ||
install(TARGETS sherpa-ncnn-wasm-main DESTINATION bin/wasm) | ||
|
||
install( | ||
FILES | ||
"sherpa-ncnn.js" | ||
"app.js" | ||
"index.html" | ||
"$<TARGET_FILE_DIR:sherpa-ncnn-wasm-main>/sherpa-ncnn-wasm-main.js" | ||
"$<TARGET_FILE_DIR:sherpa-ncnn-wasm-main>/sherpa-ncnn-wasm-main.wasm" | ||
"$<TARGET_FILE_DIR:sherpa-ncnn-wasm-main>/sherpa-ncnn-wasm-main.data" | ||
DESTINATION | ||
bin/wasm | ||
) |
Oops, something went wrong.