diff --git a/.github/workflows/build.yaml b/.github/workflows/build-openvino.yaml similarity index 94% rename from .github/workflows/build.yaml rename to .github/workflows/build-openvino.yaml index a6049eb..5a43b1d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build-openvino.yaml @@ -1,4 +1,4 @@ -name: Build and Test WasmEdge WASI-NN examples +name: Build and Test WasmEdge WASI-NN OpenVINO backend on: push: @@ -47,6 +47,7 @@ jobs: cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DWASMEDGE_PLUGIN_WASI_NN_BACKEND="OpenVINO" .;\ cmake --build build;" - name: Build and run Rust example - Mobilenet + continue-on-error: true run: | bash -c "\ source /opt/intel/openvino_2021/bin/setupvars.sh;\ @@ -56,6 +57,7 @@ jobs: ./download_mobilenet.sh;\ wasmedge --dir .:. wasmedge-wasinn-example-mobilenet.wasm mobilenet.xml mobilenet.bin tensor-1x224x224x3-f32.bgr" - name: Build and run Rust example - Mobilenet Image + continue-on-error: true run: | bash -c "\ source /opt/intel/openvino_2021/bin/setupvars.sh;\ diff --git a/.github/workflows/build-pytorch.yaml b/.github/workflows/build-pytorch.yaml new file mode 100644 index 0000000..6a5fbc6 --- /dev/null +++ b/.github/workflows/build-pytorch.yaml @@ -0,0 +1,55 @@ +name: Build and Test WasmEdge WASI-NN PyTorch backend + +on: + push: + branches: [master] + paths-ignore: + - "**/*.md" + pull_request: + branches: [master] + paths-ignore: + - "**/*.md" + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + container: + image: wasmedge/wasmedge:latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Install PyTorch + shell: bash + env: + PYTORCH_VERSION: "1.8.2" + PYTORCH_INSTALL_TO: "." + run: | + apt update + apt install unzip + bash ./scripts/install_libtorch.sh + - name: Build WasmEdge Wasi-NN with PyTorch backend using g++ + shell: bash + env: + CMAKE_BUILD_TYPE: "Release" + PYTORCH_INSTALL_TO: "." + run: | + export Torch_DIR=$(pwd)/${PYTORCH_INSTALL_TO}/libtorch + git clone https://github.com/WasmEdge/WasmEdge + cd ./WasmEdge + cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DWASMEDGE_PLUGIN_WASI_NN_BACKEND="PyTorch" . + cmake --build build + - name: Build and run Rust example - Mobilenet + shell: bash + env: + PYTORCH_INSTALL_TO: "." + run: | + export Torch_DIR=$(pwd)/${PYTORCH_INSTALL_TO}/libtorch + export LD_LIBRARY_PATH=$Torch_DIR/lib:$LD_LIBRARY_PATH + cd WasmEdge && cmake --install build && cd .. + cd pytorch-mobilenet-image + ./download_data.sh + wasmedge --dir .:. wasmedge-wasinn-example-mobilenet-image.wasm mobilenet.pt input.jpg diff --git a/scripts/install_libtorch.sh b/scripts/install_libtorch.sh index ad7dce9..faec86f 100755 --- a/scripts/install_libtorch.sh +++ b/scripts/install_libtorch.sh @@ -6,10 +6,26 @@ if [[ ! -n ${PYTORCH_VERSION} ]]; then PYTORCH_VERSION="1.8.2" fi -DOWNLOAD_TO=$1 -if [ ! -d $1/libtorch ]; then - curl -s -L -O --remote-name-all https://download.pytorch.org/libtorch/lts/1.8/cpu/libtorch-cxx11-abi-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip - echo "b76d6dd4380e2233ce6f7654e672e13aae7c871231d223a4267ef018dcbfb616 libtorch-cxx11-abi-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip" | sha256sum -c - unzip -q "libtorch-cxx11-abi-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip" - rm -f "libtorch-cxx11-abi-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip" +if [[ ! -n ${PYTORCH_INSTALL_TO} ]]; then + PYTORCH_INSTALL_TO=. +fi + +PYTORCH_LINK="libtorch-cxx11-abi" +PYTORCH_SHA="b76d6dd4380e2233ce6f7654e672e13aae7c871231d223a4267ef018dcbfb616" + +for i in "$@"; do + case $i in + --disable-cxx11-abi) + PYTORCH_LINK="libtorch" + PYTORCH_SHA="b5ddadc9addc054d8503f4086546f0cbcfdc3fc70087863bbd7b0e3300e3247f" + shift + ;; + esac +done + +if [ ! -d ${PYTORCH_INSTALL_TO}/libtorch ]; then + curl -s -L -O --remote-name-all https://download.pytorch.org/libtorch/lts/1.8/cpu/${PYTORCH_LINK}-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip + echo "${PYTORCH_SHA} ${PYTORCH_LINK}-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip" | sha256sum -c + unzip -q "${PYTORCH_LINK}-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip" -d ${PYTORCH_INSTALL_TO} + rm -f "${PYTORCH_LINK}-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip" fi