Persist GPU capability snapshot without volatile
This commit is contained in:
1 parent
6adac6b7a7
commit
85c6eaece7
2 files changed
+7
-11
No files matched your search
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace PerfectNumbers.Core.Gpu;
|
namespace PerfectNumbers.Core.Gpu;
|
||||||
|
|
||||||
@@ -15,23 +14,18 @@ internal enum GpuPow2ModStatus
|
|||||||
internal static class PrimeOrderGpuHeuristics
|
internal static class PrimeOrderGpuHeuristics
|
||||||
{
|
{
|
||||||
private static readonly ConcurrentDictionary<ulong, byte> OverflowedPrimes = new();
|
private static readonly ConcurrentDictionary<ulong, byte> OverflowedPrimes = new();
|
||||||
private static int s_modulusBitLimit = PrimeOrderGpuCapability.Default.ModulusBits;
|
private static PrimeOrderGpuCapability s_capability = PrimeOrderGpuCapability.Default;
|
||||||
private static int s_exponentBitLimit = PrimeOrderGpuCapability.Default.ExponentBits;
|
|
||||||
|
|
||||||
internal static void OverrideCapabilitiesForTesting(PrimeOrderGpuCapability capability)
|
internal static void OverrideCapabilitiesForTesting(PrimeOrderGpuCapability capability)
|
||||||
{
|
{
|
||||||
Volatile.Write(ref s_modulusBitLimit, capability.ModulusBits);
|
s_capability = capability;
|
||||||
Volatile.Write(ref s_exponentBitLimit, capability.ExponentBits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void ResetCapabilitiesForTesting()
|
internal static void ResetCapabilitiesForTesting()
|
||||||
{
|
{
|
||||||
OverrideCapabilitiesForTesting(PrimeOrderGpuCapability.Default);
|
s_capability = PrimeOrderGpuCapability.Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PrimeOrderGpuCapability Capabilities
|
|
||||||
=> new(Volatile.Read(ref s_modulusBitLimit), Volatile.Read(ref s_exponentBitLimit));
|
|
||||||
|
|
||||||
internal static void MarkOverflow(ulong prime) => OverflowedPrimes[prime] = 0;
|
internal static void MarkOverflow(ulong prime) => OverflowedPrimes[prime] = 0;
|
||||||
|
|
||||||
internal static void ClearOverflow(ulong prime) => OverflowedPrimes.TryRemove(prime, out _);
|
internal static void ClearOverflow(ulong prime) => OverflowedPrimes.TryRemove(prime, out _);
|
||||||
@@ -51,7 +45,7 @@ internal static class PrimeOrderGpuHeuristics
|
|||||||
return GpuPow2ModStatus.Overflow;
|
return GpuPow2ModStatus.Overflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrimeOrderGpuCapability capability = Capabilities;
|
PrimeOrderGpuCapability capability = s_capability;
|
||||||
|
|
||||||
if (!SupportsPrime(prime, capability))
|
if (!SupportsPrime(prime, capability))
|
||||||
{
|
{
|
||||||
@@ -92,7 +86,7 @@ internal static class PrimeOrderGpuHeuristics
|
|||||||
return GpuPow2ModStatus.Overflow;
|
return GpuPow2ModStatus.Overflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrimeOrderGpuCapability capability = Capabilities;
|
PrimeOrderGpuCapability capability = s_capability;
|
||||||
|
|
||||||
if (!SupportsPrime(prime, capability))
|
if (!SupportsPrime(prime, capability))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
|
- 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.
|
||||||
- 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