Skip to content

Commit

Permalink
Implement Backend for AVX512Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware committed Mar 18, 2024
1 parent 364984c commit 12ade2f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
15 changes: 15 additions & 0 deletions src/core/backend/avx512/accumulation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::qm31::PackedQM31;
use super::AVX512Backend;
use crate::core::air::accumulation::AccumulationOps;
use crate::core::fields::qm31::SecureField;
use crate::core::fields::secure::SecureColumn;

impl AccumulationOps for AVX512Backend {
fn accumulate(column: &mut SecureColumn<Self>, alpha: SecureField, other: &SecureColumn<Self>) {
let alpha = PackedQM31::broadcast(alpha);
for i in 0..column.len() {
let res_coeff = column.get_vec(i) * alpha + other.get_vec(i);
column.set_vec(i, res_coeff);
}
}
}
23 changes: 19 additions & 4 deletions src/core/backend/avx512/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod accumulation;
pub mod bit_reverse;
pub mod circle;
pub mod cm31;
Expand All @@ -10,9 +11,10 @@ use bytemuck::{cast_slice, cast_slice_mut, Pod, Zeroable};
use num_traits::Zero;

use self::bit_reverse::bit_reverse_m31;
use self::cm31::PackedCM31;
pub use self::m31::{PackedBaseField, K_BLOCK_SIZE};
use self::qm31::PackedQM31;
use super::{Column, ColumnOps};
use super::{Backend, Column, ColumnOps};
use crate::core::fields::m31::BaseField;
use crate::core::fields::secure::SecureColumn;
use crate::core::fields::{FieldExpOps, FieldOps};
Expand All @@ -23,8 +25,7 @@ pub const VECS_LOG_SIZE: usize = 4;
#[derive(Copy, Clone, Debug)]
pub struct AVX512Backend;

// BaseField.
// TODO(spapini): Unite with the M31AVX512 type.
impl Backend for AVX512Backend {}

unsafe impl Pod for PackedBaseField {}
unsafe impl Zeroable for PackedBaseField {
Expand Down Expand Up @@ -130,14 +131,28 @@ impl FromIterator<BaseField> for BaseFieldVec {
}

impl SecureColumn<AVX512Backend> {
pub fn set(&mut self, vec_index: usize, value: PackedQM31) {
pub fn set_vec(&mut self, vec_index: usize, value: PackedQM31) {
unsafe {
*self.cols[0].data.get_unchecked_mut(vec_index) = value.a().a();
*self.cols[1].data.get_unchecked_mut(vec_index) = value.a().b();
*self.cols[2].data.get_unchecked_mut(vec_index) = value.b().a();
*self.cols[3].data.get_unchecked_mut(vec_index) = value.b().b();
}
}
pub fn get_vec(&self, vec_index: usize) -> PackedQM31 {
unsafe {
PackedQM31([
PackedCM31([
*self.cols[0].data.get_unchecked(vec_index),
*self.cols[1].data.get_unchecked(vec_index),
]),
PackedCM31([
*self.cols[2].data.get_unchecked(vec_index),
*self.cols[3].data.get_unchecked(vec_index),
]),
])
}
}
}

#[cfg(all(target_arch = "x86_64", target_feature = "avx512f"))]
Expand Down
2 changes: 1 addition & 1 deletion src/core/backend/avx512/quotients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl QuotientOps for AVX512Backend {
random_coeff,
(domain_points_x, domain_points_y),
);
values.set(vec_row, row_accumlator);
values.set_vec(vec_row, row_accumlator);
}
SecureEvaluation { domain, values }
}
Expand Down
12 changes: 1 addition & 11 deletions src/core/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,14 @@ pub use cpu::CPUBackend;
use super::air::accumulation::AccumulationOps;
use super::commitment_scheme::quotients::QuotientOps;
use super::fields::m31::BaseField;
use super::fields::qm31::SecureField;
use super::fields::FieldOps;
use super::fri::FriOps;
use super::poly::circle::PolyOps;

pub mod avx512;
pub mod cpu;

pub trait Backend:
Copy
+ Clone
+ Debug
+ FieldOps<BaseField>
+ FieldOps<SecureField>
+ PolyOps
+ QuotientOps
+ FriOps
+ AccumulationOps
Copy + Clone + Debug + FieldOps<BaseField> + PolyOps + QuotientOps + AccumulationOps
{
}

Expand Down

0 comments on commit 12ade2f

Please sign in to comment.