Skip to content

Commit

Permalink
trace to evals
Browse files Browse the repository at this point in the history
  • Loading branch information
ohad-starkware committed Dec 23, 2024
1 parent 278d03e commit 9cbe4ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions crates/air_utils/src/trace/examle_lookup_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ impl LookupData {
Self { lu0, lu1 }
}

pub fn iter_mut(&mut self) -> LookupDataIterMut {
pub fn iter_mut(&mut self) -> LookupDataIterMut<'_> {
LookupDataIterMut::new(&mut self.lu0, &mut self.lu1)
}

pub fn par_iter_mut(&mut self) -> ParLookupDataIterMut {
pub fn par_iter_mut(&mut self) -> ParLookupDataIterMut<'_> {
ParLookupDataIterMut {
lu0: &mut self.lu0,
lu1: &mut self.lu1,
Expand Down
28 changes: 16 additions & 12 deletions crates/air_utils/src/trace/iterable_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use bytemuck::{cast_slice, Zeroable};
use itertools::Itertools;
use rayon::iter::plumbing::{bridge, Consumer, Producer, ProducerCallback, UnindexedConsumer};
use rayon::prelude::*;
use stwo_prover::core::backend::simd::column::BaseColumn;
use stwo_prover::core::backend::simd::m31::{PackedM31, N_LANES};
use stwo_prover::core::backend::simd::SimdBackend;
use stwo_prover::core::fields::m31::M31;
use stwo_prover::core::poly::circle::CircleEvaluation;
use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation};
use stwo_prover::core::poly::BitReversedOrder;

/// A 2D Matrix of [`PackedM31`] values.
Expand Down Expand Up @@ -51,16 +52,16 @@ use stwo_prover::core::poly::BitReversedOrder;
pub struct IterableTrace<const N: usize> {
data: [Vec<PackedM31>; N],

/// Number of M31 rows in each column.
length: usize,
/// Log number of M31 rows in each column.
log_size: u32,
}

impl<const N: usize> IterableTrace<N> {
pub fn zeroed(log_size: u32) -> Self {
let length = 1 << log_size;
let n_simd_elems = length / N_LANES;
let data = [(); N].map(|_| vec![PackedM31::zeroed(); n_simd_elems]);
Self { data, length }
Self { data, log_size }
}

/// # Safety
Expand All @@ -70,12 +71,8 @@ impl<const N: usize> IterableTrace<N> {
todo!()
}

pub fn len(&self) -> usize {
self.length
}

pub fn is_empty(&self) -> bool {
self.length == 0
pub fn log_size(&self) -> u32 {
self.log_size
}

pub fn iter_mut(&mut self) -> RowIterMut<'_, N> {
Expand All @@ -101,11 +98,18 @@ impl<const N: usize> IterableTrace<N> {
}

pub fn to_evals(self) -> [CircleEvaluation<SimdBackend, M31, BitReversedOrder>; N] {
todo!()
let domain = CanonicCoset::new(self.log_size).circle_domain();
self.data.map(|column| {
let eval = BaseColumn {
data: column,
length: 1 << self.log_size,
};
CircleEvaluation::<SimdBackend, M31, BitReversedOrder>::new(domain, eval)
})
}

pub fn pretty_print(&self, row_limit: usize) -> String {
assert!(row_limit <= self.len());
assert!(row_limit <= 1 << self.log_size);
let cpu_trace: Vec<&[u32]> = self
.data
.iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/air_utils/src/trace/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod examle_lookup_data;
pub mod iterable_trace;
pub mod examle_lookup_data;

0 comments on commit 9cbe4ea

Please sign in to comment.