From 53cee5a3fea0f60ed6fc0341cb042cbf6d5ce4d1 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 23 Aug 2023 15:12:15 -0700 Subject: [PATCH 1/8] wasi-nn: rename example directories This also slightly improves the READMEs. --- .../classification-example-named/README.md | 2 -- .../examples/classification-example/README.md | 2 -- .../Cargo.lock | 14 +++++++------- .../Cargo.toml | 2 +- .../examples/image-classification-named/README.md | 2 ++ .../src/main.rs | 0 .../Cargo.lock | 14 +++++++------- .../Cargo.toml | 2 +- .../examples/image-classification/README.md | 3 +++ .../src/main.rs | 0 10 files changed, 21 insertions(+), 20 deletions(-) delete mode 100644 crates/wasi-nn/examples/classification-example-named/README.md delete mode 100644 crates/wasi-nn/examples/classification-example/README.md rename crates/wasi-nn/examples/{classification-example-named => image-classification-named}/Cargo.lock (98%) rename crates/wasi-nn/examples/{classification-example-named => image-classification-named}/Cargo.toml (90%) create mode 100644 crates/wasi-nn/examples/image-classification-named/README.md rename crates/wasi-nn/examples/{classification-example-named => image-classification-named}/src/main.rs (100%) rename crates/wasi-nn/examples/{classification-example => image-classification}/Cargo.lock (92%) rename crates/wasi-nn/examples/{classification-example => image-classification}/Cargo.toml (92%) create mode 100644 crates/wasi-nn/examples/image-classification/README.md rename crates/wasi-nn/examples/{classification-example => image-classification}/src/main.rs (100%) diff --git a/crates/wasi-nn/examples/classification-example-named/README.md b/crates/wasi-nn/examples/classification-example-named/README.md deleted file mode 100644 index aa56ad0cbaf7..000000000000 --- a/crates/wasi-nn/examples/classification-example-named/README.md +++ /dev/null @@ -1,2 +0,0 @@ -This example project demonstrates using the `wasi-nn` API to perform ML inference. It consists of Rust code that is -built using the `wasm32-wasi` target. See `ci/run-wasi-nn-example.sh` for how this is used. diff --git a/crates/wasi-nn/examples/classification-example/README.md b/crates/wasi-nn/examples/classification-example/README.md deleted file mode 100644 index aa56ad0cbaf7..000000000000 --- a/crates/wasi-nn/examples/classification-example/README.md +++ /dev/null @@ -1,2 +0,0 @@ -This example project demonstrates using the `wasi-nn` API to perform ML inference. It consists of Rust code that is -built using the `wasm32-wasi` target. See `ci/run-wasi-nn-example.sh` for how this is used. diff --git a/crates/wasi-nn/examples/classification-example-named/Cargo.lock b/crates/wasi-nn/examples/image-classification-named/Cargo.lock similarity index 98% rename from crates/wasi-nn/examples/classification-example-named/Cargo.lock rename to crates/wasi-nn/examples/image-classification-named/Cargo.lock index 6a1c9eb0f62f..55e7015b4c7a 100644 --- a/crates/wasi-nn/examples/classification-example-named/Cargo.lock +++ b/crates/wasi-nn/examples/image-classification-named/Cargo.lock @@ -2,6 +2,13 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "image-classification-named" +version = "0.0.0" +dependencies = [ + "wasi-nn", +] + [[package]] name = "proc-macro2" version = "1.0.66" @@ -65,10 +72,3 @@ checksum = "03d01b90f0cca3f19682e90e1bc3f5e3e441031e19e56ce7dbf034f3b3597552" dependencies = [ "thiserror", ] - -[[package]] -name = "wasi-nn-example-named" -version = "0.0.0" -dependencies = [ - "wasi-nn", -] diff --git a/crates/wasi-nn/examples/classification-example-named/Cargo.toml b/crates/wasi-nn/examples/image-classification-named/Cargo.toml similarity index 90% rename from crates/wasi-nn/examples/classification-example-named/Cargo.toml rename to crates/wasi-nn/examples/image-classification-named/Cargo.toml index b4653659bd3d..85e44e0e4ed5 100644 --- a/crates/wasi-nn/examples/classification-example-named/Cargo.toml +++ b/crates/wasi-nn/examples/image-classification-named/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wasi-nn-example-named" +name = "image-classification-named" version = "0.0.0" authors = ["The Wasmtime Project Developers"] readme = "README.md" diff --git a/crates/wasi-nn/examples/image-classification-named/README.md b/crates/wasi-nn/examples/image-classification-named/README.md new file mode 100644 index 000000000000..623f99d7b15a --- /dev/null +++ b/crates/wasi-nn/examples/image-classification-named/README.md @@ -0,0 +1,2 @@ +This example project is similar to +[`image-classification`](../image-classification/) but uses named models. diff --git a/crates/wasi-nn/examples/classification-example-named/src/main.rs b/crates/wasi-nn/examples/image-classification-named/src/main.rs similarity index 100% rename from crates/wasi-nn/examples/classification-example-named/src/main.rs rename to crates/wasi-nn/examples/image-classification-named/src/main.rs diff --git a/crates/wasi-nn/examples/classification-example/Cargo.lock b/crates/wasi-nn/examples/image-classification/Cargo.lock similarity index 92% rename from crates/wasi-nn/examples/classification-example/Cargo.lock rename to crates/wasi-nn/examples/image-classification/Cargo.lock index a649a0429289..fcc72d489e28 100644 --- a/crates/wasi-nn/examples/classification-example/Cargo.lock +++ b/crates/wasi-nn/examples/image-classification/Cargo.lock @@ -3,14 +3,14 @@ version = 3 [[package]] -name = "wasi-nn" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c909acded993dc129e02f64a7646eb7b53079f522a814024a88772f41558996" - -[[package]] -name = "wasi-nn-example" +name = "image-classification" version = "0.0.0" dependencies = [ "wasi-nn", ] + +[[package]] +name = "wasi-nn" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c909acded993dc129e02f64a7646eb7b53079f522a814024a88772f41558996" diff --git a/crates/wasi-nn/examples/classification-example/Cargo.toml b/crates/wasi-nn/examples/image-classification/Cargo.toml similarity index 92% rename from crates/wasi-nn/examples/classification-example/Cargo.toml rename to crates/wasi-nn/examples/image-classification/Cargo.toml index 7cedd6252c43..917a9ed27376 100644 --- a/crates/wasi-nn/examples/classification-example/Cargo.toml +++ b/crates/wasi-nn/examples/image-classification/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wasi-nn-example" +name = "image-classification" version = "0.0.0" authors = ["The Wasmtime Project Developers"] readme = "README.md" diff --git a/crates/wasi-nn/examples/image-classification/README.md b/crates/wasi-nn/examples/image-classification/README.md new file mode 100644 index 000000000000..9d00ca1b9a1d --- /dev/null +++ b/crates/wasi-nn/examples/image-classification/README.md @@ -0,0 +1,3 @@ +This example project demonstrates using the `wasi-nn` API to perform ML +inference. It consists of Rust code that is built using the `wasm32-wasi` +target. It is used by `wasi-nn`'s tests. diff --git a/crates/wasi-nn/examples/classification-example/src/main.rs b/crates/wasi-nn/examples/image-classification/src/main.rs similarity index 100% rename from crates/wasi-nn/examples/classification-example/src/main.rs rename to crates/wasi-nn/examples/image-classification/src/main.rs From 2420a06eee95b4a72feb987a1c4b49bb77fb024e Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 23 Aug 2023 15:19:22 -0700 Subject: [PATCH 2/8] wasi-nn: add the `test_check` module This testing-only module has code (i.e., `test_check!`) to check whether OpenVINO and some test artifacts are available. The test artifacts are downloaded and cached if not present, which brings in the rather large `reqwest` dependency tree. To avoid this in regular use, the entire `test_check` module is hidden behind a `test-check` feature which is defaulted to on (so developers can run the tests) but turned off when used as a Wasmtime dependency. --- Cargo.lock | 336 ++++++++++++++++++++++++++++++++++++-- Cargo.toml | 2 +- crates/wasi-nn/Cargo.toml | 20 ++- crates/wasi-nn/src/lib.rs | 116 +++++++++++++ 4 files changed, 460 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7de50af65fd8..0a5922c8724d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -543,6 +543,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + [[package]] name = "cpp_demangle" version = "0.3.5" @@ -1159,6 +1175,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -1244,10 +1275,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" dependencies = [ "futures-core", + "futures-io", "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -1310,6 +1344,25 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "h2" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.11", + "indexmap 2.0.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "h2" version = "0.4.0" @@ -1321,7 +1374,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 1.0.0", "indexmap 2.0.0", "slab", "tokio", @@ -1383,6 +1436,17 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "856b5cb0902c2b6d65d5fd97dfa30f9b70c7538e770b98eab5ed52d8db923e01" +[[package]] +name = "http" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http" version = "1.0.0" @@ -1394,6 +1458,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http 0.2.11", + "pin-project-lite", +] + [[package]] name = "http-body" version = "1.0.0" @@ -1401,7 +1476,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", - "http", + "http 1.0.0", ] [[package]] @@ -1412,8 +1487,8 @@ checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" dependencies = [ "bytes", "futures-util", - "http", - "http-body", + "http 1.0.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -1444,6 +1519,30 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "hyper" +version = "0.14.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.22", + "http 0.2.11", + "http-body 0.4.5", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + [[package]] name = "hyper" version = "1.0.1" @@ -1453,9 +1552,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", - "http", - "http-body", + "h2 0.4.0", + "http 1.0.0", + "http-body 1.0.0", "httparse", "httpdate", "itoa", @@ -1464,6 +1563,19 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper 0.14.27", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "id-arena" version = "2.2.1" @@ -1761,6 +1873,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -1781,6 +1899,24 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1869,6 +2005,50 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +[[package]] +name = "openssl" +version = "0.10.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "729b745ad4a5575dd06a3e1af1414bd330ee561c01b3899eb584baeaa8def17e" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "openvino" version = "0.5.0" @@ -1932,6 +2112,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" + [[package]] name = "plotters" version = "0.3.1" @@ -2205,6 +2391,43 @@ dependencies = [ "winapi", ] +[[package]] +name = "reqwest" +version = "0.11.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.3.22", + "http 0.2.11", + "http-body 0.4.5", + "hyper 0.14.27", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "ring" version = "0.16.20" @@ -2296,6 +2519,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +dependencies = [ + "windows-sys", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -2312,6 +2544,29 @@ dependencies = [ "untrusted", ] +[[package]] +name = "security-framework" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.17" @@ -2352,6 +2607,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "sha2" version = "0.10.2" @@ -2697,6 +2964,16 @@ dependencies = [ "syn 2.0.32", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.24.0" @@ -2730,6 +3007,12 @@ dependencies = [ "serde", ] +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" version = "0.1.37" @@ -2893,6 +3176,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "verify-component-adapter" version = "17.0.0" @@ -3042,6 +3331,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.87" @@ -3325,10 +3626,10 @@ dependencies = [ "criterion", "env_logger 0.10.0", "filecheck", - "http", + "http 1.0.0", "http-body-util", "humantime 2.1.0", - "hyper", + "hyper 1.0.1", "libc", "listenfd", "log", @@ -3698,10 +3999,10 @@ dependencies = [ "base64", "bytes", "futures", - "http", - "http-body", + "http 1.0.0", + "http-body 1.0.0", "http-body-util", - "hyper", + "hyper 1.0.1", "rustls", "sha2", "test-log", @@ -3721,10 +4022,12 @@ version = "17.0.0" dependencies = [ "anyhow", "openvino", + "reqwest", "thiserror", "tracing", "walkdir", "wasmtime", + "wasmtime-wasi", "wiggle", ] @@ -4051,6 +4354,15 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + [[package]] name = "winx" version = "0.36.1" diff --git a/Cargo.toml b/Cargo.toml index d89162d30eba..f57e079b2ca5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -167,7 +167,7 @@ wasmtime-runtime = { path = "crates/runtime", version = "=17.0.0" } wasmtime-wast = { path = "crates/wast", version = "=17.0.0" } wasmtime-wasi = { path = "crates/wasi", version = "17.0.0", default-features = false } wasmtime-wasi-http = { path = "crates/wasi-http", version = "=17.0.0", default-features = false } -wasmtime-wasi-nn = { path = "crates/wasi-nn", version = "17.0.0" } +wasmtime-wasi-nn = { path = "crates/wasi-nn", version = "17.0.0", default-features = false } wasmtime-wasi-threads = { path = "crates/wasi-threads", version = "17.0.0" } wasmtime-component-util = { path = "crates/component-util", version = "=17.0.0" } wasmtime-component-macro = { path = "crates/component-macro", version = "=17.0.0" } diff --git a/crates/wasi-nn/Cargo.toml b/crates/wasi-nn/Cargo.toml index 9b42aa00fb1a..c2884624093c 100644 --- a/crates/wasi-nn/Cargo.toml +++ b/crates/wasi-nn/Cargo.toml @@ -20,12 +20,30 @@ anyhow = { workspace = true } wiggle = { workspace = true } # This dependency is necessary for the WIT-generation macros to work: -wasmtime = { workspace = true, features = ["component-model"] } +wasmtime = { workspace = true, features = ["component-model", "cranelift"] } # These dependencies are necessary for the wasi-nn implementation: tracing = { workspace = true } openvino = { version = "0.5.0", features = ["runtime-linking"] } thiserror = { workspace = true } +# These dependencies are only for the `test-check` feature. They would be better +# as `dev-dependencies` but then would not be available to integration tests: +reqwest = { version = "0.11", features = ["blocking"], optional = true } + [build-dependencies] walkdir = { workspace = true } + +[dev-dependencies] +wasmtime-wasi = { workspace = true } + +[features] +# When turned on, checks that the system has all the necessary ML frameworks and +# artifacts to run this crate's tests. If these are not available, the tests +# will be skipped; set `FORCE_WASINN_TEST_CHECK=1` or `CI=true` to fail if the +# checks fail. +test-check = ["dep:reqwest"] +# We'll enable the `test-check` feature by default so `cargo test` will "just +# work"; this means we need to carefully turn off `default-features` at the use +# sites to avoid unwanted dependencies. +default = ["test-check"] diff --git a/crates/wasi-nn/src/lib.rs b/crates/wasi-nn/src/lib.rs index 71d089d07489..f6ced2b7ea25 100644 --- a/crates/wasi-nn/src/lib.rs +++ b/crates/wasi-nn/src/lib.rs @@ -83,3 +83,119 @@ where Self(Box::new(value)) } } + +/// For testing, this module checks: +/// - that OpenVINO can be found in the environment +/// - that some ML model artifacts can be downloaded and cached. +#[cfg(feature = "test-check")] +pub mod test_check { + use anyhow::{anyhow, Context, Result}; + use std::{env, fs, fs::File, path::Path, path::PathBuf, process::Command}; + + /// Return the directory in which the test artifacts are stored. + pub fn artifacts_dir() -> PathBuf { + PathBuf::from(env!("OUT_DIR")).join("mobilenet") + } + + /// Early-return from a test if the test environment is not met. If the `CI` + /// or `FORCE_WASINN_TEST_CHECK` environment variables are set, though, this + /// will return an error instead. + #[macro_export] + macro_rules! test_check { + () => { + if let Err(e) = $crate::test_check::check() { + if std::env::var_os("CI").is_some() + || std::env::var_os("FORCE_WASINN_TEST_CHECK").is_some() + { + return Err(e); + } else { + println!("> ignoring test: {}", e); + return Ok(()); + } + } + }; + } + + /// Return `Ok` if all checks pass. + pub fn check() -> Result<()> { + check_openvino_is_installed()?; + check_openvino_artifacts_are_available()?; + Ok(()) + } + + /// Return `Ok` if we find a working OpenVINO installation. + fn check_openvino_is_installed() -> Result<()> { + match std::panic::catch_unwind(|| { + println!("> found openvino version: {}", openvino::version()) + }) { + Ok(_) => Ok(()), + Err(e) => Err(anyhow!("unable to find an OpenVINO installation: {:?}", e)), + } + } + + /// Return `Ok` if we find the cached MobileNet test artifacts; this will + /// download the artifacts if necessary. + fn check_openvino_artifacts_are_available() -> Result<()> { + const BASE_URL: &str = "https://github.com/intel/openvino-rs/raw/main/crates/openvino/tests/fixtures/mobilenet"; + let artifacts_dir = artifacts_dir(); + if !artifacts_dir.is_dir() { + fs::create_dir(&artifacts_dir)?; + } + for (from, to) in [ + ("mobilenet.bin", "model.bin"), + ("mobilenet.xml", "model.xml"), + ("tensor-1x224x224x3-f32.bgr", "tensor.bgr"), + ] { + let remote_url = [BASE_URL, from].join("/"); + let local_path = artifacts_dir.join(to); + if !local_path.is_file() { + download(&remote_url, &local_path) + .with_context(|| "unable to retrieve test artifact")?; + } else { + println!("> using cached artifact: {}", local_path.display()) + } + } + Ok(()) + } + + /// Retrieve the bytes at the `from` URL and place them in the `to` file. + fn download(from: &str, to: &Path) -> anyhow::Result<()> { + println!("> downloading:\n {} ->\n {}", from, to.display()); + let mut file = File::create(to)?; + let _ = reqwest::blocking::get(from)?.copy_to(&mut file)?; + Ok(()) + } + + /// Build the given crate as `wasm32-wasi` and return the path to the built + /// module. + pub fn cargo_build(crate_dir: impl AsRef) -> PathBuf { + let crate_dir = crate_dir.as_ref(); + let crate_name = crate_dir.file_name().unwrap().to_str().unwrap(); + let cargo_toml = crate_dir.join("Cargo.toml"); + let wasm = crate_dir.join(format!("target/wasm32-wasi/release/{}.wasm", crate_name)); + let result = Command::new("cargo") + .arg("build") + .arg("--release") + .arg("--target=wasm32-wasi") + .arg("--manifest-path") + .arg(cargo_toml) + .output() + .unwrap(); + if !wasm.is_file() { + panic!("no file found at: {}", wasm.display()); + } + if !result.status.success() { + panic!( + "cargo build failed: {}\n{}", + result.status, + String::from_utf8_lossy(&result.stderr) + ); + } + wasm + } +} + +#[cfg(all(test, not(feature = "test-check")))] +compile_error!( + "to run wasi-nn tests we need to enable a feature: `cargo test --features test-check`" +); From ec7e7653f0a8a34a2e1fb3d31f6a84a9e87011a8 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 23 Aug 2023 15:23:08 -0700 Subject: [PATCH 3/8] wasi-nn: add an internal OpenVINO test This checks that the internal backend APIs can be used directly to load the MobileNet model and perform an image classification from a test artifact. --- crates/wasi-nn/src/backend/openvino.rs | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/crates/wasi-nn/src/backend/openvino.rs b/crates/wasi-nn/src/backend/openvino.rs index be9c0250dbb7..f8eaeb5c93c2 100644 --- a/crates/wasi-nn/src/backend/openvino.rs +++ b/crates/wasi-nn/src/backend/openvino.rs @@ -178,3 +178,56 @@ fn read(path: &Path) -> anyhow::Result> { file.read_to_end(&mut buffer)?; Ok(buffer) } + +#[cfg(test)] +mod tests { + use super::*; + use anyhow::Result; + use std::{mem, slice}; + + #[test] + fn image_classification_directly_on_backend() -> Result<()> { + crate::test_check!(); + + // Compute a MobileNet classification using the test artifacts. + let mut backend = OpenvinoBackend::default(); + let graph = backend.load_from_dir( + crate::test_check::artifacts_dir().as_path(), + ExecutionTarget::Cpu, + )?; + let mut context = graph.init_execution_context()?; + let data = read( + crate::test_check::artifacts_dir() + .join("tensor.bgr") + .as_path(), + )?; + let tensor = Tensor { + dimensions: vec![1, 3, 224, 224], + tensor_type: TensorType::Fp32, + data, + }; + context.set_input(0, &tensor)?; + context.compute()?; + let mut destination = vec![0f32; 1001]; + let destination_ = unsafe { + slice::from_raw_parts_mut( + destination.as_mut_ptr().cast(), + destination.len() * mem::size_of::(), + ) + }; + context.get_output(0, destination_)?; + + // Find the top score which should be the entry for "pizza" (see + // https://github.com/leferrad/tensorflow-mobilenet/blob/master/imagenet/labels.txt, + // e.g.) + let (id, score) = destination + .iter() + .enumerate() + .max_by(|a, b| a.1.partial_cmp(&b.1).unwrap()) + .unwrap(); + println!("> top match: label #{} = {}", id, score); + assert_eq!(id, 964); + + Ok(()) + } +} From d9931543a29f0aa4a10e048a578b13020819f8c8 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 23 Aug 2023 15:24:53 -0700 Subject: [PATCH 4/8] wasi-nn: add an E2E test checking a wasi-nn embedding This performs the same inference as before, but tests that all of the wasi-nn embedding APIs work as expected. It relies on compiling the test programs in the `examples` directory. --- crates/wasi-nn/src/ctx.rs | 6 +++ crates/wasi-nn/tests/e2e.rs | 79 +++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 crates/wasi-nn/tests/e2e.rs diff --git a/crates/wasi-nn/src/ctx.rs b/crates/wasi-nn/src/ctx.rs index 40cfb9d53d2d..0863bf9a7ede 100644 --- a/crates/wasi-nn/src/ctx.rs +++ b/crates/wasi-nn/src/ctx.rs @@ -56,6 +56,12 @@ impl WasiNnCtx { } } +impl Default for WasiNnCtx { + fn default() -> Self { + Self::new(backend::list(), Registry::from(InMemoryRegistry::new())) + } +} + /// Possible errors while interacting with [WasiNnCtx]. #[derive(Debug, Error)] pub enum WasiNnError { diff --git a/crates/wasi-nn/tests/e2e.rs b/crates/wasi-nn/tests/e2e.rs new file mode 100644 index 000000000000..755625adb6f2 --- /dev/null +++ b/crates/wasi-nn/tests/e2e.rs @@ -0,0 +1,79 @@ +//! Embed wasi-nn in Wasmtime and compute an inference by: +//! - downloading any necessary model artifacts (`test_check!`) +//! - setting up a wasi + wasi-nn environment +//! - build an `example` crate into a `*.wasm` file +//! - run the `*.wasm` file. + +use anyhow::Result; +use wasmtime::{Engine, Linker, Module, Store}; +use wasmtime_wasi::{ambient_authority, Dir, WasiCtx, WasiCtxBuilder}; +use wasmtime_wasi_nn::{backend, InMemoryRegistry, WasiNnCtx}; + +#[test] +fn image_classification() -> Result<()> { + wasmtime_wasi_nn::test_check!(); + + // Set up a WASI environment that includes wasi-nn and opens the MobileNet + // artifacts directory as `fixture` in the guest. + let engine = Engine::default(); + let (mut store, mut linker) = embed_wasi_nn(&engine, WasiNnCtx::default())?; + + // Build and run the example crate. + let wasm_file = wasmtime_wasi_nn::test_check::cargo_build("examples/image-classification"); + let module = Module::from_file(&engine, wasm_file)?; + linker.module(&mut store, "", &module)?; + linker + .get_default(&mut store, "")? + .typed::<(), ()>(&store)? + .call(&mut store, ())?; + + Ok(()) +} + +#[test] +fn image_classification_with_names() -> Result<()> { + wasmtime_wasi_nn::test_check!(); + + // Set up a WASI environment that includes wasi-nn and uses a registry with + // the "mobilenet" name populated. + let engine = Engine::default(); + let mut openvino = backend::openvino::OpenvinoBackend::default(); + let mut registry = InMemoryRegistry::new(); + let mobilenet_dir = wasmtime_wasi_nn::test_check::artifacts_dir(); + registry.load(&mut openvino, &mobilenet_dir)?; + let wasi_nn = WasiNnCtx::new([openvino.into()], registry.into()); + let (mut store, mut linker) = embed_wasi_nn(&engine, wasi_nn)?; + + // Build and run the example crate. + let wasm_file = + wasmtime_wasi_nn::test_check::cargo_build("examples/image-classification-named"); + let module = Module::from_file(&engine, wasm_file)?; + linker.module(&mut store, "", &module)?; + linker + .get_default(&mut store, "")? + .typed::<(), ()>(&store)? + .call(&mut store, ())?; + + Ok(()) +} + +struct Host { + wasi: WasiCtx, + wasi_nn: WasiNnCtx, +} + +fn embed_wasi_nn(engine: &Engine, wasi_nn: WasiNnCtx) -> Result<(Store, Linker)> { + let mut linker = Linker::new(&engine); + let host_dir = Dir::open_ambient_dir( + wasmtime_wasi_nn::test_check::artifacts_dir(), + ambient_authority(), + )?; + let wasi = WasiCtxBuilder::new() + .inherit_stdio() + .preopened_dir(host_dir, "fixture")? + .build(); + let store = Store::::new(&engine, Host { wasi, wasi_nn }); + wasmtime_wasi_nn::witx::add_to_linker(&mut linker, |s: &mut Host| &mut s.wasi_nn)?; + wasmtime_wasi::add_to_linker(&mut linker, |s: &mut Host| &mut s.wasi)?; + Ok((store, linker)) +} From 7879e24d83194e8b5b597de1d9d06bb1db54f008 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 23 Aug 2023 15:28:13 -0700 Subject: [PATCH 5/8] wasi-nn: add CLI tests These tests are Rust versions of what `ci/run-wasi-nn-example.sh` executed. Now that all of the test-checking (ML backend? artifacts?) can be done via Rust, the Bash script is no longer needed; this change removes it. This change also switches over CI to run all of the new wasi-nn tests by modifying the `main.yml` workflow and the `ci/run-tests.sh` script. --- .github/workflows/main.yml | 32 +++++--------------------------- ci/run-tests.sh | 1 + tests/all/cli_tests.rs | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b4cb5cfd7d80..0d8810d84543 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -422,6 +422,11 @@ jobs: - run: echo CARGO_BUILD_TARGET=${{ matrix.target }} >> $GITHUB_ENV if: matrix.target != '' + # Install OpenVINO for testing wasmtime-wasi-nn. + - uses: abrown/install-openvino-action@v6 + with: + version: 2022.3.0 + # Fix an ICE for now in gcc when compiling zstd with debuginfo (??) - run: echo CFLAGS=-g0 >> $GITHUB_ENV if: matrix.target == 'x86_64-pc-windows-gnu' @@ -522,32 +527,6 @@ jobs: # Windows fails GitHub Actions will confusingly mark the failed Windows job # as cancelled instead of failed. - # Build and test the wasi-nn module. - test_wasi_nn: - needs: determine - if: needs.determine.outputs.run-full - name: Test wasi-nn module - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - uses: ./.github/actions/install-rust - - run: rustup target add wasm32-wasi - - uses: abrown/install-openvino-action@v7 - with: - version: 2022.3.0 - apt: true - - run: ./ci/run-wasi-nn-example.sh - env: - RUST_BACKTRACE: 1 - - # common logic to cancel the entire run if this job fails - - run: gh run cancel ${{ github.run_id }} - if: failure() && github.event_name != 'pull_request' - env: - GH_TOKEN: ${{ github.token }} - build-preview1-component-adapter: name: Build wasi-preview1-component-adapter needs: determine @@ -775,7 +754,6 @@ jobs: - checks - checks_winarm64 - fuzz_targets - - test_wasi_nn - bench - meta_deterministic_check - verify-publish diff --git a/ci/run-tests.sh b/ci/run-tests.sh index db338dc2409e..738332b736ad 100755 --- a/ci/run-tests.sh +++ b/ci/run-tests.sh @@ -5,6 +5,7 @@ cargo test \ --features wasi-http \ --features component-model \ --features serve \ + --features wasmtime-wasi-nn/test-check \ --workspace \ --exclude test-programs \ $@ diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs index 03783844b7b3..d7cda6716e6a 100644 --- a/tests/all/cli_tests.rs +++ b/tests/all/cli_tests.rs @@ -609,6 +609,44 @@ fn run_simple_with_wasi_threads() -> Result<()> { Ok(()) } +#[cfg(feature = "wasi-nn")] +#[test] +fn image_classification_with_wasi_nn() -> Result<()> { + wasmtime_wasi_nn::test_check!(); + let wasm = + wasmtime_wasi_nn::test_check::cargo_build("crates/wasi-nn/examples/image-classification"); + let artifacts_dir = wasmtime_wasi_nn::test_check::artifacts_dir(); + let artifacts_dir = artifacts_dir.display(); + let stdout = run_wasmtime(&[ + "run", + "--wasi-modules=experimental-wasi-nn", + &format!("--mapdir=fixture::{artifacts_dir}"), + &format!("{}", wasm.display()), + ])?; + assert!(stdout.contains("InferenceResult(963")); + Ok(()) +} + +#[cfg(feature = "wasi-nn")] +#[test] +fn image_classification_with_wasi_nn_and_named_models() -> Result<()> { + wasmtime_wasi_nn::test_check!(); + let wasm = wasmtime_wasi_nn::test_check::cargo_build( + "crates/wasi-nn/examples/image-classification-named", + ); + let artifacts_dir = wasmtime_wasi_nn::test_check::artifacts_dir(); + let artifacts_dir = artifacts_dir.display(); + let stdout = run_wasmtime(&[ + "run", + "--wasi-modules=experimental-wasi-nn", + &format!("--mapdir=fixture::{artifacts_dir}"), + &format!("--wasi-nn-graph=openvino::{artifacts_dir}"), + &format!("{}", wasm.display()), + ])?; + assert!(stdout.contains("InferenceResult(963")); + Ok(()) +} + #[test] fn wasm_flags() -> Result<()> { // Any argument after the wasm module should be interpreted as for the From 8c3323f361936a8ba2564f7eafc8d67fa16604dd Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 25 Aug 2023 17:56:05 -0700 Subject: [PATCH 6/8] review: replace `reqwest` dependency with `curl` As suggested by @alexcrichton, we assume that `curl` is present on the host system to avoid bringing the `reqwest` crate and its entire dependency tree. This assumption seems a safe one, especially on CI, where these tests will mainly run. --- Cargo.lock | 335 ++------------------------------------ crates/wasi-nn/Cargo.toml | 6 +- crates/wasi-nn/src/lib.rs | 16 +- 3 files changed, 25 insertions(+), 332 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a5922c8724d..57ff5398e8da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -543,22 +543,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" - [[package]] name = "cpp_demangle" version = "0.3.5" @@ -1175,21 +1159,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.1.0" @@ -1275,13 +1244,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" dependencies = [ "futures-core", - "futures-io", "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -1344,25 +1310,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -[[package]] -name = "h2" -version = "0.3.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 0.2.11", - "indexmap 2.0.0", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "h2" version = "0.4.0" @@ -1374,7 +1321,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http 1.0.0", + "http", "indexmap 2.0.0", "slab", "tokio", @@ -1436,17 +1383,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "856b5cb0902c2b6d65d5fd97dfa30f9b70c7538e770b98eab5ed52d8db923e01" -[[package]] -name = "http" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - [[package]] name = "http" version = "1.0.0" @@ -1458,17 +1394,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" -dependencies = [ - "bytes", - "http 0.2.11", - "pin-project-lite", -] - [[package]] name = "http-body" version = "1.0.0" @@ -1476,7 +1401,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", - "http 1.0.0", + "http", ] [[package]] @@ -1487,8 +1412,8 @@ checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" dependencies = [ "bytes", "futures-util", - "http 1.0.0", - "http-body 1.0.0", + "http", + "http-body", "pin-project-lite", ] @@ -1519,30 +1444,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "hyper" -version = "0.14.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2 0.3.22", - "http 0.2.11", - "http-body 0.4.5", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "hyper" version = "1.0.1" @@ -1552,9 +1453,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2 0.4.0", - "http 1.0.0", - "http-body 1.0.0", + "h2", + "http", + "http-body", "httparse", "httpdate", "itoa", @@ -1563,19 +1464,6 @@ dependencies = [ "want", ] -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper 0.14.27", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "id-arena" version = "2.2.1" @@ -1873,12 +1761,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - [[package]] name = "miniz_oxide" version = "0.7.1" @@ -1899,24 +1781,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -2005,50 +1869,6 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" -[[package]] -name = "openssl" -version = "0.10.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729b745ad4a5575dd06a3e1af1414bd330ee561c01b3899eb584baeaa8def17e" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.32", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "openvino" version = "0.5.0" @@ -2112,12 +1932,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" - [[package]] name = "plotters" version = "0.3.1" @@ -2391,43 +2205,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "reqwest" -version = "0.11.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" -dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2 0.3.22", - "http 0.2.11", - "http-body 0.4.5", - "hyper 0.14.27", - "hyper-tls", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "ring" version = "0.16.20" @@ -2519,15 +2296,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" -dependencies = [ - "windows-sys", -] - [[package]] name = "scopeguard" version = "1.1.0" @@ -2544,29 +2312,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "security-framework" -version = "2.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "1.0.17" @@ -2607,18 +2352,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "sha2" version = "0.10.2" @@ -2964,16 +2697,6 @@ dependencies = [ "syn 2.0.32", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.24.0" @@ -3007,12 +2730,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - [[package]] name = "tracing" version = "0.1.37" @@ -3176,12 +2893,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "verify-component-adapter" version = "17.0.0" @@ -3331,18 +3042,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" version = "0.2.87" @@ -3626,10 +3325,10 @@ dependencies = [ "criterion", "env_logger 0.10.0", "filecheck", - "http 1.0.0", + "http", "http-body-util", "humantime 2.1.0", - "hyper 1.0.1", + "hyper", "libc", "listenfd", "log", @@ -3999,10 +3698,10 @@ dependencies = [ "base64", "bytes", "futures", - "http 1.0.0", - "http-body 1.0.0", + "http", + "http-body", "http-body-util", - "hyper 1.0.1", + "hyper", "rustls", "sha2", "test-log", @@ -4022,7 +3721,6 @@ version = "17.0.0" dependencies = [ "anyhow", "openvino", - "reqwest", "thiserror", "tracing", "walkdir", @@ -4354,15 +4052,6 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - [[package]] name = "winx" version = "0.36.1" diff --git a/crates/wasi-nn/Cargo.toml b/crates/wasi-nn/Cargo.toml index c2884624093c..3e04b56c4c6e 100644 --- a/crates/wasi-nn/Cargo.toml +++ b/crates/wasi-nn/Cargo.toml @@ -27,10 +27,6 @@ tracing = { workspace = true } openvino = { version = "0.5.0", features = ["runtime-linking"] } thiserror = { workspace = true } -# These dependencies are only for the `test-check` feature. They would be better -# as `dev-dependencies` but then would not be available to integration tests: -reqwest = { version = "0.11", features = ["blocking"], optional = true } - [build-dependencies] walkdir = { workspace = true } @@ -42,7 +38,7 @@ wasmtime-wasi = { workspace = true } # artifacts to run this crate's tests. If these are not available, the tests # will be skipped; set `FORCE_WASINN_TEST_CHECK=1` or `CI=true` to fail if the # checks fail. -test-check = ["dep:reqwest"] +test-check = [] # We'll enable the `test-check` feature by default so `cargo test` will "just # work"; this means we need to carefully turn off `default-features` at the use # sites to avoid unwanted dependencies. diff --git a/crates/wasi-nn/src/lib.rs b/crates/wasi-nn/src/lib.rs index f6ced2b7ea25..01b0a74a90cd 100644 --- a/crates/wasi-nn/src/lib.rs +++ b/crates/wasi-nn/src/lib.rs @@ -90,7 +90,7 @@ where #[cfg(feature = "test-check")] pub mod test_check { use anyhow::{anyhow, Context, Result}; - use std::{env, fs, fs::File, path::Path, path::PathBuf, process::Command}; + use std::{env, fs, path::Path, path::PathBuf, process::Command}; /// Return the directory in which the test artifacts are stored. pub fn artifacts_dir() -> PathBuf { @@ -160,9 +160,17 @@ pub mod test_check { /// Retrieve the bytes at the `from` URL and place them in the `to` file. fn download(from: &str, to: &Path) -> anyhow::Result<()> { - println!("> downloading:\n {} ->\n {}", from, to.display()); - let mut file = File::create(to)?; - let _ = reqwest::blocking::get(from)?.copy_to(&mut file)?; + let mut curl = Command::new("curl"); + curl.arg("--location").arg(from).arg("--output").arg(to); + println!("> downloading: {:?}", &curl); + let result = curl.output().unwrap(); + if !result.status.success() { + panic!( + "curl failed: {}\n{}", + result.status, + String::from_utf8_lossy(&result.stderr) + ); + } Ok(()) } From aa85952a6c353ce24546069c37d95122ed340a04 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 30 Aug 2023 10:29:36 -0700 Subject: [PATCH 7/8] fix: setup environment --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0d8810d84543..c28ee5b37882 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -426,6 +426,7 @@ jobs: - uses: abrown/install-openvino-action@v6 with: version: 2022.3.0 + - run: echo OPENVINO_BUILD_DIR="${{ env.OPENVINO_INSTALL_DIR }}" >> $GITHUB_ENV # Fix an ICE for now in gcc when compiling zstd with debuginfo (??) - run: echo CFLAGS=-g0 >> $GITHUB_ENV From e1eb40caec4f8243b3a672d0abbd4a49e8102451 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 5 Oct 2023 15:56:19 -0700 Subject: [PATCH 8/8] fix: update install-openvino-action --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c28ee5b37882..f1677b9cdb93 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -423,7 +423,7 @@ jobs: if: matrix.target != '' # Install OpenVINO for testing wasmtime-wasi-nn. - - uses: abrown/install-openvino-action@v6 + - uses: abrown/install-openvino-action@v7 with: version: 2022.3.0 - run: echo OPENVINO_BUILD_DIR="${{ env.OPENVINO_INSTALL_DIR }}" >> $GITHUB_ENV