Skip to content

Commit

Permalink
Multi crate infrastructure (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharsamocha7 authored Apr 16, 2024
1 parent 61963ec commit a5e69d9
Show file tree
Hide file tree
Showing 100 changed files with 243 additions and 218 deletions.
195 changes: 101 additions & 94 deletions Cargo.lock

Large diffs are not rendered by default.

62 changes: 6 additions & 56 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,72 +1,22 @@
[package]
[workspace]
members = ["crates/prover"]

[workspace.package]
name = "stwo"
version = "0.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
[workspace.dependencies]
blake2 = "0.10.6"
blake3 = "1.5.0"
derivative = "2.2.0"
hex = "0.4.3"
itertools = "0.12.0"
num-traits = "0.2.17"
thiserror = "1.0.56"
bytemuck = { version = "1.14.3", features = ["derive"] }
bytemuck = "1.14.3"
tracing = "0.1.40"

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
rand = { version = "0.8.5", features = ["small_rng"] }
tracing-subscriber = "0.3.18"
test-log = { version = "0.2.15", features = ["trace"] }

[lib]
bench = false

[lints.rust]
warnings = "deny"
future-incompatible = "deny"
nonstandard-style = "deny"
rust-2018-idioms = "deny"
unused = "deny"

[features]
avx512 = []

[profile.bench]
codegen-units = 1
lto = true

[[bench]]
name = "bit_rev"
harness = false

[[bench]]
name = "fft"
harness = false

[[bench]]
harness = false
name = "field"

[[bench]]
harness = false
name = "matrix"

[[bench]]
name = "merkle"
harness = false

[[bench]]
name = "fri"
harness = false

[[bench]]
name = "eval_at_point"
harness = false

[[bench]]
name = "quotients"
harness = false
68 changes: 68 additions & 0 deletions crates/prover/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[package]
name = "prover"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
blake2.workspace = true
blake3.workspace = true
derivative.workspace = true
hex.workspace = true
itertools.workspace = true
num-traits.workspace = true
thiserror.workspace = true
bytemuck = { workspace = true, features = ["derive"] }
tracing.workspace = true

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
rand = { version = "0.8.5", features = ["small_rng"] }
test-log = { version = "0.2.15", features = ["trace"] }
tracing-subscriber = "0.3.18"

[lib]
bench = false

[lints.rust]
warnings = "deny"
future-incompatible = "deny"
nonstandard-style = "deny"
rust-2018-idioms = "deny"
unused = "deny"

[features]
avx512 = []

[[bench]]
name = "bit_rev"
harness = false

[[bench]]
name = "fft"
harness = false

[[bench]]
harness = false
name = "field"

[[bench]]
harness = false
name = "matrix"

[[bench]]
name = "merkle"
harness = false

[[bench]]
name = "fri"
harness = false

[[bench]]
name = "eval_at_point"
harness = false

[[bench]]
name = "quotients"
harness = false
File renamed without changes.
12 changes: 6 additions & 6 deletions benches/bit_rev.rs → crates/prover/benches/bit_rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use criterion::Criterion;

#[cfg(target_arch = "x86_64")]
pub fn cpu_bit_rev(c: &mut criterion::Criterion) {
use stwo::core::fields::m31::BaseField;
use prover::core::fields::m31::BaseField;

const SIZE: usize = 1 << 24;
let mut data: Vec<_> = (0..SIZE as u32)
Expand All @@ -13,18 +13,18 @@ pub fn cpu_bit_rev(c: &mut criterion::Criterion) {

c.bench_function("cpu bit_rev 24bit", |b| {
b.iter(|| {
stwo::core::utils::bit_reverse(&mut data);
prover::core::utils::bit_reverse(&mut data);
})
});
}

#[cfg(target_arch = "x86_64")]
pub fn avx512_bit_rev(c: &mut criterion::Criterion) {
use bytemuck::cast_slice_mut;
use stwo::core::backend::avx512::bit_reverse::bit_reverse_m31;
use stwo::core::backend::avx512::m31::PackedBaseField;
use stwo::core::fields::m31::BaseField;
use stwo::platform;
use prover::core::backend::avx512::bit_reverse::bit_reverse_m31;
use prover::core::backend::avx512::m31::PackedBaseField;
use prover::core::fields::m31::BaseField;
use prover::platform;
if !platform::avx512_detected() {
return;
}
Expand Down
24 changes: 12 additions & 12 deletions benches/eval_at_point.rs → crates/prover/benches/eval_at_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use criterion::{black_box, Criterion};

#[cfg(target_arch = "x86_64")]
pub fn cpu_eval_at_secure_point(c: &mut criterion::Criterion) {
use prover::core::backend::CPUBackend;
use prover::core::circle::CirclePoint;
use prover::core::fields::m31::BaseField;
use prover::core::fields::qm31::QM31;
use prover::core::poly::circle::{CanonicCoset, CircleEvaluation, PolyOps};
use prover::core::poly::NaturalOrder;
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use stwo::core::backend::CPUBackend;
use stwo::core::circle::CirclePoint;
use stwo::core::fields::m31::BaseField;
use stwo::core::fields::qm31::QM31;
use stwo::core::poly::circle::{CanonicCoset, CircleEvaluation, PolyOps};
use stwo::core::poly::NaturalOrder;
let log_size = 20;
let rng = &mut StdRng::seed_from_u64(0);

Expand Down Expand Up @@ -44,14 +44,14 @@ pub fn cpu_eval_at_secure_point(c: &mut criterion::Criterion) {

#[cfg(target_arch = "x86_64")]
pub fn avx512_eval_at_secure_point(c: &mut criterion::Criterion) {
use prover::core::backend::avx512::AVX512Backend;
use prover::core::circle::CirclePoint;
use prover::core::fields::m31::BaseField;
use prover::core::fields::qm31::QM31;
use prover::core::poly::circle::{CanonicCoset, CircleEvaluation, PolyOps};
use prover::core::poly::NaturalOrder;
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use stwo::core::backend::avx512::AVX512Backend;
use stwo::core::circle::CirclePoint;
use stwo::core::fields::m31::BaseField;
use stwo::core::fields::qm31::QM31;
use stwo::core::poly::circle::{CanonicCoset, CircleEvaluation, PolyOps};
use stwo::core::poly::NaturalOrder;
let log_size = 20;
let rng = &mut StdRng::seed_from_u64(0);

Expand Down
22 changes: 11 additions & 11 deletions benches/fft.rs → crates/prover/benches/fft.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#![feature(iter_array_chunks)]

use criterion::{BenchmarkId, Criterion, Throughput};
use stwo::core::backend::avx512::fft::ifft::get_itwiddle_dbls;
use stwo::core::backend::avx512::fft::transpose_vecs;
use stwo::core::backend::avx512::{BaseFieldVec, PackedBaseField};
use stwo::core::fields::m31::BaseField;
use stwo::core::poly::circle::CanonicCoset;
use prover::core::backend::avx512::fft::ifft::get_itwiddle_dbls;
use prover::core::backend::avx512::fft::transpose_vecs;
use prover::core::backend::avx512::{BaseFieldVec, PackedBaseField};
use prover::core::fields::m31::BaseField;
use prover::core::poly::circle::CanonicCoset;

#[cfg(target_arch = "x86_64")]
pub fn avx512_ifft(c: &mut criterion::Criterion) {
use stwo::core::backend::avx512::fft::ifft;
use stwo::platform;
use prover::core::backend::avx512::fft::ifft;
use prover::platform;
if !platform::avx512_detected() {
return;
}
Expand Down Expand Up @@ -39,8 +39,8 @@ pub fn avx512_ifft(c: &mut criterion::Criterion) {

#[cfg(target_arch = "x86_64")]
pub fn avx512_ifft_parts(c: &mut criterion::Criterion) {
use stwo::core::backend::avx512::fft::ifft;
use stwo::platform;
use prover::core::backend::avx512::fft::ifft;
use prover::platform;
if !platform::avx512_detected() {
return;
}
Expand Down Expand Up @@ -95,8 +95,8 @@ pub fn avx512_ifft_parts(c: &mut criterion::Criterion) {

#[cfg(target_arch = "x86_64")]
pub fn avx512_rfft(c: &mut criterion::Criterion) {
use stwo::core::backend::avx512::fft::rfft;
use stwo::platform;
use prover::core::backend::avx512::fft::rfft;
use prover::platform;
if !platform::avx512_detected() {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions benches/field.rs → crates/prover/benches/field.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use criterion::Criterion;
use prover::core::fields::cm31::CM31;
use prover::core::fields::m31::{M31, P};
use prover::core::fields::qm31::SecureField;
use rand::rngs::ThreadRng;
use rand::Rng;
use stwo::core::fields::cm31::CM31;
use stwo::core::fields::m31::{M31, P};
use stwo::core::fields::qm31::SecureField;
pub const N_ELEMENTS: usize = 1 << 16;
pub const N_STATE_ELEMENTS: usize = 8;

Expand Down Expand Up @@ -131,8 +131,8 @@ pub fn qm31_operations_bench(c: &mut criterion::Criterion) {

#[cfg(target_arch = "x86_64")]
pub fn avx512_m31_operations_bench(c: &mut criterion::Criterion) {
use stwo::core::backend::avx512::m31::{PackedBaseField, K_BLOCK_SIZE};
use stwo::platform;
use prover::core::backend::avx512::m31::{PackedBaseField, K_BLOCK_SIZE};
use prover::platform;

if !platform::avx512_detected() {
return;
Expand Down
14 changes: 7 additions & 7 deletions benches/fri.rs → crates/prover/benches/fri.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use stwo::core::backend::CPUBackend;
use stwo::core::fields::m31::BaseField;
use stwo::core::fields::qm31::SecureField;
use stwo::core::fields::secure_column::SecureColumn;
use stwo::core::fri::FriOps;
use stwo::core::poly::circle::{CanonicCoset, PolyOps};
use stwo::core::poly::line::{LineDomain, LineEvaluation};
use prover::core::backend::CPUBackend;
use prover::core::fields::m31::BaseField;
use prover::core::fields::qm31::SecureField;
use prover::core::fields::secure_column::SecureColumn;
use prover::core::fri::FriOps;
use prover::core::poly::circle::{CanonicCoset, PolyOps};
use prover::core::poly::line::{LineDomain, LineEvaluation};

fn folding_benchmark(c: &mut Criterion) {
const LOG_SIZE: u32 = 12;
Expand Down
6 changes: 3 additions & 3 deletions benches/matrix.rs → crates/prover/benches/matrix.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use prover::core::fields::m31::{M31, P};
use prover::core::fields::qm31::QM31;
use prover::math::matrix::{RowMajorMatrix, SquareMatrix};
use rand::Rng;
use stwo::core::fields::m31::{M31, P};
use stwo::core::fields::qm31::QM31;
use stwo::math::matrix::{RowMajorMatrix, SquareMatrix};

const MATRIX_SIZE: usize = 24;
const QM31_MATRIX_SIZE: usize = 6;
Expand Down
10 changes: 5 additions & 5 deletions benches/merkle.rs → crates/prover/benches/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use criterion::Criterion;
pub fn cpu_merkle(c: &mut criterion::Criterion) {
use itertools::Itertools;
use num_traits::Zero;
use stwo::commitment_scheme::ops::MerkleOps;
use stwo::core::backend::avx512::AVX512Backend;
use stwo::core::backend::{CPUBackend, Col};
use stwo::core::fields::m31::BaseField;
use stwo::platform;
use prover::commitment_scheme::ops::MerkleOps;
use prover::core::backend::avx512::AVX512Backend;
use prover::core::backend::{CPUBackend, Col};
use prover::core::fields::m31::BaseField;
use prover::platform;

const N_COLS: usize = 1 << 8;
const LOG_SIZE: u32 = 16;
Expand Down
16 changes: 8 additions & 8 deletions benches/quotients.rs → crates/prover/benches/quotients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

use criterion::{black_box, Criterion};
use itertools::Itertools;
use stwo::core::backend::CPUBackend;
use stwo::core::circle::SECURE_FIELD_CIRCLE_GEN;
use stwo::core::commitment_scheme::quotients::{ColumnSampleBatch, QuotientOps};
use stwo::core::fields::m31::BaseField;
use stwo::core::fields::qm31::SecureField;
use stwo::core::poly::circle::{CanonicCoset, CircleEvaluation};
use stwo::core::poly::BitReversedOrder;
use prover::core::backend::CPUBackend;
use prover::core::circle::SECURE_FIELD_CIRCLE_GEN;
use prover::core::commitment_scheme::quotients::{ColumnSampleBatch, QuotientOps};
use prover::core::fields::m31::BaseField;
use prover::core::fields::qm31::SecureField;
use prover::core::poly::circle::{CanonicCoset, CircleEvaluation};
use prover::core::poly::BitReversedOrder;

pub fn cpu_quotients(c: &mut criterion::Criterion) {
const LOG_SIZE: u32 = 16;
Expand Down Expand Up @@ -43,7 +43,7 @@ pub fn cpu_quotients(c: &mut criterion::Criterion) {

#[cfg(target_arch = "x86_64")]
pub fn avx512_quotients(c: &mut criterion::Criterion) {
use stwo::core::backend::avx512::AVX512Backend;
use prover::core::backend::avx512::AVX512Backend;

const LOG_SIZE: u32 = 20;
const SIZE: usize = 1 << LOG_SIZE;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub trait Name {
/// # Example
///
/// ```
/// use stwo::commitment_scheme::blake3_hash::Blake3Hasher;
/// use stwo::commitment_scheme::hasher::Hasher;
/// use prover::commitment_scheme::blake3_hash::Blake3Hasher;
/// use prover::commitment_scheme::hasher::Hasher;
///
/// let mut hasher = Blake3Hasher::new();
/// hasher.update(&[1, 2, 3]);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a5e69d9

Please sign in to comment.