webmachinelearning / webnn-native

🧠⚙️ Standalone native implementation of the Web Neural Network API
Apache License 2.0
52 stars 21 forks source link
Backend \ OS Windows Linux
null (for unit test) null backend
DirectMLX DirectMLX backend (Windows)
Node Binding (DirectMLX backend / Windows)
Memory leak check - DirectMLX backend (Windows)
OpenVINO OpenVINO backend (Windows)
Node Binding (OpenVINO backend / Windows)
OpenVINO backend (Linux)
Node Binding (OpenVINO backend / Linux)
XNNPACK XNNPACK backend (Windows) XNNPACK backend (Linux)
oneDNN oneDNN backend (Windows) oneDNN backend (Linux)
MLAS MLAS backend (Windows)

clang format

WebNN-native

WebNN-native is a native implementation of the Web Neural Network API.

It provides several building blocks:

WebNN-native uses the code of other open source projects:

Build and Run

Install depot_tools

WebNN-native uses the Chromium build system and dependency management so you need to install depot_tools and add it to the PATH.

Notes:

Get the code

Get the source code as follows:

# Clone the repo as "webnn-native"
> git clone https://github.com/webmachinelearning/webnn-native.git webnn-native && cd webnn-native

# Bootstrap the gclient configuration
> cp scripts/standalone.gclient .gclient

# Fetch external dependencies and toolchains with gclient
> gclient sync

Setting up the build

Generate build files using gn args out/Debug or gn args out/Release.

A text editor will appear asking build options, the most common option is is_debug=true/false; otherwise gn args out/Release --list shows all the possible options.

To build with a backend, please set the corresponding option from following table.

Backend Option
DirectML webnn_enable_dml=true
DirectMLX webnn_enable_dmlx=true
OpenVINO webnn_enable_openvino=true
XNNPACK webnn_enable_xnnpack=true
oneDNN webnn_enable_onednn=true
MLAS webnn_enable_mlas=true

Build

Then use ninja -C out/Release or ninja -C out/Debug to build WebNN-native.

Notes

Run tests

Run unit tests:

> ./out/Release/webnn_unittests

Run end2end tests on a default device:

> ./out/Release/webnn_end2end_tests

You can also specify a device to run end2end tests using "-d" option, for example:

> ./out/Release/webnn_end2end_tests -d gpu

Currently "cpu", "gpu" and "default" are supported, more devices are to be supported in the future.

Notes:

Run examples

License

Apache 2.0 Public License, please see LICENSE.