Skip to content

Commit

Permalink
add Op::Unit for general purpose debugging or data collection (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino authored Nov 16, 2023
1 parent 732a397 commit 3cb513b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lem/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ fn synthesize_block<F: LurkField, CS: ConstraintSystem<F>, C: Coprocessor<F>>(
bound_allocations.insert_ptr(tgt[0].clone(), div_ptr);
bound_allocations.insert_ptr(tgt[1].clone(), rem_ptr);
}
Op::Emit(_) => (),
Op::Emit(_) | Op::Unit(_) => (),
Op::Hide(tgt, sec, pay) => {
let sec = bound_allocations.get_ptr(sec)?;
let pay = bound_allocations.get_ptr(pay)?;
Expand Down Expand Up @@ -1501,7 +1501,7 @@ impl Func {
// three implies_u64, one sub and one linear
num_constraints += 197;
}
Op::Not(..) | Op::Emit(_) | Op::Cproc(..) | Op::Copy(..) => (),
Op::Not(..) | Op::Emit(_) | Op::Cproc(..) | Op::Copy(..) | Op::Unit(_) => (),
Op::Cons2(_, tag, _) => {
// tag for the image
globals.insert(FWrap(tag.to_field()));
Expand Down
1 change: 1 addition & 0 deletions src/lem/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ impl Block {
bindings.insert_ptr(tgt_secret.clone(), Ptr::Atom(Tag::Expr(Num), *secret));
hints.commitment.push(Some(SlotData::FPtr(*secret, *ptr)))
}
Op::Unit(f) => f(),
}
}
match &self.ctrl {
Expand Down
13 changes: 13 additions & 0 deletions src/lem/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ macro_rules! op {
let func = Box::new($func.clone());
$crate::lem::Op::Call(out, func, inp)
}
};
( unit($f:expr) ) => {
$crate::lem::Op::Unit($f)
}
}

Expand Down Expand Up @@ -591,6 +594,16 @@ macro_rules! block {
$($tail)*
)
};
(@seq {$($limbs:expr)*}, unit($f:expr) ; $($tail:tt)*) => {
$crate::block! (
@seq
{
$($limbs)*
$crate::op!(unit($f))
},
$($tail)*
)
};
(@seq {$($limbs:expr)*}, let ($($tgt:ident),*) = $func:ident($($arg:ident),*) ; $($tail:tt)*) => {
$crate::block! (
@seq
Expand Down
5 changes: 5 additions & 0 deletions src/lem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub enum Op {
/// `Open(s, p, h)` binds `s` and `p` to the secret and payload (respectively)
/// of the commitment that resulted on (num or comm) `h`
Open(Var, Var, Var),
Unit(fn()),
}

impl Func {
Expand Down Expand Up @@ -451,6 +452,7 @@ impl Func {
is_unique(tgt_secret, map);
is_unique(tgt_ptr, map);
}
Op::Unit(_) => (),
}
}
match &block.ctrl {
Expand Down Expand Up @@ -736,6 +738,9 @@ impl Block {
let pay = insert_one(map, uniq, &pay);
ops.push(Op::Open(sec, pay, comm_or_num))
}
Op::Unit(x) => {
ops.push(Op::Unit(x));
}
}
}
let ctrl = match self.ctrl {
Expand Down

1 comment on commit 3cb513b

@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 GeForce RTX 4070
AMD Ryzen 9 3950X 16-Core Processor
125.711 GB RAM

Benchmark Results

LEM Fibonacci Prove - rc = 100

fib-ref=732a397013f12f139aa9d647c5e63f58f3b7c808 fib-ref=3cb513b7a70dbea1f557fd38566fa53d9208b77b
num-100 3.98 s (✅ 1.00x) 3.94 s (✅ 1.01x faster)
num-200 8.10 s (✅ 1.00x) 8.06 s (✅ 1.01x faster)

LEM Fibonacci Prove - rc = 600

fib-ref=732a397013f12f139aa9d647c5e63f58f3b7c808 fib-ref=3cb513b7a70dbea1f557fd38566fa53d9208b77b
num-100 3.06 s (✅ 1.00x) 3.05 s (✅ 1.00x faster)
num-200 7.02 s (✅ 1.00x) 7.01 s (✅ 1.00x faster)

Made with criterion-table

Please sign in to comment.