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

draft: Iai on CI #65

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
24 changes: 24 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
CARGO_TERM_COLOR: always

jobs:
iai:
name: Bench (iai)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install Valgrind
run: sudo apt install valgrind # sudo is necessary!
- name: Build
run: cargo build --verbose
- name: Bench
run: cargo bench --verbose
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ petgraph = "0.6.2"
rsgm = { git = "https://github.com/pmall-neu/rsgm" }
rand_chacha = "0.3.1"

[dev-dependencies]
iai = "0.1"

[lib]
name = "rsdd"
Expand Down Expand Up @@ -59,3 +61,7 @@ path = "bin/bayesian_network_compiler.rs"
[[bin]]
name = "semantic_hash_experiment"
path = "bin/semantic_hash_experiment.rs"

[[bench]]
name = "iai"
harness = false
86 changes: 86 additions & 0 deletions benches/iai.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
use iai::black_box;
use rsdd::{
builder::{canonicalize::CompressionCanonicalizer, sdd_builder::SddManager},
repr::{cnf::Cnf, var_label::VarLabel, vtree::VTree},
};

// subset of DIMACS from CNFs from test.rs
static C1_A: &str = "
p cnf 5 3
1 2 0
-1 2 0
";

static C1_B: &str = "
p cnf 2 1
2 0
";

static C2_A: &str = "
p cnf 5 3
1 2 3 0
1 2 0
-1 2 0
";

static C2_B: &str = "
p cnf 2 1
2 0
";

static C3_A: &str = "
p cnf 5 3
1 2 3 4 5 0
1 2 0
-1 2 0
";

static C3_B: &str = "
p cnf 2 1
2 0
";

fn sdd_benchmark_helper(cnf1: Cnf, cnf2: Cnf) {
let v: Vec<VarLabel> = (0..cnf1.num_vars())
.map(|x| VarLabel::new(x as u64))
.collect();
let vtree = VTree::even_split(&v, 1);
let mut man = SddManager::<CompressionCanonicalizer>::new(vtree);
let r1 = man.from_cnf(&cnf1);
let r2 = man.from_cnf(&cnf2);
assert!(
man.sdd_eq(r1, r2),
"Not eq\nCNF 1: {:?}\nCNF 2: {:?}\nSDD 1:{}\n SDD 2: {}",
cnf1,
cnf2,
man.print_sdd(r1),
man.print_sdd(r2)
);
}

fn iai_benchmark_sdd_canonicity_c1() {
sdd_benchmark_helper(
Cnf::from_file(String::from(black_box(C1_A))),
Cnf::from_file(String::from(black_box(C1_B))),
)
}

fn iai_benchmark_sdd_canonicity_c2() {
sdd_benchmark_helper(
Cnf::from_file(String::from(black_box(C2_A))),
Cnf::from_file(String::from(black_box(C2_B))),
)
}

fn iai_benchmark_sdd_canonicity_c3() {
sdd_benchmark_helper(
Cnf::from_file(String::from(black_box(C3_A))),
Cnf::from_file(String::from(black_box(C3_B))),
)
}

iai::main!(
iai_benchmark_sdd_canonicity_c1,
iai_benchmark_sdd_canonicity_c2,
iai_benchmark_sdd_canonicity_c3
);