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

Pushing halide #164

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
25 changes: 23 additions & 2 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,29 @@ pub fn write_output<L: SynthLanguage>(
get_derivability_results(ruleset, DeriveType::Lhs, baseline, limits);
let ((forwards_lhs_rhs, backwards_lhs_rhs), (lhs_rhs_f, lhs_rhs_b), results_lhs_rhs) =
get_derivability_results(ruleset, DeriveType::LhsAndRhs, baseline, limits);
let ((forwards_all, backwards_all), (all_f, all_b), results_all) =
get_derivability_results(ruleset, DeriveType::AllRules, baseline, limits);

let (forwards_all, backwards_all) = (0, 0);
let (all_f, all_b) = (Duration::default(), Duration::default());
let results_all = json!({
"enumo_derives_baseline_derivable": vec!([""]),
"enumo_derives_baseline_underivable": vec!([""]),
"baseline_derives_enumo_derivable": vec!([""]),
"baseline_derives_enumo_underivable": vec!([""]),
});

if recipe_name == "halide" {
let (forwards_all, backwards_all) = (0, 0);
let (all_f, all_b) = (Duration::default(), Duration::default());
let results_all = json!({
"enumo_derives_baseline_derivable": vec!([""]),
"enumo_derives_baseline_underivable": vec!([""]),
"baseline_derives_enumo_derivable": vec!([""]),
"baseline_derives_enumo_underivable": vec!([""]),
});
} else {
let ((forwards_all, backwards_all), (all_f, all_b), results_all) =
get_derivability_results(ruleset, DeriveType::AllRules, baseline, limits);
}

// get linecount of recipe
let cnt = count_lines(recipe_name);
Expand Down
30 changes: 5 additions & 25 deletions tests/halide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,41 +324,21 @@ mod test {
#[test]
fn recipe() {
let baseline: Ruleset<Pred> = Ruleset::from_file("baseline/halide.rules");

let start = Instant::now();
let all_rules = halide_rules();
let rules = halide_rules();
let duration = start.elapsed();

logger::write_output(
&all_rules,
&rules,
&baseline,
"halide",
"halide",
"halide_handwritten",
Limits {
iter: 2,
node: 200000,
node: 100_000,
},
duration,
);

// oopsla-halide-baseline branch
// Run on leviathan 3/31/2023
// time cargo run --release --bin halide -- synth --iters 1 --use-smt
// real 0m3.354s
// user 0m3.274s
// sys 0m0.076s
let oopsla_halide: Ruleset<Pred> = Ruleset::from_file("baseline/oopsla-halide.rules");
let oopsla_duration = Duration::from_secs_f32(3.354);

logger::write_output(
&oopsla_halide,
&baseline,
"oopsla halide (1 iter)",
"halide",
Limits {
iter: 2,
node: 200000,
},
oopsla_duration,
)
}
}
167 changes: 156 additions & 11 deletions tests/recipes/halide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn recursive_rules(
bops: &Workload,
tops: &Workload,
prior: Ruleset<Pred>,
limits: Limits,
) -> Ruleset<Pred> {
let lang = Workload::new(&[
"const",
Expand All @@ -25,7 +26,17 @@ fn recursive_rules(
if n < 1 {
Ruleset::default()
} else {
let mut rec = recursive_rules(metric, n - 1, consts, vars, uops, bops, tops, prior.clone());
let mut rec = recursive_rules(
metric,
n - 1,
consts,
vars,
uops,
bops,
tops,
prior.clone(),
limits,
);
let wkld = lang
.iter_metric("expr", metric, n)
.filter(Filter::Contains("var".parse().unwrap()))
Expand All @@ -35,18 +46,15 @@ fn recursive_rules(
.plug("bop", bops)
.plug("top", tops);
rec.extend(prior);
let new = Pred::run_workload(wkld, rec.clone(), Limits::default());
let new = Pred::run_workload(wkld, rec.clone(), limits);
let mut all = new;
all.extend(rec);
all
}
}

pub fn halide_rules() -> Ruleset<Pred> {
// This is porting the halide recipe at incremental/halide.spec
// on the branch "maybe-useful" in the old recipes repo
let mut all_rules = Ruleset::default();

// Bool rules up to size 5:
let bool_only = recursive_rules(
Metric::Atoms,
Expand All @@ -57,10 +65,13 @@ pub fn halide_rules() -> Ruleset<Pred> {
&Workload::new(&["&&", "||", "^"]),
&Workload::Set(vec![]),
all_rules.clone(),
Limits {
iter: 3,
node: 100_000,
},
);
all_rules.extend(bool_only);

// Rational rules up to size 5:
// Rational rules up to size 6:
let rat_only = recursive_rules(
Metric::Atoms,
5,
Expand All @@ -70,10 +81,13 @@ pub fn halide_rules() -> Ruleset<Pred> {
&Workload::new(&["+", "-", "*", "min", "max"]), // No div for now
&Workload::Set(vec![]),
all_rules.clone(),
Limits {
iter: 3,
node: 100_000,
},
);
all_rules.extend(rat_only);

// Pred rules up to size 5
// Pred rules up to size 6:
let pred_only = recursive_rules(
Metric::Atoms,
5,
Expand All @@ -83,10 +97,13 @@ pub fn halide_rules() -> Ruleset<Pred> {
&Workload::new(&["<", "<=", "==", "!="]),
&Workload::new(&["select"]),
all_rules.clone(),
Limits {
iter: 3,
node: 100_000,
},
);
all_rules.extend(pred_only);

// All terms up to size 4
// All terms up to size 5
let full = recursive_rules(
Metric::Atoms,
4,
Expand All @@ -98,7 +115,135 @@ pub fn halide_rules() -> Ruleset<Pred> {
]),
&Workload::new(&["select"]),
all_rules.clone(),
Limits {
iter: 3,
node: 100_000,
},
);
all_rules.extend(full);
let nested_bops_full = Workload::new(&["(bop e e)", "v", "0", "1"])
.plug("e", &Workload::new(&["(bop v v)", "(uop v)", "v"]))
.plug(
"bop",
&Workload::new(&["&&", "||", "!=", "<=", "==", "max", "min"]),
)
.plug("uop", &Workload::new(&["-", "!"]))
.plug("v", &Workload::new(&["a", "b", "c"]))
.filter(Filter::Canon(vec![
"a".to_string(),
"b".to_string(),
"c".to_string(),
]));
let new = Pred::run_workload(
nested_bops_full,
all_rules.clone(),
Limits {
iter: 2,
node: 300_000,
},
);
all_rules.extend(new.clone());
println!("nested_bops_full finished.");
new.to_file("nested_bops_full.rules");

let nested_bops = Workload::new(&["(bop e e)", "v", "0", "1"])
.plug("e", &Workload::new(&["(bop v v)", "v"]))
.plug("bop", &Workload::new(&["+", "-", "*", "max", "min"]))
.plug("v", &Workload::new(&["a", "b", "c", "d"]))
.filter(Filter::Canon(vec![
"a".to_string(),
"b".to_string(),
"c".to_string(),
"d".to_string(),
]));
let new = Pred::run_workload(
nested_bops,
all_rules.clone(),
Limits {
iter: 2,
node: 300_000,
},
);
all_rules.extend(new.clone());
println!("nested_bops finished.");
new.to_file("nested-bops.rules");

let triple_nested_bops = Workload::new(&[
"(bop e e)",
"(bop (bop (bop v v) v) v)",
"(bop v (bop v (bop v v)))",
"0",
"1",
])
.plug("e", &Workload::new(&["(bop v v)", "v"]))
.plug("bop", &Workload::new(&["+", "-", "*", "max", "min"]))
.plug("v", &Workload::new(&["a", "b", "c", "d"]))
.filter(Filter::Canon(vec![
"a".to_string(),
"b".to_string(),
"c".to_string(),
"d".to_string(),
]));
let new = Pred::run_workload(
triple_nested_bops,
all_rules.clone(),
Limits {
iter: 2,
node: 300_000,
},
);
all_rules.extend(new.clone());
let select_max = Workload::new(&["(max s s)", "(min s s)", "(select v s s)"])
.plug("s", &Workload::new(&["(select v v v)", "(bop v v)", "v"]))
.plug(
"v",
&Workload::new(&["a", "b", "c", "d", "e", "f", "0", "1"]),
)
.plug("bop", &Workload::new(&["+", "-", "*", "min", "max"]))
.filter(Filter::Canon(vec![
"a".to_string(),
"b".to_string(),
"c".to_string(),
"d".to_string(),
"e".to_string(),
"f".to_string(),
"0".to_string(),
"1".to_string(),
]));
let new = Pred::run_workload(
select_max,
all_rules.clone(),
Limits {
iter: 2,
node: 300_000,
},
);
all_rules.extend(new.clone());
let select_arith = Workload::new(&["(select v e e)", "(bop v e)", "(bop e v)"])
.plug("e", &Workload::new(&["(bop v v)", "(select v v v)", "v"]))
.plug("bop", &Workload::new(&["+", "-", "*", "<", "max", "min"]))
.plug(
"v",
&Workload::new(&["a", "b", "c", "d", "e", "f", "0", "1"]),
)
.filter(Filter::Canon(vec![
"a".to_string(),
"b".to_string(),
"c".to_string(),
"d".to_string(),
"e".to_string(),
"f".to_string(),
"0".to_string(),
"1".to_string(),
]));
let new = Pred::run_workload(
select_arith,
all_rules.clone(),
Limits {
iter: 2,
node: 300_000,
},
);
all_rules.extend(new.clone());
all_rules
}