Use precomputed small prime squares in GPU sieve

This commit is contained in:
Marek Lemańczyk committed 2025-10-26 22:28:04 +01:00
1 parent 794e092e57
commit 3d458fc6da
4 files changed
+22 -9

No files matched your search

@@ -7,7 +7,12 @@ namespace PerfectNumbers.Core.Gpu;
internal static class PrimeTesterKernels
{
// GPU kernel: small-prime sieve only. Returns 1 if passes sieve (probable prime), 0 otherwise.
public static void SmallPrimeSieveKernel(Index1D index, ArrayView<ulong> numbers, ArrayView<uint> smallPrimes, ArrayView<byte> results)
public static void SmallPrimeSieveKernel(
Index1D index,
ArrayView<ulong> numbers,
ArrayView<uint> smallPrimes,
ArrayView<ulong> smallPrimeSquares,
ArrayView<byte> results)
{
ulong n = numbers[index];
@@ -28,7 +33,7 @@ internal static class PrimeTesterKernels
for (int i = 0; i < length; i++)
{
ulong prime = smallPrimes[i];
ulong primeSquare = (ulong)prime * prime;
ulong primeSquare = smallPrimeSquares[i];
bool withinRange = primeSquare <= n;
ulong remainder = n % prime;
bool divides = remainder == 0UL;