From b2a7190c1473cf8a6a1898eb1fedeacdff684c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Sat, 4 Oct 2025 22:40:23 +0200 Subject: [PATCH] Inline GPU capability checks for pow2 heuristics --- PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs | 14 ++------------ todo.txt | 1 - 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs b/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs index 433e5aa..0a9fcbf 100644 --- a/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs +++ b/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs @@ -73,7 +73,7 @@ internal static class PrimeOrderGpuHeuristics PrimeOrderGpuCapability capability = s_capability; - if (!SupportsPrime(prime, capability)) + if (prime.GetBitLength() > capability.ModulusBits) { overflowRegistry[prime] = 0; return GpuPow2ModStatus.Overflow; @@ -81,7 +81,7 @@ internal static class PrimeOrderGpuHeuristics for (int i = 0; i < exponents.Length; i++) { - if (!SupportsExponent(exponents[i], capability)) + if (exponents[i].GetBitLength() > capability.ExponentBits) { return GpuPow2ModStatus.Overflow; } @@ -91,16 +91,6 @@ internal static class PrimeOrderGpuHeuristics return computed ? GpuPow2ModStatus.Success : GpuPow2ModStatus.Unavailable; } - private static bool SupportsPrime(ulong prime, PrimeOrderGpuCapability capability) - { - return prime.GetBitLength() <= capability.ModulusBits; - } - - private static bool SupportsExponent(ulong exponent, PrimeOrderGpuCapability capability) - { - return exponent.GetBitLength() <= capability.ExponentBits; - } - private static bool TryComputeOnGpu(ReadOnlySpan exponents, ulong prime, Span results) { try diff --git a/todo.txt b/todo.txt index 2ef5cb1..0f130aa 100644 --- a/todo.txt +++ b/todo.txt @@ -1,3 +1,2 @@ -- Inline the PrimeOrderGpuHeuristics capability checks at each call site and delete the temporary SupportsPrime/SupportsExponent helpers once the overflow gating is stable. - Swap PrimeOrderGpuHeuristics.Pow2ModCpu for the existing Pow2MontgomeryModWindowed helper and plan the same windowed ladder for the GPU kernel implementation. - Extend the GPU numeric type probe to cover proposed custom types such as GpuUInt256 and GpuUInt512 once their definitions are available so we can plan the wide-order heuristics on the device.