Ensure GPU residue copies are synchronized and cover high divisor sets

This commit is contained in:
Marek Lemańczyk committed 2025-09-20 22:49:37 +02:00
1 parent 633c94906a
commit 7449f146d9
7 files changed
+215 -2

No files matched your search

@@ -98,6 +98,7 @@ public class MersenneNumberResidueGpuTester(bool useGpuOrder)
stream.Synchronize();
orderBuffer.View.CopyToCPU(ref MemoryMarshal.GetReference(orders), currentSize);
stream.Synchronize();
if (!Volatile.Read(ref isPrime))
{
break;
+13 -2
View File
@@ -25,7 +25,18 @@ public sealed class PrimeTester(bool useInternal = false)
Span<byte> outFlags = stackalloc byte[1];
one[0] = n;
IsPrimeBatchGpu(one, outFlags);
return outFlags[0] != 0;
if (outFlags[0] != 0)
{
return true;
}
// Defensive fallback: GPU sieve produced a composite verdict.
// Confirm with CPU logic to prevent false negatives observed on
// some accelerators (see TODO below for dedicated regression).
// TODO: Investigate ILGPU small-prime sieve divergence on discrete GPUs
// so that the CPU confirmation can be removed once resolved.
return IsPrimeInternal(n, ct);
}
// Note: GPU-backed primality path is implemented via IsPrimeGpu/IsPrimeBatchGpu and is routed
@@ -249,7 +260,7 @@ public sealed class PrimeTester(bool useInternal = false)
return;
}
if ((n & 1UL) == 0UL || (n % 5UL) == 0UL)
if ((n & 1UL) == 0UL || (n > 5UL && (n % 5UL) == 0UL))
{
results[index] = 0;
return;