GPU stabilization improvements to prevent calculation crashes

This commit is contained in:
mlemanczyk committed 2025-11-09 21:52:16 +01:00
1 parent a338bb0d0b
commit d0b1639a5d
40 files changed
+2318 -1764

No files matched your search

@@ -0,0 +1,33 @@
using ILGPU;
using ILGPU.Runtime;
namespace PerfectNumbers.Core.Gpu
{
public struct AcceleratorPool(int capacity)
{
internal readonly Accelerator[] Accelerators = [.. Enumerable.Range(1, capacity).Select(_ => {
return SharedGpuContext.CreateAccelerator();
})];
private int _index;
public Accelerator Rent()
{
Atomic.CompareExchange(ref _index, capacity, 0);
var index = Atomic.Add(ref _index, 1);
if (index >= capacity)
{
index -= capacity;
}
return Accelerators[index];
}
public void Return(Accelerator accelerator)
{
// Intentionally left empty - there's nothing to do here. We're not really renting anything.
}
public static readonly AcceleratorPool Shared = new(PerfectNumberConstants.RollingAccelerators);
}
}