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

Update to wasmtime 3.0 and enable wasi-nn calls #209

Merged
merged 17 commits into from
Jan 17, 2023
456 changes: 301 additions & 155 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use {
/// Create a new server, bind it to an address, and serve responses until an error occurs.
pub async fn serve(opts: Opts) -> Result<(), Error> {
// Load the wasm module into an execution context
let mut ctx = ExecuteCtx::new(opts.input(), opts.profiling_strategy())?
let mut ctx = ExecuteCtx::new(opts.input(), opts.profiling_strategy(), opts.wasi_modules())?
.with_log_stderr(opts.log_stderr())
.with_log_stdout(opts.log_stdout());

Expand Down
51 changes: 49 additions & 2 deletions cli/src/opts.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! Command line arguments.

use {
clap::Parser,
clap::{Parser, ValueEnum},
std::net::{IpAddr, Ipv4Addr},
std::{
collections::HashSet,
net::SocketAddr,
path::{Path, PathBuf},
},
viceroy_lib::{Error, ProfilingStrategy},
viceroy_lib::{config::ExperimentalModule, Error, ProfilingStrategy},
};

// Command-line arguments for the Viceroy CLI.
Expand Down Expand Up @@ -43,6 +44,9 @@ pub struct Opts {
// Whether to enable wasmtime's builtin profiler.
#[arg(long = "profiler", value_parser = check_wasmtime_profiler_mode)]
profiler: Option<ProfilingStrategy>,
/// Set of experimental WASI modules to link against.
#[arg(value_enum, long = "experimental_modules", required = false)]
experimental_modules: Vec<ExperimentalModuleArg>,
}

impl Opts {
Expand Down Expand Up @@ -83,6 +87,49 @@ impl Opts {
pub fn profiling_strategy(&self) -> ProfilingStrategy {
self.profiler.unwrap_or(ProfilingStrategy::None)
}

// Set of experimental wasi modules to link against.
pub fn wasi_modules(&self) -> HashSet<ExperimentalModule> {
self.experimental_modules.iter().map(|x| x.into()).collect()
}
}

/// Enum of available (experimental) wasi modules
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Hash)]
pub enum ExperimentalModuleArg {
WasiNn,
}

impl From<ExperimentalModuleArg> for ExperimentalModule {
fn from(arg: ExperimentalModuleArg) -> ExperimentalModule {
match arg {
ExperimentalModuleArg::WasiNn => ExperimentalModule::WasiNn,
}
}
}

impl From<&ExperimentalModuleArg> for ExperimentalModule {
fn from(arg: &ExperimentalModuleArg) -> ExperimentalModule {
match arg {
ExperimentalModuleArg::WasiNn => ExperimentalModule::WasiNn,
}
}
}

impl From<ExperimentalModule> for ExperimentalModuleArg {
fn from(module: ExperimentalModule) -> ExperimentalModuleArg {
match module {
ExperimentalModule::WasiNn => ExperimentalModuleArg::WasiNn,
}
}
}

impl From<&ExperimentalModule> for ExperimentalModuleArg {
fn from(module: &ExperimentalModule) -> ExperimentalModuleArg {
match module {
ExperimentalModule::WasiNn => ExperimentalModuleArg::WasiNn,
}
}
}

/// A parsing function used by [`Opts`][opts] to check that the input is a valid Wasm module in
Expand Down
8 changes: 6 additions & 2 deletions cli/tests/integration/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

use futures::stream::StreamExt;
use hyper::{service, Body as HyperBody, Request, Response, Server};
use std::{convert::Infallible, future::Future, net::SocketAddr, path::PathBuf, sync::Arc};
use std::{
collections::HashSet, convert::Infallible, future::Future, net::SocketAddr, path::PathBuf,
sync::Arc,
};
use tokio::sync::Mutex;
use tracing_subscriber::filter::EnvFilter;
use viceroy_lib::{
Expand Down Expand Up @@ -197,7 +200,7 @@ impl Test {
.try_init()
.ok();

let ctx = ExecuteCtx::new(&self.module_path, ProfilingStrategy::None)
let ctx = ExecuteCtx::new(&self.module_path, ProfilingStrategy::None, HashSet::new())
.expect("failed to set up execution context")
.with_backends(self.backends.clone())
.with_dictionaries(self.dictionaries.clone())
Expand Down Expand Up @@ -250,6 +253,7 @@ impl Test {
.clone()
.handle_request(req.map(Into::into), addr.ip())
.await
.map(|result| result.0)
.expect("failed to handle the request");
responses.push(resp);
}
Expand Down
Loading