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