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

wasi-parallel: implement CPU parallelism #4949

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "crates/wasi-crypto/spec"]
path = crates/wasi-crypto/spec
url = https://github.com/WebAssembly/wasi-crypto.git
[submodule "crates/wasi-parallel/spec"]
path = crates/wasi-parallel/spec
url = https://github.com/WebAssembly/wasi-parallel
111 changes: 106 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ wasmtime-wast = { workspace = true }
wasmtime-wasi = { workspace = true }
wasmtime-wasi-crypto = { workspace = true, optional = true }
wasmtime-wasi-nn = { workspace = true, optional = true }
wasmtime-wasi-parallel = { workspace = true, optional = true }
clap = { workspace = true, features = ["color", "suggestions", "derive"] }
anyhow = { workspace = true }
target-lexicon = { workspace = true }
Expand Down Expand Up @@ -114,6 +115,7 @@ wasmtime-wast = { path = "crates/wast", version = "=2.0.0" }
wasmtime-wasi = { path = "crates/wasi", version = "2.0.0" }
wasmtime-wasi-crypto = { path = "crates/wasi-crypto", version = "2.0.0" }
wasmtime-wasi-nn = { path = "crates/wasi-nn", version = "2.0.0" }
wasmtime-wasi-parallel = { path = "crates/wasi-parallel", version = "2.0.0" }
wasmtime-component-util = { path = "crates/component-util", version = "=2.0.0" }
wasmtime-component-macro = { path = "crates/component-macro", version = "=2.0.0" }
wasmtime-asm-macros = { path = "crates/asm-macros", version = "=2.0.0" }
Expand Down Expand Up @@ -178,6 +180,7 @@ jitdump = ["wasmtime/jitdump"]
vtune = ["wasmtime/vtune"]
wasi-crypto = ["dep:wasmtime-wasi-crypto"]
wasi-nn = ["dep:wasmtime-wasi-nn"]
wasi-parallel = ["wasmtime-wasi-parallel"]
memory-init-cow = ["wasmtime/memory-init-cow", "wasmtime-cli-flags/memory-init-cow"]
pooling-allocator = ["wasmtime/pooling-allocator", "wasmtime-cli-flags/pooling-allocator"]
all-arch = ["wasmtime/all-arch"]
Expand Down
3 changes: 3 additions & 0 deletions crates/bench-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ impl BenchState {
wasmtime_wasi_crypto::add_to_linker(&mut linker, |cx| &mut cx.wasi_crypto)?;
}

#[cfg(feature = "wasi-parallel")]
wasmtime_wasi_parallel::add_to_linker(&mut linker, |cx| &mut cx.wasi_parallel)?;

Ok(Self {
linker,
compilation_timer,
Expand Down
22 changes: 18 additions & 4 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ pub const SUPPORTED_WASI_MODULES: &[(&str, &str)] = &[
"experimental-wasi-crypto",
"enables support for the WASI cryptography APIs (experimental), see https://github.com/WebAssembly/wasi-crypto",
),
(
"experimental-wasi-parallel",
"enables support for the WASI parallel APIs (experimental)",
),
];

fn pick_profiling_strategy(jitdump: bool, vtune: bool) -> Result<ProfilingStrategy> {
Expand Down Expand Up @@ -478,6 +482,7 @@ fn parse_wasi_modules(modules: &str) -> Result<WasiModules> {
"wasi-common" => Ok(wasi_modules.wasi_common = enable),
"experimental-wasi-nn" => Ok(wasi_modules.wasi_nn = enable),
"experimental-wasi-crypto" => Ok(wasi_modules.wasi_crypto = enable),
"experimental-wasi-parallel" => Ok(wasi_modules.wasi_parallel = enable),
"default" => bail!("'default' cannot be specified with other WASI modules"),
_ => bail!("unsupported WASI module '{}'", module),
};
Expand Down Expand Up @@ -509,6 +514,9 @@ pub struct WasiModules {

/// Enable the experimental wasi-crypto implementation.
pub wasi_crypto: bool,

/// Enable the experimental wasi-parallel implementation.
pub wasi_parallel: bool,
}

impl Default for WasiModules {
Expand All @@ -517,6 +525,7 @@ impl Default for WasiModules {
wasi_common: true,
wasi_nn: false,
wasi_crypto: false,
wasi_parallel: false,
}
}
}
Expand All @@ -528,6 +537,7 @@ impl WasiModules {
wasi_common: false,
wasi_nn: false,
wasi_crypto: false,
wasi_parallel: false,
}
}
}
Expand Down Expand Up @@ -674,7 +684,8 @@ mod test {
WasiModules {
wasi_common: true,
wasi_nn: false,
wasi_crypto: false
wasi_crypto: false,
wasi_parallel: false
}
);
}
Expand All @@ -687,7 +698,8 @@ mod test {
WasiModules {
wasi_common: true,
wasi_nn: false,
wasi_crypto: false
wasi_crypto: false,
wasi_parallel: false
}
);
}
Expand All @@ -704,7 +716,8 @@ mod test {
WasiModules {
wasi_common: false,
wasi_nn: true,
wasi_crypto: false
wasi_crypto: false,
wasi_parallel: false
}
);
}
Expand All @@ -718,7 +731,8 @@ mod test {
WasiModules {
wasi_common: false,
wasi_nn: false,
wasi_crypto: false
wasi_crypto: false,
wasi_parallel: false
}
);
}
Expand Down
1 change: 1 addition & 0 deletions crates/wasi-parallel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/tests/wasm/*
47 changes: 47 additions & 0 deletions crates/wasi-parallel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "wasmtime-wasi-parallel"
version.workspace = true
authors.workspace = true
description = "Wasmtime implementation of the wasi-parallel API"
documentation = "https://docs.rs/wasmtime-wasi-parallel"
license = "Apache-2.0 WITH LLVM-exception"
categories = ["wasm", "parallel"]
keywords = ["webassembly", "wasm", "parallel"]
repository = "https://github.com/bytecodealliance/wasmtime"
readme = "README.md"
edition = "2018"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind bumping this to 2021 with edition.workspace = true?


[dependencies]
# These dependencies are necessary for the witx-generation macros to work:
anyhow = { workspace = true }
wiggle = { workspace = true }

# These dependencies are necessary for the wasi-parallel implementation:
indexmap = "1.6"
log = { workspace = true }
num_cpus = "1.13"
rand = "0.8"
scoped_threadpool = "0.1"
wasmtime = { workspace = true, default-features = false, features = ["cranelift", "wat"] }
wasmtime-runtime = { workspace = true }
wasmtime-wasi = { workspace = true }

[dev-dependencies]
criterion = "0.4"
pretty_env_logger = "0.4"

[build-dependencies]
walkdir = "2.3"

[features]
# Enable building Rust tests to Wasm. Not all environments will have a
# `wasm32-wasi` target installed so this feature is not enabled by default.
build-tests = []

[[bench]]
name = "nstream"
harness = false

[[bench]]
name = "sum"
harness = false
Loading