Revert "Merge pull request #251 from mlemanczyk/codex/refactor-prime-checking-on-gpu-n5t2pm"

This reverts commit 936ce239db, reversing
changes made to e14b77e504.
This commit is contained in:
mlemanczyk committed 2025-11-02 11:22:14 +01:00
1 parent 936ce239db
commit 2281d9535e
23 files changed
+880 -1187

No files matched your search

@@ -1,19 +1,9 @@
using System.Runtime.CompilerServices;
using ILGPU;
using ILGPU.Algorithms;
using ILGPU.Runtime;
namespace PerfectNumbers.Core.Gpu;
internal enum HeuristicGpuDivisorTableKind : byte
{
GroupA = 0,
GroupBEnding1 = 1,
GroupBEnding7 = 7,
GroupBEnding9 = 9,
Combined = 255,
}
internal static class PrimeTesterKernels
{
// GPU kernel: small-prime sieve only. Returns 1 if passes sieve (probable prime), 0 otherwise.
@@ -61,13 +51,13 @@ internal static class PrimeTesterKernels
int length = (int)primes.Length;
for (int i = 0; i < length; i++)
{
ulong prime = primes[i];
ulong primeSquare = primeSquares[i];
if (primeSquare > n)
{
break;
}
ulong prime = primes[i];
if (n % prime == 0UL)
{
result = 0;
@@ -78,31 +68,19 @@ internal static class PrimeTesterKernels
results[index] = result;
}
public static void HeuristicTrialDivisionKernel(
Index1D index,
ArrayView<int> resultFlag,
ulong n,
ulong maxDivisorSquare,
HeuristicGpuDivisorTableKind tableKind,
HeuristicGpuDivisorTables tables)
public static void HeuristicTrialDivisionKernel(Index1D index, ArrayView<ulong> divisors, ulong n, ArrayView<int> resultFlag)
{
byte nMod10 = (byte)(n % 10UL);
ArrayView1D<ulong, Stride1D.Dense> divisors = tables.SelectDivisors(tableKind, nMod10);
ArrayView1D<ulong, Stride1D.Dense> divisorSquares = tables.SelectDivisorSquares(tableKind, nMod10);
ulong divisor = divisors[index];
if (divisor <= 1UL)
{
return;
}
int divisorLength = (int)divisorSquares.Length;
int threadIndex = index;
bool skipThread = threadIndex >= divisorLength;
ulong divisorSquare = skipThread ? 0UL : divisorSquares[threadIndex];
skipThread = skipThread | (divisorSquare > maxDivisorSquare);
ulong divisor = skipThread ? 1UL : divisors[threadIndex];
ulong remainder = skipThread ? 1UL : n % divisor;
bool hasFactor = !skipThread & (remainder == 0UL);
if (hasFactor)
{
resultFlag[0] = 1;
}
ulong residue = n % divisor;
if (residue == 0UL)
{
resultFlag[0] = 1;
}
}
public static void SharesFactorKernel(Index1D index, ArrayView<ulong> numbers, ArrayView<byte> results)