Skip to content

Replace precomputed prime table with on-the-fly Miller-Rabin computation#802

Open
PointKernel wants to merge 5 commits intoNVIDIA:devfrom
PointKernel:next-prime-on-the-fly
Open

Replace precomputed prime table with on-the-fly Miller-Rabin computation#802
PointKernel wants to merge 5 commits intoNVIDIA:devfrom
PointKernel:next-prime-on-the-fly

Conversation

@PointKernel
Copy link
Copy Markdown
Member

This PR replaces the precomputed prime table lookup with an on-the-fly calculation. While the new approach is slightly slower, it adds at most ~2 µs of overhead, making the performance impact negligible, and eliminates the need to store a large precomputed prime table.

@PointKernel PointKernel added the type: improvement Improvement / enhancement to an existing function label Apr 16, 2026
Copy link
Copy Markdown
Collaborator

@sleeepyjack sleeepyjack left a comment

Choose a reason for hiding this comment

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

Ha, a Miller-Rabin test in the wild! My old Discrete Math 101 professor would be proud of us :)

The diff in the prime.hpp is too large for the GH web UI to open. I inspected the file manually. One thing that caught my eye is that we use 128bit integers to prevent overflow. We have a macro check CUCO_HAS_INT128 that we should use in this case and have a fallback ready.

if constexpr (cuco::is_double_hashing<probe>::value) {
return (CGSize == 1) ? 422 // 211 x 1 x 2
: 412; // 103 x 2 x 2
: 404; // 101 x 2 x 2
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why is this change needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: improvement Improvement / enhancement to an existing function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants