Skip to content

Commit

Permalink
Add RISC-V Trace benchmark for Core
Browse files Browse the repository at this point in the history
Summary:

Test Plan:
  • Loading branch information
duc-nx committed Aug 13, 2024
1 parent 15bfc3f commit 7b94aac
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: CI

on:
pull_request:
types: [opened, synchronize, reopened, labeled]
push:
branches:
- main
Expand Down Expand Up @@ -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
20 changes: 14 additions & 6 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 34 additions & 0 deletions core/benches/riscv_machine.rs
Original file line number Diff line number Diff line change
@@ -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<M: Memory>(machine: &str) -> Result<(), Box<dyn std::error::Error>> {
let vmopts = VMOpts {
machine: Some(machine.to_string()),
k: 1,
..Default::default()
};

nvm::trace_vm::<M>(&vmopts, false, false, false)?;

Ok(())
}

#[library_benchmark]
#[benches::multiple("nop10")]
fn bench_trace_riscv_machine_with_unchecked_memory(machine: &str) {
trace_riscv_machine::<Paged>(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::<MerkleTrie>(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);
2 changes: 1 addition & 1 deletion vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
ark-bn254.workspace = true

0 comments on commit 7b94aac

Please sign in to comment.