Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
avoid some more memcopies
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarilli committed Dec 20, 2023
1 parent 517bb26 commit 5c3e7a2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/copy_permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ where
rhs.push(p);
}
assert_eq!(lhs.len(), rhs.len());
let omega_values = ComplexPoly::<CosetEvaluations>::from_real(omega_values.clone())?;
let omega_values = ComplexPoly::<CosetEvaluations>::from_real(omega_values)?;

for (
((((existing_lhs, existing_rhs), variable_cols_chunk), sigma_cols_chunk), alpha),
Expand Down Expand Up @@ -180,7 +180,7 @@ where
current_num.add_constant(&gamma)?;

// dnumerator w + beta * sigma(x) + gamma
let mut current_denum = ComplexPoly::<CosetEvaluations>::from_real(sigma_col.clone())?;
let mut current_denum = ComplexPoly::<CosetEvaluations>::from_real(sigma_col)?;
current_denum.scale_real(&beta)?;
current_denum.add_assign_real(&variable_col)?;
current_denum.add_constant(&gamma)?;
Expand Down
2 changes: 1 addition & 1 deletion src/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ macro_rules! impl_common_complex_poly {
($form:tt) => {
impl<'a> ComplexPoly<'a, $form> {
#[allow(dead_code)]
pub fn from_real(c0: Poly<'a, $form>) -> CudaResult<ComplexPoly<'a, $form>> {
pub fn from_real(c0: &Poly<'a, $form>) -> CudaResult<ComplexPoly<'a, $form>> {
assert!(c0.is_owned());
let domain_size = c0.storage.len();
assert!(domain_size.is_power_of_two());
Expand Down
32 changes: 7 additions & 25 deletions src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ fn gpu_prove_from_trace<
// asynchronous H2D copies complete before h_vec gets dropped.
copy_permutation_challenges_partial_product_terms.copy_from_slice(&h_vec)?;

let mut quotient = ComplexPoly::<LDE>::zero(quotient_degree * domain_size)?;
let mut quotient = ComplexPoly::<LDE>::empty(quotient_degree * domain_size)?;
let base_monomial_setup = raw_setup.into_monomials()?;
let mut setup_holder =
SetupCache::from_monomial(base_monomial_setup, fri_lde_degree, used_lde_degree)?;
Expand Down Expand Up @@ -843,7 +843,7 @@ fn gpu_prove_from_trace<
let mut challenges = dvec!(h_challenges.len());
challenges.copy_from_slice(&h_challenges)?;

let mut deep_quotient = ComplexPoly::<LDE>::zero(fri_lde_degree * domain_size)?;
let mut deep_quotient = ComplexPoly::<LDE>::empty(fri_lde_degree * domain_size)?;
let z = h_z.clone().into();
let z_omega = h_z_omega.clone().into();
for coset_idx in 0..fri_lde_degree {
Expand Down Expand Up @@ -1729,10 +1729,7 @@ pub fn compute_denom_at_base_point<'a>(
point: &DF,
) -> CudaResult<Poly<'a, CosetEvaluations>> {
// TODO: This pattern is a temporary workaround, not optimal
let mut denom = Poly::<CosetEvaluations>::zero(roots.domain_size())?;
denom
.storage
.copy_from_device_slice(roots.storage.as_ref())?;
let mut denom = roots.clone();
denom.sub_constant(point)?;
denom.inverse()?;
Ok(denom)
Expand All @@ -1743,11 +1740,7 @@ pub fn compute_denom_at_ext_point<'a>(
point: &DExt,
) -> CudaResult<ComplexPoly<'a, CosetEvaluations>> {
// TODO: This pattern is a temporary workaround, not optimal
let mut denom = ComplexPoly::<CosetEvaluations>::zero(roots.domain_size())?;
denom
.c0
.storage
.copy_from_device_slice(roots.storage.as_ref())?;
let mut denom = ComplexPoly::<CosetEvaluations>::from_real(roots)?;
denom.sub_constant(point)?;
denom.inverse()?;
Ok(denom)
Expand All @@ -1769,11 +1762,7 @@ fn compute_deep_quotiening_over_coset(
challenges: &DVec<EF>,
) -> CudaResult<ComplexPoly<'static, CosetEvaluations>> {
let domain_size = trace_polys.variable_cols[0].domain_size();
// TODO:
// When we add an API to allocate empty vectors without pre-zeroing them,
// construct quotient that way. It will be fine because
// deep_quotient_except_public_inputs sets quotient disregarding initial values.
let mut quotient = ComplexPoly::<CosetEvaluations>::zero(domain_size)?;
let mut quotient = ComplexPoly::<CosetEvaluations>::empty(domain_size)?;

let denom_at_z = compute_denom_at_ext_point(&roots, &z)?;
let denom_at_z_omega = compute_denom_at_ext_point(&roots, &z_omega)?;
Expand Down Expand Up @@ -1835,7 +1824,7 @@ fn compute_deep_quotiening_over_coset(
for (open_at, set) in public_input_opening_tuples.into_iter() {
let open_at_df: DF = open_at.clone().into();
let denom_at_point = compute_denom_at_base_point(&roots, &open_at_df)?;
// deep_quotient_add_opening accumulates into quotient_for_row, so it does need to be pre-zeroed
// deep_quotient_public_input accumulates into quotient_for_row, so it does need to be pre-zeroed
let mut quotient_for_row = ComplexPoly::<CosetEvaluations>::zero(domain_size)?;
for (column, expected_value) in set.into_iter() {
deep_quotient_public_input(
Expand All @@ -1846,14 +1835,7 @@ fn compute_deep_quotiening_over_coset(
)?;
challenge_id += 1;
}
// TODO: If mul_assign (and similar calls) can handle ComplexPolys interacting with Polys,
// we wouldn't need the denom_at_point_ext intermediate
let mut denom_at_point_ext = ComplexPoly::<CosetEvaluations>::zero(domain_size)?;
denom_at_point_ext
.c0
.storage
.copy_from_device_slice(&denom_at_point.storage.as_ref())?;
quotient_for_row.mul_assign(&denom_at_point_ext)?;
quotient_for_row.mul_assign_real(&denom_at_point)?;
quotient.add_assign(&quotient_for_row)?;
}

Expand Down

0 comments on commit 5c3e7a2

Please sign in to comment.