diff --git a/EvenPerfectBitScanner.Benchmarks/PrimeTesterBenchmarks.cs b/EvenPerfectBitScanner.Benchmarks/PrimeTesterBenchmarks.cs index 981de9b..d3bae87 100644 --- a/EvenPerfectBitScanner.Benchmarks/PrimeTesterBenchmarks.cs +++ b/EvenPerfectBitScanner.Benchmarks/PrimeTesterBenchmarks.cs @@ -86,7 +86,7 @@ public class PrimeTesterBenchmarks for (int i = 0; i < values.Length; i++) { - if (PrimeTester.IsPrimeGpuFallback(values[i], cancellationToken)) + if (PrimeTester.Exclusive.IsPrimeGpu(values[i], cancellationToken)) { primeCount++; } diff --git a/PerfectNumbers.Core/HeuristicPrimeTester.cs b/PerfectNumbers.Core/HeuristicPrimeTester.cs index d5d70a6..ca6e9ea 100644 --- a/PerfectNumbers.Core/HeuristicPrimeTester.cs +++ b/PerfectNumbers.Core/HeuristicPrimeTester.cs @@ -102,7 +102,7 @@ public sealed class HeuristicPrimeTester { if (!EnableHeuristicPrimeTesting) { - return PrimeTester.IsPrimeGpuFallback(n, ct); + return PrimeTester.Exclusive.IsPrimeGpu(n, ct); } return IsPrimeGpu(n); @@ -119,7 +119,7 @@ public sealed class HeuristicPrimeTester { if (!EnableHeuristicPrimeTesting) { - return PrimeTester.IsPrimeGpuFallback(n, CancellationToken.None); + return PrimeTester.Exclusive.IsPrimeGpu(n, CancellationToken.None); } return HeuristicIsPrimeGpuCore(n, sqrtLimit, nMod10); diff --git a/PerfectNumbers.Core/PrimeTester.cs b/PerfectNumbers.Core/PrimeTester.cs index 4e56414..b7c49c8 100644 --- a/PerfectNumbers.Core/PrimeTester.cs +++ b/PerfectNumbers.Core/PrimeTester.cs @@ -72,18 +72,14 @@ public sealed class PrimeTester return Exclusive.IsPrimeGpu(n, CancellationToken.None); } - public static bool IsPrimeGpu(ulong n, ulong limit, byte nMod10) - { - return Exclusive.IsPrimeGpu(n, CancellationToken.None); - } + // Legacy overload retained for heuristic toggles; tests and benchmarks now call the thread-local instance directly. + // public static bool IsPrimeGpu(ulong n, ulong limit, byte nMod10) + // { + // return Exclusive.IsPrimeGpu(n, CancellationToken.None); + // } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsPrimeGpu(ulong n, CancellationToken ct) - { - return IsPrimeGpuFallback(n, ct); - } - - public static bool IsPrimeGpuFallback(ulong n, CancellationToken ct) { bool forceCpu = GpuContextPool.ForceCpu; Span one = stackalloc ulong[1]; diff --git a/docs/HeuristicIsPrimePlan.md b/docs/HeuristicIsPrimePlan.md index 46868da..fee5049 100644 --- a/docs/HeuristicIsPrimePlan.md +++ b/docs/HeuristicIsPrimePlan.md @@ -140,7 +140,7 @@ The plan incorporates the updated divisor-class heuristics (Groups A/B, wheels, * [done] Streamed GPU batches from the same enumerator and Montgomery preparation data, removing the filtered-divisor scratch arrays while continuing to feed the existing kernel and hit bookkeeping. 9. [done] **Route legacy prime checks through heuristics** * [done] Introduce `HeuristicPrimeTester` so heuristic CPU/GPU checks live alongside the legacy `PrimeTester` implementations while callers opt in explicitly. - * [done] Maintain legacy paths for benchmarking via `PrimeTester.IsPrimeInternal`, `PrimeTester.IsPrimeGpuFallback`, and the global `HeuristicPrimeTester.EnableHeuristicPrimeTesting` switch so benchmark harnesses can compare behaviours. + * [done] Maintain legacy paths for benchmarking via `PrimeTester.IsPrimeInternal`, `PrimeTester.Exclusive.IsPrimeGpu`, and the global `HeuristicPrimeTester.EnableHeuristicPrimeTesting` switch so benchmark harnesses can compare behaviours. 10. **Validation and benchmarking** * Create targeted unit tests covering boundary cases for Group A/B transitions, wheel enumerations, residue deltas, and the stop-on-hit behaviour. * Expand GPU test harnesses to assert equivalence between CPU/GPU heuristics on sampled composite and prime inputs and to verify the residue-stream contract with by-divisor sessions. diff --git a/docs/HeuristicIsPrimeSpecification.md b/docs/HeuristicIsPrimeSpecification.md index c0282a7..df89eec 100644 --- a/docs/HeuristicIsPrimeSpecification.md +++ b/docs/HeuristicIsPrimeSpecification.md @@ -62,7 +62,7 @@ No other endings are allowed or reordered. ## Default Prime Tester Entry Points * `PrimeTester.IsPrime` and `PrimeTester.IsPrimeGpu` continue to run the legacy trial-division and GPU sieve paths. Use `HeuristicPrimeTester` when the heuristic CPU/GPU flow is required. -* Toggle `HeuristicPrimeTester.EnableHeuristicPrimeTesting` or fall back to `PrimeTester.IsPrimeInternal` / `PrimeTester.IsPrimeGpuFallback` to control heuristic rollouts in test harnesses. +* Toggle `HeuristicPrimeTester.EnableHeuristicPrimeTesting` or fall back to `PrimeTester.IsPrimeInternal` / `PrimeTester.Exclusive.IsPrimeGpu` to control heuristic rollouts in test harnesses. * Benchmark harnesses can compare behaviours by calling the legacy helpers on `PrimeTester` alongside the heuristic equivalents on `HeuristicPrimeTester`. ## Integration with the By-Divisor Pipeline