Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integrations tests openvino 0.7.2 #9

Open
wants to merge 8 commits into
base: yordan/openvino_http_imagenet_example
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# shellcheck shell=bash
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
fi
#if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
# source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
#fi

dotenv_if_exists
#dotenv_if_exists

use flake
watch_file "$(find ./ -name "*.nix" -printf '"%p" ')"
#use flake
#watch_file "$(find ./ -name "*.nix" -printf '"%p" ')"
113 changes: 5 additions & 108 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions crates/componentize/src/abi_conformance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
//! (i.e. inbound requests) or by the host (i.e. outbound requests).
//!
//! - For a guest-implemented function, the host will call the function and assert the result matches what is
//! expected (see [`Report::inbound_http`] for an example).
//! expected (see [`Report::inbound_http`] for an example).
//!
//! - For a host-implemented function, the host will call a guest-implemented function according to the specified
//! [`InvocationStyle`] with a set of arguments indicating which host function to call and with what arguments.
//! The host then asserts that host function was indeed called with the expected arguments (see
//! [`Report::http`] for an example).
//! [`InvocationStyle`] with a set of arguments indicating which host function to call and with what arguments.
//! The host then asserts that host function was indeed called with the expected arguments (see
//! [`Report::http`] for an example).

#![deny(warnings)]

