Skip to content

Commit

Permalink
Separate coroutine circuits. (#1076)
Browse files Browse the repository at this point in the history
* Separate coroutine circuits.

* Add per-coroutine-circuit rc.

---------

Co-authored-by: porcuquine <porcuquine@users.noreply.github.com>
  • Loading branch information
porcuquine and porcuquine authored Jan 31, 2024
1 parent fbd3e1c commit fe1fdeb
Show file tree
Hide file tree
Showing 3 changed files with 397 additions and 119 deletions.
38 changes: 23 additions & 15 deletions src/coroutine/memoset/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};

use super::{
query::{CircuitQuery, Query},
CircuitScope, CircuitTranscript, LogMemo, Scope,
CircuitScope, CircuitTranscript, LogMemo, LogMemoCircuit, Scope,
};
use crate::circuit::gadgets::constraints::alloc_is_zero;
use crate::circuit::gadgets::pointer::AllocatedPtr;
Expand Down Expand Up @@ -88,6 +88,22 @@ impl<F: LurkField> Query<F> for DemoQuery<F> {
}
}

fn to_circuit<CS: ConstraintSystem<F>>(&self, cs: &mut CS, s: &Store<F>) -> Self::CQ {
match self {
DemoQuery::Factorial(n) => {
Self::CQ::Factorial(AllocatedPtr::alloc_infallible(cs, || s.hash_ptr(n)))
}
_ => unreachable!(),
}
}

fn dummy_from_index(s: &Store<F>, index: usize) -> Self {
match index {
0 => Self::Factorial(s.num(0.into())),
_ => unreachable!(),
}
}

fn index(&self) -> usize {
match self {
Self::Factorial(_) => 0,
Expand All @@ -106,7 +122,7 @@ impl<F: LurkField> CircuitQuery<F> for DemoCircuitQuery<F> {
cs: &mut CS,
g: &GlobalAllocator<F>,
store: &Store<F>,
scope: &mut CircuitScope<F, LogMemo<F>>,
scope: &mut CircuitScope<F, LogMemoCircuit<F>>,
acc: &AllocatedPtr<F>,
transcript: &CircuitTranscript<F>,
) -> Result<(AllocatedPtr<F>, AllocatedPtr<F>, CircuitTranscript<F>), SynthesisError> {
Expand Down Expand Up @@ -208,19 +224,11 @@ impl<F: LurkField> CircuitQuery<F> for DemoCircuitQuery<F> {
}

fn from_ptr<CS: ConstraintSystem<F>>(cs: &mut CS, s: &Store<F>, ptr: &Ptr) -> Option<Self> {
let query = DemoQuery::from_ptr(s, ptr);
if let Some(q) = query {
match q {
DemoQuery::Factorial(n) => {
Some(Self::Factorial(AllocatedPtr::alloc_infallible(cs, || {
s.hash_ptr(&n)
})))
}
_ => unreachable!(),
}
} else {
None
}
DemoQuery::from_ptr(s, ptr).map(|q| q.to_circuit(cs, s))
}

fn dummy_from_index<CS: ConstraintSystem<F>>(cs: &mut CS, s: &Store<F>, index: usize) -> Self {
DemoQuery::dummy_from_index(s, index).to_circuit(cs, s)
}

fn symbol(&self) -> Symbol {
Expand Down
Loading

1 comment on commit fe1fdeb

@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
32 vCPUs
125 GB RAM
Workflow run: https://github.com/lurk-lab/lurk-rs/actions/runs/7719066991

Benchmark Results

LEM Fibonacci Prove - rc = 100

ref=fbd3e1c29071fcbd639f3750de7cb992e3054819 ref=fe1fdeb990a0b5074c1fc5a537e35f85fc87b673
num-100 1.34 s (✅ 1.00x) 1.35 s (✅ 1.00x slower)
num-200 2.57 s (✅ 1.00x) 2.58 s (✅ 1.00x slower)

LEM Fibonacci Prove - rc = 600

ref=fbd3e1c29071fcbd639f3750de7cb992e3054819 ref=fe1fdeb990a0b5074c1fc5a537e35f85fc87b673
num-100 1.61 s (✅ 1.00x) 1.61 s (✅ 1.00x slower)
num-200 2.69 s (✅ 1.00x) 2.70 s (✅ 1.00x slower)

Made with criterion-table

Please sign in to comment.