Skip to content

Commit

Permalink
remove LEM path (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-barrett authored Jan 15, 2024
1 parent f9f8754 commit 57dc325
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 189 deletions.
2 changes: 1 addition & 1 deletion src/lem/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn compute_frame<F: LurkField, C: Coprocessor<F>>(
};
assert_eq!(func.input_params.len(), input.len());
let preimages = Hints::new_from_func(func);
let (frame, _) = func.call(input, store, preimages, emitted, lang, pc)?;
let frame = func.call(input, store, preimages, emitted, lang, pc)?;
let must_break = matches!(frame.output[2].tag(), Tag::Cont(Terminal | Error));
Ok((frame, must_break))
}
Expand Down
80 changes: 29 additions & 51 deletions src/lem/interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{anyhow, bail, Context, Result};

use super::{
path::Path,
pointers::{Ptr, RawPtr},
slot::{SlotData, Val},
store::{fetch_ptrs, intern_ptrs, Store},
Expand Down Expand Up @@ -140,11 +139,10 @@ impl Block {
store: &Store<F>,
mut bindings: VarMap<Val>,
mut hints: Hints,
mut path: Path,
emitted: &mut Vec<Ptr>,
lang: &Lang<F, C>,
pc: usize,
) -> Result<(Frame, Path)> {
) -> Result<Frame> {
for op in &self.ops {
match op {
Op::Cproc(out, sym, inp) => {
Expand All @@ -164,10 +162,7 @@ impl Block {
Op::Call(out, func, inp) => {
// Get the argument values
let inp_ptrs = bindings.get_many_ptr(inp)?;
let (frame, func_path) =
func.call(&inp_ptrs, store, hints, emitted, lang, pc)?;
// Extend the path
path.extend_from_path(&func_path);
let frame = func.call(&inp_ptrs, store, hints, emitted, lang, pc)?;
// Bind the output variables to the output values
hints = frame.hints;
for (var, ptr) in out.iter().zip(frame.output.into_iter()) {
Expand Down Expand Up @@ -476,14 +471,12 @@ impl Block {
let ptr = bindings.get_ptr(match_var)?;
let tag = ptr.tag();
if let Some(block) = cases.get(tag) {
path.push_tag_inplace(*tag);
block.run(input, store, bindings, hints, path, emitted, lang, pc)
block.run(input, store, bindings, hints, emitted, lang, pc)
} else {
path.push_default_inplace();
let Some(def) = def else {
bail!("No match for tag {}", tag)
};
def.run(input, store, bindings, hints, path, emitted, lang, pc)
def.run(input, store, bindings, hints, emitted, lang, pc)
}
}
Ctrl::MatchSymbol(match_var, cases, def) => {
Expand All @@ -495,23 +488,20 @@ impl Block {
bail!("Symbol bound to {match_var} wasn't interned");
};
if let Some(block) = cases.get(&sym) {
path.push_symbol_inplace(sym);
block.run(input, store, bindings, hints, path, emitted, lang, pc)
block.run(input, store, bindings, hints, emitted, lang, pc)
} else {
path.push_default_inplace();
let Some(def) = def else {
bail!("No match for symbol {sym}")
};
def.run(input, store, bindings, hints, path, emitted, lang, pc)
def.run(input, store, bindings, hints, emitted, lang, pc)
}
}
Ctrl::If(b, true_block, false_block) => {
let b = bindings.get_bool(b)?;
path.push_bool_inplace(b);
if b {
true_block.run(input, store, bindings, hints, path, emitted, lang, pc)
true_block.run(input, store, bindings, hints, emitted, lang, pc)
} else {
false_block.run(input, store, bindings, hints, path, emitted, lang, pc)
false_block.run(input, store, bindings, hints, emitted, lang, pc)
}
}
Ctrl::Return(output_vars) => {
Expand All @@ -520,17 +510,14 @@ impl Block {
output.push(bindings.get_ptr(var)?)
}
let input = input.to_vec();
Ok((
Frame {
input,
output,
emitted: emitted.clone(),
hints,
blank: false,
pc,
},
path,
))
Ok(Frame {
input,
output,
emitted: emitted.clone(),
hints,
blank: false,
pc,
})
}
}
}
Expand All @@ -545,7 +532,7 @@ impl Func {
emitted: &mut Vec<Ptr>,
lang: &Lang<F, C>,
pc: usize,
) -> Result<(Frame, Path)> {
) -> Result<Frame> {
let mut bindings = VarMap::new();
for (i, param) in self.input_params.iter().enumerate() {
bindings.insert_ptr(param.clone(), args[i]);
Expand All @@ -559,17 +546,10 @@ impl Func {
let commitment_init = hints.commitment.len();
let bit_decomp_init = hints.bit_decomp.len();

let mut res = self.body.run(
args,
store,
bindings,
hints,
Path::default(),
emitted,
lang,
pc,
)?;
let hints = &mut res.0.hints;
let mut res = self
.body
.run(args, store, bindings, hints, emitted, lang, pc)?;
let hints = &mut res.hints;

let hash4_used = hints.hash4.len() - hash4_init;
let hash6_used = hints.hash6.len() - hash6_init;
Expand Down Expand Up @@ -604,15 +584,13 @@ impl Func {
lang: &Lang<F, C>,
pc: usize,
) -> Result<Frame> {
Ok(self
.call(
args,
store,
Hints::new_from_func(self),
&mut vec![],
lang,
pc,
)?
.0)
self.call(
args,
store,
Hints::new_from_func(self),
&mut vec![],
lang,
pc,
)
}
}
1 change: 0 additions & 1 deletion src/lem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub mod eval;
pub(crate) mod interpreter;
mod macros;
pub mod multiframe;
mod path;
pub mod pointers;
mod slot;
pub mod store;
Expand Down
135 changes: 0 additions & 135 deletions src/lem/path.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/lem/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn synthesize_test_helper(
let mut cs_prev = None;
for input in inputs {
let input = [input, nil, outermost];
let (frame, _) = func
let frame = func
.call(&input, store, Default::default(), &mut vec![], &lang, 0)
.unwrap();

Expand Down

1 comment on commit 57dc325

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Table of Contents

Overview

This benchmark report shows the Fibonacci GPU benchmark.
NVIDIA L4
Intel(R) Xeon(R) CPU @ 2.20GHz
125.78 GB RAM
Workflow run: https://github.com/lurk-lab/lurk-rs/actions/runs/7531893309

Benchmark Results

LEM Fibonacci Prove - rc = 100

fib-ref=f9f87545a3ffa0cf921fa2557021a7b9040b7ad5 fib-ref=57dc325d780a3c65c0bdb590177b2aece54b1c95
num-100 1.74 s (✅ 1.00x) 1.74 s (✅ 1.00x faster)
num-200 3.36 s (✅ 1.00x) 3.36 s (✅ 1.00x slower)

LEM Fibonacci Prove - rc = 600

fib-ref=f9f87545a3ffa0cf921fa2557021a7b9040b7ad5 fib-ref=57dc325d780a3c65c0bdb590177b2aece54b1c95
num-100 2.02 s (✅ 1.00x) 2.02 s (✅ 1.00x faster)
num-200 3.38 s (✅ 1.00x) 3.38 s (✅ 1.00x faster)

Made with criterion-table

Please sign in to comment.