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

@@ -348,32 +348,40 @@ public class GpuKernelCompilationTests
private static void CompileGpuKernelPoolKernels(Accelerator accelerator)
{
_ = accelerator;
GpuPrimeWorkLimiter.Acquire();
GpuPrimeWorkLimiter.Acquire();
AcceleratorStream stream = accelerator.CreateStream();
try
{
_ = GpuKernelPool.Kernels.Order;
_ = GpuKernelPool.Kernels.Incremental;
_ = GpuKernelPool.Kernels.Pow2Mod;
_ = GpuKernelPool.Kernels.IncrementalOrder;
_ = GpuKernelPool.Kernels.Pow2ModOrder;
{
var kernels = GpuKernelPool.GetOrAddKernels(accelerator, stream);
_ = kernels.Order;
_ = kernels.Incremental;
_ = kernels.Pow2Mod;
_ = kernels.IncrementalOrder;
_ = kernels.Pow2ModOrder;
}
finally
{
{
stream.Synchronize();
stream.Dispose();
GpuPrimeWorkLimiter.Release();
}
GpuPrimeWorkLimiter.Acquire();
stream = accelerator.CreateStream();
GpuPrimeWorkLimiter.Acquire();
try
{
_ = GpuKernelPool.Kernels.Order;
_ = GpuKernelPool.Kernels.Incremental;
_ = GpuKernelPool.Kernels.Pow2Mod;
_ = GpuKernelPool.Kernels.IncrementalOrder;
_ = GpuKernelPool.Kernels.Pow2ModOrder;
var kernels = GpuKernelPool.GetOrAddKernels(accelerator, stream);
_ = kernels.Order;
_ = kernels.Incremental;
_ = kernels.Pow2Mod;
_ = kernels.IncrementalOrder;
_ = kernels.Pow2ModOrder;
}
finally
{
stream.Synchronize();
stream.Dispose();
GpuPrimeWorkLimiter.Release();
}
}
@@ -150,7 +150,7 @@ public class NttGpuMathTests
var modulus = new GpuUInt128(0UL, 17UL);
var primitiveRoot = new GpuUInt128(0UL, 3UL);
var accelerator = SharedGpuContext.Accelerator;
var accelerator = SharedGpuContext.CreateAccelerator();
var stream = accelerator.CreateStream();
var method = typeof(NttGpuMath).GetMethod("GetSquareCache", BindingFlags.NonPublic | BindingFlags.Static);
@@ -170,6 +170,7 @@ public class NttGpuMathTests
twiddlesInvMont.CopyToCPU(stream, inverse);
stream.Synchronize();
stream.Dispose();
accelerator.Dispose();
for (int i = 0; i < count; i++)
{
@@ -340,7 +341,7 @@ public class NttGpuMathTests
values[1] = new GpuUInt128(0UL, 2UL);
var modulus = new GpuUInt128(0UL, 17UL);
var primitiveRoot = new GpuUInt128(0UL, 3UL);
Accelerator accelerator = SharedGpuContext.Accelerator;
Accelerator accelerator = SharedGpuContext.CreateAccelerator();
var stream = accelerator.CreateStream();
var buffer = accelerator.Allocate1D<GpuUInt128>(values.Length);
buffer.View.CopyFromCPU(stream, ref values[0], values.Length);
@@ -348,6 +349,7 @@ public class NttGpuMathTests
stream.Synchronize();
stream.Dispose();
buffer.Dispose();
accelerator.Dispose();
// Verify that the square cache now holds entries for the accelerator.
var field = typeof(NttGpuMath).GetField("SquareCache", BindingFlags.NonPublic | BindingFlags.Static)!;
@@ -33,20 +33,21 @@ public class NttMontgomeryTests
NttGpuMath.Square(cpu, modulus, primitiveRoot);
// Device execution
var accelerator = SharedGpuContext.Accelerator;
var accelerator = SharedGpuContext.CreateAccelerator();
var stream = accelerator.CreateStream();
using var buffer = accelerator.Allocate1D<GpuUInt128>(gpu.Length);
buffer.View.CopyFromCPU(stream, ref gpu[0], gpu.Length);
NttGpuMath.SquareDevice(accelerator, stream, buffer.View, modulus, primitiveRoot);
buffer.View.CopyToCPU(stream, ref gpu[0], gpu.Length);
stream.Synchronize();
stream.Dispose();
accelerator.Dispose();
for (int i = 0; i < cpu.Length; i++)
{
gpu[i].Should().Be(cpu[i]);
}
stream.Dispose();
}
[Fact]