Skip to content

Commit

Permalink
Expose inference counts on Machine; publish to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
infogulch committed Nov 22, 2023
1 parent 503e45e commit 11832b5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ jobs:
path: |
target/criterion/*
target/iai/*
target/benchmark_inference_counts.json
# Publish binaries when building for a tag
release:
Expand Down
37 changes: 35 additions & 2 deletions benches/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,47 @@ mod test {
#[test]
fn validate_benchmarks() {
use super::prolog_benches;
use scryer_prolog::machine::parsed_results::QueryResolution;
use scryer_prolog::machine::parsed_results::{QueryMatch, QueryResolution};
use std::{fmt::Write, fs};

struct BenchResult {
pub name: &'static str,
pub setup_inference_count: u64,
pub query_inference_count: u64,
}

let mut results: Vec<BenchResult> = vec![];

use scryer_prolog::machine::parsed_results::QueryMatch;
for (_, r) in prolog_benches() {
let mut machine = r.make_machine();
let setup_inference_count = machine.get_inference_count();

let result = machine.run_query(r.query.to_string()).unwrap();
let query_inference_count = machine.get_inference_count() - setup_inference_count;

let expected = QueryResolution::Matches(vec![QueryMatch::from(r.bindings.clone())]);
assert_eq!(result, expected, "validating benchmark {}", r.name);

results.push(BenchResult {
name: r.name,
setup_inference_count,
query_inference_count,
})
}

let mut json: String = Default::default();
json.push('[');
for r in results {
json.push('\n');
write!(
json,
r#"{{"name":"{}","setup_inference_count":{},"query_inference_count":{}}},"#,
r.name, r.setup_inference_count, r.query_inference_count
)
.unwrap();
}
json.pop(); // trailing comma
json.push_str("\n]");
fs::write("target/benchmark_inference_counts.json", json).expect("Unable to write file");
}
}
9 changes: 9 additions & 0 deletions src/machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ impl Machine {
)
}

pub fn get_inference_count(&mut self) -> u64 {
self.machine_st
.cwil
.global_count
.clone()
.try_into()
.unwrap()
}

pub fn throw_session_error(&mut self, err: SessionError, key: PredicateKey) {
let err = self.machine_st.session_error(err);
let stub = functor_stub(key.0, key.1);
Expand Down

0 comments on commit 11832b5

Please sign in to comment.