forked from tangledgroup/llama-cpp-wasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-single-thread.sh
executable file
·47 lines (39 loc) · 1.68 KB
/
build-single-thread.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
set -e
LLAMA_CPP_WASM_BUILD_DIR=build
LLAMA_CPP_WASM_DIST_DIR=dist
LLAMA_CPP_WASM_DIST_LLAMA_DIR=$LLAMA_CPP_WASM_DIST_DIR/llama-st
LLAMA_CPP_GIT_HASH="8c933b7"
LLAMA_CPP_SOURCE_DIR=$LLAMA_CPP_WASM_BUILD_DIR/llama.cpp
LLAMA_CPP_BUILD_DIR=$LLAMA_CPP_WASM_BUILD_DIR/build
#
# compile llama.cpp
#
if [ -d $LLAMA_CPP_WASM_BUILD_DIR ]; then
rm -rf $LLAMA_CPP_WASM_BUILD_DIR
fi
mkdir -p $LLAMA_CPP_WASM_BUILD_DIR
git clone https://github.com/ggerganov/llama.cpp.git $LLAMA_CPP_SOURCE_DIR
cd $LLAMA_CPP_SOURCE_DIR
git reset --hard $LLAMA_CPP_GIT_HASH
git apply ../../00-llama-cpp-enable-main.patch
cd ../..
mkdir -p $LLAMA_CPP_BUILD_DIR
cd $LLAMA_CPP_BUILD_DIR
emcc --clear-cache
emcmake cmake ../../$LLAMA_CPP_SOURCE_DIR
# export EMCC_CFLAGS="-O3 -DNDEBUG -flto -s BUILD_AS_WORKER=1 -s EXPORT_ALL=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s INITIAL_MEMORY=2GB -s MAXIMUM_MEMORY=4GB -s ALLOW_MEMORY_GROWTH -s FORCE_FILESYSTEM=1 -s EXPORTED_FUNCTIONS=_main -s EXPORTED_RUNTIME_METHODS=callMain -s NO_EXIT_RUNTIME=1"
export EMCC_CFLAGS="-O3 -msimd128 -fno-rtti -DNDEBUG -flto=full -s BUILD_AS_WORKER=1 -s EXPORT_ALL=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s INITIAL_MEMORY=800MB -s MAXIMUM_MEMORY=4GB -s ALLOW_MEMORY_GROWTH -s FORCE_FILESYSTEM=1 -s EXPORTED_FUNCTIONS=_main -s EXPORTED_RUNTIME_METHODS=callMain -s NO_EXIT_RUNTIME=1"
emmake make main -j
cd ../..
#
# bundle llama-cpp-wasm dist
#
if [ -d $LLAMA_CPP_WASM_DIST_LLAMA_DIR ]; then
rm -rf $LLAMA_CPP_WASM_DIST_LLAMA_DIR
fi
mkdir -p $LLAMA_CPP_WASM_DIST_LLAMA_DIR
cp -rv src/llama/* $LLAMA_CPP_WASM_DIST_LLAMA_DIR
cp $LLAMA_CPP_BUILD_DIR/bin/main.* $LLAMA_CPP_WASM_DIST_LLAMA_DIR
rm -rf docs/llama-st
cp -rv $LLAMA_CPP_WASM_DIST_LLAMA_DIR docs/