Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: optimize opening proof gpu usage #569

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

sagar-a16z
Copy link
Contributor

@sagar-a16z sagar-a16z commented Jan 24, 2025

  • Supports building --features icicle on MacOS (skips the CUDA backend from icicle-jolt)
  • Ammortizes gpu copy costs for KZG Opening proofs
  • Reduce vector allocations by using std::Borrow
  • Batched hyperKZG witness generation
  • Reintroduced GPU usage for trace commitments where scalars are > 10bit. (needs review, potential memory regression)
  • removed cloning of scalars before appending to transcript in HyperKZG

Brings a 1.4x(30%) speedup to the KZG opening proof. GPU opening proofs are ~2.8x(65%) faster than CPU now.
Net improvement of 15% in prover time GPU vs CPU.

@sagar-a16z sagar-a16z force-pushed the sagar/optimized_opening branch 3 times, most recently from d7344b6 to 6373f3f Compare January 26, 2025 21:10
@sagar-a16z sagar-a16z changed the title Sagar/optimized opening Optimize opening proof gpu usage Jan 26, 2025
@sagar-a16z sagar-a16z changed the title Optimize opening proof gpu usage fix: optimize opening proof gpu usage Jan 26, 2025
@sagar-a16z sagar-a16z force-pushed the sagar/optimized_opening branch 4 times, most recently from 1e19b77 to cc0b559 Compare January 27, 2025 02:08
@sagar-a16z sagar-a16z marked this pull request as ready for review January 29, 2025 00:40
@sagar-a16z sagar-a16z requested a review from moodlezoup January 29, 2025 00:40
@sagar-a16z sagar-a16z force-pushed the sagar/optimized_opening branch from 180d219 to 293fd54 Compare January 29, 2025 02:36
Copy link
Collaborator

@moodlezoup moodlezoup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just a couple of nits but looks good to merge otherwise

Comment on lines +293 to +295
// let q_k_com: Vec<P::G1Affine> = optimal_iter!(quotients)
// .map(|q| UnivariateKZG::commit(&pp.commit_pp, q).unwrap())
// .collect();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
// let q_k_com: Vec<P::G1Affine> = optimal_iter!(quotients)
// .map(|q| UnivariateKZG::commit(&pp.commit_pp, q).unwrap())
// .collect();

@@ -230,30 +230,66 @@ where
Ok(commitments.into_iter().map(|c| c.into_affine()).collect())
}

// This API will try to minimize copies to the GPU or just do the batches in parallel on the CPU
#[tracing::instrument(skip_all, name = "KZG::commit_variable_batch_with_mode")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[tracing::instrument(skip_all, name = "KZG::commit_variable_batch_with_mode")]
#[tracing::instrument(skip_all, name = "KZG::commit_variable_batch")]

Ok(commitments.into_iter().map(|c| c.into_affine()).collect())
}

#[tracing::instrument(skip_all, name = "KZG::commit_variable_batch_with_mode")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[tracing::instrument(skip_all, name = "KZG::commit_variable_batch_with_mode")]
#[tracing::instrument(skip_all, name = "KZG::commit_variable_batch_univariate")]

})
.collect::<Vec<_>>();

// TODO(sagar): Are the coefficients of these witness polynomials always of the same length?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can delete this comment

MultilinearPolynomial::I64Scalars(poly) => {
Either::Right((i, max_num_bits, poly.coeffs_as_field_elements()))
}
_ => Either::Left((i, max_num_bits, poly)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ => Either::Left((i, max_num_bits, poly)),
MultilinearPolynomial::U8Scalars(_) => unreachable!("MultilinearPolynomial::U8Scalars cannot have more than 10 bits")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants