-
Notifications
You must be signed in to change notification settings - Fork 36
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
[Design Discussion] Zk Accel API via trait object [skip ci - Don't merge] #13
base: taiko/unstable
Are you sure you want to change the base?
Conversation
Deprecate pre-ZAL API Insert patch in `Cargo.toml` for `../halo2curves`
.map(|commitment| { | ||
let evals: Vec<F> = rotations_vec | ||
.par_iter() | ||
// .par_iter() | ||
.iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires Send + Sync but having ZalEngine being part of Commitment prevents that
@@ -192,7 +192,8 @@ where | |||
let v: ChallengeV<_> = transcript.squeeze_challenge_scalar(); | |||
|
|||
let quotient_polynomials = rotation_sets | |||
.par_iter() | |||
// .par_iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -62,7 +62,7 @@ where | |||
mut msm_accumulator: DualMSM<'params, E>, | |||
) -> Result<Self::Guard, Error> | |||
where | |||
I: IntoIterator<Item = VerifierQuery<'com, E::G1Affine, MSMKZG<E>>> + Clone, | |||
I: IntoIterator<Item = VerifierQuery<'com, E::G1Affine, MSMKZG<'params, E>>> + Clone, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -58,7 +58,7 @@ where | |||
mut msm_accumulator: DualMSM<'params, E>, | |||
) -> Result<Self::Guard, Error> | |||
where | |||
I: IntoIterator<Item = VerifierQuery<'com, E::G1Affine, MSMKZG<E>>> + Clone, | |||
I: IntoIterator<Item = VerifierQuery<'com, E::G1Affine, MSMKZG<'params, E>>> + Clone, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the In the first place, stuffing the engine in those data-structure was to avoid changing the function signature everywhere, but in the end we have to. Hence we should probably make the engine an input only in the functions that require MSM evaluation and pass it as an extra input:
|
Regarding the lifetime issue. I think it could make a lot of sense to use the |
I think I need to understand better what is the nature of the ZAL engine object. Here is my current understanding: We have a caller, e.g. the
If this is the way, I don't think we can avoid doing heavy annotation of lifetimes. My intuition is, that if we do not annotate it every where we pass something, that contains a reference, how can the lifetime checker know which lifetimes to link? This seems to be a heavy drawback of the An alternative could be to put it in an The last approach, i.e.
raises some questions, I need input on:
I think it boils down to that the API is clear, but the semantics are still in flux. |
Yes for the engine object.
Yes exactly.
Adding lifetimes within Halo2 is OK, having new lifetimes that leak into end users like zkevm-circuits or Powdr is API breakage. If we break the API, I think the smarter way is to just not store the engine in the low-level datastructure of Halo2 and just pass it around: no lifetimes, no issues of Send+Sync, easy to understand, maintain and refactor.
This is possible, though Regarding overhead, the whole point of Send+Sync is to allow the following section: halo2/halo2_proofs/src/poly/kzg/multiopen/shplonk.rs Lines 121 to 134 in fb69aa2
with 3 nested parallel loops, that will all increment and decrement Arc, leading to cache flushes, for a resource that is not even used in those loops. So we use Arc to allow this section to be parallel but introduce overhead. Hence:
Halo2 doesn't need to know, it only has a pointer to it. It may use thread-local resources.
In Halo2, there is no part of the code that call 2 MSMs in parallel. In general I think if we use an "accelerator", Halo2 expresses concurrency to it (with the async API) and let it handle parallelism best. And it would mess up with thread-local storage. For example, assuming Cuda, you would really want those concurrent MSMs to be issued on different cuda streams: Similarly for OpenCL event queues: Or approaches using a supervisor thread with load-balancing queue to reduce contention: but only the accel runtime knows of those, not rayon. Also the async API is out-of-scope for this PR. Implementation complexity would be easier though, in order:
This is a per-accelerator design decision.
If 2 MSMs can be issued in parallel, then we can use the async API, but it's not in scope for this. And Halo2 doesn't issue multiple MSMs in parallel as far as I've seen.
Cannot be moved to another thread, cannot be copied is the less restrictive constraint for engine design. But we use a reference to it. It is possible to allow an engine to be called from any thread with locks or lock-free queues but debugging concurrent data structure to remove deadlocks, livelocks and race conditions is extremely time-consuming, when it doesn't straight up require formal verification.
Same as above.
No, just like you can't copy a database handle, memory allocated, a network connection or a GPU. It's an uncopyable and unmovable resource and you interact with it through a reference to it.
N/A
|
This draft PR should not be merged, it's for laying out design tradeoffs of ZAL in Halo2.
see #12 for the generics approach
This uses:
MsmAccel<C: CurveAffine>
to Halo2Zal: https://github.com/taikoxyz/halo2curves/blob/zal-on-0.3.2/src/zal.rs
Issues:
'zal
lifetime parameter on some traits, but at a high level it gets merged into the'params
lifetime.cc @einar-taiko