2022-10-12 04:09:29 +00:00
|
|
|
# WASI-NN
|
|
|
|
|
|
|
|
## How to use
|
|
|
|
|
|
|
|
Enable WASI-NN in the WAMR by spefiying it in the cmake building configuration as follows,
|
|
|
|
|
|
|
|
```
|
|
|
|
set (WAMR_BUILD_WASI_NN 1)
|
|
|
|
```
|
|
|
|
|
|
|
|
The definition of the functions provided by WASI-NN is in the header file `core/iwasm/libraries/wasi-nn/wasi_nn.h`.
|
|
|
|
|
|
|
|
By only including this file in your WASM application you will bind WASI-NN into your module.
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
|
|
|
To run the tests we assume that the current directory is the root of the repository.
|
|
|
|
|
|
|
|
|
2023-02-02 00:09:46 +00:00
|
|
|
### Build the runtime
|
|
|
|
|
|
|
|
Build the runtime image for your execution target type.
|
|
|
|
|
|
|
|
`EXECUTION_TYPE` can be:
|
|
|
|
* `cpu`
|
|
|
|
* `nvidia-gpu`
|
2023-05-05 08:29:36 +00:00
|
|
|
* `vx-delegate`
|
2023-08-14 12:03:56 +00:00
|
|
|
* `tpu`
|
2022-10-12 04:09:29 +00:00
|
|
|
|
|
|
|
```
|
2023-02-02 00:09:46 +00:00
|
|
|
EXECUTION_TYPE=cpu
|
|
|
|
docker build -t wasi-nn-${EXECUTION_TYPE} -f core/iwasm/libraries/wasi-nn/test/Dockerfile.${EXECUTION_TYPE} .
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Build wasm app
|
|
|
|
|
2022-10-12 04:09:29 +00:00
|
|
|
```
|
2023-02-02 00:09:46 +00:00
|
|
|
docker build -t wasi-nn-compile -f core/iwasm/libraries/wasi-nn/test/Dockerfile.compile .
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
docker run -v $PWD/core/iwasm/libraries/wasi-nn:/wasi-nn wasi-nn-compile
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Run wasm app
|
2022-10-12 04:09:29 +00:00
|
|
|
|
|
|
|
If all the tests have run properly you will the the following message in the terminal,
|
|
|
|
|
|
|
|
```
|
|
|
|
Tests: passed!
|
|
|
|
```
|
|
|
|
|
2023-02-02 00:09:46 +00:00
|
|
|
* CPU
|
|
|
|
|
|
|
|
```
|
|
|
|
docker run \
|
2023-06-27 00:07:30 +00:00
|
|
|
-v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \
|
|
|
|
-v $PWD/core/iwasm/libraries/wasi-nn/test/models:/models \
|
|
|
|
wasi-nn-cpu \
|
|
|
|
--dir=/ \
|
2023-02-02 00:09:46 +00:00
|
|
|
--env="TARGET=cpu" \
|
|
|
|
/assets/test_tensorflow.wasm
|
|
|
|
```
|
|
|
|
|
|
|
|
* (NVIDIA) GPU
|
2023-08-14 12:03:56 +00:00
|
|
|
* Requirements:
|
|
|
|
* [NVIDIA docker](https://github.com/NVIDIA/nvidia-docker).
|
2023-02-02 00:09:46 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
docker run \
|
|
|
|
--runtime=nvidia \
|
2023-06-27 00:07:30 +00:00
|
|
|
-v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \
|
|
|
|
-v $PWD/core/iwasm/libraries/wasi-nn/test/models:/models \
|
|
|
|
wasi-nn-nvidia-gpu \
|
|
|
|
--dir=/ \
|
2023-02-02 00:09:46 +00:00
|
|
|
--env="TARGET=gpu" \
|
|
|
|
/assets/test_tensorflow.wasm
|
|
|
|
```
|
|
|
|
|
2023-08-14 12:03:56 +00:00
|
|
|
* vx-delegate for NPU (x86 simulator)
|
2023-05-05 08:29:36 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
docker run \
|
2023-08-14 12:03:56 +00:00
|
|
|
-v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \
|
|
|
|
wasi-nn-vx-delegate \
|
|
|
|
--dir=/ \
|
2023-05-05 08:29:36 +00:00
|
|
|
--env="TARGET=gpu" \
|
2023-08-14 12:03:56 +00:00
|
|
|
/assets/test_tensorflow_quantized.wasm
|
2023-05-05 08:29:36 +00:00
|
|
|
```
|
|
|
|
|
2023-08-14 12:03:56 +00:00
|
|
|
* (Coral) TPU
|
|
|
|
* Requirements:
|
|
|
|
* [Coral USB](https://coral.ai/products/accelerator/).
|
2023-05-05 08:29:36 +00:00
|
|
|
|
2023-08-14 12:03:56 +00:00
|
|
|
```
|
|
|
|
docker run \
|
|
|
|
--privileged \
|
|
|
|
--device=/dev/bus/usb:/dev/bus/usb \
|
|
|
|
-v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \
|
|
|
|
wasi-nn-tpu \
|
|
|
|
--dir=/ \
|
|
|
|
--env="TARGET=tpu" \
|
|
|
|
/assets/test_tensorflow_quantized.wasm
|
|
|
|
```
|
2023-02-02 00:09:46 +00:00
|
|
|
|
2022-10-12 04:09:29 +00:00
|
|
|
## What is missing
|
|
|
|
|
2023-01-25 10:32:40 +00:00
|
|
|
Supported:
|
|
|
|
|
|
|
|
* Graph encoding: `tensorflowlite`.
|
2023-08-14 12:03:56 +00:00
|
|
|
* Execution target: `cpu`, `gpu` and `tpu`.
|
2023-01-25 10:32:40 +00:00
|
|
|
* Tensor type: `fp32`.
|