Merge remote-tracking branch 'github/codex/optimize-evenperfectbitscanner-for-static-arrays-khd9w8' into work
# Conflicts: # PerfectNumbers.Core/Gpu/GpuContextPool.cs # PerfectNumbers.Core/Gpu/GpuKernelLease.cs # PerfectNumbers.Core/Gpu/GpuKernelPool.cs # PerfectNumbers.Core/Gpu/GpuStaticTableInitializer.cs # PerfectNumbers.Core/Gpu/Kernels/PrimeOrderSpecialMaxKernels.cs # PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs # PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs # PerfectNumbers.Core/PrimeTester.cs
This commit is contained in:
1 parent
507daaddb9
commit
4c4d4243fb
23 files changed
+858
-633
No files matched your search
@@ -8,16 +8,10 @@ public static class GpuPrimeWorkLimiter
|
||||
private static SemaphoreSlim _semaphore = new(1, int.MaxValue);
|
||||
private static int _currentLimit = 1;
|
||||
|
||||
public static Lease Acquire()
|
||||
{
|
||||
// TODO: Inline the pooled limiter guard from the GpuLimiterThroughputBenchmarks so prime-sieve
|
||||
// GPU jobs stop allocating Lease instances on every acquisition.
|
||||
var sem = _semaphore;
|
||||
sem.Wait();
|
||||
return new Lease(sem);
|
||||
}
|
||||
public static void Acquire() => _semaphore.Wait();
|
||||
public static void Release() => _semaphore.Release();
|
||||
|
||||
public static void SetLimit(int value)
|
||||
public static void SetLimit(int value)
|
||||
{
|
||||
if (value <= 0)
|
||||
{
|
||||
@@ -36,19 +30,4 @@ public static class GpuPrimeWorkLimiter
|
||||
_currentLimit = value;
|
||||
previous.Dispose();
|
||||
}
|
||||
|
||||
public sealed class Lease : IDisposable
|
||||
{
|
||||
private readonly SemaphoreSlim _sem;
|
||||
|
||||
internal Lease(SemaphoreSlim sem)
|
||||
{
|
||||
_sem = sem;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_sem.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user