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 21, 2024
1 parent cf86ffd commit 7abd323
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
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
9 changes: 8 additions & 1 deletion vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ 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

[dev-dependencies]
iai-callgrind = "0.13.0"

[[bench]]
name = "riscv_machine"
harness = false
34 changes: 34 additions & 0 deletions vm/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_vm::{memory::paged::Paged, memory::trie::MerkleTrie, memory::Memory, trace_vm, 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()
};

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);

0 comments on commit 7abd323

Please sign in to comment.