Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Mirrors branch main from private at 9c7cceefc844b0fa24e163690bf064b7c…
Browse files Browse the repository at this point in the history
…54a8435 (#15)

What

This PR updates the mirror with the latest in Boojum before FOSing the repo.
  • Loading branch information
shahar4 authored Sep 22, 2023
1 parent 9e16c34 commit 082efb8
Show file tree
Hide file tree
Showing 121 changed files with 1,050 additions and 1,221 deletions.
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
# The following configs are in an increasing performance order for x86_64.
# rustflags = ["-Ctarget-feature=+avx2"]
# rustflags = ["-Ctarget-feature=+avx512vl,+avx512f"]
# rustflags = ["-Ctarget-feature=+avx512vl,+avx512f,+avx512bw,+avx512cd,+avx512dq"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.vscode/

/target
/profiling-target/target
/Cargo.lock
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ itertools = "0.10"
blake2 = "0.10"
sha2 = "0.10"
num-modular = "0.5.1"
# packed_simd = { version = "0.3.8", package = "packed_simd_2" }
packed_simd = { version = "0.3.9" }
pairing = { package = "pairing_ce", git = "https://github.com/matter-labs/pairing.git" }
crypto-bigint = "*"
crypto-bigint = "0.5"
convert_case = "*"
firestorm = "*"
tracing = { version = "0.1.37", optional = true }
Expand Down
55 changes: 30 additions & 25 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![allow(
dead_code, // OK for benches
clippy::let_unit_value, // False positives
clippy::needless_range_loop, // Suggests less readable code
)]
#![feature(iter_collect_into)]
#![feature(allocator_api)]

Expand All @@ -16,13 +21,13 @@ const MUL_UPPER_BOUND: usize = 1024;
fn criterion_benchmark_multiplication(c: &mut Criterion) {
let aa: [GoldilocksField; MUL_UPPER_BOUND] = (0..MUL_UPPER_BOUND)
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect::<Vec<_>>()
.try_into()
.unwrap();
let bb: [GoldilocksField; MUL_UPPER_BOUND] = (0..MUL_UPPER_BOUND)
.map(|x| x as u64 + MUL_UPPER_BOUND as u64)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect::<Vec<_>>()
.try_into()
.unwrap();
Expand Down Expand Up @@ -82,7 +87,7 @@ fn criterion_benchmark_poseidon2_statevec(c: &mut Criterion) {
fn criterion_benchmark_keccak(c: &mut Criterion) {
let input = [0u8; 64];
c.bench_function("Keccak256", |b| {
b.iter(|| Keccak256::digest(&mut black_box(input)))
b.iter(|| Keccak256::digest(black_box(input)))
});
}

Expand Down Expand Up @@ -206,11 +211,11 @@ fn criterion_benchmark_add_vectors_naive(c: &mut Criterion) {

let mut aa: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();
let bb: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();

c.bench_function("Naive Vec add", |b| {
Expand All @@ -223,11 +228,11 @@ fn criterion_benchmark_add_vectors_vectorized(c: &mut Criterion) {

let aa: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();
let bb: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();

let mut aa = boojum::utils::cast_check_alignment(aa);
Expand All @@ -247,11 +252,11 @@ fn criterion_benchmark_add_vectors_simd(c: &mut Criterion) {

(0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect_into(&mut aa);
(0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect_into(&mut bb);

let mut aa = boojum::utils::cast_check_alignment(aa);
Expand All @@ -271,11 +276,11 @@ fn criterion_benchmark_add_vectors_portable_simd(c: &mut Criterion) {

(0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect_into(&mut aa);
(0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect_into(&mut bb);

let mut aa = boojum::utils::cast_check_alignment(aa);
Expand All @@ -293,11 +298,11 @@ fn criterion_benchmark_add_vectors_mixedgl(c: &mut Criterion) {

let aa: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();
let bb: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();

// let mut aa: Vec<MixedGL> = boojum::utils::cast_check_alignment(aa);
Expand All @@ -323,11 +328,11 @@ fn criterion_benchmark_mul_vectors_naive(c: &mut Criterion) {

let aa: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();
let bb: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();

let mut aa: Vec<MixedGL> =
Expand All @@ -350,11 +355,11 @@ fn criterion_benchmark_mul_vectors_vectorized(c: &mut Criterion) {

let aa: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();
let bb: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();

let mut aa = boojum::utils::cast_check_alignment(aa);
Expand All @@ -374,11 +379,11 @@ fn criterion_benchmark_mul_vectors_simd(c: &mut Criterion) {

(0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect_into(&mut aa);
(0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect_into(&mut bb);

let mut aa = boojum::utils::cast_check_alignment(aa);
Expand All @@ -398,11 +403,11 @@ fn criterion_benchmark_mul_vectors_portable_simd_long(c: &mut Criterion) {

(0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect_into(&mut aa);
(0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect_into(&mut bb);

let mut aa = boojum::utils::cast_check_alignment(aa);
Expand All @@ -424,11 +429,11 @@ fn criterion_benchmark_mul_vectors_portable_simd(c: &mut Criterion) {

(0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect_into(&mut aa);
(0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect_into(&mut bb);

let mut aa = boojum::utils::cast_check_alignment(aa);
Expand All @@ -444,11 +449,11 @@ fn criterion_benchmark_mul_vectors_mixedgl(c: &mut Criterion) {

let aa: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 1)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();
let bb: Vec<GoldilocksField> = (0..(degree * 2))
.map(|x| x as u64 + 2)
.map(|el| GoldilocksField::from_u64_with_reduction(el))
.map(GoldilocksField::from_u64_with_reduction)
.collect();

let mut aa: Vec<MixedGL> =
Expand Down
2 changes: 1 addition & 1 deletion src/algebraic_props/round_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub fn absorb_into_state_vararg<
if to_absorb.array_chunks::<AW>().remainder().is_empty() == false {
let mut tmp = [F::ZERO; AW];
let remainder = to_absorb.array_chunks::<AW>().remainder();
tmp[..remainder.len()].copy_from_slice(&remainder);
tmp[..remainder.len()].copy_from_slice(remainder);
T::absorb_into_state::<M>(state, &tmp);
T::round_function(state);
}
Expand Down
8 changes: 4 additions & 4 deletions src/cs/cs_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ pub trait CsBuilderImpl<F: SmallField, TImpl> {

pub struct CsBuilder<TImpl, F: SmallField, GC: GateConfigurationHolder<F>, TB: StaticToolboxHolder>
{
pub(crate) phantom: std::marker::PhantomData<F>,
pub phantom: std::marker::PhantomData<F>,

pub(crate) implementation: TImpl,
pub(crate) gates_config: GC,
pub(crate) toolbox: TB,
pub implementation: TImpl,
pub gates_config: GC,
pub toolbox: TB,
}

pub fn new_builder<TImpl: CsBuilderImpl<F, TImpl>, F: SmallField>(
Expand Down
12 changes: 6 additions & 6 deletions src/cs/cs_builder_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,20 +444,20 @@ impl<F: SmallField, P: PrimeFieldLikeVectorized<Base = F>, CFG: CSConfig>
evaluation_data_over_specialized_columns,
specialized_gates_rough_stats: HashMap::with_capacity(16),
gates_application_sets,
copy_permutation_data: copy_permutation_data,
witness_placement_data: witness_placement_data,
copy_permutation_data,
witness_placement_data,
next_available_row: 0,
next_available_place_idx: 0,
next_lookup_table_index: INITIAL_LOOKUP_TABLE_ID_VALUE,
lookup_marker_gate_idx: lookup_marker_gate_idx,
constants_requested_per_row: constants_requested_per_row,
constants_for_gates_in_specialized_mode: constants_for_gates_in_specialized_mode,
lookup_marker_gate_idx,
constants_requested_per_row,
constants_for_gates_in_specialized_mode,
lookup_table_marker_into_id: HashMap::with_capacity(32),
lookup_tables: Vec::with_capacity(32),
lookup_multiplicities: Vec::with_capacity(8),
table_ids_as_variables: Vec::with_capacity(32),
public_inputs: Vec::with_capacity(8),
max_trace_len: max_trace_len,
max_trace_len,
static_toolbox: builder.toolbox,
row_cleanups,
columns_cleanups,
Expand Down
2 changes: 1 addition & 1 deletion src/cs/cs_builder_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct CsVerifierBuilder<F: SmallField, EXT: FieldExtension<2, BaseField = F
impl<F: SmallField, EXT: FieldExtension<2, BaseField = F>> CsVerifierBuilder<F, EXT> {
pub fn new_from_parameters(parameters: CSGeometry) -> Self {
Self {
parameters: parameters,
parameters,
lookup_parameters: LookupParameters::NoLookup,

gate_type_ids_for_specialized_columns: Vec::with_capacity(16),
Expand Down
8 changes: 2 additions & 6 deletions src/cs/gates/boolean_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ impl<F: PrimeField> GateConstraintEvaluator<F> for BooleanConstraitEvaluator {
}

#[inline(always)]
fn unique_params(&self) -> Self::UniqueParameterizationParams {
()
}
fn unique_params(&self) -> Self::UniqueParameterizationParams {}

#[inline]
fn type_name() -> std::borrow::Cow<'static, str> {
Expand Down Expand Up @@ -83,7 +81,6 @@ impl<F: PrimeField> GateConstraintEvaluator<F> for BooleanConstraitEvaluator {
&self,
_ctx: &mut P::Context,
) -> Self::GlobalConstants<P> {
()
}

type RowSharedConstants<P: field::traits::field_like::PrimeFieldLike<Base = F>> = ();
Expand All @@ -97,7 +94,6 @@ impl<F: PrimeField> GateConstraintEvaluator<F> for BooleanConstraitEvaluator {
_trace_source: &S,
_ctx: &mut P::Context,
) -> Self::RowSharedConstants<P> {
()
}

#[inline(always)]
Expand Down Expand Up @@ -125,7 +121,7 @@ impl<F: PrimeField> GateConstraintEvaluator<F> for BooleanConstraitEvaluator {
}
}

const UNIQUE_IDENTIFIER: &'static str = "Boolean constraint gate";
const UNIQUE_IDENTIFIER: &str = "Boolean constraint gate";
const PRINCIPAL_WIDTH: usize = 1;

impl<F: SmallField> Gate<F> for BooleanConstraintGate {
Expand Down
4 changes: 1 addition & 3 deletions src/cs/gates/bounded_boolean_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ impl<F: PrimeField> GateConstraintEvaluator<F> for BoundedBooleanConstraitEvalua
&self,
_ctx: &mut P::Context,
) -> Self::GlobalConstants<P> {
()
}

type RowSharedConstants<P: field::traits::field_like::PrimeFieldLike<Base = F>> = ();
Expand All @@ -102,7 +101,6 @@ impl<F: PrimeField> GateConstraintEvaluator<F> for BoundedBooleanConstraitEvalua
_trace_source: &S,
_ctx: &mut P::Context,
) -> Self::RowSharedConstants<P> {
()
}

#[inline(always)]
Expand Down Expand Up @@ -130,7 +128,7 @@ impl<F: PrimeField> GateConstraintEvaluator<F> for BoundedBooleanConstraitEvalua
}
}

const UNIQUE_IDENTIFIER: &'static str = "Boolean constraint gate";
const UNIQUE_IDENTIFIER: &str = "Boolean constraint gate";
const PRINCIPAL_WIDTH: usize = 1;

// Just keep a position that we can use next
Expand Down
2 changes: 0 additions & 2 deletions src/cs/gates/bounded_constant_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ impl<F: PrimeField> GateConstraintEvaluator<F> for BoundedConstantAllocatorConst
&self,
_ctx: &mut P::Context,
) -> Self::GlobalConstants<P> {
()
}

// there are no constants that would be shared between instances
Expand All @@ -114,7 +113,6 @@ impl<F: PrimeField> GateConstraintEvaluator<F> for BoundedConstantAllocatorConst
_trace_source: &S,
_ctx: &mut P::Context,
) -> Self::RowSharedConstants<P> {
()
}

#[inline(always)]
Expand Down
6 changes: 1 addition & 5 deletions src/cs/gates/conditional_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ impl<F: PrimeField, const N: usize> GateConstraintEvaluator<F>
}

#[inline(always)]
fn unique_params(&self) -> Self::UniqueParameterizationParams {
()
}
fn unique_params(&self) -> Self::UniqueParameterizationParams {}

#[inline]
fn type_name() -> std::borrow::Cow<'static, str> {
Expand Down Expand Up @@ -91,7 +89,6 @@ impl<F: PrimeField, const N: usize> GateConstraintEvaluator<F>
&self,
_ctx: &mut P::Context,
) -> Self::GlobalConstants<P> {
()
}

type RowSharedConstants<P: field::traits::field_like::PrimeFieldLike<Base = F>> = ();
Expand All @@ -105,7 +102,6 @@ impl<F: PrimeField, const N: usize> GateConstraintEvaluator<F>
_trace_source: &S,
_ctx: &mut P::Context,
) -> Self::RowSharedConstants<P> {
()
}

#[inline(always)]
Expand Down
Loading

0 comments on commit 082efb8

Please sign in to comment.