leonwanghui commented on a change in pull request #5892: URL: https://github.com/apache/incubator-tvm/pull/5892#discussion_r457875722
########## File path: apps/wasm-standalone/wasm-graphruntime/src/runtime.rs ########## @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use super::types::Tensor; +use anyhow::Result; +use serde_json; +use wasmtime::*; +use wasmtime_wasi::{Wasi, WasiCtx}; + +pub fn execute(wasm_backend_file: String, input_data: Tensor) -> Result<Tensor> { + let engine = Engine::new(Config::new().wasm_simd(true)); + let store = Store::new(&engine); + + // First set up our linker which is going to be linking modules together. We + // want our linker to have wasi available, so we set that up here as well. + let mut linker = Linker::new(&store); + // Create an instance of `Wasi` which contains a `WasiCtx`. Note that + // `WasiCtx` provides a number of ways to configure what the target program + // will have access to. + let wasi = Wasi::new(&store, WasiCtx::new(std::env::args())?); + wasi.add_to_linker(&mut linker)?; + + let module = Module::from_file(&store, &wasm_backend_file)?; + let instance = linker.instantiate(&module)?; + let memory = instance + .get_memory("memory") + .ok_or(anyhow::format_err!("failed to find `memory` export"))?; Review comment: @nhynes It's suggested by wasmtime official guidelines (https://bytecodealliance.github.io/wasmtime/examples-rust-embed.html). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
