Inline GPU overflow tracking helpers
This commit is contained in:
1 parent
85c6eaece7
commit
ea08d3f71f
3 files changed
+19
-20
No files matched your search
@@ -11,7 +11,7 @@ public class PrimeOrderGpuHeuristicsTests
|
|||||||
{
|
{
|
||||||
public PrimeOrderGpuHeuristicsTests()
|
public PrimeOrderGpuHeuristicsTests()
|
||||||
{
|
{
|
||||||
PrimeOrderGpuHeuristics.ClearAllOverflowForTesting();
|
PrimeOrderGpuHeuristics.OverflowRegistry.Clear();
|
||||||
PrimeOrderGpuHeuristics.ResetCapabilitiesForTesting();
|
PrimeOrderGpuHeuristics.ResetCapabilitiesForTesting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ public class PrimeOrderGpuHeuristicsTests
|
|||||||
const ulong prime = 97UL;
|
const ulong prime = 97UL;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PrimeOrderGpuHeuristics.MarkOverflow(prime);
|
PrimeOrderGpuHeuristics.OverflowRegistry[prime] = 0;
|
||||||
|
|
||||||
GpuPow2ModStatus status = PrimeOrderGpuHeuristics.TryPow2Mod(1UL, prime, out ulong remainder);
|
GpuPow2ModStatus status = PrimeOrderGpuHeuristics.TryPow2Mod(1UL, prime, out ulong remainder);
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ public class PrimeOrderGpuHeuristicsTests
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
PrimeOrderGpuHeuristics.ClearOverflow(prime);
|
PrimeOrderGpuHeuristics.OverflowRegistry.TryRemove(prime, out _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public class PrimeOrderGpuHeuristicsTests
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
PrimeOrderGpuHeuristics.ResetCapabilitiesForTesting();
|
PrimeOrderGpuHeuristics.ResetCapabilitiesForTesting();
|
||||||
PrimeOrderGpuHeuristics.ClearOverflow(prime);
|
PrimeOrderGpuHeuristics.OverflowRegistry.TryRemove(prime, out _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ public class PrimeOrderGpuHeuristicsTests
|
|||||||
const ulong prime = 193UL;
|
const ulong prime = 193UL;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PrimeOrderGpuHeuristics.MarkOverflow(prime);
|
PrimeOrderGpuHeuristics.OverflowRegistry[prime] = 0;
|
||||||
|
|
||||||
ulong[] remainders = new ulong[2];
|
ulong[] remainders = new ulong[2];
|
||||||
ulong[] exponents = { 1UL, 2UL };
|
ulong[] exponents = { 1UL, 2UL };
|
||||||
@@ -103,7 +103,7 @@ public class PrimeOrderGpuHeuristicsTests
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
PrimeOrderGpuHeuristics.ClearOverflow(prime);
|
PrimeOrderGpuHeuristics.OverflowRegistry.TryRemove(prime, out _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ public class PrimeOrderGpuHeuristicsTests
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
PrimeOrderGpuHeuristics.ResetCapabilitiesForTesting();
|
PrimeOrderGpuHeuristics.ResetCapabilitiesForTesting();
|
||||||
PrimeOrderGpuHeuristics.ClearOverflow(prime);
|
PrimeOrderGpuHeuristics.OverflowRegistry.TryRemove(prime, out _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ public class PrimeOrderGpuHeuristicsTests
|
|||||||
const ulong prime = 7UL;
|
const ulong prime = 7UL;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PrimeOrderGpuHeuristics.MarkOverflow(prime);
|
PrimeOrderGpuHeuristics.OverflowRegistry[prime] = 0;
|
||||||
|
|
||||||
PrimeOrderCalculator.PrimeOrderResult result = PrimeOrderCalculator.Calculate(prime, null, PrimeOrderCalculator.PrimeOrderSearchConfig.HeuristicDefault);
|
PrimeOrderCalculator.PrimeOrderResult result = PrimeOrderCalculator.Calculate(prime, null, PrimeOrderCalculator.PrimeOrderSearchConfig.HeuristicDefault);
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ public class PrimeOrderGpuHeuristicsTests
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
PrimeOrderGpuHeuristics.ClearOverflow(prime);
|
PrimeOrderGpuHeuristics.OverflowRegistry.TryRemove(prime, out _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,8 @@ internal static class PrimeOrderGpuHeuristics
|
|||||||
private static readonly ConcurrentDictionary<ulong, byte> OverflowedPrimes = new();
|
private static readonly ConcurrentDictionary<ulong, byte> OverflowedPrimes = new();
|
||||||
private static PrimeOrderGpuCapability s_capability = PrimeOrderGpuCapability.Default;
|
private static PrimeOrderGpuCapability s_capability = PrimeOrderGpuCapability.Default;
|
||||||
|
|
||||||
|
internal static ConcurrentDictionary<ulong, byte> OverflowRegistry => OverflowedPrimes;
|
||||||
|
|
||||||
internal static void OverrideCapabilitiesForTesting(PrimeOrderGpuCapability capability)
|
internal static void OverrideCapabilitiesForTesting(PrimeOrderGpuCapability capability)
|
||||||
{
|
{
|
||||||
s_capability = capability;
|
s_capability = capability;
|
||||||
@@ -26,12 +28,6 @@ internal static class PrimeOrderGpuHeuristics
|
|||||||
s_capability = PrimeOrderGpuCapability.Default;
|
s_capability = PrimeOrderGpuCapability.Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void MarkOverflow(ulong prime) => OverflowedPrimes[prime] = 0;
|
|
||||||
|
|
||||||
internal static void ClearOverflow(ulong prime) => OverflowedPrimes.TryRemove(prime, out _);
|
|
||||||
|
|
||||||
internal static void ClearAllOverflowForTesting() => OverflowedPrimes.Clear();
|
|
||||||
|
|
||||||
public static GpuPow2ModStatus TryPow2Mod(ulong exponent, ulong prime, out ulong remainder)
|
public static GpuPow2ModStatus TryPow2Mod(ulong exponent, ulong prime, out ulong remainder)
|
||||||
{
|
{
|
||||||
remainder = 0UL;
|
remainder = 0UL;
|
||||||
@@ -40,7 +36,9 @@ internal static class PrimeOrderGpuHeuristics
|
|||||||
return GpuPow2ModStatus.Unavailable;
|
return GpuPow2ModStatus.Unavailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OverflowedPrimes.ContainsKey(prime))
|
ConcurrentDictionary<ulong, byte> overflowRegistry = OverflowedPrimes;
|
||||||
|
|
||||||
|
if (overflowRegistry.ContainsKey(prime))
|
||||||
{
|
{
|
||||||
return GpuPow2ModStatus.Overflow;
|
return GpuPow2ModStatus.Overflow;
|
||||||
}
|
}
|
||||||
@@ -49,7 +47,7 @@ internal static class PrimeOrderGpuHeuristics
|
|||||||
|
|
||||||
if (!SupportsPrime(prime, capability))
|
if (!SupportsPrime(prime, capability))
|
||||||
{
|
{
|
||||||
MarkOverflow(prime);
|
overflowRegistry[prime] = 0;
|
||||||
return GpuPow2ModStatus.Overflow;
|
return GpuPow2ModStatus.Overflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +79,9 @@ internal static class PrimeOrderGpuHeuristics
|
|||||||
return GpuPow2ModStatus.Unavailable;
|
return GpuPow2ModStatus.Unavailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OverflowedPrimes.ContainsKey(prime))
|
ConcurrentDictionary<ulong, byte> overflowRegistry = OverflowedPrimes;
|
||||||
|
|
||||||
|
if (overflowRegistry.ContainsKey(prime))
|
||||||
{
|
{
|
||||||
return GpuPow2ModStatus.Overflow;
|
return GpuPow2ModStatus.Overflow;
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ internal static class PrimeOrderGpuHeuristics
|
|||||||
|
|
||||||
if (!SupportsPrime(prime, capability))
|
if (!SupportsPrime(prime, capability))
|
||||||
{
|
{
|
||||||
MarkOverflow(prime);
|
overflowRegistry[prime] = 0;
|
||||||
return GpuPow2ModStatus.Overflow;
|
return GpuPow2ModStatus.Overflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
- Inline the overflow tracking helpers in PrimeOrderGpuHeuristics so call sites can cache the dictionary locally and reduce delegate indirection.
|
|
||||||
- Move the ulong bit-length helper into ULongExtensions and update PrimeOrderGpuHeuristics (and any other callers) to reuse it.
|
- Move the ulong bit-length helper into ULongExtensions and update PrimeOrderGpuHeuristics (and any other callers) to reuse it.
|
||||||
- Implement the GPU heuristics for PrimeOrderCalculator using ILGPU. Reuse the numeric type compatibility probe results to select between EInteger, ERational, GpuUInt128, or any new GPU-specific big-integer representations, guarantee parity with the CPU heuristic algorithm (including 128-bit primes), prefer the shift-first multiply/shift variant to stay within device ranges, and wire the calculator through the accelerator path.
|
- Implement the GPU heuristics for PrimeOrderCalculator using ILGPU. Reuse the numeric type compatibility probe results to select between EInteger, ERational, GpuUInt128, or any new GPU-specific big-integer representations, guarantee parity with the CPU heuristic algorithm (including 128-bit primes), prefer the shift-first multiply/shift variant to stay within device ranges, and wire the calculator through the accelerator path.
|
||||||
- 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.
|
- 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.
|
||||||
Reference in new issue
Block a user