Expand Down Expand Up @@ -88,7 +88,7 @@ pub struct TestConfig {
/// - Guest-implemented exports which behave as prescribed by the test (e.g. `inbound_http` and `inbound_redis`)
///
/// - Host-implemented imports which are called by the guest with the arguments specified by the host
/// (e.g. `http`)
/// (e.g. `http`)
#[derive(Serialize, PartialEq, Eq, Debug)]
pub struct Report {
/// Result of the Spin inbound HTTP test
Expand Down
9 changes: 7 additions & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tokio = "1.0"
bytes = "1.0"
spin-telemetry = { path = "../telemetry" }
http = "1.0"
openvino = { version = "0.6.0", features = ["runtime-linking",] }
openvino = { version = "0.7.2", features = ["runtime-linking",], optional = true }
table = { path = "../table" }

[target.'cfg(unix)'.dependencies]
Expand All @@ -37,4 +37,9 @@ futures = "0.3"

[build-dependencies]
curl = { version = "^0.4", features = ["rustls"] }
anyhow = "^1"
anyhow = "^1"

[features]
default = ["has_gpu", "openvino"]
openvino = ["dep:openvino"]
has_gpu = []
4 changes: 4 additions & 0 deletions crates/core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ fn main() {
}

println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/*.rs");
println!("cargo:rerun-if-changed=tests/integration_test.rs");
println!("cargo:rerun-if-changed=tests/core-wasi-test/src/*.rs");
println!("cargo:rerun-if-changed=tests/test_host_components/src/*.rs");
}

fn try_download(url: &str, filename: &PathBuf) -> Result<(), anyhow::Error> {
Expand Down
53 changes: 42 additions & 11 deletions crates/core/tests/core-wasi-test/src/imagenet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ml::test::test::{graph, inference, tensor};
use image2tensor::convert_image_to_tensor_bytes;
use crate::ml::test::test::{graph, inference, tensor, errors};
use image2tensor::convert_image_bytes_to_tensor_bytes;

use crate::imagenet_classes;
use crate::Path;
Expand Down Expand Up @@ -40,6 +40,43 @@ fn map_string_to_execution_target(target: &str) -> Result<graph::ExecutionTarget
}
}


pub fn preprocess_image_for_imagenet(
image_file_data: &[u8],
tensor_dimensions:&[u32],
) -> Vec<u8> {
let tensor_data = convert_image_bytes_to_tensor_bytes(
image_file_data,
tensor_dimensions[2],
tensor_dimensions[3],
image2tensor::TensorType::F32,
image2tensor::ColorOrder::BGR,
)
.unwrap();

let mut new_tensor_data = Vec::<f32>::new();

let num_colors = tensor_dimensions[1] as usize;
let height = tensor_dimensions[2] as usize;
let width = tensor_dimensions[3] as usize;

for c in 0..num_colors {
for y in 0..height {
for x in 0..width {
let offset = ((y * width + x) * 3 + c) * 4;
let v = f32::from_le_bytes(
tensor_data[offset..offset + 4]
.try_into()
.expect("Needed 4 bytes for a float"),
);
new_tensor_data.push(v);
}
}
}
let (_head, body, _tail) = unsafe { new_tensor_data.align_to::<u8>() };
body.to_vec()
}

pub fn imagenet_openvino_test(
path_as_string: String,
target_as_string: String,
Expand Down Expand Up @@ -84,7 +121,7 @@ pub fn imagenet_openvino_test(
};
let context = {
let start_for_elapsed_macro = std::time::Instant::now();
let context = graph::Graph::init_execution_context(&imagenet_graph).unwrap();
let context = graph::Graph::init_execution_context(&imagenet_graph).map_err(|e| errors::Error::data(&e) ).expect("XXXXXXXX -> init_execution_context failed");
let elapsed = start_for_elapsed_macro.elapsed();
eprintln!(
"Created context with ID: {:?} {}",
Expand All @@ -95,14 +132,8 @@ pub fn imagenet_openvino_test(
};

let tensor_dimensions: Vec<u32> = vec![1, 3, 224, 224];
let tensor_data = convert_image_to_tensor_bytes(
&image_file, //"images/0.jpg",
tensor_dimensions[2],
tensor_dimensions[3],
image2tensor::TensorType::F32,
image2tensor::ColorOrder::BGR,
)
.unwrap();
let image_file_bytes = std::fs::read(&image_file).unwrap();
let tensor_data = preprocess_image_for_imagenet(&image_file_bytes, &tensor_dimensions);

let tensor_id = {
let start_for_elapsed_macro = std::time::Instant::now();
Expand Down
14 changes: 9 additions & 5 deletions crates/core/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::{
};

mod test_host_components;
use crate::test_host_components::ml::ml::MLHostComponent;

use crate::test_host_components::ml_host_component::MLHostComponent;
use crate::test_host_components::multiplier::{Multiplier, MultiplierHostComponent};

use anyhow::Context;
Expand Down Expand Up @@ -58,7 +59,6 @@ async fn test_read_only_preopened_dir_write_fails() {
.expect("trap error was not an I32Exit");
assert_eq!(trap.0, 1);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_read_write_preopened_dir() {
let filename = "test_file";
Expand Down Expand Up @@ -161,6 +161,7 @@ async fn test_host_component_data_update() {
assert_eq!(stdout, "500");
}

#[cfg(feature = "openvino")]
#[tokio::test(flavor = "multi_thread")]
async fn test_host_component_imagenet_openvino_cpu() {
let engine = test_engine();
Expand All @@ -186,6 +187,8 @@ async fn test_host_component_imagenet_openvino_cpu() {
assert_eq!(stdout, "0.47 -> Eskimo dog, husky\n0.37 -> Siberian husky\n0.01 -> malamute, malemute, Alaskan malamute");
}

#[cfg(feature = "openvino")]
#[cfg(feature = "has_gpu")]
#[tokio::test(flavor = "multi_thread")]
async fn test_host_component_imagenet_openvino_gpu() {
let engine = test_engine();
Expand All @@ -208,11 +211,11 @@ async fn test_host_component_imagenet_openvino_gpu() {
)
.await
.unwrap();
assert_eq!(stdout, "0.96 -> mountain bike, all-terrain bike, off-roader\n0.01 -> bicycle-built-for-two, tandem bicycle, tandem\n0.00 -> alp");
assert_eq!(stdout, "0.97 -> mountain bike, all-terrain bike, off-roader\n0.01 -> bicycle-built-for-two, tandem bicycle, tandem\n0.00 -> alp");
}

#[tokio::test(flavor = "multi_thread")]
#[cfg(not(tarpaulin))]
// #[cfg(not(tarpaulin))]
async fn test_panic() {
let err = run_core_wasi_test(["panic"], |_| {}).await.unwrap_err();
let trap = err.downcast::<Trap>().expect("trap");
Expand All @@ -230,7 +233,8 @@ fn test_config() -> Config {
fn test_engine() -> Engine<()> {
let mut builder = Engine::builder(&test_config()).unwrap();
builder.add_host_component(MultiplierHostComponent).unwrap();
builder.add_host_component(MLHostComponent).unwrap();

builder.add_host_component(MLHostComponent {}).unwrap();

builder
.link_import(|l, _| wasmtime_wasi::add_to_linker_async(l))
Expand Down
Loading