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

Refactor cpu prover #629

Merged
merged 5 commits into from
Jul 11, 2024
Merged

Refactor cpu prover #629

merged 5 commits into from
Jul 11, 2024

Conversation

bxue-l2
Copy link
Contributor

@bxue-l2 bxue-l2 commented Jul 9, 2024

Why are these changes needed?

This PR refactors GPU provers by

  • adding new interface responsible for computation, and it is useful for gpu implementation in the future
  • adding parallelization among different tasks including (proof), (lengthCommitment) and so on
  • adding better log and remove verbosity flag

The encode task has 5 smaller tasks, and the time spent is the sum of all small task. With the second optimization, the time spent would be the max of all tasks. Empricially speaking, it would reduce the encoding tie from 8.15sec to 5.18 second, which is about 37.5% improvement.

Checks

  • I've made sure the lint is passing in this PR.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

@bxue-l2 bxue-l2 requested review from mooselumph and jianoaix July 9, 2024 01:54
@bxue-l2 bxue-l2 requested a review from dmanc July 9, 2024 02:09
Copy link
Contributor

@dmanc dmanc left a comment

Choose a reason for hiding this comment

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

lgtm

m := uint64(len(polyFr)) - 1
dim := (m - j) / l

toeV := make([]fr.Element, 2*dimE-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Make 2*dimE-1 a constant

"github.com/consensys/gnark-crypto/ecc/bn254/fr"
)

type CpuComputer struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Rename to CPUComputer or CPUProofComputer

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to CPUProofComputer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dont think we should add cpu into the name, since in the future, it could have been a gpu. Either cpu or gpu, I don't think it makes sense to have both

"github.com/consensys/gnark-crypto/ecc/bn254/fr"
)

type ProofComputeDevice interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about just ProofComputer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is its old name

@bxue-l2
Copy link
Contributor Author

bxue-l2 commented Jul 9, 2024

Actually, I made a mistake, this optimization would not save us from 8.15 sec to 5.18sec. Probably only going to save us 100-200ms. This is because the bottleneck proving part isn't parallelized, and that total time is 8.15.

The parallelization is only saving 100ms for encoding.

type RsEncodeResult struct {
Frames []rs.Frame
Indices []uint32
Err error
Copy link
Contributor

Choose a reason for hiding this comment

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

here and below: it's more readable to move the error to the bottom of this field list

Copy link
Contributor

Choose a reason for hiding this comment

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

The file name could be proof_computer.go

"github.com/consensys/gnark-crypto/ecc/bn254/fr"
)

type CpuComputer struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to CPUProofComputer

Copy link
Contributor

Choose a reason for hiding this comment

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

Can the file name match closer to the content?
If file name is encoder (encode as a verb isn't fit well for file name), maybe the interface below should be ProofEncoder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how about proof_device.go

@bxue-l2 bxue-l2 merged commit 4dd73e2 into Layr-Labs:master Jul 11, 2024
6 checks passed
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.

3 participants