Hi Folks,
I am new to wasmtime. So was trying to find a way to calculate the CPU consumption per module for metering purposes. I saw something related to "FUEL" (https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.consume_fuel ), but is there a direct way to calculate [ Ghz-seconds]? Alternatively, Is there a way to map FUEL to [Ghz-seconds]?
No, fuel is deterministic and roughly corresponds to amount of wasm instructions executed. You seem to want the amount of cycles the cpu used to execute it which is highly dependent on the exact cpu, what the result is of the compilation, the exact state of the caches and a dozen other factors. The only way to get that is to use the cpu profiling functionality of the OS. For example perf_event_open on Linux (doesn't work with the default perf paranoid level config unless you are root)
Hello,
quick question regarding Fuel:
Currently almost all opcodes are cost "1" with some being cost "0", although we don't provide a strong guarantee about what opcodes "cost" at this time
okay, thank you Alex! Are there plans to document/customize different opcodes costs?
I don't believe anyone's currently working on that, but it seems like a reasonable-enough feature to add to me. I think there was some historical discussion about adding it but now I forget where that happened...
In the release build , is it possible to generate .wasm file in the target folder using cargo build --target wasm32-wasi ? I want the component model wasm file.
Is there any way that I can generate .wasm file from .wat based on component model?
@Alex Crichton
In the release build , is it possible to generate .wasm file in the target folder using cargo build --target wasm32-wasi ? I want the component model wasm file.
Wasi doesn't yet use the component model.
Is there any way that I can generate .wasm file from .wat based on component model?
A .wat file describes the interface of a .wasm file. You have to compile the .wasm file from another language that supports compiling to wasm.
I'm interested in wasm file which is based on component model . so I'm compiling the the component model module but I'm not sure how to compile component model module?
Hi @Shivam. Currently there's a tool called wit-component
in the wit-bindgen
repository (https://github.com/bytecodealliance/wit-bindgen/tree/main/crates/wit-component) that can create a component based on the component model from a core wasm module that was built with wit-bindgen. There's also a cargo-component
tool for Rust component development that should be available very soon to easily create components (it automates bindings generation and using wit-component
to create a wasm component). As WASI preview2 (which is based on the component model) isn't yet ready, these tools are expecting you to target wasm32-unknown-unknown
(in the case of cargo-component
, the target is implicitly set for you).
@Peter Huene Note that wasm32-unknown-unknown's call conv is not compatible with C.
The intention is to default to WASI once it does support the component model
I'm not sure that if i can generate a .wasm from the .wat file? I checked it , it depending on the .wit format and generates a .rs file. Is there any way that I can generate .wasm file from .wat format of component model?
Also where i can find the binary ? for testing a .wat format?
wasm-tools parse
can be used to convert a .wat
file to a .wasm
file and it supports the component model; it can be installed from here: https://github.com/bytecodealliance/wasm-tools
if by testing you mean executing your component defined in either wat or wasm, wasmtime has under-development support for executing components (under the component-model
feature), but you need to use the Wasmtime Rust API to instantiate the component
Hello everyone first time here, I was wondering if it is possible to add import functions to a wasm module using wasmtime. I want the user to give me some code which I can essentially add to at runtime
Woops I meant exports * get the naming confused sometimes
You want to add functions to a wasm module at runtime?
Dynamically adding code to a running instance is not currently possible.
Ahh I see thank you, I might use some code generation on the client side instead. Thank you
Thanks Peter!
Hi, I'm using the wasmtime::component
module to load in a WASM file, define some functions that it can use, and then run some functions that it exports. The WASM file is another rust crate that I compile to the wasm32-wasi
target. I'm getting the error attempted to parse a wasm module with a component parser
which I assume means that the Rust compiler outputs a WASM module rather than a WASM component. Is it possible for the Rust compiler to generate a component? If not, how can I create a WASM component? The reason I'm using components in the first place is because I'd like to use structs across the FFI boundary between the Rust runner and WASM file.
Klim Tsoutsman has marked this topic as resolved.
Klim Tsoutsman said:
Hi, I'm using the
wasmtime::component
module to load in a WASM file, define some functions that it can use, and then run some functions that it exports. The WASM file is another rust crate that I compile to thewasm32-wasi
target. I'm getting the errorattempted to parse a wasm module with a component parser
which I assume means that the Rust compiler outputs a WASM module rather than a WASM component. Is it possible for the Rust compiler to generate a component? If not, how can I create a WASM component? The reason I'm using components in the first place is because I'd like to use structs across the FFI boundary between the Rust runner and WASM file.
Sorry, I probably should have scrolled up in the chat to see if my question has already been answered. Peter Huene literally answered the same question yesterday :)
Is it possible for the Rust compiler to generate a component? If not, how can I create a WASM component?
To answer this, the Rust compiler does not generate components at this time, only core wasm modules. We're working on tooling like cargo component
to generate components
(deleted)
Last updated: Nov 22 2024 at 17:03 UTC