diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63365f5f..556838ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,7 @@ name: CI on: pull_request: + types: [opened, synchronize, reopened, labeled] push: branches: - main @@ -70,3 +71,22 @@ jobs: runs-on: ubuntu-latest steps: - uses: bnjbvr/cargo-machete@main + + bench-riscv: + runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'benchmark') + steps: + - uses: actions/checkout@v4 + - name: Install valgrind + run: sudo apt-get install -y valgrind + - name: Install iai-callgrind-runner + run: | + version=$(cargo metadata --format-version=1 |\ + jq '.packages[] | select(.name == "iai-callgrind").version' |\ + tr -d '"' + ) + cargo install iai-callgrind-runner --version $version + - name: Run benchmarks + run: | + cargo bench --bench riscv_machine + diff --git a/core/Cargo.toml b/core/Cargo.toml index 4d04d02e..d4166ea5 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -36,13 +36,21 @@ ark-grumpkin.workspace = true [features] default = ["parallel", "prover_nova"] parallel = [ - "ark-ff/parallel", - "ark-ec/parallel", - "ark-std/parallel", - "ark-crypto-primitives/parallel", - "ark-r1cs-std/parallel", - "nexus-nova/parallel", + "ark-ff/parallel", + "ark-ec/parallel", + "ark-std/parallel", + "ark-crypto-primitives/parallel", + "ark-r1cs-std/parallel", + "nexus-nova/parallel", ] prover_hypernova = ["dep:nexus-nova", "dep:spartan"] prover_nova = ["dep:nexus-nova", "dep:spartan"] prover_jolt = ["dep:nexus-jolt"] + + +[dev-dependencies] +iai-callgrind = "0.12.2" + +[[bench]] +name = "riscv_machine" +harness = false diff --git a/core/benches/riscv_machine.rs b/core/benches/riscv_machine.rs new file mode 100644 index 00000000..3aacc499 --- /dev/null +++ b/core/benches/riscv_machine.rs @@ -0,0 +1,34 @@ +use iai_callgrind::{library_benchmark, library_benchmark_group, main}; +use nexus_core::nvm::{self, memory::Memory, memory::MerkleTrie, memory::Paged, VMOpts}; + +fn trace_riscv_machine(machine: &str) -> Result<(), Box> { + let vmopts = VMOpts { + machine: Some(machine.to_string()), + k: 1, + ..Default::default() + }; + + nvm::trace_vm::(&vmopts, false, false, false)?; + + Ok(()) +} + +#[library_benchmark] +#[benches::multiple("nop10")] +fn bench_trace_riscv_machine_with_unchecked_memory(machine: &str) { + trace_riscv_machine::(machine).expect("Failed to trace RISC-V VM with Paged memory"); +} + +#[library_benchmark] +#[benches::multiple("nop10")] +fn bench_trace_riscv_machine_with_checked_memory(machine: &str) { + trace_riscv_machine::(machine) + .expect("Failed to trace RISC-V VM with MerkleTrie memory"); +} + +library_benchmark_group!( + name = bench_riscv_emulator; + benchmarks = bench_trace_riscv_machine_with_unchecked_memory, bench_trace_riscv_machine_with_checked_memory +); + +main!(library_benchmark_groups = bench_riscv_emulator); diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 3bcf8a49..8ea5cd16 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -21,4 +21,4 @@ ark-std.workspace = true ark-relations.workspace = true ark-serialize.workspace = true ark-r1cs-std.workspace = true -ark-bn254.workspace = true \ No newline at end of file +ark-bn254.workspace = true