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

feat: Initial multivalue WASM proposal support #4379

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cdb30e4
Multi value
ark0f Nov 22, 2024
46c8b0f
Enable `multivalue` proposal for some libs
ark0f Nov 28, 2024
cc44b16
Temporary enable cranelift in embedded executor
ark0f Nov 28, 2024
e2c8398
Add multivalue bench check
ark0f Nov 28, 2024
22ba0f1
Add bench for `call_indirect` results
ark0f Nov 28, 2024
0cbd424
Update `gear_core::gas_metering`
ark0f Nov 28, 2024
c14e8e2
Update cargo files
ark0f Dec 6, 2024
9342e3a
Update wasmparser
ark0f Nov 21, 2024
a342a7d
Update wasm-smith
ark0f Nov 21, 2024
775a4d0
Remove unused `wasmi-validation` patch
ark0f Nov 21, 2024
c180557
Remove `parity-wasm` & `wasm-instrument` patch
ark0f Nov 21, 2024
e496cb7
Update cargo files
ark0f Dec 6, 2024
f88219e
Formalize deps
ark0f Dec 6, 2024
463c28c
Revert "Multi value"
ark0f Dec 6, 2024
2335df5
Revert "Remove unused `wasmi-validation` patch"
ark0f Dec 6, 2024
8739595
Enable cranelift via `cfg`
ark0f Dec 6, 2024
c215f14
Remove redundant bench tests
ark0f Dec 6, 2024
fcb188e
Fix `call_indirect` weight calculation
ark0f Dec 6, 2024
4ad2bd4
Revert "Update wasm-smith"
ark0f Dec 6, 2024
94b4c70
Revert "Update wasmparser"
ark0f Dec 6, 2024
7adaba3
Fix Cargo.lock after reverts
ark0f Dec 6, 2024
7724179
Revert `parity-wasm` patch
ark0f Dec 6, 2024
cee7759
Disable bench without cfg
ark0f Dec 6, 2024
9bbcaf5
Update gsdk metadata
ark0f Dec 7, 2024
2749c0b
Fix bench
ark0f Dec 7, 2024
0d3a4f8
Merge remote-tracking branch 'origin/master' into al/wasm-multi-value
ark0f Dec 7, 2024
2284259
After-merge fixes
ark0f Dec 7, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ jobs:
run: |
# fast benchmark tests before long run
cargo test -p "pallet-*" --features runtime-benchmarks,runtime-benchmarks-checkers --locked ${{ matrix.profiles.flags }} bench
# check `multivalue` proposal works
RUSTFLAGS="--cfg force_wasmer_cranelift_i_know_what_i_do" \
cargo test -p pallet-gear --features runtime-benchmarks,runtime-benchmarks-checkers --locked ${{ matrix.profiles.flags }} \
benchmarking::bench_instr_call_indirect_per_result -- --exact

- name: "Test: Benchmarks in WASM"
# unoptimized benchmarks take a few hours to run
Expand Down
152 changes: 134 additions & 18 deletions Cargo.lock

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

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ homepage = "https://gear-tech.io"
repository = "https://github.com/gear-tech/gear"
rust-version = "1.81"

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)', 'cfg(fuzz)', 'cfg(force_wasmer_cranelift_i_know_what_i_do)'] }

[workspace]
resolver = "2"

Expand Down Expand Up @@ -554,9 +557,6 @@ fs4 = "0.11.1" # utils/gear-wasmer
bytes = "1.8.0" # utils/gear-wasmer-cache
loom = "0.7.2" # utils/gear-wasmer-cache

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)', 'cfg(fuzz)'] }

[profile.dev.package.corosensei]
opt-level = 3

Expand Down Expand Up @@ -592,9 +592,10 @@ debug = true
[patch.crates-io]
# sp-io = { version = "38.0.0", git = "https://github.com/gear-tech/polkadot-sdk.git", branch = "gear-polkadot-stable2409" }
# sp-application-crypto = { version = "38.0.0", git = "https://github.com/gear-tech/polkadot-sdk.git", branch = "gear-polkadot-stable2409" }

# these patched dependecies force their `sign_ext` feature to be used by Substrate dependencies

Choose a reason for hiding this comment

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

Are these patches necessary? Substrate (runtime) does not use sign-ext: https://github.com/paritytech/polkadot-sdk/blob/906fa9e51306635245a22e03160d1c761fae6cc3/substrate/utils/wasm-builder/src/wasm_project.rs#L850. Same goes for outdated version wasmi 0.13.2 in our Cargo.lock.

parity-wasm = { version = "0.45.0", git = "https://github.com/gear-tech/parity-wasm", branch = "v0.45.0-sign-ext" }
wasmi-validation = { version = "0.5.0", git = "https://github.com/gear-tech/wasmi", branch = "v0.13.2-sign-ext" }
# wasm-instrument = { version = "0.3.0", git = "https://github.com/gear-tech/wasm-instrument", branch = "v0.3.0-sign-ext" }
wasm-instrument = { version = "0.4.0", git = "https://github.com/gear-tech/wasm-instrument", branch = "v0.4.0-sign-ext" }

# TODO: remove after https://github.com/BLAKE3-team/BLAKE3/pull/230
Expand Down
18 changes: 14 additions & 4 deletions core/src/gas_metering/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,21 @@ impl Rules for CustomConstantCostRules {
/// This type provides real gas cost of instructions on pallet-gear.
pub struct ScheduleRules<'a> {
schedule: &'a Schedule,
params: Vec<u32>,
funcs: Vec<(u32, u32)>,
}

impl Schedule {
/// Returns real gas rules that are used by pallet gear.
pub fn rules(&self, module: &Module) -> impl Rules + '_ {
ScheduleRules {
schedule: self,
params: module
funcs: module
.type_section()
.iter()
.flat_map(|section| section.types())
.map(|func| {
let Type::Function(func) = func;
func.params().len() as u32
(func.params().len() as u32, func.results().len() as u32)
})
.collect(),
}
Expand All @@ -211,6 +211,7 @@ impl<'a> Rules for ScheduleRules<'a> {

let w = &self.schedule.instruction_weights;
let max_params = self.schedule.limits.parameters;
let max_results = self.schedule.limits.results;

let weight = match *instruction {
End | Unreachable | Return | Else | Block(_) | Loop(_) | Nop | Drop => 0,
Expand Down Expand Up @@ -240,7 +241,16 @@ impl<'a> Rules for ScheduleRules<'a> {
GetGlobal(_) => w.global_get,
SetGlobal(_) => w.global_set,
CurrentMemory(_) => w.memory_current,
CallIndirect(idx, _) => *self.params.get(idx as usize).unwrap_or(&max_params),
CallIndirect(idx, _) => {
let (params, results) = self
.funcs
.get(idx as usize)
.copied()
.unwrap_or((max_params, max_results));
w.call_indirect
.saturating_add(w.call_indirect_per_param.saturating_mul(params))
.saturating_add(w.call_indirect_per_result.saturating_mul(results))
}
BrTable(ref data) => w
.br_table
.saturating_add(w.br_table_per_entry.saturating_mul(data.table.len() as u32)),
Expand Down
Loading
Loading