Fast CPU Points Generation Library

22 replies 120 views
falcon2019Full Member
Posts: 50 · Reputation: 425
#1Apr 25, 2021, 09:54 PM
Yo! I just wrote a C library that showcases how to use libsecp256k1 for super quick batch additions. It can scan a specified range from start to end really fast. You can stream the generated points or use it to test your CPU's performance. Check it out on GitHub!
4 Reply Quote Share
dan.walletSenior Member
Posts: 9 · Reputation: 848
#2Apr 27, 2021, 10:29 AM
Sounds interesting! How does it actually work?
4 Reply Quote Share
0xWolfMember
Posts: 54 · Reputation: 180
#3Apr 27, 2021, 12:04 PM
Just set a start point, define a size, and pick the number of threads. The rest is all magic! It uses only two EC point multiplications, so it’s efficient. To generate a billion points, it’s crazy fast.
3 Reply Quote Share
falcon2019Full Member
Posts: 50 · Reputation: 425
#4Apr 28, 2021, 05:08 AM
I bet some people are gonna spend days breaking down that code.
5 Reply Quote Share
f4rm_2021Member
Posts: 1 · Reputation: 82
#5Apr 30, 2021, 02:45 AM
Results on my old Ryzen 7 5800H: Using 16 threads, I’m hitting about 42.63 million keys per second. Sure, it’s slower than your i9 by 45-50%, but still pretty decent! Have you tried RELIC? I think it’s faster than libsecp256k1.
4 Reply Quote Share
falcon2019Full Member
Posts: 50 · Reputation: 425
#6Apr 30, 2021, 08:10 AM
Wait, what does your code actually do? How does it fit into this whole discussion?
4 Reply Quote Share
GigaSageSenior Member
Posts: 1 · Reputation: 1319
#7Apr 30, 2021, 08:45 AM
This library is all about generating all affine points in a specific range. I’m not clear on what your code does though.
0 Reply Quote Share
falcon2019Full Member
Posts: 50 · Reputation: 425
#8Apr 30, 2021, 09:53 AM
Appreciate the code! Just skimmed it on my phone. Is it just batch inverse and additions? I think I have an OpenCL version that does something similar. I’ll benchmark it on my 7950X.
0 Reply Quote Share
sam.gasNewbie
Posts: 10 · Reputation: 11
#9May 1, 2021, 04:44 PM
Definitely! The inversion tree is parallelized, allowing SIMD optimizations. Field multiplications can run in parallel, making it quicker to create and break down the inverses.
1 Reply Quote Share
atlas_2014Full Member
Posts: 5 · Reputation: 324
#10May 1, 2021, 09:37 PM
Awesome! I have some ideas to improve it. You could precompute neg(x1) outside the loop, saving some operations. Might help speed things up a bit.
3 Reply Quote Share
falcon2019Full Member
Posts: 50 · Reputation: 425
#11May 2, 2021, 07:17 AM
You’re spot on! That would save a few operations. And yeah, small optimizations can make a difference. I also forgot to add -march=native for native CPU instructions. Gonna fix that.
1 Reply Quote Share
atlas_2014Full Member
Posts: 5 · Reputation: 324
#12May 2, 2021, 10:59 AM
But what’s the main point of this code? How exactly are the X points stored?
5 Reply Quote Share
falcon2019Full Member
Posts: 50 · Reputation: 425
#13May 2, 2021, 04:19 PM
It’s about fast point generation across the entire range. Check db.c for how the X coordinates are stored. They’re saved as little-endian bytes, with an integer key offset. What did you expect?
0 Reply Quote Share
falcon2019Full Member
Posts: 50 · Reputation: 425
#14May 2, 2021, 08:39 PM
So is it all in one file? How do I even run this? I know C++ and Python, but C is a whole different beast.
3 Reply Quote Share
atlas_2014Full Member
Posts: 5 · Reputation: 324
#15May 3, 2021, 01:55 AM
Compile it according to the README. You can manipulate the database however you want, just treat the values as offsets. The code is stable, but watch out for specific edge cases I’ll fix.
4 Reply Quote Share
falcon2019Full Member
Posts: 50 · Reputation: 425
#16May 3, 2021, 05:16 AM
I cleaned up some ops in a separate branch: Pre-computed negated x2. Still, speed fluctuates too much to notice a difference.
3 Reply Quote Share
atlas_2014Full Member
Posts: 5 · Reputation: 324
#17May 3, 2021, 07:32 AM
But what’s the database structure? If it’s all in one file, isn’t that gonna slow down lookups?
0 Reply Quote Share
falcon2019Full Member
Posts: 50 · Reputation: 425
#18May 3, 2021, 12:51 PM
If a single file with a B*-tree structure has no advantage for lookups, I’m not sure what does. Maybe a ton of text files and linear searches?
2 Reply Quote Share
atlas_2014Full Member
Posts: 5 · Reputation: 324
#19May 3, 2021, 04:15 PM
Haha, yeah right! You can do what you want with the generated points. But storing everything on disk isn’t optimal either.
1 Reply Quote Share
falcon2019Full Member
Posts: 50 · Reputation: 425
#20May 3, 2021, 05:12 PM
How much RAM do we need for 2^30 points? And what GPUs could keep operation speeds instant?
0 Reply Quote Share

Related topics