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: clean up SIS, placeholder #596

Merged
merged 31 commits into from
Jan 17, 2025
Merged

refactor: clean up SIS, placeholder #596

merged 31 commits into from
Jan 17, 2025

Conversation

gbotrel
Copy link
Collaborator

@gbotrel gbotrel commented Jan 7, 2025

Description

Clean up sis package, +simplify usage. Improves perf, sister PR in linea-monorepo.

What this PR does

  • functional changes to sis; interface changes from Write([]byte) / Sum() []byte to Hash(v, res []fr.Element)
  • the log2(bound) must now be divisible by 8 (size of byte)
  • instead of having a pattern where depending on the degree / log2(bound) we decompose bytes artisanally in buffers and copy things all over the place, uses a LimbIterator and VectorIterator. That also enables to define the core logic in this package only for matrix hashes as defined in linea-monorepo (which can now instantiate a specialized MatrixIterator)
  • port the generated code of "partialFFT" (not use directly in single hash but useful for Matrix hashing)

Summary by copilot

This pull request includes various changes to the ecc/bls12-377/fr/fft/fft.go file to optimize and improve the FFT implementation, as well as updates to the ecc/bls12-377/fr/sis/sis_test.go file to enhance the test coverage and performance. The most important changes include the optimization of FFT operations, the addition of new kernel functions, and improvements to the test cases.

FFT Optimizations and Improvements:

  • Removed heap allocation in the fftOptions function to improve performance for small FFTs. (ecc/bls12-377/fr/fft/fft.go) [1] [2]
  • Replaced element-wise multiplication with vectorized operations to enhance performance. (ecc/bls12-377/fr/fft/fft.go) [1] [2] [3]

New Kernel Functions:

  • Added new kernel functions kerDIFNP_64 and kerDITNP_64 to handle specific FFT sizes more efficiently. (ecc/bls12-377/fr/fft/fft.go)

Test Case Enhancements:

  • Updated test cases to skip certain scenarios and added more detailed logging for better test coverage. (ecc/bls12-377/fr/sis/sis_test.go) [1] [2]
  • Refactored and consolidated limb decomposition tests for better maintainability. (ecc/bls12-377/fr/sis/sis_test.go) [1] [2]

Other Changes:

  • Removed unused imports and redundant test functions to clean up the codebase. (ecc/bls12-377/fr/sis/sis_test.go) [1] [2] [3]

These changes collectively improve the performance, readability, and maintainability of the FFT implementation and its associated tests.

Benchmarks (on c7a / hp7a)

Note that when degree == 64, we have a special unrolled FFT, like before.

benchmark                                                              old ns/op     new ns/op     delta
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=5-192       3022719       2536620       -16.08%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=5-192       3021276       2536144       -16.06%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=5-192       6068463       5151716       -15.11%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=5-192       6153993       5132615       -16.60%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=5-192       12220952      10228376      -16.30%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=5-192       12166948      10210808      -16.08%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=5-192       25234309      21304715      -15.57%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=5-192       24481830      20703963      -15.43%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=5-192      49004898      43958093      -10.30%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=5-192      49887447      43735837      -12.33%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=5-192      97709485      90429276      -7.45%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=5-192      98769330      88874069      -10.02%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=5-192      194571063     176142024     -9.47%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=5-192      195710218     175182175     -10.49%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=6-192       2891496       2474968       -14.41%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=6-192       2887962       2477755       -14.20%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=6-192       5804094       4937156       -14.94%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=6-192       5798851       4946557       -14.70%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=6-192       11630721      9867145       -15.16%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=6-192       11639163      9886181       -15.06%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=6-192       23320903      19771001      -15.22%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=6-192       23838220      19850282      -16.73%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=6-192      47026608      39594336      -15.80%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=6-192      46913980      39444064      -15.92%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=6-192      94219892      79160855      -15.98%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=6-192      94770495      79261034      -16.37%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=6-192      189404150     157882197     -16.64%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=6-192      189252490     158017885     -16.50%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=6-192      1669098       1257369       -24.67%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=6-192      1663960       1255097       -24.57%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=16/log2-degree=6-192      3386086       2506506       -25.98%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=16/log2-degree=6-192      3396692       2507373       -26.18%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=16/log2-degree=6-192      6846404       5005118       -26.89%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=16/log2-degree=6-192      6816475       5010445       -26.50%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=16/log2-degree=6-192      13679808      10003808      -26.87%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=16/log2-degree=6-192      13706987      10008536      -26.98%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=16/log2-degree=6-192     27386158      20030297      -26.86%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=16/log2-degree=6-192     27403790      20030627      -26.91%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=16/log2-degree=6-192     54541907      40053105      -26.56%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=16/log2-degree=6-192     54492018      40088310      -26.43%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=16/log2-degree=6-192     112485299     80365282      -28.55%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=16/log2-degree=6-192     110826104     80219404      -27.62%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=9-192      2243459       1651832       -26.37%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=9-192      2251115       1645036       -26.92%

