mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-09 13:16:26 +00:00
Update build script to enable running tensorflow workload in linux-sgx (#435)
This commit is contained in:
parent
c9c882e43d
commit
ad4aa9a85f
|
@ -3,8 +3,8 @@
|
||||||
<ProdID>0</ProdID>
|
<ProdID>0</ProdID>
|
||||||
<ISVSVN>0</ISVSVN>
|
<ISVSVN>0</ISVSVN>
|
||||||
<StackMaxSize>0x100000</StackMaxSize>
|
<StackMaxSize>0x100000</StackMaxSize>
|
||||||
<HeapMaxSize>0x1000000</HeapMaxSize>
|
<HeapMaxSize>0x2000000</HeapMaxSize>
|
||||||
<ReservedMemMaxSize>0x400000</ReservedMemMaxSize>
|
<ReservedMemMaxSize>0x1000000</ReservedMemMaxSize>
|
||||||
<ReservedMemExecutable>1</ReservedMemExecutable>
|
<ReservedMemExecutable>1</ReservedMemExecutable>
|
||||||
<TCSNum>10</TCSNum>
|
<TCSNum>10</TCSNum>
|
||||||
<TCSPolicy>1</TCSPolicy>
|
<TCSPolicy>1</TCSPolicy>
|
||||||
|
|
|
@ -11,7 +11,14 @@ And set up ensdk environment:
|
||||||
```bash
|
```bash
|
||||||
source emsdk_env.sh
|
source emsdk_env.sh
|
||||||
```
|
```
|
||||||
Then run ./build.sh to build tensorflow and run it with iwasm, which basically contains the following steps:
|
Then run
|
||||||
|
```bash
|
||||||
|
./build.sh
|
||||||
|
# for linux platform, or
|
||||||
|
./build.sh --sgx
|
||||||
|
# for linux-sgx platform
|
||||||
|
```
|
||||||
|
to build tensorflow and run it with iwasm, which basically contains the following steps:
|
||||||
- hack emcc to delete some objects in libc.a
|
- hack emcc to delete some objects in libc.a
|
||||||
- build tf-lite with emcc compiler
|
- build tf-lite with emcc compiler
|
||||||
- build iwasm with pthread enable and include libiary under libc-emcc
|
- build iwasm with pthread enable and include libiary under libc-emcc
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
####################################
|
####################################
|
||||||
# build tensorflow-lite sample #
|
# build tensorflow-lite sample #
|
||||||
####################################
|
####################################
|
||||||
set -x
|
set -xe
|
||||||
set -e
|
|
||||||
|
|
||||||
EMSDK_WASM_DIR="$EM_CACHE/wasm"
|
EMSDK_WASM_DIR="$EM_CACHE/wasm"
|
||||||
BUILD_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
BUILD_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
OUT_DIR=${BUILD_SCRIPT_DIR}/out
|
OUT_DIR="${BUILD_SCRIPT_DIR}/out"
|
||||||
TENSORFLOW_DIR="${BUILD_SCRIPT_DIR}/tensorflow"
|
TENSORFLOW_DIR="${BUILD_SCRIPT_DIR}/tensorflow"
|
||||||
TF_LITE_BUILD_DIR=${TENSORFLOW_DIR}/tensorflow/lite/tools/make
|
TF_LITE_BUILD_DIR="${TENSORFLOW_DIR}/tensorflow/lite/tools/make"
|
||||||
WAMR_DIR="${BUILD_SCRIPT_DIR}/../../../product-mini/platforms/linux"
|
WAMR_PLATFORM_DIR="${BUILD_SCRIPT_DIR}/../../../product-mini/platforms"
|
||||||
|
WAMRC_DIR="${BUILD_SCRIPT_DIR}/../../../wamr-compiler"
|
||||||
|
|
||||||
function Clear_Before_Exit
|
function Clear_Before_Exit
|
||||||
{
|
{
|
||||||
|
@ -64,34 +64,66 @@ fi
|
||||||
if [ -d "${TF_LITE_BUILD_DIR}/gen" ]; then
|
if [ -d "${TF_LITE_BUILD_DIR}/gen" ]; then
|
||||||
rm -fr ${TF_LITE_BUILD_DIR}/gen
|
rm -fr ${TF_LITE_BUILD_DIR}/gen
|
||||||
fi
|
fi
|
||||||
make -j 4 -C "${TENSORFLOW_DIR}" -f ${TF_LITE_BUILD_DIR}/Makefile $@
|
make -j 4 -C "${TENSORFLOW_DIR}" -f ${TF_LITE_BUILD_DIR}/Makefile
|
||||||
|
|
||||||
# 2.5 copy /make/gen target files to out/
|
# 2.5 copy /make/gen target files to out/
|
||||||
rm -rf ${OUT_DIR}
|
rm -rf ${OUT_DIR}
|
||||||
mkdir ${OUT_DIR}
|
mkdir ${OUT_DIR}
|
||||||
cp -r ${TF_LITE_BUILD_DIR}/gen/linux_x86_64/bin/. ${OUT_DIR}/
|
cp -r ${TF_LITE_BUILD_DIR}/gen/linux_x86_64/bin/. ${OUT_DIR}/
|
||||||
|
|
||||||
# 3. build iwasm with pthread and libc_emcc enable
|
# 3. compile tf-model.wasm to tf-model.aot with wamrc
|
||||||
cd ${WAMR_DIR}
|
# 3.1 build wamr-compiler
|
||||||
|
cd ${WAMRC_DIR}
|
||||||
|
./build_llvm.sh
|
||||||
rm -fr build && mkdir build
|
rm -fr build && mkdir build
|
||||||
cd build && cmake .. -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1
|
cd build && cmake ..
|
||||||
make
|
make
|
||||||
|
# 3.2 compile tf-mode.wasm to tf-model.aot
|
||||||
|
WAMRC_CMD="$(pwd)/wamrc"
|
||||||
|
cd ${OUT_DIR}
|
||||||
|
if [[ $1 == '--sgx' ]]; then
|
||||||
|
${WAMRC_CMD} -sgx -o benchmark_model.aot benchmark_model.wasm
|
||||||
|
else
|
||||||
|
${WAMRC_CMD} -o benchmark_model.aot benchmark_model.wasm
|
||||||
|
fi
|
||||||
|
|
||||||
# 4. run tensorflow with iwasm
|
# 4. build iwasm with pthread and libc_emcc enable
|
||||||
|
# platform:
|
||||||
|
# linux by default
|
||||||
|
# linux-sgx if $1 equals '--sgx'
|
||||||
|
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
|
||||||
|
make
|
||||||
|
cd ../enclave-sample
|
||||||
|
make
|
||||||
|
else
|
||||||
|
cd ${WAMR_PLATFORM_DIR}/linux
|
||||||
|
rm -fr build && mkdir build
|
||||||
|
cd build && cmake .. -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1
|
||||||
|
make
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 5. run tensorflow with iwasm
|
||||||
cd ${BUILD_SCRIPT_DIR}
|
cd ${BUILD_SCRIPT_DIR}
|
||||||
# 4.1 download tf-lite model
|
# 5.1 download tf-lite model
|
||||||
if [ ! -f mobilenet_quant_v1_224.tflite ]; then
|
if [ ! -f mobilenet_quant_v1_224.tflite ]; then
|
||||||
wget "https://storage.googleapis.com/download.tensorflow.org/models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip"
|
wget "https://storage.googleapis.com/download.tensorflow.org/models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip"
|
||||||
unzip mobilenet_v1_224_android_quant_2017_11_08.zip
|
unzip mobilenet_v1_224_android_quant_2017_11_08.zip
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 4.2 run tf-lite model with iwasm
|
# 5.2 run tf-lite model with iwasm
|
||||||
echo "---> run tensorflow benchmark model with iwasm"
|
echo "---> run tensorflow benchmark model with iwasm"
|
||||||
${WAMR_DIR}/build/iwasm --heap-size=10475860 \
|
if [[ $1 == '--sgx' ]]; then
|
||||||
${OUT_DIR}/benchmark_model.wasm \
|
IWASM_CMD="${WAMR_PLATFORM_DIR}/linux-sgx/enclave-sample/iwasm"
|
||||||
|
else
|
||||||
|
IWASM_CMD="${WAMR_PLATFORM_DIR}/linux/build/iwasm"
|
||||||
|
fi
|
||||||
|
|
||||||
|
${IWASM_CMD} --heap-size=10475860 \
|
||||||
|
${OUT_DIR}/benchmark_model.aot \
|
||||||
--graph=mobilenet_quant_v1_224.tflite --max_secs=300
|
--graph=mobilenet_quant_v1_224.tflite --max_secs=300
|
||||||
|
|
||||||
Clear_Before_Exit
|
Clear_Before_Exit
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user