From b60488d6d0f8251b498efb9bb51921303d1c90dd Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 5 Jan 2024 16:20:20 +0100 Subject: [PATCH] turn of experiments, adjust benchmarks for now --- benches/benchmarks.rs | 316 ++++++++++++++++++++-------------------- src/dag/resolver_box.rs | 3 +- src/experiments.rs | 4 +- src/lib.rs | 2 +- 4 files changed, 163 insertions(+), 162 deletions(-) diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs index 1dd551b..7583da5 100644 --- a/benches/benchmarks.rs +++ b/benches/benchmarks.rs @@ -192,104 +192,104 @@ fn criterion_benchmark_poseidon2_inner_statevec(c: &mut Criterion) { // }); // } -fn criterion_benchmark_add_naive(c: &mut Criterion) { - let degree: usize = 1 << 24; +// fn criterion_benchmark_add_naive(c: &mut Criterion) { +// let degree: usize = 1 << 24; - let aa: Vec = (0..(degree * 2)).map(|x| x as u64 + 1).collect(); - let bb: Vec = (0..(degree * 2)).map(|x| x as u64 + 2).collect(); - let mut cc: Vec = Vec::with_capacity(degree * 2); +// let aa: Vec = (0..(degree * 2)).map(|x| x as u64 + 1).collect(); +// let bb: Vec = (0..(degree * 2)).map(|x| x as u64 + 2).collect(); +// let mut cc: Vec = Vec::with_capacity(degree * 2); - c.bench_function("Naive", |b| { - b.iter(|| unsafe { - boojum::experiments::naive(black_box(&aa), black_box(&bb), black_box(&mut cc)) - }) - }); -} +// c.bench_function("Naive", |b| { +// b.iter(|| unsafe { +// boojum::experiments::naive(black_box(&aa), black_box(&bb), black_box(&mut cc)) +// }) +// }); +// } -fn criterion_benchmark_add_vectors_naive(c: &mut Criterion) { - let degree: usize = 1 << 24; +// fn criterion_benchmark_add_vectors_naive(c: &mut Criterion) { +// let degree: usize = 1 << 24; - let mut aa: Vec = (0..(degree * 2)) - .map(|x| x as u64 + 1) - .map(GoldilocksField::from_u64_with_reduction) - .collect(); - let bb: Vec = (0..(degree * 2)) - .map(|x| x as u64 + 2) - .map(GoldilocksField::from_u64_with_reduction) - .collect(); +// let mut aa: Vec = (0..(degree * 2)) +// .map(|x| x as u64 + 1) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect(); +// let bb: Vec = (0..(degree * 2)) +// .map(|x| x as u64 + 2) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect(); - c.bench_function("Naive Vec add", |b| { - b.iter(|| boojum::experiments::vec_add_native(black_box(&mut aa), black_box(&bb))) - }); -} +// c.bench_function("Naive Vec add", |b| { +// b.iter(|| boojum::experiments::vec_add_native(black_box(&mut aa), black_box(&bb))) +// }); +// } -fn criterion_benchmark_add_vectors_vectorized(c: &mut Criterion) { - let degree: usize = 1 << 24; +// fn criterion_benchmark_add_vectors_vectorized(c: &mut Criterion) { +// let degree: usize = 1 << 24; - let aa: Vec = (0..(degree * 2)) - .map(|x| x as u64 + 1) - .map(GoldilocksField::from_u64_with_reduction) - .collect(); - let bb: Vec = (0..(degree * 2)) - .map(|x| x as u64 + 2) - .map(GoldilocksField::from_u64_with_reduction) - .collect(); +// let aa: Vec = (0..(degree * 2)) +// .map(|x| x as u64 + 1) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect(); +// let bb: Vec = (0..(degree * 2)) +// .map(|x| x as u64 + 2) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect(); - let mut aa = boojum::utils::cast_check_alignment(aa); - let bb = boojum::utils::cast_check_alignment(bb); +// let mut aa = boojum::utils::cast_check_alignment(aa); +// let bb = boojum::utils::cast_check_alignment(bb); - c.bench_function("Unrolled Vec add", |b| { - b.iter(|| boojum::experiments::vec_add_vectorized(black_box(&mut aa), black_box(&bb))) - }); -} +// c.bench_function("Unrolled Vec add", |b| { +// b.iter(|| boojum::experiments::vec_add_vectorized(black_box(&mut aa), black_box(&bb))) +// }); +// } -fn criterion_benchmark_add_vectors_simd(c: &mut Criterion) { - let degree: usize = 1 << 24; +// fn criterion_benchmark_add_vectors_simd(c: &mut Criterion) { +// let degree: usize = 1 << 24; - use boojum::experiments::GLV; - let mut aa = boojum::utils::allocate_with_alignment_of::(degree * 2); - let mut bb = boojum::utils::allocate_with_alignment_of::(degree * 2); +// use boojum::experiments::GLV; +// let mut aa = boojum::utils::allocate_with_alignment_of::(degree * 2); +// let mut bb = boojum::utils::allocate_with_alignment_of::(degree * 2); - (0..(degree * 2)) - .map(|x| x as u64 + 1) - .map(GoldilocksField::from_u64_with_reduction) - .collect_into(&mut aa); - (0..(degree * 2)) - .map(|x| x as u64 + 2) - .map(GoldilocksField::from_u64_with_reduction) - .collect_into(&mut bb); +// (0..(degree * 2)) +// .map(|x| x as u64 + 1) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect_into(&mut aa); +// (0..(degree * 2)) +// .map(|x| x as u64 + 2) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect_into(&mut bb); - let mut aa = boojum::utils::cast_check_alignment(aa); - let bb = boojum::utils::cast_check_alignment(bb); +// let mut aa = boojum::utils::cast_check_alignment(aa); +// let bb = boojum::utils::cast_check_alignment(bb); - c.bench_function("SIMD Vec add", |b| { - b.iter(|| boojum::experiments::vec_add_simd(black_box(&mut aa), black_box(&bb))) - }); -} +// c.bench_function("SIMD Vec add", |b| { +// b.iter(|| boojum::experiments::vec_add_simd(black_box(&mut aa), black_box(&bb))) +// }); +// } -fn criterion_benchmark_add_vectors_portable_simd(c: &mut Criterion) { - let degree: usize = 1 << 24; +// fn criterion_benchmark_add_vectors_portable_simd(c: &mut Criterion) { +// let degree: usize = 1 << 24; - use boojum::experiments::GLV; - let mut aa = boojum::utils::allocate_with_alignment_of::(degree * 2); - let mut bb = boojum::utils::allocate_with_alignment_of::(degree * 2); +// use boojum::experiments::GLV; +// let mut aa = boojum::utils::allocate_with_alignment_of::(degree * 2); +// let mut bb = boojum::utils::allocate_with_alignment_of::(degree * 2); - (0..(degree * 2)) - .map(|x| x as u64 + 1) - .map(GoldilocksField::from_u64_with_reduction) - .collect_into(&mut aa); - (0..(degree * 2)) - .map(|x| x as u64 + 2) - .map(GoldilocksField::from_u64_with_reduction) - .collect_into(&mut bb); +// (0..(degree * 2)) +// .map(|x| x as u64 + 1) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect_into(&mut aa); +// (0..(degree * 2)) +// .map(|x| x as u64 + 2) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect_into(&mut bb); - let mut aa = boojum::utils::cast_check_alignment(aa); - let bb = boojum::utils::cast_check_alignment(bb); +// let mut aa = boojum::utils::cast_check_alignment(aa); +// let bb = boojum::utils::cast_check_alignment(bb); - c.bench_function("Portable SIMD Vec add", |b| { - b.iter(|| boojum::experiments::vec_add_portable_simd(black_box(&mut aa), black_box(&bb))) - }); -} +// c.bench_function("Portable SIMD Vec add", |b| { +// b.iter(|| boojum::experiments::vec_add_portable_simd(black_box(&mut aa), black_box(&bb))) +// }); +// } use boojum::utils::clone_respecting_allignment; @@ -350,99 +350,99 @@ fn criterion_benchmark_mul_vectors_naive(c: &mut Criterion) { }); } -fn criterion_benchmark_mul_vectors_vectorized(c: &mut Criterion) { - let degree: usize = 1 << 24; - - let aa: Vec = (0..(degree * 2)) - .map(|x| x as u64 + 1) - .map(GoldilocksField::from_u64_with_reduction) - .collect(); - let bb: Vec = (0..(degree * 2)) - .map(|x| x as u64 + 2) - .map(GoldilocksField::from_u64_with_reduction) - .collect(); - - let mut aa = boojum::utils::cast_check_alignment(aa); - let bb = boojum::utils::cast_check_alignment(bb); +// fn criterion_benchmark_mul_vectors_vectorized(c: &mut Criterion) { +// let degree: usize = 1 << 24; - c.bench_function("Unrolled Vec mul", |b| { - b.iter(|| boojum::experiments::vec_mul_vectorized(black_box(&mut aa), black_box(&bb))) - }); -} +// let aa: Vec = (0..(degree * 2)) +// .map(|x| x as u64 + 1) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect(); +// let bb: Vec = (0..(degree * 2)) +// .map(|x| x as u64 + 2) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect(); -fn criterion_benchmark_mul_vectors_simd(c: &mut Criterion) { - let degree: usize = 1 << 24; +// let mut aa = boojum::utils::cast_check_alignment(aa); +// let bb = boojum::utils::cast_check_alignment(bb); - use boojum::experiments::GLV; - let mut aa = boojum::utils::allocate_with_alignment_of::(degree * 2); - let mut bb = boojum::utils::allocate_with_alignment_of::(degree * 2); +// c.bench_function("Unrolled Vec mul", |b| { +// b.iter(|| boojum::experiments::vec_mul_vectorized(black_box(&mut aa), black_box(&bb))) +// }); +// } - (0..(degree * 2)) - .map(|x| x as u64 + 1) - .map(GoldilocksField::from_u64_with_reduction) - .collect_into(&mut aa); - (0..(degree * 2)) - .map(|x| x as u64 + 2) - .map(GoldilocksField::from_u64_with_reduction) - .collect_into(&mut bb); +// fn criterion_benchmark_mul_vectors_simd(c: &mut Criterion) { +// let degree: usize = 1 << 24; - let mut aa = boojum::utils::cast_check_alignment(aa); - let bb = boojum::utils::cast_check_alignment(bb); +// use boojum::experiments::GLV; +// let mut aa = boojum::utils::allocate_with_alignment_of::(degree * 2); +// let mut bb = boojum::utils::allocate_with_alignment_of::(degree * 2); - c.bench_function("SIMD Vec mul", |b| { - b.iter(|| boojum::experiments::vec_mul_simd(black_box(&mut aa), black_box(&bb))) - }); -} +// (0..(degree * 2)) +// .map(|x| x as u64 + 1) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect_into(&mut aa); +// (0..(degree * 2)) +// .map(|x| x as u64 + 2) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect_into(&mut bb); -fn criterion_benchmark_mul_vectors_portable_simd_long(c: &mut Criterion) { - let degree: usize = 1 << 24; +// let mut aa = boojum::utils::cast_check_alignment(aa); +// let bb = boojum::utils::cast_check_alignment(bb); - use boojum::experiments::GLV; - let mut aa = boojum::utils::allocate_with_alignment_of::(degree * 2); - let mut bb = boojum::utils::allocate_with_alignment_of::(degree * 2); - - (0..(degree * 2)) - .map(|x| x as u64 + 1) - .map(GoldilocksField::from_u64_with_reduction) - .collect_into(&mut aa); - (0..(degree * 2)) - .map(|x| x as u64 + 2) - .map(GoldilocksField::from_u64_with_reduction) - .collect_into(&mut bb); - - let mut aa = boojum::utils::cast_check_alignment(aa); - let bb = boojum::utils::cast_check_alignment(bb); +// c.bench_function("SIMD Vec mul", |b| { +// b.iter(|| boojum::experiments::vec_mul_simd(black_box(&mut aa), black_box(&bb))) +// }); +// } - c.bench_function("Portable SIMD long Vec mul", |b| { - b.iter(|| { - boojum::experiments::vec_mul_portable_simd_long(black_box(&mut aa), black_box(&bb)) - }) - }); -} +// fn criterion_benchmark_mul_vectors_portable_simd_long(c: &mut Criterion) { +// let degree: usize = 1 << 24; + +// use boojum::experiments::GLV; +// let mut aa = boojum::utils::allocate_with_alignment_of::(degree * 2); +// let mut bb = boojum::utils::allocate_with_alignment_of::(degree * 2); + +// (0..(degree * 2)) +// .map(|x| x as u64 + 1) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect_into(&mut aa); +// (0..(degree * 2)) +// .map(|x| x as u64 + 2) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect_into(&mut bb); + +// let mut aa = boojum::utils::cast_check_alignment(aa); +// let bb = boojum::utils::cast_check_alignment(bb); + +// c.bench_function("Portable SIMD long Vec mul", |b| { +// b.iter(|| { +// boojum::experiments::vec_mul_portable_simd_long(black_box(&mut aa), black_box(&bb)) +// }) +// }); +// } -fn criterion_benchmark_mul_vectors_portable_simd(c: &mut Criterion) { - let degree: usize = 1 << 24; +// fn criterion_benchmark_mul_vectors_portable_simd(c: &mut Criterion) { +// let degree: usize = 1 << 24; - use boojum::experiments::GLV; - let mut aa = boojum::utils::allocate_with_alignment_of::(degree * 2); - let mut bb = boojum::utils::allocate_with_alignment_of::(degree * 2); +// use boojum::experiments::GLV; +// let mut aa = boojum::utils::allocate_with_alignment_of::(degree * 2); +// let mut bb = boojum::utils::allocate_with_alignment_of::(degree * 2); - (0..(degree * 2)) - .map(|x| x as u64 + 1) - .map(GoldilocksField::from_u64_with_reduction) - .collect_into(&mut aa); - (0..(degree * 2)) - .map(|x| x as u64 + 2) - .map(GoldilocksField::from_u64_with_reduction) - .collect_into(&mut bb); +// (0..(degree * 2)) +// .map(|x| x as u64 + 1) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect_into(&mut aa); +// (0..(degree * 2)) +// .map(|x| x as u64 + 2) +// .map(GoldilocksField::from_u64_with_reduction) +// .collect_into(&mut bb); - let mut aa = boojum::utils::cast_check_alignment(aa); - let bb = boojum::utils::cast_check_alignment(bb); +// let mut aa = boojum::utils::cast_check_alignment(aa); +// let bb = boojum::utils::cast_check_alignment(bb); - c.bench_function("Portable SIMD Vec mul", |b| { - b.iter(|| boojum::experiments::vec_mul_portable_simd(black_box(&mut aa), black_box(&bb))) - }); -} +// c.bench_function("Portable SIMD Vec mul", |b| { +// b.iter(|| boojum::experiments::vec_mul_portable_simd(black_box(&mut aa), black_box(&bb))) +// }); +// } fn criterion_benchmark_mul_vectors_mixedgl(c: &mut Criterion) { let degree: usize = 1 << 24; diff --git a/src/dag/resolver_box.rs b/src/dag/resolver_box.rs index befeb40..6a5201f 100644 --- a/src/dag/resolver_box.rs +++ b/src/dag/resolver_box.rs @@ -1,5 +1,6 @@ use crate::log; -use std::{intrinsics::size_of, marker::PhantomData}; +use std::marker::PhantomData; +use std::mem::size_of; use crate::{ cs::{traits::cs::DstBuffer, Place}, diff --git a/src/experiments.rs b/src/experiments.rs index f875aa3..b0992e7 100644 --- a/src/experiments.rs +++ b/src/experiments.rs @@ -4,8 +4,8 @@ use std::ops::Shl; use std::ops::Shr; use std::ops::Sub; -// use std::simd::num::*; -// use std::simd::cmp::*; +use std::simd::num::*; +use std::simd::cmp::*; use packed_simd::FromCast; use crate::field::{goldilocks::GoldilocksField, Field}; diff --git a/src/lib.rs b/src/lib.rs index ef3744e..72775d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,7 @@ pub use sha2; pub use sha3; // #[cfg(target_arch = "aarch64")] -pub mod experiments; +// pub mod experiments; pub mod log_utils;