Skip to content

Commit

Permalink
Generalize benchmark setup; remove dep on N to allow big tables
Browse files Browse the repository at this point in the history
  • Loading branch information
sragss committed Jul 29, 2023
1 parent 97d6c85 commit 2f0db91
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ harness = false
[profile.release]
debug = true
codegen-units = 1
lto = "fat"
lto = "fat"
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![imgs/lasso_logo.png](imgs/lasso_logo.png)

# Lasso
Lookup Arguments via Sum-check and Sparse polynomial commitments, including for Oversized tables

Expand All @@ -23,10 +25,9 @@ Lookup Arguments via Sum-check and Sparse polynomial commitments, including for

## Cmds
- `cargo build --release`
- `cargo run --release `
- `cargo run --release -- --chart`: Display performance gant chart
- `cargo run --release --features ark-msm`: Run without MSM small field optimizations
- `cargo run --release -- --name <bench_name>`
- `cargo run --release -- --name <bench_name> --chart`: Display performance gant chart
- `cargo run --release --name <bench_name> --features ark-msm`: Run without MSM small field optimizations
- `sudo cargo flamegraph`
- `cargo bench`

*Note on benching / flamegraphing: Turn off the parallel feature in Cargo.toml (`multicore`) and / or `export RAYON_NUM_THREADS=1` to make flamegraph more interpretable. Turning off `multicore` and leaving `unset RAYON_NUM_THREADS` allows testing Arkworks MSM parallelism without Lasso parallelism.*
Binary file added imgs/lasso_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 87 additions & 16 deletions src/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use ark_curve25519::{EdwardsProjective, Fr};
use ark_ff::PrimeField;
use ark_std::{log2, test_rng};
use merlin::Transcript;
use num_integer::Roots;
use rand_chacha::rand_core::RngCore;

pub fn gen_indices<const C: usize>(sparsity: usize, memory_size: usize) -> Vec<[usize; C]> {
Expand All @@ -40,19 +39,16 @@ pub fn gen_random_point<F: PrimeField>(memory_bits: usize) -> Vec<F> {
}

macro_rules! single_pass_lasso {
($span_name:expr, $field:ty, $group:ty, $subtable_strategy:ty, $N:expr, $C:expr, $M:expr, $sparsity:expr) => {
($span_name:expr, $field:ty, $group:ty, $subtable_strategy:ty, $C:expr, $M:expr, $sparsity:expr) => {
(tracing::info_span!($span_name), move || {
const N: usize = $N;
const C: usize = $C;
const M: usize = $M;
const S: usize = $sparsity;
type F = $field;
type G = $group;
type SubtableStrategy = $subtable_strategy;

let m_computed = N.nth_root(C as u32);
assert_eq!(m_computed, M);
let log_m = log2(m_computed) as usize;
let log_m = log2(M) as usize;
let log_s: usize = log2($sparsity) as usize;

let r: Vec<F> = gen_random_point::<F>(log_s);
Expand All @@ -77,14 +73,96 @@ macro_rules! single_pass_lasso {
};
}

pub fn benchmarks() -> Vec<(tracing::Span, fn())> {
#[derive(Debug, Clone, clap::ValueEnum)]
pub enum BenchType {
JoltDemo,
Halo2Comparison,
}

pub fn benchmarks(bench_type: BenchType) -> Vec<(tracing::Span, fn())> {
match bench_type {
BenchType::JoltDemo => jolt_demo_benchmarks(),
BenchType::Halo2Comparison => halo2_comparison_benchmarks(),
_ => panic!("BenchType does not have a mapping")
}
}

fn jolt_demo_benchmarks() -> Vec<(tracing::Span, fn())> {
vec![
single_pass_lasso!(
"And(2^128, 2^10)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 8,
/* M= */ 1 << 16,
/* S= */ 1 << 10
),
single_pass_lasso!(
"And(2^128, 2^12)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 8,
/* M= */ 1 << 16,
/* S= */ 1 << 12
),
single_pass_lasso!(
"And(2^128, 2^14)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 8,
/* M= */ 1 << 16,
/* S= */ 1 << 14
),
single_pass_lasso!(
"And(2^128, 2^16)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 8,
/* M= */ 1 << 16,
/* S= */ 1 << 16
),
single_pass_lasso!(
"And(2^128, 2^18)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 8,
/* M= */ 1 << 16,
/* S= */ 1 << 18
),
single_pass_lasso!(
"And(2^128, 2^20)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 8,
/* M= */ 1 << 16,
/* S= */ 1 << 20
),
single_pass_lasso!(
"And(2^128, 2^22)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 8,
/* M= */ 1 << 16,
/* S= */ 1 << 22
),
]
}


fn halo2_comparison_benchmarks() -> Vec<(tracing::Span, fn())> {
vec![
single_pass_lasso!(
"And(2^10)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* N= */ 1 << 16,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 10
Expand All @@ -94,7 +172,6 @@ pub fn benchmarks() -> Vec<(tracing::Span, fn())> {
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* N= */ 1 << 16,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 12
Expand All @@ -104,7 +181,6 @@ pub fn benchmarks() -> Vec<(tracing::Span, fn())> {
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* N= */ 1 << 16,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 14
Expand All @@ -114,7 +190,6 @@ pub fn benchmarks() -> Vec<(tracing::Span, fn())> {
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* N= */ 1 << 16,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 16
Expand All @@ -124,7 +199,6 @@ pub fn benchmarks() -> Vec<(tracing::Span, fn())> {
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* N= */ 1 << 16,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 18
Expand All @@ -134,7 +208,6 @@ pub fn benchmarks() -> Vec<(tracing::Span, fn())> {
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* N= */ 1 << 16,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 20
Expand All @@ -144,7 +217,6 @@ pub fn benchmarks() -> Vec<(tracing::Span, fn())> {
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* N= */ 1 << 16,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 22
Expand All @@ -154,10 +226,9 @@ pub fn benchmarks() -> Vec<(tracing::Span, fn())> {
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* N= */ 1 << 16,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 24
),
]
}
}
12 changes: 8 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
use libspartan::benches::bench::benchmarks;
use libspartan::benches::bench::{benchmarks, BenchType};
use tracing_subscriber::{self, fmt::format::FmtSpan};

use clap::Parser;

/// Search for a pattern in a file and display the lines that contain it.
#[derive(Parser)]
#[derive(Parser, Debug)]
struct Cli {
/// Whether to present in chart format
#[clap(long, short, action)]
chart: bool,

/// Type of benchmark to run
#[clap(long, value_enum)]
name: BenchType
}

fn main() {
let args = Cli::parse();
if args.chart {
tracing_texray::init();
benchmarks().iter().for_each(|(span, bench)| {
benchmarks(args.name).iter().for_each(|(span, bench)| {
tracing_texray::examine(span.to_owned()).in_scope(|| bench());
});
} else {
Expand All @@ -24,7 +28,7 @@ fn main() {
.with_span_events(FmtSpan::CLOSE)
.finish();
tracing::subscriber::set_global_default(collector).expect("setting tracing default failed");
benchmarks().iter().for_each(|(span, bench)| {
benchmarks(args.name).iter().for_each(|(span, bench)| {
span.to_owned().in_scope(|| {
bench();
tracing::info!("Bench Complete");
Expand Down

0 comments on commit 2f0db91

Please sign in to comment.