Merge pull request #186 from mlemanczyk/codex/modify-gpukernellease-for-pooling
Reuse pooled GPU kernel leases
This commit is contained in:
2 files changed
+18
-23
No files matched your search
@@ -6,7 +6,7 @@ using static PerfectNumbers.Core.Gpu.GpuContextPool;
|
||||
|
||||
namespace PerfectNumbers.Core.Gpu;
|
||||
|
||||
public sealed class GpuKernelLease : IDisposable
|
||||
public sealed class GpuKernelLease
|
||||
{
|
||||
private static readonly ConcurrentQueue<GpuKernelLease> Pool = new();
|
||||
|
||||
@@ -702,8 +702,7 @@ public sealed class GpuKernelLease : IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
System.GC.SuppressFinalize(this);
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public readonly struct ExecutionScope
|
||||
@@ -715,7 +714,7 @@ public sealed class GpuKernelLease : IDisposable
|
||||
_lock = sync;
|
||||
if (_lock is not null)
|
||||
{
|
||||
// Monitor.Enter(_lock);
|
||||
Monitor.Enter(_lock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -723,7 +722,7 @@ public sealed class GpuKernelLease : IDisposable
|
||||
{
|
||||
if (_lock is not null)
|
||||
{
|
||||
// Monitor.Exit(_lock);
|
||||
Monitor.Exit(_lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,10 +82,6 @@ internal static partial class PrimeOrderCalculator
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
ulong factor = factorSpan[i].Value;
|
||||
if (factor == 0UL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ulong reduced = phi / factor;
|
||||
if (Pow2EqualsOneCpu(reduced, prime, divisorData))
|
||||
{
|
||||
@@ -643,16 +639,16 @@ internal static partial class PrimeOrderCalculator
|
||||
private static bool Pow2EqualsOneCpu(ulong exponent, ulong prime, in MontgomeryDivisorData divisorData)
|
||||
{
|
||||
// if (IsGpuPow2Allowed)
|
||||
// {
|
||||
{
|
||||
ulong remainder = exponent.Pow2MontgomeryModWindowedGpu(divisorData, false);
|
||||
// GpuPow2ModStatus status = PrimeOrderGpuHeuristics.TryPow2Mod(exponent, prime, out ulong remainder, divisorData);
|
||||
// if (status == GpuPow2ModStatus.Success)
|
||||
// {
|
||||
return remainder == 1UL;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// return exponent.Pow2MontgomeryModWindowedCpu(divisorData, keepMontgomery: false) == 1UL;
|
||||
return exponent.Pow2MontgomeryModWindowedCpu(divisorData, keepMontgomery: false) == 1UL;
|
||||
}
|
||||
|
||||
// [ThreadStatic]
|
||||
@@ -748,21 +744,21 @@ internal static partial class PrimeOrderCalculator
|
||||
// int dictionaryCount = counts.Count;
|
||||
// if (dictionaryCount <= FactorSlotCount)
|
||||
// {
|
||||
int copyIndex = 0;
|
||||
foreach (KeyValuePair<ulong, int> entry in counts)
|
||||
{
|
||||
primeSlots[copyIndex] = entry.Key;
|
||||
exponentSlots[copyIndex] = entry.Value;
|
||||
copyIndex++;
|
||||
}
|
||||
// int copyIndex = 0;
|
||||
// foreach (KeyValuePair<ulong, int> entry in counts)
|
||||
// {
|
||||
// primeSlots[copyIndex] = entry.Key;
|
||||
// exponentSlots[copyIndex] = entry.Value;
|
||||
// copyIndex++;
|
||||
// }
|
||||
|
||||
factorCount = copyIndex;
|
||||
ThreadStaticPools.ReturnUlongIntDictionary(counts);
|
||||
counts = null;
|
||||
// factorCount = copyIndex;
|
||||
// ThreadStaticPools.ReturnUlongIntDictionary(counts);
|
||||
// counts = null;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// useDictionary = true;
|
||||
useDictionary = true;
|
||||
// factorCount = dictionaryCount;
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user