Initial BitContradiction implementation on GPU

This commit is contained in:
mlemanczyk committed 2026-01-25 16:37:22 +01:00
1 parent e61d166eb1
commit 17763033e1
13 files changed
+1969 -23

No files matched your search

+19 -1
View File
@@ -2,6 +2,7 @@ using System.Runtime.CompilerServices;
using ILGPU;
using ILGPU.Runtime;
using PerfectNumbers.Core.Gpu.Accelerators;
using PerfectNumbers.Core.Gpu.Kernels;
namespace PerfectNumbers.Core.Gpu;
@@ -26,7 +27,7 @@ public class GpuKernelPool
internal static KernelContainer GetOrAddKernels(int acceleratorIndex, AcceleratorStream stream, KernelType kernelType)
{
var pool = _pool ??= [];
var pool = _pool ??= new KernelContainer[_accelerators.Length];
if (pool[acceleratorIndex] is not { } kernels)
{
kernels = new();
@@ -58,6 +59,11 @@ public class GpuKernelPool
InitPow2ModOrderKernelScan(accelerator, kernels);
}
if (kernelType.HasFlag(KernelType.BitContradictionScan))
{
InitBitContradictionKernel(accelerator, kernels);
}
PreloadStaticTables(accelerator, kernels, stream, kernelType);
pool[acceleratorIndex] = kernels;
@@ -113,6 +119,18 @@ public class GpuKernelPool
});
}
static void InitBitContradictionKernel(Accelerator accelerator, KernelContainer kernels)
{
InitOnce(ref kernels.BitContradiction, () =>
{
var loaded = accelerator.LoadAutoGroupedStreamKernel<Index1D, ulong, ArrayView1D<ulong, Stride1D.Dense>, int, ArrayView1D<int, Stride1D.Dense>>(BitContradictionKernels.BitContradictionKernelScan);
var kernel = KernelUtil.GetKernel(loaded);
return kernel.CreateLauncherDelegate<Action<AcceleratorStream, Index1D, ulong, ArrayView1D<ulong, Stride1D.Dense>, int, ArrayView1D<int, Stride1D.Dense>>>();
});
}
static void InitPow2ModOrderKernelScan(Accelerator accelerator, KernelContainer kernels)
{
InitOnce(ref kernels.Pow2ModOrder, () =>