Skip to content

Commit

Permalink
Rename CPU* structs to Cpu* to conform to Rust's naming convention (#617
Browse files Browse the repository at this point in the history
)
  • Loading branch information
andrewmilson authored May 20, 2024
1 parent d4372f9 commit 8d16c06
Show file tree
Hide file tree
Showing 37 changed files with 216 additions and 216 deletions.
4 changes: 2 additions & 2 deletions crates/prover/benches/eval_at_point.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng};
use stwo_prover::core::backend::cpu::CPUBackend;
use stwo_prover::core::backend::cpu::CpuBackend;
use stwo_prover::core::backend::simd::SimdBackend;
use stwo_prover::core::circle::CirclePoint;
use stwo_prover::core::fields::m31::BaseField;
Expand All @@ -25,7 +25,7 @@ fn bench_eval_at_secure_point<B: PolyOps>(c: &mut Criterion, id: &str) {

fn eval_at_secure_point_benches(c: &mut Criterion) {
bench_eval_at_secure_point::<SimdBackend>(c, "simd");
bench_eval_at_secure_point::<CPUBackend>(c, "cpu");
bench_eval_at_secure_point::<CpuBackend>(c, "cpu");
}

criterion_group!(
Expand Down
6 changes: 3 additions & 3 deletions crates/prover/benches/fri.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use stwo_prover::core::backend::CPUBackend;
use stwo_prover::core::backend::CpuBackend;
use stwo_prover::core::fields::m31::BaseField;
use stwo_prover::core::fields::qm31::SecureField;
use stwo_prover::core::fields::secure_column::SecureColumn;
Expand All @@ -19,10 +19,10 @@ fn folding_benchmark(c: &mut Criterion) {
},
);
let alpha = SecureField::from_u32_unchecked(2213980, 2213981, 2213982, 2213983);
let twiddles = CPUBackend::precompute_twiddles(domain.coset());
let twiddles = CpuBackend::precompute_twiddles(domain.coset());
c.bench_function("fold_line", |b| {
b.iter(|| {
black_box(CPUBackend::fold_line(
black_box(CpuBackend::fold_line(
black_box(&evals),
black_box(alpha),
&twiddles,
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/benches/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use itertools::Itertools;
use num_traits::Zero;
use stwo_prover::core::backend::simd::SimdBackend;
use stwo_prover::core::backend::{CPUBackend, Col};
use stwo_prover::core::backend::{Col, CpuBackend};
use stwo_prover::core::fields::m31::{BaseField, N_BYTES_FELT};
use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleHasher;
use stwo_prover::core::vcs::ops::MerkleOps;
Expand All @@ -28,7 +28,7 @@ fn bench_blake2s_merkle<B: MerkleOps<Blake2sMerkleHasher>>(c: &mut Criterion, id

fn blake2s_merkle_benches(c: &mut Criterion) {
bench_blake2s_merkle::<SimdBackend>(c, "simd");
bench_blake2s_merkle::<CPUBackend>(c, "cpu");
bench_blake2s_merkle::<CpuBackend>(c, "cpu");
}

criterion_group!(
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/benches/quotients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use itertools::Itertools;
use stwo_prover::core::backend::cpu::CPUBackend;
use stwo_prover::core::backend::cpu::CpuBackend;
use stwo_prover::core::backend::simd::SimdBackend;
use stwo_prover::core::circle::SECURE_FIELD_CIRCLE_GEN;
use stwo_prover::core::fields::m31::BaseField;
Expand Down Expand Up @@ -44,7 +44,7 @@ fn bench_quotients<B: QuotientOps, const LOG_N_ROWS: u32, const LOG_N_COLS: u32>

fn quotients_benches(c: &mut Criterion) {
bench_quotients::<SimdBackend, 20, 8>(c, "simd");
bench_quotients::<CPUBackend, 16, 8>(c, "cpu");
bench_quotients::<CpuBackend, 16, 8>(c, "cpu");
}

criterion_group!(
Expand Down
10 changes: 5 additions & 5 deletions crates/prover/src/core/air/accumulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use itertools::Itertools;
use tracing::{span, Level};

use crate::core::backend::{Backend, CPUBackend};
use crate::core::backend::{Backend, CpuBackend};
use crate::core::fields::m31::BaseField;
use crate::core::fields::qm31::SecureField;
use crate::core::fields::secure_column::SecureColumn;
Expand Down Expand Up @@ -147,7 +147,7 @@ pub struct ColumnAccumulator<'a, B: Backend> {
pub random_coeff_powers: Vec<SecureField>,
pub col: &'a mut SecureColumn<B>,
}
impl<'a> ColumnAccumulator<'a, CPUBackend> {
impl<'a> ColumnAccumulator<'a, CpuBackend> {
pub fn accumulate(&mut self, index: usize, evaluation: SecureField) {
let val = self.col.at(index) + evaluation;
self.col.set(index, val);
Expand All @@ -163,7 +163,7 @@ mod tests {
use rand::{Rng, SeedableRng};

use super::*;
use crate::core::backend::cpu::CPUCircleEvaluation;
use crate::core::backend::cpu::CpuCircleEvaluation;
use crate::core::circle::CirclePoint;
use crate::core::fields::m31::{M31, P};
use crate::qm31;
Expand Down Expand Up @@ -225,7 +225,7 @@ mod tests {
let alpha = qm31!(2, 3, 4, 5);

// Use accumulator.
let mut accumulator = DomainEvaluationAccumulator::<CPUBackend>::new(
let mut accumulator = DomainEvaluationAccumulator::<CpuBackend>::new(
alpha,
LOG_SIZE_BOUND,
evaluations.len(),
Expand Down Expand Up @@ -273,7 +273,7 @@ mod tests {
let mut res = SecureField::default();
for (log_size, values) in log_sizes.into_iter().zip(evaluations) {
res = res * alpha
+ CPUCircleEvaluation::new(CanonicCoset::new(log_size).circle_domain(), values)
+ CpuCircleEvaluation::new(CanonicCoset::new(log_size).circle_domain(), values)
.interpolate()
.eval_at_point(point);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/core/backend/cpu/accumulation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::CPUBackend;
use super::CpuBackend;
use crate::core::air::accumulation::AccumulationOps;
use crate::core::fields::secure_column::SecureColumn;

impl AccumulationOps for CPUBackend {
impl AccumulationOps for CpuBackend {
fn accumulate(column: &mut SecureColumn<Self>, other: &SecureColumn<Self>) {
for i in 0..column.len() {
let res_coeff = column.at(i) + other.at(i);
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/core/backend/cpu/blake2s.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use itertools::Itertools;

use crate::core::backend::CPUBackend;
use crate::core::backend::CpuBackend;
use crate::core::fields::m31::BaseField;
use crate::core::vcs::blake2_hash::Blake2sHash;
use crate::core::vcs::blake2_merkle::Blake2sMerkleHasher;
use crate::core::vcs::ops::{MerkleHasher, MerkleOps};

impl MerkleOps<Blake2sMerkleHasher> for CPUBackend {
impl MerkleOps<Blake2sMerkleHasher> for CpuBackend {
fn commit_on_layer(
log_size: u32,
prev_layer: Option<&Vec<Blake2sHash>>,
Expand Down
8 changes: 4 additions & 4 deletions crates/prover/src/core/backend/cpu/circle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use num_traits::Zero;

use super::CPUBackend;
use super::CpuBackend;
use crate::core::backend::{Col, ColumnOps};
use crate::core::circle::{CirclePoint, Coset};
use crate::core::fft::{butterfly, ibutterfly};
Expand All @@ -15,7 +15,7 @@ use crate::core::poly::utils::{domain_line_twiddles_from_tree, fold};
use crate::core::poly::BitReversedOrder;
use crate::core::utils::bit_reverse;

impl PolyOps for CPUBackend {
impl PolyOps for CpuBackend {
type Twiddles = Vec<BaseField>;

fn new_canonical_ordered(
Expand All @@ -32,7 +32,7 @@ impl PolyOps for CPUBackend {
for i in 0..half_len {
new_values.push(values[domain.size() - 1 - (i << 1)]);
}
CPUBackend::bit_reverse_column(&mut new_values);
CpuBackend::bit_reverse_column(&mut new_values);
CircleEvaluation::new(domain, new_values)
}

Expand Down Expand Up @@ -214,7 +214,7 @@ fn circle_twiddles_from_line_twiddles(
}

impl<F: ExtensionOf<BaseField>, EvalOrder> IntoIterator
for CircleEvaluation<CPUBackend, F, EvalOrder>
for CircleEvaluation<CpuBackend, F, EvalOrder>
{
type Item = F;
type IntoIter = std::vec::IntoIter<F>;
Expand Down
22 changes: 11 additions & 11 deletions crates/prover/src/core/backend/cpu/fri.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::CPUBackend;
use super::CpuBackend;
use crate::core::fields::m31::BaseField;
use crate::core::fields::qm31::SecureField;
use crate::core::fields::secure_column::SecureColumn;
Expand All @@ -8,7 +8,7 @@ use crate::core::poly::line::LineEvaluation;
use crate::core::poly::twiddles::TwiddleTree;

// TODO(spapini): Optimized these functions as well.
impl FriOps for CPUBackend {
impl FriOps for CpuBackend {
fn fold_line(
eval: &LineEvaluation<Self>,
alpha: SecureField,
Expand Down Expand Up @@ -51,7 +51,7 @@ impl FriOps for CPUBackend {
}
}

impl CPUBackend {
impl CpuBackend {
/// Used to decompose a general polynomial to a polynomial inside the fft-space, and
/// the remainder terms.
/// A coset-diff on a [`CirclePoly`] that is in the FFT space will return zero.
Expand Down Expand Up @@ -89,8 +89,8 @@ impl CPUBackend {
mod tests {
use num_traits::Zero;

use crate::core::backend::cpu::{CPUCircleEvaluation, CPUCirclePoly};
use crate::core::backend::CPUBackend;
use crate::core::backend::cpu::{CpuCircleEvaluation, CpuCirclePoly};
use crate::core::backend::CpuBackend;
use crate::core::fields::m31::BaseField;
use crate::core::fields::qm31::SecureField;
use crate::core::fields::secure_column::SecureColumn;
Expand All @@ -109,9 +109,9 @@ mod tests {

// Polynomial is out of FFT space.
coeffs[1 << domain_log_half_size] = m31!(1);
assert!(!CPUCirclePoly::new(coeffs.clone()).is_in_fft_space(domain_log_half_size));
assert!(!CpuCirclePoly::new(coeffs.clone()).is_in_fft_space(domain_log_half_size));

let poly = CPUCirclePoly::new(coeffs);
let poly = CpuCirclePoly::new(coeffs);
let values = poly.evaluate(domain);
let secure_column = SecureColumn {
columns: [
Expand All @@ -121,22 +121,22 @@ mod tests {
values.values.clone(),
],
};
let secure_eval = SecureEvaluation::<CPUBackend> {
let secure_eval = SecureEvaluation::<CpuBackend> {
domain,
values: secure_column.clone(),
};

let (g, lambda) = CPUBackend::decompose(&secure_eval);
let (g, lambda) = CpuBackend::decompose(&secure_eval);

// Sanity check.
assert_ne!(lambda, SecureField::zero());

// Assert the new polynomial is in the FFT space.
for i in 0..4 {
let basefield_column = g.columns[i].clone();
let eval = CPUCircleEvaluation::new(domain, basefield_column);
let eval = CpuCircleEvaluation::new(domain, basefield_column);
let coeffs = eval.interpolate().coeffs;
assert!(CPUCirclePoly::new(coeffs).is_in_fft_space(domain_log_half_size));
assert!(CpuCirclePoly::new(coeffs).is_in_fft_space(domain_log_half_size));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/prover/src/core/backend/cpu/lookups/mle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use std::iter::zip;

use num_traits::{One, Zero};

use crate::core::backend::CPUBackend;
use crate::core::backend::CpuBackend;
use crate::core::fields::m31::BaseField;
use crate::core::fields::qm31::SecureField;
use crate::core::fields::{ExtensionOf, Field};
use crate::core::lookups::mle::{Mle, MleOps};
use crate::core::lookups::sumcheck::MultivariatePolyOracle;
use crate::core::lookups::utils::UnivariatePoly;

impl MleOps<BaseField> for CPUBackend {
impl MleOps<BaseField> for CpuBackend {
fn fix_first_variable(
mle: Mle<Self, BaseField>,
assignment: SecureField,
Expand All @@ -26,7 +26,7 @@ impl MleOps<BaseField> for CPUBackend {
}
}

impl MleOps<SecureField> for CPUBackend {
impl MleOps<SecureField> for CpuBackend {
fn fix_first_variable(
mle: Mle<Self, SecureField>,
assignment: SecureField,
Expand All @@ -46,7 +46,7 @@ impl MleOps<SecureField> for CPUBackend {
}
}

impl MultivariatePolyOracle for Mle<CPUBackend, SecureField> {
impl MultivariatePolyOracle for Mle<CpuBackend, SecureField> {
fn n_variables(&self) -> usize {
self.n_variables()
}
Expand Down
18 changes: 9 additions & 9 deletions crates/prover/src/core/backend/cpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ use crate::core::poly::circle::{CircleEvaluation, CirclePoly};
use crate::core::utils::bit_reverse;

#[derive(Copy, Clone, Debug)]
pub struct CPUBackend;
pub struct CpuBackend;

impl Backend for CPUBackend {}
impl Backend for CpuBackend {}

impl<T: Debug + Clone + Default> ColumnOps<T> for CPUBackend {
impl<T: Debug + Clone + Default> ColumnOps<T> for CpuBackend {
type Column = Vec<T>;

fn bit_reverse_column(column: &mut Self::Column) {
bit_reverse(column)
}
}

impl<F: Field> FieldOps<F> for CPUBackend {
impl<F: Field> FieldOps<F> for CpuBackend {
/// Batch inversion using the Montgomery's trick.
// TODO(Ohad): Benchmark this function.
fn batch_inverse(column: &Self::Column, dst: &mut Self::Column) {
Expand All @@ -49,17 +49,17 @@ impl<T: Debug + Clone + Default> Column<T> for Vec<T> {
}
}

pub type CPUCirclePoly = CirclePoly<CPUBackend>;
pub type CPUCircleEvaluation<F, EvalOrder> = CircleEvaluation<CPUBackend, F, EvalOrder>;
pub type CPUMle<F> = Mle<CPUBackend, F>;
pub type CpuCirclePoly = CirclePoly<CpuBackend>;
pub type CpuCircleEvaluation<F, EvalOrder> = CircleEvaluation<CpuBackend, F, EvalOrder>;
pub type CpuMle<F> = Mle<CpuBackend, F>;

#[cfg(test)]
mod tests {
use itertools::Itertools;
use rand::prelude::*;
use rand::rngs::SmallRng;

use crate::core::backend::{CPUBackend, Column, FieldOps};
use crate::core::backend::{Column, CpuBackend, FieldOps};
use crate::core::fields::qm31::QM31;
use crate::core::fields::FieldExpOps;

Expand All @@ -70,7 +70,7 @@ mod tests {
let expected = column.iter().map(|e| e.inverse()).collect_vec();
let mut dst = Column::zeros(column.len());

CPUBackend::batch_inverse(&column, &mut dst);
CpuBackend::batch_inverse(&column, &mut dst);

assert_eq!(expected, dst);
}
Expand Down
Loading

0 comments on commit 8d16c06

Please sign in to comment.