benchmark                                                              old allocs     new allocs     delta
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=5-192       2067           1028           -50.27%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=5-192       2067           1028           -50.27%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=5-192       4115           2052           -50.13%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=5-192       4115           2052           -50.13%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=5-192       8211           4100           -50.07%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=5-192       8211           4100           -50.07%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=5-192       16403          8196           -50.03%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=5-192       16403          8196           -50.03%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=5-192      32787          16388          -50.02%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=5-192      32787          16388          -50.02%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=5-192      65556          32772          -50.01%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=5-192      65556          32772          -50.01%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=5-192      131093         65540          -50.00%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=5-192      131093         65540          -50.00%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=6-192       20             4              -80.00%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=6-192       20             4              -80.00%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=6-192       20             4              -80.00%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=6-192       20             4              -80.00%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=6-192       20             4              -80.00%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=6-192       20             4              -80.00%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=6-192       20             4              -80.00%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=6-192       20             4              -80.00%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=6-192      20             4              -80.00%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=6-192      20             4              -80.00%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=6-192      21             4              -80.95%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=6-192      21             4              -80.95%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=6-192      22             4              -81.82%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=6-192      22             4              -81.82%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=6-192      532            4              -99.25%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=6-192      532            4              -99.25%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=16/log2-degree=6-192      1044           4              -99.62%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=16/log2-degree=6-192      1044           4              -99.62%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=16/log2-degree=6-192      2068           4              -99.81%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=16/log2-degree=6-192      2068           4              -99.81%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=16/log2-degree=6-192      4116           4              -99.90%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=16/log2-degree=6-192      4116           4              -99.90%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=16/log2-degree=6-192     8212           4              -99.95%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=16/log2-degree=6-192     8212           4              -99.95%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=16/log2-degree=6-192     16404          4              -99.98%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=16/log2-degree=6-192     16404          4              -99.98%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=16/log2-degree=6-192     32789          4              -99.99%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=16/log2-degree=6-192     32789          4              -99.99%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=9-192      87             36             -58.62%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=9-192      87             36             -58.62%

benchmark                                                              old bytes     new bytes     delta
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=5-192       72116         50320         -30.22%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=5-192       72119         50320         -30.23%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=5-192       138156        99472         -28.00%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=5-192       138156        99472         -28.00%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=5-192       271262        197776        -27.09%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=5-192       271408        197776        -27.13%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=5-192       541626        394384        -27.19%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=5-192       541402        394384        -27.16%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=5-192      1098680       787600        -28.31%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=5-192      1098680       787600        -28.31%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=5-192      2278325       1574032       -30.91%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=5-192      2278328       1574032       -30.91%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=5-192      4899760       3146896       -35.77%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=5-192      4899762       3146896       -35.77%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=6-192       12724         2192          -82.77%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=8/log2-degree=6-192       12717         2192          -82.76%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=6-192       13199         2192          -83.39%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=8/log2-degree=6-192       13199         2192          -83.39%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=6-192       15440         2192          -85.80%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=8/log2-degree=6-192       15440         2192          -85.80%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=6-192       23044         2192          -90.49%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=8/log2-degree=6-192       24751         2192          -91.14%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=6-192      56248         2192          -96.10%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=8/log2-degree=6-192      60219         2192          -96.36%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=6-192      187317        2192          -98.83%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=8/log2-degree=6-192      187318        2192          -98.83%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=6-192      711600        2192          -99.69%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=8/log2-degree=6-192      711600        2192          -99.69%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=6-192      29042         2192          -92.45%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=6-192      29034         2192          -92.45%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=16/log2-degree=6-192      45698         2192          -95.20%
BenchmarkSIS/ring-sis/inputs=2048/log2-bound=16/log2-degree=6-192      45698         2192          -95.20%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=16/log2-degree=6-192      79585         2192          -97.25%
BenchmarkSIS/ring-sis/inputs=4096/log2-bound=16/log2-degree=6-192      79585         2192          -97.25%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=16/log2-degree=6-192      150184        2192          -98.54%
BenchmarkSIS/ring-sis/inputs=8192/log2-bound=16/log2-degree=6-192      150813        2192          -98.55%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=16/log2-degree=6-192     302296        2192          -99.27%
BenchmarkSIS/ring-sis/inputs=16384/log2-bound=16/log2-degree=6-192     299088        2192          -99.27%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=16/log2-degree=6-192     641702        2192          -99.66%
BenchmarkSIS/ring-sis/inputs=32768/log2-bound=16/log2-degree=6-192     636709        2192          -99.66%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=16/log2-degree=6-192     1480560       2192          -99.85%
BenchmarkSIS/ring-sis/inputs=65536/log2-bound=16/log2-degree=6-192     1480560       2192          -99.85%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=9-192      100753        18064         -82.07%
BenchmarkSIS/ring-sis/inputs=1024/log2-bound=16/log2-degree=9-192      100748        18064         -82.07%

@gbotrel gbotrel marked this pull request as draft January 7, 2025 16:19
Copy link
Contributor

@ThomasPiellard ThomasPiellard left a comment

Choose a reason for hiding this comment

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

Looks good, not very important but why didn't you use the iter package ?

ecc/bls12-377/fr/sis/sis.go Show resolved Hide resolved
@gbotrel
Copy link
Collaborator Author

gbotrel commented Jan 17, 2025

Looks good, not very important but why didn't you use the iter package ?

iter is in go std since go 1.23 only, that would break our "compatible with latest 2 golang" promise. Syntactic sugar for later :) --> see here in comments

@gbotrel gbotrel merged commit 0493a37 into master Jan 17, 2025
5 checks passed
@gbotrel gbotrel deleted the refactor/sis branch January 17, 2025 14:54
@ivokub ivokub mentioned this pull request Jan 20, 2025
16 tasks
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