Skip to content

Commit bd44117

Browse files
authored
Add wasi-nn example as smoke test case (#3501)
1 parent dc21c62 commit bd44117

2 files changed

Lines changed: 112 additions & 18 deletions

File tree

core/iwasm/libraries/wasi-nn/README.md

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@ By only including this file in your WASM application you will bind WASI-NN into
1616

1717
To run the tests we assume that the current directory is the root of the repository.
1818

19-
2019
### Build the runtime
2120

2221
Build the runtime image for your execution target type.
2322

2423
`EXECUTION_TYPE` can be:
25-
* `cpu`
26-
* `nvidia-gpu`
27-
* `vx-delegate`
28-
* `tpu`
24+
25+
- `cpu`
26+
- `nvidia-gpu`
27+
- `vx-delegate`
28+
- `tpu`
2929

3030
```
3131
EXECUTION_TYPE=cpu
3232
docker build -t wasi-nn-${EXECUTION_TYPE} -f core/iwasm/libraries/wasi-nn/test/Dockerfile.${EXECUTION_TYPE} .
3333
```
3434

35-
3635
### Build wasm app
3736

3837
```
@@ -43,7 +42,6 @@ docker build -t wasi-nn-compile -f core/iwasm/libraries/wasi-nn/test/Dockerfile.
4342
docker run -v $PWD/core/iwasm/libraries/wasi-nn:/wasi-nn wasi-nn-compile
4443
```
4544

46-
4745
### Run wasm app
4846

4947
If all the tests have run properly you will the the following message in the terminal,
@@ -52,7 +50,7 @@ If all the tests have run properly you will the the following message in the ter
5250
Tests: passed!
5351
```
5452

55-
* CPU
53+
- CPU
5654

5755
```
5856
docker run \
@@ -64,9 +62,9 @@ docker run \
6462
/assets/test_tensorflow.wasm
6563
```
6664

67-
* (NVIDIA) GPU
68-
* Requirements:
69-
* [NVIDIA docker](https://github.com/NVIDIA/nvidia-docker).
65+
- (NVIDIA) GPU
66+
- Requirements:
67+
- [NVIDIA docker](https://github.com/NVIDIA/nvidia-docker).
7068

7169
```
7270
docker run \
@@ -79,7 +77,7 @@ docker run \
7977
/assets/test_tensorflow.wasm
8078
```
8179

82-
* vx-delegate for NPU (x86 simulator)
80+
- vx-delegate for NPU (x86 simulator)
8381

8482
```
8583
docker run \
@@ -90,9 +88,9 @@ docker run \
9088
/assets/test_tensorflow_quantized.wasm
9189
```
9290

93-
* (Coral) TPU
94-
* Requirements:
95-
* [Coral USB](https://coral.ai/products/accelerator/).
91+
- (Coral) TPU
92+
- Requirements:
93+
- [Coral USB](https://coral.ai/products/accelerator/).
9694

9795
```
9896
docker run \
@@ -109,6 +107,45 @@ docker run \
109107

110108
Supported:
111109

112-
* Graph encoding: `tensorflowlite`.
113-
* Execution target: `cpu`, `gpu` and `tpu`.
114-
* Tensor type: `fp32`.
110+
- Graph encoding: `tensorflowlite`.
111+
- Execution target: `cpu`, `gpu` and `tpu`.
112+
- Tensor type: `fp32`.
113+
114+
## Smoke test
115+
116+
Use [classification-example](https://github.com/bytecodealliance/wasi-nn/tree/main/rust/examples/classification-example) as a smoke test case to make sure the wasi-nn support in WAMR is working properly.
117+
118+
> [!Important]
119+
> It requires openvino.
120+
121+
### Prepare the model and the wasm
122+
123+
``` bash
124+
$ pwd
125+
/workspaces/wasm-micro-runtime/core/iwasm/libraries/wasi-nn/test
126+
127+
$ docker build -t wasi-nn-example:v1.0 -f Dockerfile.wasi-nn-example .
128+
```
129+
130+
There are model files(*mobilenet\**) and wasm files(*wasi-nn-example.wasm*) in the directory */workspaces/wasi-nn/rust/examples/classification-example/build* in the image of wasi-nn-example:v1.0.
131+
132+
### build iwasm and test
133+
134+
*TODO: May need alternative steps to build the iwasm and test in the container of wasi-nn-example:v1.0*
135+
136+
``` bash
137+
$ pwd
138+
/workspaces/wasm-micro-runtime
139+
140+
$ docker run --rm -it -v $(pwd):/workspaces/wasm-micro-runtime wasi-nn-example:v1.0 /bin/bash
141+
```
142+
143+
> [!Caution]
144+
> The following steps are executed in the container of wasi-nn-example:v1.0.
145+
146+
``` bash
147+
$ cd /workspaces/wasm-micro-runtime/product-mini/platforms/linux
148+
$ cmake -S . -B build -DWAMR_BUILD_WASI_NN=1 -DWAMR_BUILD_WASI_EPHEMERAL_NN=1
149+
$ cmake --build build
150+
$ ./build/iwasm -v=5 --map-dir=/workspaces/wasi-nn/rust/examples/classification-example/build/::fixture /workspaces/wasi-nn/rust/examples/classification-example/build/wasi-nn-example.wasm
151+
```
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye
5+
6+
ARG DEBIAN_FRONTEND=noninteractive
7+
ENV TZ=Asian/Shanghai
8+
9+
# hadolint ignore=DL3009
10+
RUN apt-get update \
11+
&& apt-get upgrade -y
12+
13+
#
14+
# Rust targets
15+
RUN rustup target add wasm32-wasi wasm32-unknown-unknown
16+
17+
#
18+
# Openvino
19+
# Refer to
20+
# - https://docs.openvino.ai/2022.3/openvino_docs_install_guides_installing_openvino_from_archive_linux.html
21+
# - https://docs.openvino.ai/2023.3/openvino_docs_install_guides_installing_openvino_from_archive_linux.html
22+
# - https://docs.openvino.ai/2024/get-started/install-openvino/install-openvino-archive-linux.html
23+
#
24+
# FIXME: upgrade to 2024.1 or latest after wasi-nn(rust binding) is ready
25+
WORKDIR /opt/intel
26+
RUN wget -q https://storage.openvinotoolkit.org/repositories/openvino/packages/2022.3.2/linux/l_openvino_toolkit_ubuntu20_2022.3.2.9279.e2c7e4d7b4d_x86_64.tgz
27+
RUN tar -xf l_openvino_toolkit_ubuntu20_2022.3.2.9279.e2c7e4d7b4d_x86_64.tgz \
28+
&& rm l_openvino_toolkit_ubuntu20_2022.3.2.9279.e2c7e4d7b4d_x86_64.tgz \
29+
&& mv l_openvino_toolkit_ubuntu20_2022.3.2.9279.e2c7e4d7b4d_x86_64 /opt/intel/openvino
30+
31+
WORKDIR /opt/intel/openvino
32+
RUN ./install_dependencies/install_openvino_dependencies.sh -y \
33+
&& ./setupvars.sh
34+
35+
#
36+
# wasmtime
37+
WORKDIR /opt
38+
RUN wget -q https://github.com/bytecodealliance/wasmtime/releases/download/v21.0.0/wasmtime-v21.0.0-x86_64-linux.tar.xz
39+
RUN tar -xf wasmtime-v21.0.0-x86_64-linux.tar.xz \
40+
&& rm wasmtime-v21.0.0-x86_64-linux.tar.xz \
41+
&& ln -sf "$(realpath ./wasmtime-v21.0.0-x86_64-linux/wasmtime)" /usr/local/bin/wasmtime
42+
43+
#
44+
# wasi-nn
45+
WORKDIR /workspaces/wasi-nn
46+
RUN git clone --depth 1 https://github.com/bytecodealliance/wasi-nn.git .
47+
# hadolint ignore=DL3059
48+
RUN ./build.sh rust
49+
50+
# There are model files(mobilenet*) and wasm files(wasi-nn-example.wasm) in the directory,
51+
# /workspaces/wasi-nn/rust/examples/classification-example/build
52+
53+
RUN apt-get autoremove -y \
54+
&& apt-get clean -y \
55+
&& rm -rf /tmp/*
56+
57+
WORKDIR /workspaces

0 commit comments

Comments
 (0)