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

experiment "grid-stride loop" parallism on sumcheck #739

Open
hero78119 opened this issue Dec 12, 2024 · 0 comments
Open

experiment "grid-stride loop" parallism on sumcheck #739

hero78119 opened this issue Dec 12, 2024 · 0 comments

Comments

@hero78119
Copy link
Collaborator

hero78119 commented Dec 12, 2024

Context

Discussion #730 (comment) and commit 269c9fa shows the way of traverse vector can be huge different.
For commit 269c9fa, in fabonacci benchmark with 2^20 max_step, the e2e latency for this function can drop from ~2.52s -> 1.2s, more than 50%. It motivated us to further break down the reasoning

Analysis

There might be 2 factors to account for the boost

case 1: before/after mem allocation & copy

  • vector allocation: num_col * (#threads + 1) -> num_col
  • #mem copy: num_col * #threads (from collect()) -> 0

    mem copy due to vector initialized in parallel
    which account for the factor for this boost

case 2: cache hit/miss rate

similar discuss issues Plonky2, shared by @kunxian-xia

The new way of traverse to be more CPU cache friendly. It motivated me to review ceno implementation in other part which exposed similar patterns and probably we can polishing it.

"grid-stride loop" design from CUDA: https://developer.nvidia.com/blog/cuda-pro-tip-write-flexible-kernels-grid-stride-loops/

From case 2, it motivated to experiment traverse vector in more (cpu) cache friendly pattern

In summary

# naive traverse vector via rayon
vector.par_iter().map(xxx)....

# "grid-stride loop"
(0..num_cores).into_par_iter().for_each(|thread_id| {
    vector.iter().skip(thread_id).step_by(num_cores).map(xxx)....
})

In Ceno, there is playground on on sumcheck uni-variate computation to experiment "grid-stride loop" https://github.com/scroll-tech/ceno/blob/master/sumcheck/src/prover_v2.rs#L787-L935.

verify idea in sumcheck

Ceno sumcheck implementation are based on devirgo style, see #77.
In summary, we break down multi-variate polynomials evaluations vector into #n_threads chunk, each range handle by a thread.
This design is to minimize the synchronized overhead and maximize cache hit rate on L1 cache. This design bring ~+40% performance boost on multi-cores.

However, motivated by "grid-stride loop" design and review devirgo sumcheck. I thought devirgo sumcheck might not be the ultimate implementation, because separating vector into #n_thread chunk will bring more L2/L3 cache miss giving a huge vector can't fit into cache easily. We probably can achieve both

  • less synchronization overhead
  • high cache hit rate

in one shot.

noted of benchmark

We can quick modify https://github.com/scroll-tech/ceno/blob/master/sumcheck/src/prover_v2.rs#L787-L935 to "grid-stride loop" style, and do benchmark here https://github.com/scroll-tech/ceno/blob/master/sumcheck/benches/devirgo_sumcheck.rs and compare between

  • original naive
  • devirgo sumcheck
  • "grid-stride loop" in uni-variate computation (build based on original naive version)

Follows up

If this method prove to be worthy, we can do that in rayon crate to support "grid-stride loop" on vector parallel traverse, and upstream to rayon library

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

No branches or pull requests

1 participant