Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi-nn/tests/check/openvino.rs
1693 views
1
use super::{DOWNLOAD_LOCK, artifacts_dir, download};
2
use anyhow::{Context, Result, bail};
3
use std::fs;
4
5
/// Return `Ok` if we find a working OpenVINO installation.
6
pub fn is_installed() -> Result<()> {
7
match std::panic::catch_unwind(|| {
8
println!(
9
"> found openvino version: {}",
10
openvino::version().build_number
11
)
12
}) {
13
Ok(_) => Ok(()),
14
Err(e) => bail!(
15
"unable to find an OpenVINO installation: {:?}",
16
e.downcast_ref::<String>()
17
),
18
}
19
}
20
21
/// Return `Ok` if we find the cached MobileNet test artifacts; this will
22
/// download the artifacts if necessary.
23
pub fn are_artifacts_available() -> Result<()> {
24
let _exclusively_retrieve_artifacts = DOWNLOAD_LOCK.lock().unwrap();
25
const BASE_URL: &str = "https://download.01.org/openvinotoolkit/fixtures/mobilenet";
26
let artifacts_dir = artifacts_dir();
27
if !artifacts_dir.is_dir() {
28
fs::create_dir(&artifacts_dir)?;
29
}
30
for (from, to) in [
31
("mobilenet.bin", "model.bin"),
32
("mobilenet.xml", "model.xml"),
33
("tensor-1x224x224x3-f32.bgr", "tensor.bgr"),
34
] {
35
let remote_url = [BASE_URL, from].join("/");
36
let local_path = artifacts_dir.join(to);
37
if !local_path.is_file() {
38
download(&remote_url, &local_path)
39
.with_context(|| "unable to retrieve test artifact")?;
40
} else {
41
println!("> using cached artifact: {}", local_path.display())
42
}
43
}
44
Ok(())
45
}
46
47