Implement RFC 11: Redesigning Wasmtime's APIs (#2897)

Implement Wasmtime's new API as designed by RFC 11. This is quite a large commit which has had lots of discussion externally, so for more information it's best to read the RFC thread and the PR thread.
This commit is contained in:
Alex Crichton
2021-06-03 09:10:53 -05:00
committed by GitHub
parent a5a28b1c5b
commit 7a1b7cdf92
233 changed files with 13349 additions and 11997 deletions

View File

@@ -17,7 +17,6 @@ anyhow = "1.0"
log = { version = "0.4", default-features = false }
wasmtime = { path = "../wasmtime", version = "0.27.0", default-features = false }
wasmtime-runtime = { path = "../runtime", version = "0.27.0" }
wasmtime-wiggle = { path = "../wiggle/wasmtime", version = "0.27.0" }
wasmtime-wasi = { path = "../wasi", version = "0.27.0" }
wiggle = { path = "../wiggle", version = "0.27.0" }

View File

@@ -28,7 +28,7 @@ pub enum UsageError {
impl<'a> WasiEphemeralNn for WasiNnCtx {
fn load<'b>(
&self,
&mut self,
builders: &GraphBuilderArray<'_>,
encoding: GraphEncoding,
target: ExecutionTarget,
@@ -76,7 +76,7 @@ impl<'a> WasiEphemeralNn for WasiNnCtx {
Ok(id)
}
fn init_execution_context(&self, graph: Graph) -> Result<GraphExecutionContext> {
fn init_execution_context(&mut self, graph: Graph) -> Result<GraphExecutionContext> {
let request =
if let Some((_, executable_graph)) = self.ctx.borrow_mut().graphs.get_mut(graph) {
executable_graph.create_infer_request()?
@@ -90,7 +90,7 @@ impl<'a> WasiEphemeralNn for WasiNnCtx {
}
fn set_input<'b>(
&self,
&mut self,
context: GraphExecutionContext,
index: u32,
tensor: &Tensor<'b>,
@@ -135,7 +135,7 @@ impl<'a> WasiEphemeralNn for WasiNnCtx {
Ok(())
}
fn compute(&self, context: GraphExecutionContext) -> Result<()> {
fn compute(&mut self, context: GraphExecutionContext) -> Result<()> {
if let Some(execution) = self.ctx.borrow_mut().executions.get_mut(context) {
Ok(execution.request.infer()?)
} else {
@@ -144,7 +144,7 @@ impl<'a> WasiEphemeralNn for WasiNnCtx {
}
fn get_output<'b>(
&self,
&mut self,
context: GraphExecutionContext,
index: u32,
out_buffer: &GuestPtr<'_, u8>,

View File

@@ -3,21 +3,4 @@ mod r#impl;
mod witx;
pub use ctx::WasiNnCtx;
// Defines a `struct WasiNn` with member fields and appropriate APIs for dealing with all the
// various WASI exports.
wasmtime_wiggle::wasmtime_integration!({
// The wiggle code to integrate with lives here:
target: witx,
// This must be the same witx document as used above:
witx: ["$WASI_ROOT/phases/ephemeral/witx/wasi_ephemeral_nn.witx"],
// This must be the same ctx type as used for the target:
ctx: WasiNnCtx,
// This macro will emit a struct to represent the instance, with this name and docs:
modules: {
wasi_ephemeral_nn => {
name: WasiNn,
docs: "An instantiated instance of the wasi-nn exports.",
}
},
});
pub use witx::wasi_ephemeral_nn::add_to_linker;

View File

@@ -11,7 +11,7 @@ wiggle::from_witx!({
use types::NnErrno;
impl<'a> types::UserErrorConversion for WasiNnCtx {
fn nn_errno_from_wasi_nn_error(&self, e: WasiNnError) -> Result<NnErrno, wiggle::Trap> {
fn nn_errno_from_wasi_nn_error(&mut self, e: WasiNnError) -> Result<NnErrno, wiggle::Trap> {
eprintln!("Host error: {:?}", e);
match e {
WasiNnError::OpenvinoSetupError(_) => unimplemented!(),