-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a method to share
Config
across machines (#2608)
With `Module::{serialize,deserialize}` it should be possible to share wasmtime modules across machines or CPUs. Serialization, however, embeds a hash of all configuration values, including cranelift compilation settings. By default wasmtime's selection of the native ISA would enable ISA flags according to CPU features available on the host, but the same CPU features may not be available across two machines. This commit adds a `Config::cranelift_clear_cpu_flags` method which allows clearing the target-specific ISA flags that are automatically inferred by default for the native CPU. Options can then be incrementally built back up as-desired with teh `cranelift_other_flag` method.
- Loading branch information
1 parent
e594c43
commit 503129a
Showing
16 changed files
with
125 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use wasmtime::*; | ||
|
||
#[test] | ||
fn caches_across_engines() { | ||
let mut c = Config::new(); | ||
c.cranelift_clear_cpu_flags(); | ||
|
||
let bytes = Module::new(&Engine::new(&c), "(module)") | ||
.unwrap() | ||
.serialize() | ||
.unwrap(); | ||
|
||
let res = Module::deserialize( | ||
&Engine::new(&Config::new().cranelift_clear_cpu_flags()), | ||
&bytes, | ||
); | ||
assert!(res.is_ok()); | ||
|
||
// differ in shared cranelift flags | ||
let res = Module::deserialize( | ||
&Engine::new( | ||
&Config::new() | ||
.cranelift_clear_cpu_flags() | ||
.cranelift_nan_canonicalization(true), | ||
), | ||
&bytes, | ||
); | ||
assert!(res.is_err()); | ||
|
||
// differ in cranelift settings | ||
let res = Module::deserialize( | ||
&Engine::new( | ||
&Config::new() | ||
.cranelift_clear_cpu_flags() | ||
.cranelift_opt_level(OptLevel::None), | ||
), | ||
&bytes, | ||
); | ||
assert!(res.is_err()); | ||
|
||
// differ in cpu-specific flags | ||
if cfg!(target_arch = "x86_64") { | ||
let res = Module::deserialize( | ||
&Engine::new(unsafe { | ||
&Config::new() | ||
.cranelift_clear_cpu_flags() | ||
.cranelift_other_flag("has_sse3", "true") | ||
.unwrap() | ||
}), | ||
&bytes, | ||
); | ||
assert!(res.is_err()); | ||
} | ||
} |