Stream handling simplified to avoid dictionary lookups in favor of array lookups with known indexes.

This commit is contained in:
mlemanczyk committed 2025-11-16 15:01:51 +01:00
1 parent cd7636ddbe
commit a84445ef2a
15 files changed
+68 -74

No files matched your search

@@ -363,7 +363,7 @@ public class GpuKernelCompilationTests
finally finally
{ {
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
// GpuPrimeWorkLimiter.Release(); // GpuPrimeWorkLimiter.Release();
} }
@@ -381,7 +381,7 @@ public class GpuKernelCompilationTests
finally finally
{ {
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
// GpuPrimeWorkLimiter.Release(); // GpuPrimeWorkLimiter.Release();
} }
} }
+1 -1
View File
@@ -345,7 +345,7 @@ public sealed class DivisorCycleCache
resultBuffer.View.CopyToCPU(stream, resultSpan); resultBuffer.View.CopyToCPU(stream, resultSpan);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
resultSpan.CopyTo(destination); resultSpan.CopyTo(destination);
if (rentedPow is not null) if (rentedPow is not null)
@@ -7,8 +7,7 @@ public static class AcceleratorStreamPool
{ {
private static readonly Accelerator[] _accelerators = AcceleratorPool.Shared.Accelerators; private static readonly Accelerator[] _accelerators = AcceleratorPool.Shared.Accelerators;
private static readonly SemaphoreSlim[] _locks = new SemaphoreSlim[PerfectNumberConstants.RollingAccelerators]; private static readonly SemaphoreSlim[] _locks = new SemaphoreSlim[PerfectNumberConstants.RollingAccelerators];
private static readonly ConcurrentQueue<AcceleratorStream>[] _streams = new ConcurrentQueue<AcceleratorStream> [PerfectNumberConstants.RollingAccelerators]; private static readonly AcceleratorStream[] _streams = new AcceleratorStream[PerfectNumberConstants.RollingAccelerators];
private static SemaphoreSlim CreateLock() => new(PerfectNumberConstants.ThreadsByAccelerator); private static SemaphoreSlim CreateLock() => new(PerfectNumberConstants.ThreadsByAccelerator);
@@ -17,26 +16,27 @@ public static class AcceleratorStreamPool
public static AcceleratorStream Rent(int acceleratorIndex) public static AcceleratorStream Rent(int acceleratorIndex)
{ {
var streamLock = _locks[acceleratorIndex]; var streamLock = _locks[acceleratorIndex];
var queue = _streams[acceleratorIndex];
streamLock.Wait(); streamLock.Wait();
var queue = _streams[acceleratorIndex];
return queue.TryDequeue(out var stream) if (queue != null)
? stream {
: _accelerators[acceleratorIndex].CreateStream(); return queue;
} }
public static void Return(int acceleratorIndex, AcceleratorStream stream) queue = _accelerators[acceleratorIndex].CreateStream();
_streams[acceleratorIndex] = queue;
return queue;
}
public static void Return(int acceleratorIndex)
{ {
var streamLock = _locks[acceleratorIndex]; var streamLock = _locks[acceleratorIndex];
var queue = _streams[acceleratorIndex];
queue.Enqueue(stream);
streamLock.Release(); streamLock.Release();
} }
public static void WarmUp(int acceleratorIndex) public static void WarmUp(int acceleratorIndex)
{ {
_streams[acceleratorIndex] = new();
_locks[acceleratorIndex] = CreateLock(); _locks[acceleratorIndex] = CreateLock();
} }
} }
@@ -45,25 +45,25 @@ internal sealed class HeuristicGpuTables
HeuristicGroupBDivisorsEnding9 = CopyUintSpanToDevice(accelerator, stream, DivisorGenerator.SmallPrimesLastNineWithoutLastThree); HeuristicGroupBDivisorsEnding9 = CopyUintSpanToDevice(accelerator, stream, DivisorGenerator.SmallPrimesLastNineWithoutLastThree);
HeuristicGroupBDivisorSquaresEnding9 = CopySpanToDevice(accelerator, stream, DivisorGenerator.SmallPrimesPow2LastNineWithoutLastThree); HeuristicGroupBDivisorSquaresEnding9 = CopySpanToDevice(accelerator, stream, DivisorGenerator.SmallPrimesPow2LastNineWithoutLastThree);
var combinedEnding1 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding1; // var combinedEnding1 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding1;
HeuristicCombinedDivisorsEnding1 = CopySpanToDevice(accelerator, stream, combinedEnding1); // HeuristicCombinedDivisorsEnding1 = CopySpanToDevice(accelerator, stream, combinedEnding1);
var combinedSquaresEnding1 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding1Squares; // var combinedSquaresEnding1 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding1Squares;
HeuristicCombinedDivisorSquaresEnding1 = CopySpanToDevice(accelerator, stream, combinedSquaresEnding1); // HeuristicCombinedDivisorSquaresEnding1 = CopySpanToDevice(accelerator, stream, combinedSquaresEnding1);
var combinedEnding3 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding3; // var combinedEnding3 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding3;
HeuristicCombinedDivisorsEnding3 = CopySpanToDevice(accelerator, stream, combinedEnding3); // HeuristicCombinedDivisorsEnding3 = CopySpanToDevice(accelerator, stream, combinedEnding3);
var combinedSquaresEnding3 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding3Squares; // var combinedSquaresEnding3 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding3Squares;
HeuristicCombinedDivisorSquaresEnding3 = CopySpanToDevice(accelerator, stream, combinedSquaresEnding3); // HeuristicCombinedDivisorSquaresEnding3 = CopySpanToDevice(accelerator, stream, combinedSquaresEnding3);
var combinedEnding7 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding7; // var combinedEnding7 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding7;
HeuristicCombinedDivisorsEnding7 = CopySpanToDevice(accelerator, stream, combinedEnding7); // HeuristicCombinedDivisorsEnding7 = CopySpanToDevice(accelerator, stream, combinedEnding7);
var combinedSquaresEnding7 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding7Squares; // var combinedSquaresEnding7 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding7Squares;
HeuristicCombinedDivisorSquaresEnding7 = CopySpanToDevice(accelerator, stream, combinedSquaresEnding7); // HeuristicCombinedDivisorSquaresEnding7 = CopySpanToDevice(accelerator, stream, combinedSquaresEnding7);
var combinedEnding9 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding9; // var combinedEnding9 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding9;
HeuristicCombinedDivisorsEnding9 = CopySpanToDevice(accelerator, stream, combinedEnding9); // HeuristicCombinedDivisorsEnding9 = CopySpanToDevice(accelerator, stream, combinedEnding9);
var combinedSquaresEnding9 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding9Squares; // var combinedSquaresEnding9 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding9Squares;
HeuristicCombinedDivisorSquaresEnding9 = CopySpanToDevice(accelerator, stream, combinedSquaresEnding9); // HeuristicCombinedDivisorSquaresEnding9 = CopySpanToDevice(accelerator, stream, combinedSquaresEnding9);
} }
internal readonly MemoryBuffer1D<ulong, Stride1D.Dense> HeuristicGroupADivisors; internal readonly MemoryBuffer1D<ulong, Stride1D.Dense> HeuristicGroupADivisors;
@@ -136,7 +136,7 @@ internal sealed class HeuristicPrimeTesterAccelerator
Accelerator = accelerator; Accelerator = accelerator;
EnsureCapacity(minBufferCapacity); EnsureCapacity(minBufferCapacity);
HeuristicTrialDivisionKernel = KernelUtil.GetKernel(accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView<int>, ulong, ulong, HeuristicGpuDivisorTableKind, HeuristicGpuDivisorTables>(PrimeTesterKernels.HeuristicTrialDivisionKernel)); HeuristicTrialDivisionKernel = KernelUtil.GetKernel(accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView<int>, ulong, ulong, ArrayView1D<ulong, Stride1D.Dense>, ArrayView1D<ulong, Stride1D.Dense>>(PrimeTesterKernels.HeuristicTrialDivisionKernel));
AcceleratorStream stream = AcceleratorStreamPool.Rent(acceleratorIndex); AcceleratorStream stream = AcceleratorStreamPool.Rent(acceleratorIndex);
@@ -146,7 +146,7 @@ internal sealed class HeuristicPrimeTesterAccelerator
_heuristicDivisorTables = _sharedTables.CreateHeuristicDivisorTables(); _heuristicDivisorTables = _sharedTables.CreateHeuristicDivisorTables();
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
} }
public void EnsureCapacity(int minCapacity) public void EnsureCapacity(int minCapacity)
+1 -1
View File
@@ -25,7 +25,7 @@ public class GpuKernelPool
internal static KernelContainer GetOrAddKernels(int acceleratorIndex, AcceleratorStream stream, KernelType kernelType) internal static KernelContainer GetOrAddKernels(int acceleratorIndex, AcceleratorStream stream, KernelType kernelType)
{ {
var pool = _pool ??= []; var pool = _pool ??= new KernelContainer[PerfectNumberConstants.RollingAccelerators];
if (pool[acceleratorIndex] is not {} kernels) if (pool[acceleratorIndex] is not {} kernels)
{ {
kernels = new(); kernels = new();
@@ -83,20 +83,10 @@ internal static class PrimeTesterKernels
ArrayView<int> resultFlag, ArrayView<int> resultFlag,
ulong n, ulong n,
ulong maxDivisorSquare, ulong maxDivisorSquare,
HeuristicGpuDivisorTableKind tableKind, ArrayView1D<ulong, Stride1D.Dense> divisors,
HeuristicGpuDivisorTables tables) ArrayView1D<ulong, Stride1D.Dense> divisorSquares)
{ {
byte nMod10 = (byte)(n % 10UL);
ArrayView1D<ulong, Stride1D.Dense> divisors = tables.SelectDivisors(tableKind, nMod10);
ArrayView1D<ulong, Stride1D.Dense> divisorSquares = tables.SelectDivisorSquares(tableKind, nMod10);
int divisorLength = (int)divisorSquares.Length;
int threadIndex = index; int threadIndex = index;
if (threadIndex >= divisorLength)
{
return;
}
ulong divisorSquare = divisorSquares[threadIndex]; ulong divisorSquare = divisorSquares[threadIndex];
if (divisorSquare > maxDivisorSquare) if (divisorSquare > maxDivisorSquare)
{ {
@@ -32,7 +32,7 @@ public static class Pow2MontgomeryGpuCalculator
resultBuffer.View.CopyToCPU(stream, ref result, 1); resultBuffer.View.CopyToCPU(stream, ref result, 1);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
// GpuPrimeWorkLimiter.Release(); // GpuPrimeWorkLimiter.Release();
PrimeOrderCalculatorAccelerator.Return(gpu); PrimeOrderCalculatorAccelerator.Return(gpu);
@@ -60,7 +60,7 @@ public static class Pow2MontgomeryGpuCalculator
resultBuffer.View.CopyToCPU(stream, ref result, 1); resultBuffer.View.CopyToCPU(stream, ref result, 1);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
// GpuPrimeWorkLimiter.Release(); // GpuPrimeWorkLimiter.Release();
PrimeOrderCalculatorAccelerator.Return(gpu); PrimeOrderCalculatorAccelerator.Return(gpu);
@@ -86,7 +86,7 @@ public static class Pow2MontgomeryGpuCalculator
resultBuffer.View.CopyToCPU(stream, ref result, 1); resultBuffer.View.CopyToCPU(stream, ref result, 1);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
return result; return result;
} }
@@ -102,7 +102,7 @@ internal static partial class PrimeOrderGpuHeuristics
private static SmallPrimeDeviceCache GetSmallPrimeDeviceCache(int acceleratorIndex, AcceleratorStream stream) private static SmallPrimeDeviceCache GetSmallPrimeDeviceCache(int acceleratorIndex, AcceleratorStream stream)
{ {
var pool = _smallPrimeDeviceCache ??= []; var pool = _smallPrimeDeviceCache ??= new SmallPrimeDeviceCache[PerfectNumberConstants.RollingAccelerators];
if (pool[acceleratorIndex] is {} cached) if (pool[acceleratorIndex] is {} cached)
{ {
return cached; return cached;
@@ -132,7 +132,7 @@ internal static partial class PrimeOrderGpuHeuristics
private static Kernel GetPartialFactorKernel(int acceleratorIndex) private static Kernel GetPartialFactorKernel(int acceleratorIndex)
{ {
var pool = _partialFactorKernel ??= []; var pool = _partialFactorKernel ??= new Kernel[PerfectNumberConstants.RollingAccelerators];
if (pool[acceleratorIndex] is {} cached) if (pool[acceleratorIndex] is {} cached)
{ {
return cached; return cached;
@@ -487,7 +487,7 @@ internal static partial class PrimeOrderGpuHeuristics
private static Kernel GetOrderKernel(int acceleratorIndex) private static Kernel GetOrderKernel(int acceleratorIndex)
{ {
var pool = _orderKernel ??= []; var pool = _orderKernel ??= new Kernel[PerfectNumberConstants.RollingAccelerators];
if (pool[acceleratorIndex] is {} cached) if (pool[acceleratorIndex] is {} cached)
{ {
return cached; return cached;
@@ -637,7 +637,7 @@ internal static partial class PrimeOrderGpuHeuristics
remainderBuffer.View.CopyToCPU(stream, ref MemoryMarshal.GetReference(resultSpan), length); remainderBuffer.View.CopyToCPU(stream, ref MemoryMarshal.GetReference(resultSpan), length);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
results[i] = (UInt128)resultSpan[i]; results[i] = (UInt128)resultSpan[i];
@@ -675,7 +675,7 @@ internal static partial class PrimeOrderGpuHeuristics
private static Kernel GetPow2ModKernel(int acceleratorIndex) private static Kernel GetPow2ModKernel(int acceleratorIndex)
{ {
var pool = _pow2ModKernel ??= []; var pool = _pow2ModKernel ??= new Kernel[PerfectNumberConstants.RollingAccelerators];
if (pool[acceleratorIndex] is {} cached) if (pool[acceleratorIndex] is {} cached)
{ {
return cached; return cached;
+13 -9
View File
@@ -3,6 +3,7 @@ using System.Runtime.CompilerServices;
using ILGPU.Runtime; using ILGPU.Runtime;
using PerfectNumbers.Core.Gpu; using PerfectNumbers.Core.Gpu;
using PerfectNumbers.Core.Gpu.Accelerators; using PerfectNumbers.Core.Gpu.Accelerators;
using ILGPU;
namespace PerfectNumbers.Core; namespace PerfectNumbers.Core;
@@ -239,33 +240,36 @@ public sealed class HeuristicPrimeTester
} }
private bool HeuristicTrialDivisionGpuDetectsDivisor(ulong n, ulong maxDivisorSquare, byte nMod10) private static bool HeuristicTrialDivisionGpuDetectsDivisor(ulong n, ulong maxDivisorSquare, byte nMod10)
{ {
// GpuPrimeWorkLimiter.Acquire(); // GpuPrimeWorkLimiter.Acquire();
var gpu = HeuristicPrimeTesterAccelerator.Rent(1); var gpu = HeuristicPrimeTesterAccelerator.Rent(1);
var stream = gpu.Stream; var stream = gpu.Stream!;
var kernel = gpu.HeuristicTrialDivisionKernel; var kernel = gpu.HeuristicTrialDivisionKernel;
var flagView1D = gpu.HeuristicFlag.View; var flagView1D = gpu.HeuristicFlag.View;
var flagView = flagView1D.AsContiguous();
bool compositeDetected = false; bool compositeDetected;
int compositeFlag = 0; int compositeFlag = 0;
int groupALength = HeuristicPrimeSieves.GroupADivisors.Length; int groupALength = HeuristicPrimeSieves.GroupADivisors.Length;
flagView1D.CopyFromCPU(stream, ref compositeFlag, 1); flagView1D.CopyFromCPU(stream, ref compositeFlag, 1);
var tables = gpu.HeuristicGpuTables;
ArrayView1D<ulong, Stride1D.Dense> divisors = tables.GroupADivisors;
ArrayView1D<ulong, Stride1D.Dense> divisorSquares = tables.GroupADivisorSquares;
kernel.Launch( kernel.Launch(
stream!, stream!,
1, 1,
groupALength, groupALength,
flagView, flagView1D,
n, n,
maxDivisorSquare, maxDivisorSquare,
HeuristicGpuDivisorTableKind.GroupA, divisors,
gpu.HeuristicGpuTables); divisorSquares);
flagView1D.CopyToCPU(stream, ref compositeFlag, 1); flagView1D.CopyToCPU(stream, ref compositeFlag, 1);
stream!.Synchronize(); stream.Synchronize();
compositeDetected = compositeFlag != 0; compositeDetected = compositeFlag != 0;
@@ -296,7 +300,7 @@ public sealed class HeuristicPrimeTester
stream, stream,
1, 1,
divisorLength, divisorLength,
flagView, flagView1D,
n, n,
maxDivisorSquare, maxDivisorSquare,
tableKind, tableKind,
+2 -2
View File
@@ -898,7 +898,7 @@ public class MersenneDivisorCycles
start = end + 1UL; start = end + 1UL;
} }
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
pool.Return(divisors, clearArray: false); pool.Return(divisors, clearArray: false);
pool.Return(outCycles, clearArray: false); pool.Return(outCycles, clearArray: false);
@@ -907,7 +907,7 @@ public class MersenneDivisorCycles
private static Kernel GetDivisorCycleKernel(int acceleratorIndex) private static Kernel GetDivisorCycleKernel(int acceleratorIndex)
{ {
var pool = _divisorCycleKernel ??= []; var pool = _divisorCycleKernel ??= new Kernel[PerfectNumberConstants.RollingAccelerators];
if (pool[acceleratorIndex] is {} cached) if (pool[acceleratorIndex] is {} cached)
{ {
return cached; return cached;
+1 -1
View File
@@ -204,7 +204,7 @@ public sealed class MersenneNumberTester(
qBuffer.Dispose(); qBuffer.Dispose();
} }
AcceleratorStreamPool.Return(acceleratorIndex,stream); AcceleratorStreamPool.Return(acceleratorIndex);
// GpuPrimeWorkLimiter.Release(); // GpuPrimeWorkLimiter.Release();
uInt128Pool.Return(qs); uInt128Pool.Return(qs);
} }
@@ -15,7 +15,7 @@ public static class PerfectNumberConstants
public const int MaxOddPowersCount = 128; public const int MaxOddPowersCount = 128;
public const int PooledArrayThreshold = 64; public const int PooledArrayThreshold = 64;
public static readonly int RollingAccelerators = 298; //SharedGpuContext.Device.MaxNumThreadsPerGroup; public static readonly int RollingAccelerators = 298; //SharedGpuContext.Device.MaxNumThreadsPerGroup;
public const int ThreadsByAccelerator = 4096; public const int ThreadsByAccelerator = 2;
// TODO: Load these limits from the benchmark-driven configuration so CPU and GPU scans stay aligned with the optimal // TODO: Load these limits from the benchmark-driven configuration so CPU and GPU scans stay aligned with the optimal
// divisor-cycle datasets we generate offline. // divisor-cycle datasets we generate offline.
// TODO: Promote these magic numbers into a runtime profile derived from EvenPerfectBitScanner.Benchmarks so we can retune // TODO: Promote these magic numbers into a runtime profile derived from EvenPerfectBitScanner.Benchmarks so we can retune
@@ -50,7 +50,7 @@ internal static partial class PrimeOrderCalculator
gpu.OutputUlong.View.CopyToCPU(stream, ref order, 1); gpu.OutputUlong.View.CopyToCPU(stream, ref order, 1);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
// GpuPrimeWorkLimiter.Release(); // GpuPrimeWorkLimiter.Release();
return order; return order;
@@ -114,7 +114,7 @@ internal static partial class PrimeOrderCalculator
smallPrimeFactorRemainingSlotView.CopyToCPU(stream, ref remaining, 1); smallPrimeFactorRemainingSlotView.CopyToCPU(stream, ref remaining, 1);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
// GpuPrimeWorkLimiter.Release(); // GpuPrimeWorkLimiter.Release();
for (int i = 0; i < factorCount; i++) for (int i = 0; i < factorCount; i++)
@@ -164,7 +164,7 @@ internal static partial class PrimeOrderCalculator
specialMaxResultView.CopyToCPU(stream, ref result, 1); specialMaxResultView.CopyToCPU(stream, ref result, 1);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
// GpuPrimeWorkLimiter.Release(); // GpuPrimeWorkLimiter.Release();
return result != 0; return result != 0;
} }
@@ -190,7 +190,7 @@ internal static partial class PrimeOrderCalculator
gpu.Input.View.CopyToCPU(stream, randomStateSpan); gpu.Input.View.CopyToCPU(stream, randomStateSpan);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
ThreadStaticDeterministicRandomGpu.Exclusive.SetState(randomStateSpan[0]); ThreadStaticDeterministicRandomGpu.Exclusive.SetState(randomStateSpan[0]);
bool factored = factoredSpan[0] != 0; bool factored = factoredSpan[0] != 0;
+4 -4
View File
@@ -123,7 +123,7 @@ public sealed class PrimeTester
outputView.CopyToCPU(stream, ref flag, 1); outputView.CopyToCPU(stream, ref flag, 1);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
PrimeOrderCalculatorAccelerator.Return(gpu); PrimeOrderCalculatorAccelerator.Return(gpu);
// GpuPrimeWorkLimiter.Release(); // GpuPrimeWorkLimiter.Release();
@@ -162,7 +162,7 @@ public sealed class PrimeTester
outputView.CopyToCPU(stream, ref flag, 1); outputView.CopyToCPU(stream, ref flag, 1);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
return flag != 0; return flag != 0;
} }
@@ -239,7 +239,7 @@ public sealed class PrimeTester
} }
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
PrimeOrderCalculatorAccelerator.Return(gpu); PrimeOrderCalculatorAccelerator.Return(gpu);
// GpuPrimeWorkLimiter.Release(); // GpuPrimeWorkLimiter.Release();
} }
@@ -295,7 +295,7 @@ public sealed class PrimeTester
resultBuffer.View.CopyToCPU(stream, in results); resultBuffer.View.CopyToCPU(stream, in results);
stream.Synchronize(); stream.Synchronize();
AcceleratorStreamPool.Return(acceleratorIndex, stream); AcceleratorStreamPool.Return(acceleratorIndex);
PrimeOrderCalculatorAccelerator.Return(gpu); PrimeOrderCalculatorAccelerator.Return(gpu);
} }