GPU stabilization improvements to prevent calculation crashes
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user