Skip to content

profiling setup #1207

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
50b4f23
profiling setup
erabinov Jul 30, 2024
868385c
removed unnecessary
erabinov Jul 30, 2024
82b2615
Update domain.rs
erabinov Jul 30, 2024
2dcefe3
count reduce max bits
erabinov Jul 30, 2024
56a159a
removed over-reduce
erabinov Jul 31, 2024
5c51f21
push
jtguibas Jul 31, 2024
db58cb8
hm
jtguibas Jul 31, 2024
e764454
hm
jtguibas Jul 31, 2024
41e68c1
hm
jtguibas Jul 31, 2024
39d2d15
hm
jtguibas Jul 31, 2024
1532817
boom
jtguibas Jul 31, 2024
fccb5ed
hm
jtguibas Jul 31, 2024
546356f
hm
jtguibas Jul 31, 2024
a82de5c
hm
jtguibas Jul 31, 2024
0c5dc86
hm
jtguibas Jul 31, 2024
e6a00cf
more optimizations
jtguibas Jul 31, 2024
2e5f2b6
hm
jtguibas Jul 31, 2024
37ed86d
hm
jtguibas Jul 31, 2024
97f67ed
hm
jtguibas Jul 31, 2024
339df54
hm
jtguibas Jul 31, 2024
925e30f
weird
jtguibas Jul 31, 2024
cac4737
fixed inv e
jtguibas Jul 31, 2024
fb25af3
hm
jtguibas Jul 31, 2024
990b60f
hm
jtguibas Jul 31, 2024
3e1a837
acched proof
jtguibas Jul 31, 2024
4ecafa6
hm
jtguibas Jul 31, 2024
ca3de79
fix bug
jtguibas Jul 31, 2024
28567d9
Wtf
jtguibas Jul 31, 2024
22ddb4b
fix this issue
jtguibas Jul 31, 2024
b7cfdfe
with inv e opt
jtguibas Jul 31, 2024
b56bb4a
wiht inv f opt
jtguibas Jul 31, 2024
d5c510e
sanity check
jtguibas Aug 1, 2024
9e980eb
ambitious
jtguibas Aug 1, 2024
ed7a602
subef opt
jtguibas Aug 1, 2024
86926b3
hm
jtguibas Aug 1, 2024
1fd0645
fix
jtguibas Aug 1, 2024
f8bee8f
hm
jtguibas Aug 1, 2024
2cb0be8
hm
jtguibas Aug 1, 2024
292f713
fix
jtguibas Aug 1, 2024
6ed0bb5
finally
jtguibas Aug 1, 2024
f29575d
hm
jtguibas Aug 1, 2024
1ade34f
hm
jtguibas Aug 1, 2024
0e1f4b6
fix
jtguibas Aug 1, 2024
22b2a6d
hm
jtguibas Aug 1, 2024
96b0734
fix
jtguibas Aug 1, 2024
798c5f8
get rid of reduce F
jtguibas Aug 1, 2024
f1ff20c
hm
jtguibas Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@
pub mod tests {

use std::fs::File;
use std::io::{Read, Write};

Check failure on line 728 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

unused import: `Write`

Check warning on line 728 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (fast-experimental)

unused import: `Write`

Check warning on line 728 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `Write`

Check warning on line 728 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused import: `Write`

Check warning on line 728 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused import: `Write`

Check warning on line 728 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused import: `Write`

Check warning on line 728 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused import: `Write`

use super::*;

Expand All @@ -750,55 +750,55 @@

pub fn test_e2e_prover<C: SP1ProverComponents>(
elf: &[u8],
opts: SP1ProverOpts,

Check failure on line 753 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

unused variable: `opts`

Check warning on line 753 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (fast-experimental)

unused variable: `opts`

Check warning on line 753 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

unused variable: `opts`

Check warning on line 753 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `opts`

Check warning on line 753 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `opts`

Check warning on line 753 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `opts`

Check warning on line 753 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `opts`
test_kind: Test,
) -> Result<()> {
tracing::info!("initializing prover");
let prover: SP1Prover<C> = SP1Prover::<C>::new();
let context = SP1Context::default();

Check failure on line 758 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

unused variable: `context`

Check warning on line 758 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (fast-experimental)

unused variable: `context`

Check warning on line 758 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

unused variable: `context`

Check warning on line 758 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `context`

Check warning on line 758 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `context`

Check warning on line 758 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `context`

Check warning on line 758 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `context`

tracing::info!("setup elf");
let (pk, vk) = prover.setup(elf);

Check failure on line 761 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

unused variable: `pk`

Check warning on line 761 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (fast-experimental)

unused variable: `pk`

Check warning on line 761 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

unused variable: `pk`

Check warning on line 761 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `pk`

Check warning on line 761 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `pk`

Check warning on line 761 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `pk`

Check warning on line 761 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `pk`

tracing::info!("prove core");
let stdin = SP1Stdin::new();
let core_proof = prover.prove_core(&pk, &stdin, opts, context)?;
let public_values = core_proof.public_values.clone();
// tracing::info!("prove core");
// let stdin = SP1Stdin::new();
// let core_proof = prover.prove_core(&pk, &stdin, opts, context)?;
// let public_values = core_proof.public_values.clone();

tracing::info!("verify core");
prover.verify(&core_proof.proof, &vk)?;
// tracing::info!("verify core");
// prover.verify(&core_proof.proof, &vk)?;

if test_kind == Test::Core {
return Ok(());
}
// if test_kind == Test::Core {
// return Ok(());
// }

tracing::info!("compress");
let compressed_proof = prover.compress(&vk, core_proof, vec![], opts)?;
// tracing::info!("compress");
// let compressed_proof = prover.compress(&vk, core_proof, vec![], opts)?;

tracing::info!("verify compressed");
prover.verify_compressed(&compressed_proof, &vk)?;
// tracing::info!("verify compressed");
// prover.verify_compressed(&compressed_proof, &vk)?;

if test_kind == Test::Compress {
return Ok(());
}
// if test_kind == Test::Compress {
// return Ok(());
// }

tracing::info!("shrink");
let shrink_proof = prover.shrink(compressed_proof, opts)?;
// tracing::info!("shrink");
// let shrink_proof = prover.shrink(compressed_proof, opts)?;

tracing::info!("verify shrink");
prover.verify_shrink(&shrink_proof, &vk)?;
// tracing::info!("verify shrink");
// prover.verify_shrink(&shrink_proof, &vk)?;

if test_kind == Test::Shrink {
return Ok(());
}
// if test_kind == Test::Shrink {
// return Ok(());
// }

tracing::info!("wrap bn254");
let wrapped_bn254_proof = prover.wrap_bn254(shrink_proof, opts)?;
let bytes = bincode::serialize(&wrapped_bn254_proof).unwrap();
// tracing::info!("wrap bn254");
// let wrapped_bn254_proof = prover.wrap_bn254(shrink_proof, opts)?;
// let bytes = bincode::serialize(&wrapped_bn254_proof).unwrap();

// Save the proof.
let mut file = File::create("proof-with-pis.bin").unwrap();
file.write_all(bytes.as_slice()).unwrap();
// // Save the proof.
// let mut file = File::create("proof-with-pis.bin").unwrap();
// file.write_all(bytes.as_slice()).unwrap();

// Load the proof.
let mut file = File::open("proof-with-pis.bin").unwrap();
Expand Down Expand Up @@ -828,7 +828,7 @@
let plonk_bn254_proof = prover.wrap_plonk_bn254(wrapped_bn254_proof, &artifacts_dir);
println!("{:?}", plonk_bn254_proof);

prover.verify_plonk_bn254(&plonk_bn254_proof, &vk, &public_values, &artifacts_dir)?;
// prover.verify_plonk_bn254(&plonk_bn254_proof, &vk, &public_values, &artifacts_dir)?;

Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions recursion/circuit-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ rand = "0.8.5"

[features]
native-gnark = ["sp1-recursion-gnark-ffi/native"]

[[bin]]
name = "circuit-architecture-sweep"
path = "scripts/circuit_architecture_sweep.rs"
70 changes: 35 additions & 35 deletions recursion/circuit-v2/scripts/circuit_architecture_sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use p3_baby_bear::BabyBear;

use sp1_core::{stark::StarkMachine, utils::log2_strict_usize};
use sp1_recursion_circuit_v2::build_wrap_v2::{machine_with_all_chips, test_machine};

Check warning on line 6 in recursion/circuit-v2/scripts/circuit_architecture_sweep.rs

View workflow job for this annotation

GitHub Actions / Test (fast-experimental)

unused import: `machine_with_all_chips`

Check warning on line 6 in recursion/circuit-v2/scripts/circuit_architecture_sweep.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused import: `machine_with_all_chips`

Check warning on line 6 in recursion/circuit-v2/scripts/circuit_architecture_sweep.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused import: `machine_with_all_chips`
use sp1_recursion_core::stark::config::BabyBearPoseidon2Outer;
use sp1_recursion_core_v2::machine::RecursionAir;

Expand All @@ -18,49 +18,49 @@

fn main() {
// Test the performance of the full architecture with different degrees.
let machine_maker_3 = || machine_with_all_chips::<3>(16, 16, 16);
let machine_maker_5 = || machine_with_all_chips::<5>(16, 16, 16);
let machine_maker_9 = || machine_with_all_chips::<9>(16, 16, 16);
let machine_maker_17 = || machine_with_all_chips::<17>(16, 16, 16);
test_machine(machine_maker_3);
test_machine(machine_maker_5);
test_machine(machine_maker_9);
test_machine(machine_maker_17);
// let machine_maker_3 = || machine_with_all_chips::<3>(16, 16, 16);
// let machine_maker_5 = || machine_with_all_chips::<5>(16, 16, 16);
// let machine_maker_9 = || machine_with_all_chips::<9>(16, 16, 16);
// let machine_maker_17 = || machine_with_all_chips::<17>(16, 16, 16);
// test_machine(machine_maker_3);
// test_machine(machine_maker_5);
// test_machine(machine_maker_9);
// test_machine(machine_maker_17);

// Test the performance of the machine with the full architecture for different numbers of rows
// in the precompiles. Degree is set to 9.
let machine_maker = |i| machine_with_all_chips::<9>(i, i, i);
for i in 1..=5 {
test_machine(|| machine_maker(i));
}
// let machine_maker = |i| machine_with_all_chips::<9>(i, i, i);
// for i in 1..=5 {
// test_machine(|| machine_maker(i));
// }

// Test the performance of the dummy machine for different numbers of columns in the dummy table.
// Degree is kept fixed at 9.
test_machine(|| machine_with_dummy::<9, 1>(16));
test_machine(|| machine_with_dummy::<9, 50>(16));
test_machine(|| machine_with_dummy::<9, 100>(16));
test_machine(|| machine_with_dummy::<9, 150>(16));
test_machine(|| machine_with_dummy::<9, 200>(16));
test_machine(|| machine_with_dummy::<9, 250>(16));
test_machine(|| machine_with_dummy::<9, 300>(16));
test_machine(|| machine_with_dummy::<9, 350>(16));
test_machine(|| machine_with_dummy::<9, 400>(16));
test_machine(|| machine_with_dummy::<9, 450>(16));
test_machine(|| machine_with_dummy::<9, 500>(16));
test_machine(|| machine_with_dummy::<9, 550>(16));
test_machine(|| machine_with_dummy::<9, 600>(16));
test_machine(|| machine_with_dummy::<9, 650>(16));
test_machine(|| machine_with_dummy::<9, 700>(16));
test_machine(|| machine_with_dummy::<9, 750>(16));
// test_machine(|| machine_with_dummy::<9, 1>(16));
// test_machine(|| machine_with_dummy::<9, 50>(16));
// test_machine(|| machine_with_dummy::<9, 100>(16));
// test_machine(|| machine_with_dummy::<9, 150>(16));
// test_machine(|| machine_with_dummy::<9, 200>(16));
// test_machine(|| machine_with_dummy::<9, 250>(16));
// test_machine(|| machine_with_dummy::<9, 300>(16));
// test_machine(|| machine_with_dummy::<9, 350>(16));
// test_machine(|| machine_with_dummy::<9, 400>(16));
// test_machine(|| machine_with_dummy::<9, 450>(16));
// test_machine(|| machine_with_dummy::<9, 500>(16));
// test_machine(|| machine_with_dummy::<9, 550>(16));
// test_machine(|| machine_with_dummy::<9, 600>(16));
// test_machine(|| machine_with_dummy::<9, 650>(16));
// test_machine(|| machine_with_dummy::<9, 700>(16));
test_machine(|| machine_with_dummy::<5, 130>(18));

// Test the performance of the dummy machine for different heights of the dummy table.
for i in 4..=7 {
test_machine(|| machine_with_dummy::<9, 1>(i));
}
// for i in 4..=7 {
// test_machine(|| machine_with_dummy::<9, 1>(i));
// }

// Change the degree for the dummy table, keeping other parameters fixed.
test_machine(|| machine_with_dummy::<3, 500>(16));
test_machine(|| machine_with_dummy::<5, 500>(16));
test_machine(|| machine_with_dummy::<9, 500>(16));
test_machine(|| machine_with_dummy::<17, 500>(16));
// test_machine(|| machine_with_dummy::<3, 500>(16));
// test_machine(|| machine_with_dummy::<5, 500>(16));
// test_machine(|| machine_with_dummy::<9, 500>(16));
// test_machine(|| machine_with_dummy::<17, 500>(16));
}
10 changes: 9 additions & 1 deletion recursion/circuit/src/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub fn verify_two_adic_pcs<C: Config>(
challenger: &mut MultiField32ChallengerVariable<C>,
rounds: Vec<TwoAdicPcsRoundVariable<C>>,
) {
let mut counter = 0;
let alpha = challenger.sample_ext(builder);

let fri_challenges =
Expand Down Expand Up @@ -129,12 +130,17 @@ pub fn verify_two_adic_pcs<C: Config>(
for (z, ps_at_z) in izip!(mat_points, mat_values) {
let mut acc: Ext<C::F, C::EF> =
builder.eval(SymbolicExt::from_f(C::EF::zero()));
counter += 1;
for (p_at_x, &p_at_z) in izip!(mat_opening.clone(), ps_at_z) {
let pow = log_height_pow[log_height];

// Fill in any missing powers of alpha.
(alpha_pows.len()..pow + 1).for_each(|_| {
alpha_pows.push(builder.eval(*alpha_pows.last().unwrap() * alpha));
let alpha = builder.eval(*alpha_pows.last().unwrap() * alpha);
builder.operations.push(DslIr::ReduceE(alpha));
alpha_pows.push(alpha);
});

acc = builder.eval(acc + (alpha_pows[pow] * (p_at_z - p_at_x[0])));
log_height_pow[log_height] += 1;
}
Expand All @@ -146,6 +152,8 @@ pub fn verify_two_adic_pcs<C: Config>(
})
.collect::<Vec<_>>();

println!("Counter: {}", counter);

verify_challenges(
builder,
config,
Expand Down
8 changes: 8 additions & 0 deletions recursion/compiler/src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ impl<C: Config + Debug> ConstraintCompiler<C> {
vec![a[3].id()],
],
}),
DslIr::ReduceF(a) => constraints.push(Constraint {
opcode: ConstraintOpcode::ReduceF,
args: vec![vec![a.id()]],
}),
DslIr::ReduceE(a) => constraints.push(Constraint {
opcode: ConstraintOpcode::ReduceE,
args: vec![vec![a.id()]],
}),
_ => panic!("unsupported {:?}", instruction),
};
}
Expand Down
2 changes: 2 additions & 0 deletions recursion/compiler/src/constraints/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ pub enum ConstraintOpcode {
CommitCommitedValuesDigest,
CircuitFelts2Ext,
PermuteBabyBear,
ReduceF,
ReduceE,
}
4 changes: 4 additions & 0 deletions recursion/compiler/src/ir/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub enum DslIr<C: Config> {
/// Assigns an ext field immediate to an extension field element (ext = ext field imm).
ImmE(Ext<C::F, C::EF>, C::EF),

/// Force the reduction of an extension field element.
ReduceF(Felt<C::F>),
ReduceE(Ext<C::F, C::EF>),

// Additions.
/// Add two variables (var = var + var).
AddV(Var<C::N>, Var<C::N>, Var<C::N>),
Expand Down
5 changes: 5 additions & 0 deletions recursion/compiler/src/ir/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,11 @@ impl<F: Field, EF: ExtensionField<F>> Ext<F, EF> {
(SymbolicExt::Val(lhs, _), SymbolicExt::Val(rhs, _)) => {
builder.push(DslIr::SubE(*self, *lhs, *rhs));
}
(SymbolicExt::Val(lhs, _), SymbolicExt::Base(rhs, _)) => {
let sym: SymbolicFelt<_> = rhs.as_ref().clone();
let rhs: Felt<_> = builder.eval(sym);
builder.push(DslIr::SubEF(*self, *lhs, rhs));
}
(SymbolicExt::Val(lhs, _), rhs) => {
let rhs_value = Self::uninit(builder);
rhs_value.assign_with_caches(rhs.clone(), builder, ext_cache, base_cache);
Expand Down
62 changes: 30 additions & 32 deletions recursion/gnark-ffi/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ import (

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/groth16"
"github.com/consensys/gnark/backend/plonk"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/r1cs"
"github.com/consensys/gnark/frontend/cs/scs"
"github.com/consensys/gnark/test/unsafekzg"
"github.com/succinctlabs/sp1-recursion-gnark/sp1"
"github.com/succinctlabs/sp1-recursion-gnark/sp1/babybear"
"github.com/succinctlabs/sp1-recursion-gnark/sp1/poseidon2"
Expand Down Expand Up @@ -112,36 +109,37 @@ func TestMain() error {

// Compile the circuit.
circuit := sp1.NewCircuit(inputs)
builder := scs.NewBuilder
scs, err := frontend.Compile(ecc.BN254.ScalarField(), builder, &circuit)
if err != nil {
return err
}
fmt.Println("[sp1] gnark verifier constraints:", scs.GetNbConstraints())

// Run the dummy setup.
srs, srsLagrange, err := unsafekzg.NewSRS(scs)
if err != nil {
return err
}
var pk plonk.ProvingKey
pk, _, err = plonk.Setup(scs, srs, srsLagrange)
if err != nil {
return err
}

// Generate witness.
assignment := sp1.NewCircuit(inputs)
witness, err := frontend.NewWitness(&assignment, ecc.BN254.ScalarField())
if err != nil {
return err
}

// Generate the proof.
_, err = plonk.Prove(scs, pk, witness)
// builder := scs.NewBuilder
// Compile the circuit.
r1cs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
return err
}
panic(err)
}
fmt.Println("Groth16 Constraints:", r1cs.GetNbConstraints())

// // Run the dummy setup.
// srs, srsLagrange, err := unsafekzg.NewSRS(scs)
// if err != nil {
// return err
// }
// var pk plonk.ProvingKey
// pk, _, err = plonk.Setup(scs, srs, srsLagrange)
// if err != nil {
// return err
// }

// // Generate witness.
// assignment := sp1.NewCircuit(inputs)
// witness, err := frontend.NewWitness(&assignment, ecc.BN254.ScalarField())
// if err != nil {
// return err
// }

// // Generate the proof.
// _, err = plonk.Prove(scs, pk, witness)
// if err != nil {
// return err
// }

return nil
}
Expand Down
Loading
Loading