Skip to content

Commit

Permalink
almost compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
VitaliiH authored and VitaliiH committed Jan 29, 2025
1 parent cae4522 commit d441dd2
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 169 deletions.
4 changes: 4 additions & 0 deletions crates/prover/src/core/backend/icicle/accumulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ impl AccumulationOps for IcicleBackend {
// nvtx::range_pop!();
// }
}

fn generate_secure_powers(felt: crate::core::fields::qm31::SecureField, n_powers: usize) -> Vec<crate::core::fields::qm31::SecureField> {
todo!()
}
}
57 changes: 33 additions & 24 deletions crates/prover/src/core/backend/icicle/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::mem::transmute;

use icicle_core::ntt::{FieldImpl, NTTConfig, Ordering};
use icicle_cuda_runtime::device_context::DeviceContext;
use icicle_cuda_runtime::memory::HostSlice;
use icicle_cuda_runtime::memory::{DeviceSlice, DeviceVec, HostSlice};
use icicle_m31::dcct::{self, get_dcct_root_of_unity, initialize_dcct_domain};
use icicle_m31::field::ScalarField;
use itertools::Itertools;
Expand All @@ -11,7 +11,7 @@ use super::IcicleBackend;
use crate::core::backend::icicle::column::DeviceColumn;
use crate::core::backend::{Col, Column, CpuBackend};
use crate::core::circle::{CirclePoint, Coset};
use crate::core::fields::m31::BaseField;
use crate::core::fields::m31::{BaseField, M31};
use crate::core::fields::qm31::SecureField;
use crate::core::poly::circle::{
CanonicCoset, CircleDomain, CircleEvaluation, CirclePoly, PolyOps,
Expand Down Expand Up @@ -43,12 +43,16 @@ impl PolyOps for IcicleBackend {
// todo!()
if eval.domain.log_size() <= 3 || eval.domain.log_size() == 7 {
// TODO: as property .is_dcct_available etc...
return unsafe {
transmute(CpuBackend::interpolate(
transmute(eval),
transmute(itwiddles),
))
};
// return unsafe {
// transmute(CpuBackend::interpolate(
// transmute(eval),
// transmute(itwiddles),
// ))
// };
todo!(
"log2={} size not implemented in Icicle backend",
eval.domain.log_size()
)
}

let values = eval.values;
Expand All @@ -61,12 +65,12 @@ impl PolyOps for IcicleBackend {
nvtx::range_pop!();

let mut evaluations = vec![ScalarField::zero(); values.len()];
let values: Vec<ScalarField> = unsafe { transmute(values) };

let mut cfg = NTTConfig::default();
cfg.ordering = Ordering::kMN;
nvtx::range_push!("[ICICLE] interpolate");
dcct::interpolate(
HostSlice::from_slice(&values),
unsafe { transmute::<_, &DeviceSlice<_>>(&values.data[..]) },
&cfg,
HostSlice::from_mut_slice(&mut evaluations),
)
Expand Down Expand Up @@ -102,8 +106,8 @@ impl PolyOps for IcicleBackend {
}

fn extend(poly: &CirclePoly<Self>, log_size: u32) -> CirclePoly<Self> {
// todo!()
unsafe { transmute(CpuBackend::extend(transmute(poly), log_size)) }
todo!()
// unsafe { transmute(CpuBackend::extend(transmute(poly), log_size)) }
}

fn evaluate(
Expand All @@ -113,13 +117,17 @@ impl PolyOps for IcicleBackend {
) -> CircleEvaluation<Self, BaseField, BitReversedOrder> {
// todo!()
if domain.log_size() <= 3 || domain.log_size() == 7 {
return unsafe {
transmute(CpuBackend::evaluate(
transmute(poly),
domain,
transmute(twiddles),
))
};
// return unsafe {
// transmute(CpuBackend::evaluate(
// transmute(poly),
// domain,
// transmute(twiddles),
// ))
// };
todo!(
"log2={} size not implemented in Icicle backend",
domain.log_size()
)
}

let values = poly.extend(domain.log_size()).coeffs;
Expand All @@ -130,22 +138,23 @@ impl PolyOps for IcicleBackend {
initialize_dcct_domain(domain.log_size(), rou, &DeviceContext::default()).unwrap();
nvtx::range_pop!();

let mut evaluations = vec![ScalarField::zero(); values.len()];
let values: Vec<ScalarField> = unsafe { transmute(values) };
// let mut evaluations = vec![ScalarField::zero(); values.len()];
let mut evaluations = DeviceColumn { data: DeviceVec::cuda_malloc(values.len()).unwrap()};

let mut cfg = NTTConfig::default();
cfg.ordering = Ordering::kNM;
nvtx::range_push!("[ICICLE] evaluate");
dcct::evaluate(
HostSlice::from_slice(&values),
unsafe { transmute::<&DeviceSlice<M31>, &DeviceSlice<_>>(&values.data[..])},
&cfg,
HostSlice::from_mut_slice(&mut evaluations),
unsafe { transmute::<&mut DeviceSlice<M31>, &mut DeviceSlice<_>>(&mut evaluations.data[..])},
)
.unwrap();
nvtx::range_pop!();
unsafe {
transmute(IcicleCircleEvaluation::<BaseField, BitReversedOrder>::new(
domain,
transmute(evaluations),
evaluations,
))
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/core/backend/icicle/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ impl FriOps for IcicleBackend {
fn decompose(
eval: &SecureEvaluation<Self, BitReversedOrder>,
) -> (SecureEvaluation<Self, BitReversedOrder>, SecureField) {
// todo!()
unsafe { transmute(CpuBackend::decompose(unsafe { transmute(eval) })) }
todo!()
//unsafe { transmute(CpuBackend::decompose(unsafe { transmute(eval) })) }
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/prover/src/core/backend/icicle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ mod tests {
use crate::core::vcs::prover::MerkleProver;
use crate::core::vcs::verifier::MerkleVerifier;
use crate::{m31, qm31};
use crate::core::backend::Column;

impl<F: ExtensionOf<BaseField>, EvalOrder> IntoIterator
for CircleEvaluation<IcicleBackend, F, EvalOrder>
Expand All @@ -55,13 +56,13 @@ mod tests {
{
type Item = F;
type IntoIter = std::vec::IntoIter<F>;

/// Creates a consuming iterator over the evaluations.
///
/// Evaluations are returned in the same order as elements of the domain.
fn into_iter(self) -> Self::IntoIter {
todo!()
//todo!()
// self.values.into_iter()
self.values.to_cpu().into_iter()
}
}

Expand Down
Loading

0 comments on commit d441dd2

Please sign in to comment.